-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: #2362 graphql api layer tests
- Loading branch information
Cuong Vu
committed
Aug 19, 2020
1 parent
768f5f8
commit 6e1ee78
Showing
23 changed files
with
1,762 additions
and
22 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
184 changes: 184 additions & 0 deletions
184
packages/graphql-server/src/resolvers/applicants/__tests__/api.test.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,184 @@ | ||
import { mockContext } from '../../../__stubs__/context' | ||
import { | ||
callGetApplicantsAPI, | ||
callGetApplicantByIdAPI, | ||
callGetApplicantRelationshipsAPI, | ||
callGetApplicantRelationshipByIdAPI, | ||
callCreateApplicantAPI, | ||
callUpdateApplicantAPI, | ||
callCreateApplicantRelationshipAPI, | ||
callDeleteApplicantRelationshipAPI, | ||
} from '../api' | ||
import { createPlatformAxiosInstance } from '../../../utils/axios-instances' | ||
import { applicantMock } from '../__stubs__/applicant' | ||
import { applicantsMock } from '../__stubs__/applicants' | ||
import { relationshipMock } from '../__stubs__/relationship' | ||
import { relationshipsMock } from '../__stubs__/relationships' | ||
import { createApplicantArgsMock } from '../__stubs__/create-applicant' | ||
import { createRelationshipsArgs } from '../__stubs__/create-relationships' | ||
import { updateApplicantArgsMock } from '../__stubs__/update-applicant' | ||
import { deleteRelationshipMockArgs } from '../__stubs__/delete-relatationships' | ||
import { getIdFromCreateHeaders } from '../../../utils/get-id-from-create-headers' | ||
|
||
jest.mock('../../../utils/get-id-from-create-headers', () => ({ | ||
getIdFromCreateHeaders: jest.fn(), | ||
})) | ||
|
||
jest.mock('../../../utils/handle-error', () => ({ | ||
handleError: jest.fn(() => Promise.resolve('caught error')), | ||
})) | ||
jest.mock('../../../logger') | ||
jest.mock('../../../utils/axios-instances', () => ({ | ||
createPlatformAxiosInstance: jest.fn(() => ({ | ||
get: jest.fn(), | ||
post: jest.fn(), | ||
patch: jest.fn(), | ||
put: jest.fn(), | ||
delete: jest.fn(), | ||
})), | ||
})) | ||
|
||
describe('callGetApplicantsAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: applicantsMock })), | ||
}) | ||
const args = { pageSize: 1 } | ||
const result = await callGetApplicantsAPI(args, mockContext) | ||
expect(result).toEqual(applicantsMock) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { pageSize: 1 } | ||
const result = await callGetApplicantsAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callGetApplicantByIdAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: applicantMock })), | ||
}) | ||
const args = { id: applicantMock.id } | ||
const result = await callGetApplicantByIdAPI(args, mockContext) | ||
expect(result).toEqual(applicantMock) | ||
}) | ||
|
||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { id: applicantMock.id } | ||
const result = await callGetApplicantByIdAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callGetApplicantRelationshipByIdAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: relationshipMock })), | ||
}) | ||
const args = { id: 'id', relationshipId: 'relationshipId' } | ||
const result = await callGetApplicantRelationshipByIdAPI(args, mockContext) | ||
expect(result).toEqual(relationshipMock) | ||
}) | ||
|
||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { id: 'id', relationshipId: 'relationshipId' } | ||
const result = await callGetApplicantRelationshipByIdAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callGetApplicantRelationshipsAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: relationshipsMock })), | ||
}) | ||
const args = { pageSize: 1, id: 'id' } | ||
const result = await callGetApplicantRelationshipsAPI(args, mockContext) | ||
expect(result).toEqual(relationshipsMock) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { pageSize: 1, id: 'id' } | ||
const result = await callGetApplicantRelationshipsAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callCreateApplicantAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
get: jest.fn(() => Promise.resolve({ data: applicantMock })), | ||
}) | ||
;(getIdFromCreateHeaders as jest.Mocked<any>).mockReturnValueOnce(applicantMock.id) | ||
await callCreateApplicantAPI(createApplicantArgsMock, mockContext) | ||
expect(getIdFromCreateHeaders).toHaveBeenCalledWith({ headers: 'header' }) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callCreateApplicantAPI(createApplicantArgsMock, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callCreateApplicantRelationshipAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
}) | ||
await callCreateApplicantRelationshipAPI(createRelationshipsArgs, mockContext) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callCreateApplicantRelationshipAPI(createRelationshipsArgs, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callUpdateApplicantAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
patch: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
}) | ||
await callUpdateApplicantAPI(updateApplicantArgsMock, mockContext) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
patch: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callUpdateApplicantAPI(updateApplicantArgsMock, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callDeleteApplicantRelationshipAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
delete: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
}) | ||
await callDeleteApplicantRelationshipAPI(deleteRelationshipMockArgs, mockContext) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
delete: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callDeleteApplicantRelationshipAPI(deleteRelationshipMockArgs, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) |
105 changes: 105 additions & 0 deletions
105
packages/graphql-server/src/resolvers/appointments/__tests__/api.test.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,105 @@ | ||
import { mockContext } from '../../../__stubs__/context' | ||
import { | ||
callGetAppointmentsAPI, | ||
callCreateAppointmentAPI, | ||
callUpdateAppointmentAPI, | ||
callGetAppointmentByIdAPI, | ||
} from '../api' | ||
import { createPlatformAxiosInstance } from '../../../utils/axios-instances' | ||
import { appointmentMock } from '../__stubs__/appointment' | ||
import { appointmentsMock } from '../__stubs__/appointments' | ||
import { createAppointmentArgsMock } from '../__stubs__/create-appointment' | ||
import { updateAppointmentArgsMock } from '../__stubs__/update-appointment' | ||
import { getIdFromCreateHeaders } from '../../../utils/get-id-from-create-headers' | ||
|
||
jest.mock('../../../utils/get-id-from-create-headers', () => ({ | ||
getIdFromCreateHeaders: jest.fn(), | ||
})) | ||
|
||
jest.mock('../../../utils/handle-error', () => ({ | ||
handleError: jest.fn(() => Promise.resolve('caught error')), | ||
})) | ||
jest.mock('../../../logger') | ||
jest.mock('../../../utils/axios-instances', () => ({ | ||
createPlatformAxiosInstance: jest.fn(() => ({ | ||
get: jest.fn(), | ||
post: jest.fn(), | ||
patch: jest.fn(), | ||
put: jest.fn(), | ||
delete: jest.fn(), | ||
})), | ||
})) | ||
|
||
describe('callGetAppointmentsAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: appointmentsMock })), | ||
}) | ||
const args = { pageSize: 1 } | ||
const result = await callGetAppointmentsAPI(args, mockContext) | ||
expect(result).toEqual(appointmentsMock) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { pageSize: 1 } | ||
const result = await callGetAppointmentsAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callGetAppointmentByIdAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: appointmentMock })), | ||
}) | ||
const args = { id: appointmentMock.id } | ||
const result = await callGetAppointmentByIdAPI(args, mockContext) | ||
expect(result).toEqual(appointmentMock) | ||
}) | ||
|
||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { id: appointmentMock.id } | ||
const result = await callGetAppointmentByIdAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callCreateAppointmentAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
get: jest.fn(() => Promise.resolve({ data: appointmentMock })), | ||
}) | ||
;(getIdFromCreateHeaders as jest.Mocked<any>).mockReturnValueOnce(appointmentMock.id) | ||
await callCreateAppointmentAPI(createAppointmentArgsMock, mockContext) | ||
expect(getIdFromCreateHeaders).toHaveBeenCalledWith({ headers: 'header' }) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callCreateAppointmentAPI(createAppointmentArgsMock, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callUpdateAppointmentAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
patch: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
}) | ||
await callUpdateAppointmentAPI(updateAppointmentArgsMock, mockContext) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
patch: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callUpdateAppointmentAPI(updateAppointmentArgsMock, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) |
100 changes: 100 additions & 0 deletions
100
packages/graphql-server/src/resolvers/areas/__tests__/api.test.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,100 @@ | ||
import { mockContext } from '../../../__stubs__/context' | ||
import { callGetAreasAPI, callCreateAreaAPI, callUpdateAreaAPI, callGetAreaByIdAPI } from '../api' | ||
import { createPlatformAxiosInstance } from '../../../utils/axios-instances' | ||
import { areaMock } from '../__stubs__/area' | ||
import { areasMock } from '../__stubs__/areas' | ||
import { createAreaArgsMock } from '../__stubs__/create-area' | ||
import { updateAreaArgsMock } from '../__stubs__/update-area' | ||
import { getIdFromCreateHeaders } from '../../../utils/get-id-from-create-headers' | ||
|
||
jest.mock('../../../utils/get-id-from-create-headers', () => ({ | ||
getIdFromCreateHeaders: jest.fn(), | ||
})) | ||
|
||
jest.mock('../../../utils/handle-error', () => ({ | ||
handleError: jest.fn(() => Promise.resolve('caught error')), | ||
})) | ||
jest.mock('../../../logger') | ||
jest.mock('../../../utils/axios-instances', () => ({ | ||
createPlatformAxiosInstance: jest.fn(() => ({ | ||
get: jest.fn(), | ||
post: jest.fn(), | ||
patch: jest.fn(), | ||
put: jest.fn(), | ||
delete: jest.fn(), | ||
})), | ||
})) | ||
|
||
describe('callGetAreasAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: areasMock })), | ||
}) | ||
const args = { pageSize: 1 } | ||
const result = await callGetAreasAPI(args, mockContext) | ||
expect(result).toEqual(areasMock) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { pageSize: 1 } | ||
const result = await callGetAreasAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callGetAreaByIdAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.resolve({ data: areaMock })), | ||
}) | ||
const args = { id: areaMock.id } | ||
const result = await callGetAreaByIdAPI(args, mockContext) | ||
expect(result).toEqual(areaMock) | ||
}) | ||
|
||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
get: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const args = { id: areaMock.id } | ||
const result = await callGetAreaByIdAPI(args, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callCreateAreaAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
get: jest.fn(() => Promise.resolve({ data: areaMock })), | ||
}) | ||
;(getIdFromCreateHeaders as jest.Mocked<any>).mockReturnValueOnce(areaMock.id) | ||
await callCreateAreaAPI(createAreaArgsMock, mockContext) | ||
expect(getIdFromCreateHeaders).toHaveBeenCalledWith({ headers: 'header' }) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
post: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callCreateAreaAPI(createAreaArgsMock, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) | ||
|
||
describe('callUpdateAreaAPI', () => { | ||
it('should work correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
patch: jest.fn(() => Promise.resolve({ headers: 'header' })), | ||
}) | ||
await callUpdateAreaAPI(updateAreaArgsMock, mockContext) | ||
}) | ||
it('should catch error correctly', async () => { | ||
;(createPlatformAxiosInstance as jest.Mocked<any>).mockReturnValueOnce({ | ||
patch: jest.fn(() => Promise.reject('error caught')), | ||
}) | ||
const result = await callUpdateAreaAPI(updateAreaArgsMock, mockContext) | ||
expect(result).toEqual('caught error') | ||
}) | ||
}) |
Oops, something went wrong.