diff --git a/src/__tests__/scheduling/hooks/useDeleteAppointment.test.tsx b/src/__tests__/scheduling/hooks/useDeleteAppointment.test.tsx new file mode 100644 index 0000000000..30fdd74d2b --- /dev/null +++ b/src/__tests__/scheduling/hooks/useDeleteAppointment.test.tsx @@ -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) + }) +}) diff --git a/src/__tests__/scheduling/hooks/useUpdateAppointment.test.tsx b/src/__tests__/scheduling/hooks/useUpdateAppointment.test.tsx new file mode 100644 index 0000000000..e367c475d1 --- /dev/null +++ b/src/__tests__/scheduling/hooks/useUpdateAppointment.test.tsx @@ -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) + }) +})