From 81f9ce76668a79ac7afaf3e17871cc6356a90850 Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Mon, 27 Apr 2020 21:57:20 +0530 Subject: [PATCH] test(patient-slice): fix failing test cases after adding pagination fix #1969 --- src/__tests__/patients/patients-slice.test.ts | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/__tests__/patients/patients-slice.test.ts b/src/__tests__/patients/patients-slice.test.ts index f82b4fc787..2fed0e3745 100644 --- a/src/__tests__/patients/patients-slice.test.ts +++ b/src/__tests__/patients/patients-slice.test.ts @@ -2,6 +2,8 @@ import '../../__mocks__/matchMediaMock' import { AnyAction } from 'redux' import { mocked } from 'ts-jest/utils' import { UnpagedRequest } from 'clients/db/PageRequest' +import Page from 'clients/Page' +import { Unsorted } from 'clients/db/SortRequest' import patients, { fetchPatientsStart, fetchPatientsSuccess, @@ -67,38 +69,56 @@ describe('patients slice', () => { it('should call the PatientRepository search method with the correct search criteria', async () => { const dispatch = jest.fn() const getState = jest.fn() - jest.spyOn(PatientRepository, 'search') + jest.spyOn(PatientRepository, 'searchPaged') const expectedSearchString = 'search string' await searchPatients(expectedSearchString)(dispatch, getState, null) - expect(PatientRepository.search).toHaveBeenCalledWith(expectedSearchString) + expect(PatientRepository.searchPaged).toHaveBeenCalledWith( + expectedSearchString, + UnpagedRequest, + ) }) - it('should call the PatientRepository findAll method if there is no string text', async () => { + it('should call the PatientRepository findAllPaged method if there is no string text', async () => { const dispatch = jest.fn() const getState = jest.fn() - jest.spyOn(PatientRepository, 'findAll') + jest.spyOn(PatientRepository, 'findAllPaged') await searchPatients('')(dispatch, getState, null) - expect(PatientRepository.findAll).toHaveBeenCalledTimes(1) + expect(PatientRepository.findAllPaged).toHaveBeenCalledTimes(1) }) it('should dispatch the FETCH_PATIENTS_SUCCESS action', async () => { const dispatch = jest.fn() const getState = jest.fn() - - const expectedPatients = [ - { - id: '1234', - }, - ] as Patient[] + const expectedPatients = { + content: [ + { + id: '123', + fullName: 'test test', + isApproximateDateOfBirth: false, + givenName: 'test', + familyName: 'test', + code: 'P12345', + sex: 'male', + dateOfBirth: new Date().toISOString(), + phoneNumber: '99999999', + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + rev: '', + }, + ], + hasNext: false, + hasPrevious: false, + pageRequest: UnpagedRequest, + } as Page const mockedPatientRepository = mocked(PatientRepository, true) - mockedPatientRepository.search.mockResolvedValue(expectedPatients) + mockedPatientRepository.searchPaged.mockResolvedValue(expectedPatients) - await searchPatients('search string')(dispatch, getState, null) + await searchPatients('search string', Unsorted)(dispatch, getState, null) expect(dispatch).toHaveBeenLastCalledWith({ type: fetchPatientsSuccess.type,