Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
chore: add tests for use patients
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Aug 9, 2020
1 parent 32e4322 commit 5e8284f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/__tests__/patients/hooks/usePatients.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import usePatients from '../../../patients/hooks/usePatients'
import PatientSearchRequest from '../../../patients/models/PatientSearchRequest'
import PatientRepository from '../../../shared/db/PatientRepository'
import Patient from '../../../shared/model/Patient'
import executeQuery from '../use-query-test-util'

describe('use patients', () => {
it('should search patients with the proper search request', async () => {
const expectedPatientTotalCount = 1
const expectedSearchRequest = { queryString: 'someQueryString' } as PatientSearchRequest
const expectedPatients = [{ id: '123', givenName: 'test' }] as Patient[]
jest.spyOn(PatientRepository, 'search').mockResolvedValueOnce(expectedPatients)
jest.spyOn(PatientRepository, 'count').mockResolvedValueOnce(expectedPatientTotalCount)

const actualPatients = await executeQuery(() => usePatients(expectedSearchRequest))

expect(PatientRepository.search).toHaveBeenCalledTimes(1)
expect(PatientRepository.search).toHaveBeenCalledWith(expectedSearchRequest.queryString)
expect(actualPatients).toEqual({
patients: expectedPatients,
totalCount: expectedPatientTotalCount,
})
})
})

0 comments on commit 5e8284f

Please sign in to comment.