Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Added some test
Browse files Browse the repository at this point in the history
  • Loading branch information
ziccardi committed Apr 1, 2020
1 parent 8d2e817 commit 06ba658
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/applications/ApplicationsAdmin.ts
Expand Up @@ -6,13 +6,14 @@ export class ApplicationsAdmin {
let url = `/applications`;
if (filter && filter.id) {
url = `${url}/${filter.id}`;
return (await api.get(url)).data;
} else {
let apps: PushApplication[] = (await api.get(url)).data;
if (filter) {
apps = applyPushApplicationFilter(apps, filter);
const res = (await api.get(url)).data;
if (res instanceof Array) {
return res;
}
return apps;

return [res];
} else {
return applyPushApplicationFilter((await api.get(url)).data, filter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/applications/PushApplication.ts
Expand Up @@ -25,7 +25,7 @@ export interface PushApplication extends PushApplicationFilter {
*/
export const applyPushApplicationFilter = (
apps: PushApplication[],
filter: PushApplicationFilter
filter?: PushApplicationFilter
): PushApplication[] => {
if (filter) {
return apps.filter(
Expand Down
48 changes: 47 additions & 1 deletion test/UnifiedPushAdminClient.test.ts
Expand Up @@ -19,7 +19,27 @@ describe('Applications Admin', () => {
expect(res).toHaveLength(mockData.length);
expect(mockedAxios.get).toHaveBeenCalledWith('/applications');
});
it('test find with single filter', async () => {
it('test filter by id - returning singe result', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData.find(value => value.id === '2') }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({
id: '2',
});
expect(res).toHaveLength(1);
expect(mockedAxios.get).toHaveBeenCalledWith('/applications/2');
});

it('test filter by id - returning array with one object', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: [mockData.find(value => value.id === '2')] }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({
id: '2',
});
expect(res).toHaveLength(1);
expect(mockedAxios.get).toHaveBeenCalledWith('/applications/2');
});

it('test find filter by Developer', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({
Expand All @@ -28,6 +48,18 @@ describe('Applications Admin', () => {
expect(res).toHaveLength(2);
expect(mockedAxios.get).toHaveBeenCalledWith('/applications');
});

it('test find filter by name', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData }));

const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({
name: 'Application 3',
});
expect(res).toHaveLength(1);
expect(res[0]).toEqual(mockData.find(app => app.name === 'Application 3'));
expect(mockedAxios.get).toHaveBeenCalledWith('/applications');
});

it('test find with multiple filter', async () => {
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData }));

Expand Down Expand Up @@ -61,6 +93,20 @@ describe('Variants Admin', () => {
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`);
});

it('test filter by type', async () => {
const appId = '1';
const selectedApp = mockData.filter(app => app.id === appId)[0];
mockedAxios.get.mockImplementation(() =>
Promise.resolve({ data: selectedApp.variants!.filter(variant => variant.type === 'android') })
);

const res = await upsClient.variants.find(appId, { type: 'android' });
expect(res).toHaveLength(1);
expect(res[0].type).toEqual('android');
expect(res[0].name).toEqual('Variant 1');
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}/android`);
});

it('test find with single filter', async () => {
const appId = '1';
const selectedApp = mockData.filter(app => app.id === appId)[0];
Expand Down

0 comments on commit 06ba658

Please sign in to comment.