-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into opex-get-case-data-for-qgis
- Loading branch information
Showing
50 changed files
with
668 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
shared/src/business/entities/trialSessions/SpecialTrialSessions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type SpecialTrialSession = { | ||
userId: string; | ||
trialSessionId: string; | ||
}; | ||
|
||
export type SpecialTrialSessionKey = { | ||
pk: string; | ||
sk: string; | ||
}; | ||
|
||
export type TrialSessionWorkingCopyNotes = { | ||
sessionNotes: string; | ||
trialSessionId: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
shared/src/proxies/trialSessions/getBulkSpecialTrialSessionCopyNotesProxy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
SpecialTrialSession, | ||
TrialSessionWorkingCopyNotes, | ||
} from '@shared/business/entities/trialSessions/SpecialTrialSessions'; | ||
import { post } from '../requests'; | ||
|
||
export const getBulkSpecialTrialSessionCopyNotesInteractor = ( | ||
applicationContext, | ||
{ | ||
specialTrialSessions, | ||
}: { | ||
specialTrialSessions: Array<SpecialTrialSession>; | ||
}, | ||
): Array<TrialSessionWorkingCopyNotes> => | ||
post({ | ||
applicationContext, | ||
body: { specialTrialSessions }, | ||
endpoint: '/trial-sessions/bulk-copy-notes', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
web-api/src/business/useCases/trialSessions/getBulkTrialSessionCopyNotesInteractor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { UnauthorizedError } from '@web-api/errors/errors'; | ||
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; | ||
import { getBulkTrialSessionCopyNotesInteractor } from './getBulkTrialSessionCopyNotesInteractor'; | ||
import { mockAdminUser, mockJudgeUser } from '@shared/test/mockAuthUsers'; | ||
|
||
const MOCK_WORKING_COPY_NOTES = [ | ||
{ | ||
sessionNotes: 'Test notes', | ||
trialSessionId: '123', | ||
}, | ||
{ | ||
sessionNotes: 'Test notes 2', | ||
trialSessionId: '456', | ||
}, | ||
]; | ||
describe('getBulkTrialSessionCopyNotesInteractor', () => { | ||
beforeEach(() => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getBulkTrialSessionWorkingCopyNotes.mockReturnValue( | ||
MOCK_WORKING_COPY_NOTES, | ||
); | ||
}); | ||
it('should throw an error if the user is unauthorized', async () => { | ||
await expect( | ||
getBulkTrialSessionCopyNotesInteractor( | ||
applicationContext, | ||
{ specialTrialSessions: [] }, | ||
mockAdminUser, | ||
), | ||
).rejects.toThrow(UnauthorizedError); | ||
}); | ||
|
||
it('should return session notes for multiple trial sessions', async () => { | ||
const result = await getBulkTrialSessionCopyNotesInteractor( | ||
applicationContext, | ||
{ | ||
specialTrialSessions: [ | ||
{ trialSessionId: '123', userId: '123' }, | ||
{ trialSessionId: '456', userId: '456' }, | ||
], | ||
}, | ||
mockJudgeUser, | ||
); | ||
expect(result).toEqual(MOCK_WORKING_COPY_NOTES); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
web-api/src/business/useCases/trialSessions/getBulkTrialSessionCopyNotesInteractor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
ROLE_PERMISSIONS, | ||
isAuthorized, | ||
} from '../../../../../shared/src/authorization/authorizationClientService'; | ||
import { ServerApplicationContext } from '@web-api/applicationContext'; | ||
import { | ||
SpecialTrialSession, | ||
SpecialTrialSessionKey, | ||
TrialSessionWorkingCopyNotes, | ||
} from '@shared/business/entities/trialSessions/SpecialTrialSessions'; | ||
import { UnauthorizedError } from '@web-api/errors/errors'; | ||
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; | ||
|
||
export const getBulkTrialSessionCopyNotesInteractor = async ( | ||
applicationContext: ServerApplicationContext, | ||
{ specialTrialSessions }: { specialTrialSessions: SpecialTrialSession[] }, | ||
authorizedUser: UnknownAuthUser, | ||
): Promise<Array<TrialSessionWorkingCopyNotes>> => { | ||
if (!isAuthorized(authorizedUser, ROLE_PERMISSIONS.TRIAL_SESSIONS)) { | ||
throw new UnauthorizedError('Unauthorized'); | ||
} | ||
|
||
const specialTrialSessionKeys: Array<SpecialTrialSessionKey> = | ||
specialTrialSessions.map( | ||
(t: SpecialTrialSession): SpecialTrialSessionKey => ({ | ||
pk: `trial-session-working-copy|${t.trialSessionId}`, | ||
sk: `user|${t.userId}`, | ||
}), | ||
); | ||
|
||
return await applicationContext | ||
.getPersistenceGateway() | ||
.getBulkTrialSessionWorkingCopyNotes({ | ||
applicationContext, | ||
specialTrialSessions: specialTrialSessionKeys, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
web-api/src/lambdas/trialSessions/getBulkTrialSessionCopyNotesLambda.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; | ||
import { genericHandler } from '../../genericHandler'; | ||
import { getBulkTrialSessionCopyNotesInteractor } from '@web-api/business/useCases/trialSessions/getBulkTrialSessionCopyNotesInteractor'; | ||
|
||
export const getBulkTrialSessionCopyNotesLambda = ( | ||
event, | ||
authorizedUser: UnknownAuthUser, | ||
) => | ||
genericHandler(event, async ({ applicationContext }) => { | ||
const { specialTrialSessions } = JSON.parse(event.body || '{}'); | ||
return await getBulkTrialSessionCopyNotesInteractor( | ||
applicationContext, | ||
{ | ||
specialTrialSessions, | ||
}, | ||
authorizedUser, | ||
); | ||
}); |
92 changes: 92 additions & 0 deletions
92
web-api/src/persistence/dynamo/trialSessions/getBulkTrialSessionWorkingCopies.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; | ||
import { batchGet } from '../../dynamodbClientService'; | ||
import { getBulkTrialSessionWorkingCopies } from './getBulkTrialSessionWorkingCopies'; | ||
|
||
jest.mock('../../dynamodbClientService'); | ||
|
||
const batchGetMock = batchGet as jest.Mock; | ||
|
||
batchGetMock.mockReturnValue([ | ||
{ | ||
caseMetadata: {}, | ||
entityName: 'TrialSessionWorkingCopy', | ||
filters: { | ||
basisReached: true, | ||
continued: true, | ||
definiteTrial: true, | ||
dismissed: true, | ||
motionToDismiss: true, | ||
probableSettlement: true, | ||
probableTrial: true, | ||
recall: true, | ||
rule122: true, | ||
setForTrial: true, | ||
settled: true, | ||
showAll: true, | ||
statusUnassigned: true, | ||
submittedCAV: true, | ||
}, | ||
pk: 'trial-session-working-copy|111ac21b-99f9-4321-98c8-b95db00af96b', | ||
sessionNotes: 'Judge Colvin Super notes!', | ||
sk: 'user|dabbad00-18d0-43ec-bafb-654e83405416', | ||
sort: 'docket', | ||
sortOrder: 'asc', | ||
trialSessionId: '111ac21b-99f9-4321-98c8-b95db00af96b', | ||
userId: 'dabbad00-18d0-43ec-bafb-654e83405416', | ||
}, | ||
{ | ||
caseMetadata: {}, | ||
entityName: 'TrialSessionWorkingCopy', | ||
filters: { | ||
basisReached: true, | ||
continued: true, | ||
definiteTrial: true, | ||
dismissed: true, | ||
motionToDismiss: true, | ||
probableSettlement: true, | ||
probableTrial: true, | ||
recall: true, | ||
rule122: true, | ||
setForTrial: true, | ||
settled: true, | ||
showAll: true, | ||
statusUnassigned: true, | ||
submittedCAV: true, | ||
}, | ||
pk: 'trial-session-working-copy|0d943468-bc2e-4631-84e3-b084cf5b1fbb', | ||
sessionNotes: 'Cohen Cohen Cohen Notes', | ||
sk: 'user|dabbad04-18d0-43ec-bafb-654e83405416', | ||
sort: 'docket', | ||
sortOrder: 'asc', | ||
trialSessionId: '0d943468-bc2e-4631-84e3-b084cf5b1fbb', | ||
userId: 'dabbad04-18d0-43ec-bafb-654e83405416', | ||
}, | ||
]); | ||
|
||
describe('getBulkTrialSessionWorkingCopies', () => { | ||
it('should get the trial session notes by special session array', async () => { | ||
const specialTrialSessions = [ | ||
{ pk: '123', sk: '456' }, | ||
{ pk: '456', sk: '789' }, | ||
]; | ||
|
||
const result = await getBulkTrialSessionWorkingCopies({ | ||
applicationContext, | ||
specialTrialSessions, | ||
}); | ||
expect(result).toEqual([ | ||
{ | ||
sessionNotes: 'Judge Colvin Super notes!', | ||
trialSessionId: '111ac21b-99f9-4321-98c8-b95db00af96b', | ||
}, | ||
{ | ||
sessionNotes: 'Cohen Cohen Cohen Notes', | ||
trialSessionId: '0d943468-bc2e-4631-84e3-b084cf5b1fbb', | ||
}, | ||
]); | ||
expect(batchGetMock).toHaveBeenCalledWith({ | ||
applicationContext, | ||
keys: specialTrialSessions, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.