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.
chore: removes dispatch. adds useAppointment, useDeleteAppointment ho…
…oks. refactor scheduling WIP
- Loading branch information
1 parent
812fe6a
commit 83fc431
Showing
9 changed files
with
131 additions
and
80 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Dockerc compose only for developing purpose | ||
|
||
version: "3.8" | ||
version: "3.3" | ||
|
||
services: | ||
couchdb: | ||
|
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,28 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks' | ||
|
||
import useAppointment from '../../../scheduling/hooks/useAppointment' | ||
import AppointmentRepository from '../../../shared/db/AppointmentRepository' | ||
import Appointment from '../../../shared/model/Appointment' | ||
import waitUntilQueryIsSuccessful from '../../test-utils/wait-for-query.util' | ||
|
||
describe('useAppointment', () => { | ||
it('should get an appointment by id', async () => { | ||
const expectedAppointmentId = 'some id' | ||
const expectedAppointment = { | ||
id: expectedAppointmentId, | ||
} as Appointment | ||
jest.spyOn(AppointmentRepository, 'find').mockResolvedValue(expectedAppointment) | ||
|
||
let actualData: any | ||
await act(async () => { | ||
const renderHookResult = renderHook(() => useAppointment(expectedAppointmentId)) | ||
const { result } = renderHookResult | ||
await waitUntilQueryIsSuccessful(renderHookResult) | ||
actualData = result.current.data | ||
}) | ||
|
||
expect(AppointmentRepository.find).toHaveBeenCalledTimes(1) | ||
expect(AppointmentRepository.find).toBeCalledWith(expectedAppointmentId) | ||
expect(actualData).toEqual(expectedAppointment) | ||
}) | ||
}) |
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,12 @@ | ||
import { QueryKey, useQuery } from 'react-query' | ||
|
||
import AppointmentRepository from '../../shared/db/AppointmentRepository' | ||
import Appointment from '../../shared/model/Appointment' | ||
|
||
function getAppointmentById(_: QueryKey<string>, appointmentId: string): Promise<Appointment> { | ||
return AppointmentRepository.find(appointmentId) | ||
} | ||
|
||
export default function useAppointment(appointmentId: string) { | ||
return useQuery(['appointment', appointmentId], getAppointmentById) | ||
} |
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,21 @@ | ||
import { queryCache, useMutation } from 'react-query' | ||
|
||
import AppointmentRepository from '../../shared/db/AppointmentRepository' | ||
import Appointment from '../../shared/model/Appointment' | ||
|
||
interface deleteAppointmentRequest { | ||
appointmentId: string | ||
} | ||
|
||
async function deleteAppointment(request: deleteAppointmentRequest): Promise<Appointment> { | ||
const appointment = await AppointmentRepository.find(request.appointmentId) | ||
return AppointmentRepository.delete(appointment) | ||
} | ||
|
||
export default function useDeleteAppointment() { | ||
return useMutation(deleteAppointment, { | ||
onSuccess: async () => { | ||
queryCache.invalidateQueries('appointment') | ||
}, | ||
}) | ||
} |