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.
fix(EditAppointment): refactor editing appointment to use
useUpdateAppointment
- Loading branch information
1 parent
009336b
commit 56e058f
Showing
11 changed files
with
193 additions
and
84 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
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,45 @@ | ||
import { act } from '@testing-library/react-hooks' | ||
|
||
import useAppointments from '../../../scheduling/hooks/useAppointments' | ||
import AppointmentRepository from '../../../shared/db/AppointmentRepository' | ||
import Appointment from '../../../shared/model/Appointment' | ||
|
||
describe('useAppointments', () => { | ||
it('should get an appointment by id', async () => { | ||
const expectedAppointmentId = '123' | ||
|
||
const expectedAppointments = [ | ||
{ | ||
id: '456', | ||
rev: '1', | ||
patient: expectedAppointmentId, | ||
startDateTime: new Date(2020, 1, 1, 9, 0, 0, 0).toISOString(), | ||
endDateTime: new Date(2020, 1, 1, 9, 30, 0, 0).toISOString(), | ||
location: 'location', | ||
reason: 'Follow Up', | ||
}, | ||
{ | ||
id: '123', | ||
rev: '1', | ||
patient: expectedAppointmentId, | ||
startDateTime: new Date(2020, 1, 1, 8, 0, 0, 0).toISOString(), | ||
endDateTime: new Date(2020, 1, 1, 8, 30, 0, 0).toISOString(), | ||
location: 'location', | ||
reason: 'Checkup', | ||
}, | ||
] as Appointment[] | ||
jest.spyOn(AppointmentRepository, 'findAll').mockResolvedValue(expectedAppointments) | ||
|
||
// let actualData: any | ||
await act(async () => { | ||
// const renderHookResult = renderHook(() => useAppointments()) | ||
const result = useAppointments() | ||
// await waitUntilQueryIsSuccessful(result) | ||
result.then((actualData) => { | ||
expect(AppointmentRepository.findAll).toHaveBeenCalledTimes(1) | ||
// expect(AppointmentRepository.findAll).toBeCalledWith(expectedAppointmentId) | ||
expect(actualData).toEqual(expectedAppointments) | ||
}) | ||
}) | ||
}) | ||
}) |
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
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,29 @@ | ||
import { isBefore } from 'date-fns' | ||
|
||
import Appointment from '../../../shared/model/Appointment' | ||
|
||
export class AppointmentError extends Error { | ||
patient?: string | ||
|
||
startDateTime?: string | ||
|
||
constructor(patient: string, startDateTime: string, message: string) { | ||
super(message) | ||
this.patient = patient | ||
this.startDateTime = startDateTime | ||
Object.setPrototypeOf(this, AppointmentError.prototype) | ||
} | ||
} | ||
|
||
export default function validateAppointment(appointment: Appointment): AppointmentError { | ||
const newError: any = {} | ||
|
||
if (!appointment.patient) { | ||
newError.patient = 'scheduling.appointment.errors.patientRequired' | ||
} | ||
if (isBefore(new Date(appointment.endDateTime), new Date(appointment.startDateTime))) { | ||
newError.startDateTime = 'scheduling.appointment.errors.startDateMustBeBeforeEndDate' | ||
} | ||
|
||
return newError as AppointmentError | ||
} |
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
Oops, something went wrong.