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

Commit

Permalink
Merge pull request #2086 from marcosvega91/feature/add_requested_by_lab
Browse files Browse the repository at this point in the history
feat(labs): add requestedby to new laboratory request
  • Loading branch information
matteovivona authored May 17, 2020
2 parents 99403b7 + c791de3 commit 739863f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
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

1 comment on commit 739863f

@vercel
Copy link

@vercel vercel bot commented on 739863f May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.