-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add constants for most used image dimensions
update test naming add avatarUrl unit tests add axios mock
- Loading branch information
Showing
16 changed files
with
87 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export abstract class ImageDimension { | ||
static readonly ThumbNail: [25, 25] | ||
static readonly Avatar: 64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
packages/web-app-files/tests/helpers/user/avatarUrl.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { avatarUrl } from '../../../src/helpers/user' | ||
import mockAxios from 'jest-mock-axios' | ||
|
||
beforeEach(() => { | ||
mockAxios.reset() | ||
}) | ||
|
||
const mockClient = (signUrl: any) => { | ||
const vue = jest.fn() | ||
vue.prototype.$client = jest.fn() | ||
vue.prototype.$client.signUrl = signUrl | ||
;(global as any).Vue = vue | ||
} | ||
|
||
const defaultOptions = { | ||
server: 'https://www.ocis.rules/', | ||
username: 'ocis', | ||
token: 'rules', | ||
size: 64 | ||
} | ||
|
||
const buildUrl = ({ server, username, size }: { server: string; username: string; size: number }) => | ||
[server, 'remote.php/dav/avatars/', username, `/${size}.png`].join('') | ||
|
||
describe('avatarUrl', () => { | ||
it('throws an error', async () => { | ||
const avatarUrlPromise = avatarUrl(defaultOptions) | ||
mockAxios.mockResponse({ status: 404, statusText: 'no', data: undefined }) | ||
await expect(avatarUrlPromise).rejects.toBeTruthy() | ||
expect(mockAxios.head).toHaveBeenCalledWith(buildUrl(defaultOptions), undefined) | ||
}) | ||
|
||
it('returns a unsigned url', async () => { | ||
mockClient(undefined) | ||
const avatarUrlPromise = avatarUrl(defaultOptions) | ||
mockAxios.mockResponse({ status: 200, data: undefined }) | ||
await expect(avatarUrlPromise).resolves.toBe(buildUrl(defaultOptions)) | ||
expect(mockAxios.head).toHaveBeenCalledWith(buildUrl(defaultOptions), undefined) | ||
}) | ||
|
||
it('returns a signed url', async () => { | ||
const signUrlMock = jest.fn().mockImplementation(url => { | ||
return `${url}?signed=true` | ||
}) | ||
mockClient(signUrlMock) | ||
const avatarUrlPromise = avatarUrl(defaultOptions) | ||
mockAxios.mockResponse({ status: 200, data: undefined }) | ||
await expect(avatarUrlPromise).resolves.toBe(`${buildUrl(defaultOptions)}?signed=true`) | ||
expect(mockAxios.head).toHaveBeenCalledWith(buildUrl(defaultOptions), undefined) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import mockAxios from 'jest-mock-axios' | ||
export default mockAxios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters