This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added delete and new appointment hook tests
- Loading branch information
1 parent
9d96aa3
commit da046c7
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/__tests__/scheduling/hooks/useDeleteAppointment.test.tsx
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,38 @@ | ||
import useDeleteAppointment from '../../../scheduling/hooks/useDeleteAppointment' | ||
import AppointmentRepository from '../../../shared/db/AppointmentRepository' | ||
import Appointment from '../../../shared/model/Appointment' | ||
import * as uuid from '../../../shared/util/uuid' | ||
import executeMutation from '../../test-utils/use-mutation.util' | ||
|
||
describe('use delete appoinment', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('should remove an appointment with the given id', async () => { | ||
const expectedAppointmentId = '123' | ||
|
||
const expectedAppointment = { | ||
id: '123', | ||
patient: '456', | ||
startDateTime: new Date(2020, 10, 1, 0, 0, 0, 0).toISOString(), | ||
endDateTime: new Date(2020, 10, 1, 1, 0, 0, 0).toISOString(), | ||
location: 'location', | ||
reason: 'reason', | ||
type: 'type', | ||
} as Appointment | ||
|
||
jest.spyOn(AppointmentRepository, 'find').mockResolvedValue(expectedAppointment) | ||
jest.spyOn(uuid, 'uuid').mockReturnValue(expectedAppointmentId) | ||
jest.spyOn(AppointmentRepository, 'delete').mockResolvedValue(expectedAppointment) | ||
|
||
const result = await executeMutation(() => useDeleteAppointment(), { | ||
appointmentId: expectedAppointmentId, | ||
}) | ||
|
||
expect(AppointmentRepository.find).toHaveBeenCalledTimes(1) | ||
expect(AppointmentRepository.delete).toHaveBeenCalledTimes(1) | ||
expect(AppointmentRepository.delete).toHaveBeenCalledWith(expectedAppointment) | ||
expect(result).toEqual(expectedAppointment) | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
src/__tests__/scheduling/hooks/useUpdateAppointment.test.tsx
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,36 @@ | ||
import { act } from '@testing-library/react-hooks' | ||
|
||
import useUpdateLab from '../../../labs/hooks/useUpdateLab' | ||
import useUpdateAppointment from '../../../scheduling/hooks/useUpdateAppointment' | ||
import AppointmentRepository from '../../../shared/db/AppointmentRepository' | ||
import Appointment from '../../../shared/model/Appointment' | ||
import executeMutation from '../../test-utils/use-mutation.util' | ||
|
||
describe('Use update appointment', () => { | ||
const expectedAppointment = { | ||
id: '123', | ||
patient: '456', | ||
startDateTime: new Date(2020, 10, 1, 0, 0, 0, 0).toISOString(), | ||
endDateTime: new Date(2020, 10, 1, 1, 0, 0, 0).toISOString(), | ||
location: 'location', | ||
reason: 'reason', | ||
type: 'type', | ||
} as Appointment | ||
|
||
jest.spyOn(AppointmentRepository, 'saveOrUpdate').mockResolvedValue(expectedAppointment) | ||
|
||
it('should update appointment', async () => { | ||
let actualData: any | ||
|
||
await act(async () => { | ||
actualData = await executeMutation(() => { | ||
const result = useUpdateAppointment(expectedAppointment) | ||
return [result.mutate] | ||
}, expectedAppointment) | ||
}) | ||
|
||
expect(AppointmentRepository.saveOrUpdate).toHaveBeenCalledTimes(1) | ||
expect(AppointmentRepository.saveOrUpdate).toHaveBeenCalledWith(expectedAppointment) | ||
expect(actualData).toEqual(expectedAppointment) | ||
}) | ||
}) |