From c791de39fa8c67d875f8fb1aa99baf164691b5eb Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Sun, 17 May 2020 11:24:24 +0200 Subject: [PATCH] feat(newlabrequest): add requestBy to model Add new field into the model. The field is auto filled by system when a new lab request is created. The new field will contain the user id of the current user fix #2082 --- src/__tests__/labs/lab-slice.test.ts | 18 ++++++++++++++++-- .../labs/requests/NewLabRequest.test.tsx | 11 +++++++++-- src/labs/lab-slice.ts | 2 ++ src/model/Lab.ts | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/__tests__/labs/lab-slice.test.ts b/src/__tests__/labs/lab-slice.test.ts index 21122cab33..a6dbe8de95 100644 --- a/src/__tests__/labs/lab-slice.test.ts +++ b/src/__tests__/labs/lab-slice.test.ts @@ -304,11 +304,19 @@ describe('lab slice', () => { }) it('should request a new lab', async () => { - const store = mockStore() + const store = mockStore({ + user: { + user: { + id: 'fake id', + }, + }, + } as any) + const expectedRequestedLab = { ...mockLab, requestedOn: new Date(Date.now()).toISOString(), status: 'requested', + requestedBy: store.getState().user.user.id, } as Lab await store.dispatch(requestLab(mockLab)) @@ -321,7 +329,13 @@ describe('lab slice', () => { }) it('should execute the onSuccess callback if provided', async () => { - const store = mockStore() + const store = mockStore({ + user: { + user: { + id: 'fake id', + }, + }, + } as any) const onSuccessSpy = jest.fn() await store.dispatch(requestLab(mockLab, onSuccessSpy)) diff --git a/src/__tests__/labs/requests/NewLabRequest.test.tsx b/src/__tests__/labs/requests/NewLabRequest.test.tsx index 8afe2eb98f..e496c57718 100644 --- a/src/__tests__/labs/requests/NewLabRequest.test.tsx +++ b/src/__tests__/labs/requests/NewLabRequest.test.tsx @@ -27,7 +27,10 @@ describe('New Lab Request', () => { const history = createMemoryHistory() beforeEach(() => { - const store = mockStore({ title: '', lab: { status: 'loading', error: {} } }) + const store = mockStore({ + title: '', + lab: { status: 'loading', error: {} }, + }) titleSpy = jest.spyOn(titleUtil, 'default') history.push('/labs/new') @@ -197,7 +200,11 @@ describe('New Lab Request', () => { .mockResolvedValue([{ id: expectedLab.patientId, fullName: 'some full name' }] as Patient[]) history.push('/labs/new') - const store = mockStore({ title: '', lab: { status: 'loading', error: {} } }) + const store = mockStore({ + title: '', + lab: { status: 'loading', error: {} }, + user: { user: { id: 'fake id' } }, + }) wrapper = mount( diff --git a/src/labs/lab-slice.ts b/src/labs/lab-slice.ts index 4d60aadb49..4294448a87 100644 --- a/src/labs/lab-slice.ts +++ b/src/labs/lab-slice.ts @@ -105,6 +105,7 @@ const validateLabRequest = (newLab: Lab): Error => { export const requestLab = (newLab: Lab, onSuccess?: (lab: Lab) => void): AppThunk => async ( dispatch, + getState, ) => { dispatch(requestLabStart()) @@ -115,6 +116,7 @@ export const requestLab = (newLab: Lab, onSuccess?: (lab: Lab) => void): AppThun } else { newLab.status = 'requested' newLab.requestedOn = new Date(Date.now().valueOf()).toISOString() + newLab.requestedBy = getState().user.user.id const requestedLab = await LabRepository.save(newLab) dispatch(requestLabSuccess(requestedLab)) diff --git a/src/model/Lab.ts b/src/model/Lab.ts index 64b17ce431..1a53d67542 100644 --- a/src/model/Lab.ts +++ b/src/model/Lab.ts @@ -4,6 +4,7 @@ export default interface Lab extends AbstractDBModel { code: string patientId: string type: string + requestedBy: string notes?: string result?: string status: 'requested' | 'completed' | 'canceled'