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

feat(labs): add requestedby to new laboratory request #2086

Merged
merged 1 commit into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/__tests__/labs/lab-slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
11 changes: 9 additions & 2 deletions src/__tests__/labs/requests/NewLabRequest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
<Provider store={store}>
<Router history={history}>
Expand Down
2 changes: 2 additions & 0 deletions src/labs/lab-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const validateLabRequest = (newLab: Lab): Error => {

export const requestLab = (newLab: Lab, onSuccess?: (lab: Lab) => void): AppThunk => async (
dispatch,
getState,
) => {
dispatch(requestLabStart())

Expand All @@ -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))

Expand Down
1 change: 1 addition & 0 deletions src/model/Lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down