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

Commit

Permalink
feat(patients): fix failing test due to missing mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed May 3, 2020
1 parent 652f11d commit 6ac824e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
30 changes: 18 additions & 12 deletions src/__tests__/patients/labs/LabsTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import LabRepository from '../../../clients/db/LabRepository'

const expectedPatient = {
id: '123',
labs: [
{
patientId: '123',
type: 'type',
status: 'requested',
requestedOn: new Date().toISOString(),
} as Lab,
],
} as Patient

const labs = [
{
id: 'labId',
patientId: '123',
type: 'type',
status: 'requested',
requestedOn: new Date().toISOString(),
} as Lab,
]

const mockStore = configureMockStore([thunk])
const history = createMemoryHistory()

Expand All @@ -36,7 +38,7 @@ let store: any
const setup = (patient = expectedPatient, permissions = [Permissions.WritePatients]) => {
user = { permissions }
store = mockStore({ patient, user })
jest.spyOn(LabRepository, 'findLabsByPatientId').mockResolvedValue(expectedPatient.labs as Lab[])
jest.spyOn(LabRepository, 'findAllByPatientId').mockResolvedValue(labs)
const wrapper = mount(
<Router history={history}>
<Provider store={store}>
Expand All @@ -50,7 +52,7 @@ const setup = (patient = expectedPatient, permissions = [Permissions.WritePatien

describe('Labs Tab', () => {
it('should list the patients labs', async () => {
const expectedLabs = expectedPatient.labs as Lab[]
const expectedLabs = labs
let wrapper: any
await act(async () => {
wrapper = await setup()
Expand All @@ -76,8 +78,12 @@ describe('Labs Tab', () => {
expect(tableData.at(2).text()).toEqual(expectedLabs[0].status)
})

it('should render a warning message if the patient does not have any labs', () => {
const wrapper = setup({ ...expectedPatient, labs: [] })
it('should render a warning message if the patient does not have any labs', async () => {
let wrapper: any

await act(async () => {
wrapper = await setup({ ...expectedPatient })
})

const alert = wrapper.find(components.Alert)

Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/patients/view/ViewPatient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ViewPatient from '../../../patients/view/ViewPatient'
import * as patientSlice from '../../../patients/patient-slice'
import Permissions from '../../../model/Permissions'
import LabsTab from '../../../patients/labs/LabsTab'
import LabRepository from '../../../clients/db/LabRepository'

const mockStore = configureMockStore([thunk])

Expand All @@ -48,6 +49,7 @@ describe('ViewPatient', () => {

const setup = (permissions = [Permissions.ReadPatients]) => {
jest.spyOn(PatientRepository, 'find')
jest.spyOn(LabRepository, 'findAllByPatientId').mockResolvedValue([])
const mockedPatientRepository = mocked(PatientRepository, true)
mockedPatientRepository.find.mockResolvedValue(patient)
history = createMemoryHistory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('New Appointment', () => {
mocked(AppointmentRepository, true).save.mockResolvedValue(
expectedNewAppointment as Appointment,
)
jest.spyOn(LabRepository, 'findLabsByPatientId').mockResolvedValue([] as Lab[])
jest.spyOn(LabRepository, 'findAllByPatientId').mockResolvedValue([] as Lab[])

history = createMemoryHistory()
store = mockStore({
Expand Down
2 changes: 1 addition & 1 deletion src/clients/db/LabRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class LabRepository extends Repository<Lab> {
})
}

async findLabsByPatientId(patientId: string): Promise<Lab[]> {
async findAllByPatientId(patientId: string): Promise<Lab[]> {
return super.search({
selector: {
$and: [
Expand Down
2 changes: 1 addition & 1 deletion src/patients/labs/LabsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const LabsTab = (props: Props) => {

useEffect(() => {
const fetch = async () => {
const fetchedLabs = await LabRepository.findLabsByPatientId(patientId)
const fetchedLabs = await LabRepository.findAllByPatientId(patientId)
setLabs(fetchedLabs)
}

Expand Down

0 comments on commit 6ac824e

Please sign in to comment.