This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
137 additions
and
141 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
build | ||
dist | ||
.idea | ||
coverage |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
rootDir: 'test' | ||
}; | ||
collectCoverage: true, | ||
collectCoverageFrom: ['src/**/*.ts'], | ||
roots: [ | ||
'test', | ||
'src' | ||
] | ||
}; |
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.
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,107 @@ | ||
import axios from 'axios'; | ||
import { mockData } from './mockData'; | ||
import { PushApplication, UnifiedPushAdminClient } from '../src'; | ||
import { mocked } from 'ts-jest/dist/util/testing'; | ||
|
||
jest.mock('axios'); | ||
|
||
const mockedAxios = axios as jest.Mocked<typeof axios>; | ||
|
||
mocked(axios).create = () => mockedAxios; | ||
|
||
const upsClient = new UnifiedPushAdminClient('http://localhost:9999'); | ||
|
||
describe('Applications Admin', () => { | ||
it('test find without filters', async () => { | ||
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData })); | ||
|
||
const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find(); | ||
expect(res).toHaveLength(mockData.length); | ||
expect(mockedAxios.get).toHaveBeenCalledWith('/applications'); | ||
}); | ||
it('test find with single filter', async () => { | ||
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData })); | ||
|
||
const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({ | ||
developer: 'Test Developer 2', | ||
}); | ||
expect(res).toHaveLength(2); | ||
expect(mockedAxios.get).toHaveBeenCalledWith('/applications'); | ||
}); | ||
it('test find with multiple filter', async () => { | ||
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: mockData })); | ||
|
||
const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.find({ | ||
developer: 'Test Developer 2', | ||
name: 'Application 4', | ||
}); | ||
expect(res).toHaveLength(1); | ||
expect(res[0].name).toEqual('Application 4'); | ||
expect(mockedAxios.get).toHaveBeenCalledWith('/applications'); | ||
}); | ||
|
||
it('test create app', async () => { | ||
const appToBeCreated = mockData[3]; | ||
mockedAxios.post.mockImplementationOnce((url: string, app: PushApplication) => Promise.resolve({ data: app })); | ||
|
||
const res = await new UnifiedPushAdminClient('http://localhost:9999').applications.create(appToBeCreated); | ||
expect(res).toEqual(appToBeCreated); | ||
expect(mockedAxios.post).toHaveBeenCalledWith('/applications', appToBeCreated); | ||
}); | ||
}); | ||
|
||
describe('Variants Admin', () => { | ||
it('test find without filters', async () => { | ||
const appId = '1'; | ||
const selectedApp = mockData.filter(app => app.id === appId)[0]; | ||
mockedAxios.get.mockImplementationOnce(() => Promise.resolve({ data: selectedApp })); | ||
|
||
const res = await upsClient.variants.find(appId); | ||
expect(res).toHaveLength(selectedApp!.variants!.length); | ||
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`); | ||
}); | ||
|
||
it('test find with single filter', async () => { | ||
const appId = '1'; | ||
const selectedApp = mockData.filter(app => app.id === appId)[0]; | ||
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp })); | ||
|
||
let res = await upsClient.variants.find(appId, { developer: 'developer 2' }); | ||
expect(res).toHaveLength(1); | ||
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`); | ||
|
||
res = await upsClient.variants.find(appId, { developer: 'developer 1' }); | ||
expect(res).toHaveLength(2); | ||
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`); | ||
}); | ||
|
||
it('test find one variant/no filters', async () => { | ||
const appId = '3'; | ||
const selectedApp = mockData.filter(app => app.id === appId)[0]; | ||
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp })); | ||
|
||
const res = await upsClient.variants.find(appId); | ||
expect(res).toHaveLength(1); | ||
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`); | ||
}); | ||
|
||
it('test find with bad filter', async () => { | ||
const appId = '1'; | ||
const selectedApp = mockData.filter(app => app.id === appId)[0]; | ||
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp })); | ||
|
||
const res = await upsClient.variants.find(appId, { developer: 'developer 84' }); | ||
expect(res).toHaveLength(0); | ||
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`); | ||
}); | ||
|
||
it('test app without variants', async () => { | ||
const appId = '4'; | ||
const selectedApp = mockData.filter(app => app.id === appId)[0]; | ||
mockedAxios.get.mockImplementation(() => Promise.resolve({ data: selectedApp })); | ||
|
||
const res = await upsClient.variants.find(appId, { developer: 'developer 84' }); | ||
expect(res).toHaveLength(0); | ||
expect(mockedAxios.get).toHaveBeenCalledWith(`/applications/${appId}`); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.