From 4d4787e97fe92c84e4a1c6871f4a568b3e5e43a2 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 09:56:47 -0600 Subject: [PATCH 01/47] 10504: start case correspondence + deadline --- web-api/src/database-types.ts | 31 ++++++++++++ .../caseDeadlines/createCaseDeadline.ts | 29 ++++++++++++ .../caseDeadlines/deleteCaseDeadline.ts | 47 +++++++++++++++++++ .../getCaseDeadlinesByDocketNumber.ts | 22 +++++++++ .../updateCaseCorrespondence.ts | 28 +++++++++++ 5 files changed, 157 insertions(+) create mode 100644 web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts create mode 100644 web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts create mode 100644 web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts create mode 100644 web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts diff --git a/web-api/src/database-types.ts b/web-api/src/database-types.ts index c1bee19ec32..dcb2d8cbe05 100644 --- a/web-api/src/database-types.ts +++ b/web-api/src/database-types.ts @@ -3,6 +3,8 @@ import { ColumnType, Insertable, Selectable, Updateable } from 'kysely'; export interface Database { dwMessage: MessageTable; dwCase: CaseTable; + dwCaseCorrespondence: CaseCorrespondenceTable; + dwCaseDeadline: CaseDeadlineTable; } export interface MessageTable { @@ -47,3 +49,32 @@ export interface CaseTable { export type CaseKysely = Selectable; export type NewCaseKysely = Insertable; export type UpdateCaseKysely = Updateable; + +export interface CaseCorrespondenceTable { + archived: boolean; + correspondenceId: string; + documentTitle: string; + filedBy: string; + filingDate: string; + userId: string; +} + +export type CaseCorrespondenceKysely = Selectable; +export type NewCaseCorrespondenceKysely = Insertable; +export type UpdateCaseCorrespondenceKysely = + Updateable; + +export interface CaseDeadlineTable { + associatedJudge: string; + associatedJudgeId: string; + caseDeadlineId: string; + createdAt: string; + deadlineDate: string; + description: string; + docketNumber: string; + sortableDocketNumber: number; +} + +export type CaseDeadlineKysely = Selectable; +export type NewCaseDeadlineKysely = Insertable; +export type UpdateCaseDeadlineKysely = Updateable; diff --git a/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts new file mode 100644 index 00000000000..45dd3cf49eb --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts @@ -0,0 +1,29 @@ +import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; +import { put } from '../../dynamodbClientService'; + +export const createCaseDeadline = ({ + applicationContext, + caseDeadline, +}: { + applicationContext: IApplicationContext; + caseDeadline: RawCaseDeadline; +}) => { + const { caseDeadlineId, docketNumber } = caseDeadline; + return Promise.all([ + put({ + Item: { + ...caseDeadline, + pk: `case-deadline|${caseDeadlineId}`, + sk: `case-deadline|${caseDeadlineId}`, + }, + applicationContext, + }), + put({ + Item: { + pk: `case|${docketNumber}`, + sk: `case-deadline|${caseDeadlineId}`, + }, + applicationContext, + }), + ]); +}; diff --git a/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts new file mode 100644 index 00000000000..fc25528ca4e --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts @@ -0,0 +1,47 @@ +import { get, remove } from '../../dynamodbClientService'; + +/** + * deleteCaseDeadline + * + * @param {object} providers the providers object + * @param {object} providers.applicationContext the application context + * @param {string} providers.caseDeadlineId the id of the case deadline to delete + * @param {string} providers.docketNumber the docket number of the case the deadline is attached to + * @returns {Array} the promises for the persistence delete calls + */ +export const deleteCaseDeadline = async ({ + applicationContext, + caseDeadlineId, + docketNumber, +}: { + applicationContext: IApplicationContext; + caseDeadlineId: string; + docketNumber: string; +}) => { + const originalCaseDeadline = await get({ + Key: { + pk: `case-deadline|${caseDeadlineId}`, + sk: `case-deadline|${caseDeadlineId}`, + }, + applicationContext, + }); + + if (originalCaseDeadline) { + await Promise.all([ + remove({ + applicationContext, + key: { + pk: `case-deadline|${caseDeadlineId}`, + sk: `case-deadline|${caseDeadlineId}`, + }, + }), + remove({ + applicationContext, + key: { + pk: `case|${docketNumber}`, + sk: `case-deadline|${caseDeadlineId}`, + }, + }), + ]); + } +}; diff --git a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts new file mode 100644 index 00000000000..51c13a2ece9 --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts @@ -0,0 +1,22 @@ +import { getRecordsViaMapping } from '../helpers/getRecordsViaMapping'; + +/** + * getCaseDeadlinesByDocketNumber + * + * @param {object} providers the providers object + * @param {object} providers.applicationContext the application context + * @param {string} providers.docketNumber the docket number of the case to get the case deadlines for + * @returns {Promise} the promise of the persistence call to get the records + */ +export const getCaseDeadlinesByDocketNumber = ({ + applicationContext, + docketNumber, +}: { + applicationContext: IApplicationContext; + docketNumber: string; +}) => + getRecordsViaMapping({ + applicationContext, + pk: `case|${docketNumber}`, + prefix: 'case-deadline', + }); diff --git a/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts b/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts new file mode 100644 index 00000000000..bb583599525 --- /dev/null +++ b/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts @@ -0,0 +1,28 @@ +import { put } from '../../dynamodbClientService'; + +/** + * updateCaseCorrespondence + * + * @param {object} providers the providers object + * @param {object} providers.applicationContext the application context + * @param {string} providers.docketNumber the docket number of the case the correspondence is attached to + * @param {string} providers.correspondence the correspondence document to update + * @returns {Promise} resolved promise upon completion of client request + */ +export const updateCaseCorrespondence = ({ + applicationContext, + correspondence, + docketNumber, +}: { + applicationContext: IApplicationContext; + correspondence: any; + docketNumber: string; +}) => + put({ + Item: { + ...correspondence, + pk: `case|${docketNumber}`, + sk: `correspondence|${correspondence.correspondenceId}`, + }, + applicationContext, + }); From b1f6ade24519388007bb222d401e8ae2b7f64b64 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 12:10:41 -0600 Subject: [PATCH 02/47] 10504: add additional case deadline queries --- shared/src/business/entities/CaseDeadline.ts | 10 +-- .../useCases/getCaseDeadlinesInteractor.ts | 26 +++----- .../autoGenerateDeadline.test.ts | 1 - .../useCaseHelper/autoGenerateDeadline.ts | 34 +++------- .../updateCaseAutomaticBlock.ts | 11 ++-- .../updateCaseAndAssociations.ts | 29 +++------ .../createCaseDeadlineInteractor.ts | 19 +++--- .../deleteCaseDeadlineInteractor.ts | 5 +- .../getCaseDeadlinesForCaseInteractor.ts | 32 +++------- .../updateCaseDeadlineInteractor.ts | 15 ++--- ...leAndServeCourtIssuedDocumentInteractor.ts | 1 - .../serveCourtIssuedDocumentInteractor.ts | 1 - web-api/src/database-types.ts | 4 +- .../getCaseDeadlinesForCaseLambda.ts | 4 +- .../caseDeadline/updateCaseDeadlineLambda.ts | 3 +- .../caseDeadlines/createCaseDeadline.ts | 36 +++++------ .../caseDeadlines/deleteCaseDeadline.ts | 47 +++----------- .../getCaseDeadlinesByDateRange.ts | 62 +++++++++++++++++++ .../getCaseDeadlinesByDocketNumber.ts | 34 +++++----- .../postgres/caseDeadlines/mapper.ts | 53 ++++++++++++++++ .../0005-case-deadline-correspondence.ts | 30 +++++++++ 21 files changed, 248 insertions(+), 209 deletions(-) create mode 100644 web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts create mode 100644 web-api/src/persistence/postgres/caseDeadlines/mapper.ts create mode 100644 web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts diff --git a/shared/src/business/entities/CaseDeadline.ts b/shared/src/business/entities/CaseDeadline.ts index 336b8142335..36b97ba4a7c 100644 --- a/shared/src/business/entities/CaseDeadline.ts +++ b/shared/src/business/entities/CaseDeadline.ts @@ -3,6 +3,7 @@ import { Case } from './cases/Case'; import { JoiValidationConstants } from './JoiValidationConstants'; import { JoiValidationEntity } from '@shared/business/entities/JoiValidationEntity'; import { createISODateString } from '../utilities/DateHandler'; +import { getUniqueId } from '@shared/sharedAppContext'; import joi from 'joi'; export class CaseDeadline extends JoiValidationEntity { public associatedJudge: string; @@ -15,17 +16,12 @@ export class CaseDeadline extends JoiValidationEntity { public leadDocketNumber?: string; public sortableDocketNumber: number; - constructor(rawProps, { applicationContext }) { + constructor(rawProps) { super('CaseDeadline'); - if (!applicationContext) { - throw new TypeError('applicationContext must be defined'); - } - this.associatedJudge = rawProps.associatedJudge; this.associatedJudgeId = rawProps.associatedJudgeId; - this.caseDeadlineId = - rawProps.caseDeadlineId || applicationContext.getUniqueId(); + this.caseDeadlineId = rawProps.caseDeadlineId || getUniqueId(); this.createdAt = rawProps.createdAt || createISODateString(); this.deadlineDate = rawProps.deadlineDate; this.description = rawProps.description; diff --git a/shared/src/business/useCases/getCaseDeadlinesInteractor.ts b/shared/src/business/useCases/getCaseDeadlinesInteractor.ts index 1b89604aa7d..2f104a19390 100644 --- a/shared/src/business/useCases/getCaseDeadlinesInteractor.ts +++ b/shared/src/business/useCases/getCaseDeadlinesInteractor.ts @@ -9,6 +9,7 @@ import { isAuthorized, } from '../../authorization/authorizationClientService'; import { UnauthorizedError } from '@web-api/errors/errors'; +import { getCaseDeadlinesByDateRange } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange'; import { pick } from 'lodash'; export const getCaseDeadlinesInteractor = async ( @@ -32,23 +33,16 @@ export const getCaseDeadlinesInteractor = async ( throw new UnauthorizedError('Unauthorized'); } - const { foundDeadlines, totalCount } = await applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDateRange({ - applicationContext, - endDate, - from, - judge, - pageSize, - startDate, - }); + const { foundDeadlines, totalCount } = await getCaseDeadlinesByDateRange({ + endDate, + from, + judge, + pageSize, + startDate, + }); - const validatedCaseDeadlines = CaseDeadline.validateRawCollection( - foundDeadlines, - { - applicationContext, - }, - ); + const validatedCaseDeadlines = + CaseDeadline.validateRawCollection(foundDeadlines); const caseMap = await getCasesByDocketNumbers({ applicationContext, diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts index 4ae0af5f90a..748233c601f 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts @@ -4,7 +4,6 @@ import { autoGenerateDeadline } from './autoGenerateDeadline'; describe('autoGenerateDeadline', () => { it('should create a case deadline', async () => { await autoGenerateDeadline({ - applicationContext, deadlineDate: '2019-03-01T21:42:29.073Z', description: 'Time is a created thing.', subjectCaseEntity: { diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts index f581522005c..4155df94b4b 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts @@ -1,35 +1,21 @@ import { CaseDeadline } from '../../../../shared/src/business/entities/CaseDeadline'; +import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; -/** - * autoGenerateDeadline - * - * @param {object} applicationContext the application context - * @param {string} providers.deadlineDate the date of the deadline to generated - * @param {string} providers.description the description of the deadline - * @param {Case} providers.subjectCaseEntity the subjectCaseEntity - */ export const autoGenerateDeadline = async ({ - applicationContext, deadlineDate, description, subjectCaseEntity, }) => { - const newCaseDeadline = new CaseDeadline( - { - associatedJudge: subjectCaseEntity.associatedJudge, - associatedJudgeId: subjectCaseEntity.associatedJudgeId, - deadlineDate, - description, - docketNumber: subjectCaseEntity.docketNumber, - sortableDocketNumber: subjectCaseEntity.sortableDocketNumber, - }, - { - applicationContext, - }, - ); + const newCaseDeadline = new CaseDeadline({ + associatedJudge: subjectCaseEntity.associatedJudge, + associatedJudgeId: subjectCaseEntity.associatedJudgeId, + deadlineDate, + description, + docketNumber: subjectCaseEntity.docketNumber, + sortableDocketNumber: subjectCaseEntity.sortableDocketNumber, + }); - await applicationContext.getPersistenceGateway().createCaseDeadline({ - applicationContext, + await createCaseDeadline({ caseDeadline: newCaseDeadline.validate().toRawObject(), }); }; diff --git a/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.ts b/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.ts index 61e36dfc3cf..cd5b630e537 100644 --- a/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.ts +++ b/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.ts @@ -1,3 +1,5 @@ +import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; + /** * updateCaseAutomaticBlock * @@ -13,12 +15,9 @@ export const updateCaseAutomaticBlock = async ({ if (caseEntity.trialDate || caseEntity.highPriority) { return caseEntity; } - const caseDeadlines = await applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber({ - applicationContext, - docketNumber: caseEntity.docketNumber, - }); + const caseDeadlines = await getCaseDeadlinesByDocketNumber({ + docketNumber: caseEntity.docketNumber, + }); caseEntity.updateAutomaticBlocked({ caseDeadlines }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index 067d7860670..1c133bbc7fa 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -8,6 +8,8 @@ import { PrivatePractitioner } from '../../../../../shared/src/business/entities import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { WorkItem } from '../../../../../shared/src/business/entities/WorkItem'; +import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; +import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; @@ -382,16 +384,9 @@ const updateCaseWorkItems = async ({ ); }; -/** - * Identifies user case mappings which require updates and issues persistence calls - * @param {object} args the arguments for updating the case - * @param {object} args.applicationContext the application context - * @param {object} args.caseToUpdate the case with its updated document data - * @param {object} args.oldCase the case as it is currently stored in persistence, prior to these changes - * @returns {Array} the persistence functions required to complete this action - */ const updateCaseDeadlines = async ({ - applicationContext, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + applicationContext, // cannot remove till remaining RELATED_CASE_OPERATIONS functions no longer use applicationContext caseToUpdate, oldCase, }) => { @@ -399,26 +394,20 @@ const updateCaseDeadlines = async ({ return []; } - const deadlines = await applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber({ - applicationContext, - docketNumber: caseToUpdate.docketNumber, - }); + const deadlines = await getCaseDeadlinesByDocketNumber({ + docketNumber: caseToUpdate.docketNumber, + }); deadlines.forEach(caseDeadline => { caseDeadline.associatedJudge = caseToUpdate.associatedJudge; caseDeadline.associatedJudgeId = caseToUpdate.associatedJudgeId; }); - const validCaseDeadlines = CaseDeadline.validateRawCollection(deadlines, { - applicationContext, - }); + const validCaseDeadlines = CaseDeadline.validateRawCollection(deadlines); return validCaseDeadlines.map( caseDeadline => function updateCaseDeadlines_cb() { - return applicationContext.getPersistenceGateway().createCaseDeadline({ - applicationContext, + return createCaseDeadline({ caseDeadline, }); }, diff --git a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts index 9e040f51c51..3dc26188848 100644 --- a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts @@ -7,6 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { createCaseDeadline as createDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const createCaseDeadline = async ( @@ -26,19 +27,13 @@ export const createCaseDeadline = async ( }); let caseEntity = new Case(caseDetail, { authorizedUser }); - const newCaseDeadline = new CaseDeadline( - { - ...caseDeadline, - associatedJudge: caseEntity.associatedJudge, - associatedJudgeId: caseEntity.associatedJudgeId, - }, - { - applicationContext, - }, - ); + const newCaseDeadline = new CaseDeadline({ + ...caseDeadline, + associatedJudge: caseEntity.associatedJudge, + associatedJudgeId: caseEntity.associatedJudgeId, + }); - await applicationContext.getPersistenceGateway().createCaseDeadline({ - applicationContext, + await createDeadline({ caseDeadline: newCaseDeadline.validate().toRawObject(), }); diff --git a/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.ts index e950c02150a..e12318a6412 100644 --- a/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.ts @@ -6,6 +6,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { deleteCaseDeadline as deleteDeadline } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const deleteCaseDeadline = async ( @@ -26,10 +27,8 @@ export const deleteCaseDeadline = async ( let updatedCase = new Case(caseToUpdate, { authorizedUser }); - await applicationContext.getPersistenceGateway().deleteCaseDeadline({ - applicationContext, + await deleteDeadline({ caseDeadlineId, - docketNumber, }); updatedCase = await applicationContext diff --git a/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.ts b/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.ts index f8a52dd20b3..0d17b1c2469 100644 --- a/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.ts @@ -1,26 +1,14 @@ import { CaseDeadline } from '../../../../../shared/src/business/entities/CaseDeadline'; -import { ServerApplicationContext } from '@web-api/applicationContext'; +import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; -/** - * getCaseDeadlinesForCaseInteractor - * - * @param {object} applicationContext the application context - * @param {object} providers the providers object - * @param {string} providers.docketNumber the docket number of the case to get case deadlines for - * @returns {Promise} the promise of the getCaseDeadlines call - */ -export const getCaseDeadlinesForCaseInteractor = async ( - applicationContext: ServerApplicationContext, - { docketNumber }: { docketNumber: string }, -) => { - const caseDeadlines = await applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber({ - applicationContext, - docketNumber, - }); - - return CaseDeadline.validateRawCollection(caseDeadlines, { - applicationContext, +export const getCaseDeadlinesForCaseInteractor = async ({ + docketNumber, +}: { + docketNumber: string; +}) => { + const caseDeadlines = await getCaseDeadlinesByDocketNumber({ + docketNumber, }); + + return CaseDeadline.validateRawCollection(caseDeadlines); }; diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts index ffc19a64f35..2c9df8f20a1 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts @@ -3,12 +3,12 @@ import { ROLE_PERMISSIONS, isAuthorized, } from '../../../../../shared/src/authorization/authorizationClientService'; -import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; +import { deleteCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; export const updateCaseDeadlineInteractor = async ( - applicationContext: ServerApplicationContext, { caseDeadline }: { caseDeadline: CaseDeadline }, authorizedUser: UnknownAuthUser, ) => { @@ -16,20 +16,15 @@ export const updateCaseDeadlineInteractor = async ( throw new UnauthorizedError('Unauthorized for updating case deadline'); } - const caseDeadlineToUpdate = new CaseDeadline(caseDeadline, { - applicationContext, - }) + const caseDeadlineToUpdate = new CaseDeadline(caseDeadline) .validate() .toRawObject(); - await applicationContext.getPersistenceGateway().deleteCaseDeadline({ - applicationContext, + await deleteCaseDeadline({ caseDeadlineId: caseDeadlineToUpdate.caseDeadlineId, - docketNumber: caseDeadlineToUpdate.docketNumber, }); - await applicationContext.getPersistenceGateway().createCaseDeadline({ - applicationContext, + await createCaseDeadline({ caseDeadline: caseDeadlineToUpdate, }); diff --git a/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.ts b/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.ts index 75ad15952cf..683464097bb 100644 --- a/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.ts +++ b/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.ts @@ -194,7 +194,6 @@ export const fileAndServeCourtIssuedDocument = async ( if (isSubjectCase && docketEntryEntity.shouldAutoGenerateDeadline()) { await applicationContext.getUseCaseHelpers().autoGenerateDeadline({ - applicationContext, deadlineDate: docketEntryEntity.date, description: docketEntryEntity.getAutoGeneratedDeadlineDescription(), diff --git a/web-api/src/business/useCases/courtIssuedDocument/serveCourtIssuedDocumentInteractor.ts b/web-api/src/business/useCases/courtIssuedDocument/serveCourtIssuedDocumentInteractor.ts index d9aca4768a4..e9254acf440 100644 --- a/web-api/src/business/useCases/courtIssuedDocument/serveCourtIssuedDocumentInteractor.ts +++ b/web-api/src/business/useCases/courtIssuedDocument/serveCourtIssuedDocumentInteractor.ts @@ -85,7 +85,6 @@ export const serveCourtIssuedDocument = async ( if (docketEntryToServe.shouldAutoGenerateDeadline()) { await applicationContext.getUseCaseHelpers().autoGenerateDeadline({ - applicationContext, deadlineDate: docketEntryToServe.date, description: docketEntryToServe.getAutoGeneratedDeadlineDescription(), subjectCaseEntity, diff --git a/web-api/src/database-types.ts b/web-api/src/database-types.ts index dcb2d8cbe05..387077c4e3c 100644 --- a/web-api/src/database-types.ts +++ b/web-api/src/database-types.ts @@ -51,10 +51,10 @@ export type NewCaseKysely = Insertable; export type UpdateCaseKysely = Updateable; export interface CaseCorrespondenceTable { - archived: boolean; + archived?: boolean; correspondenceId: string; documentTitle: string; - filedBy: string; + filedBy?: string; filingDate: string; userId: string; } diff --git a/web-api/src/lambdas/caseDeadline/getCaseDeadlinesForCaseLambda.ts b/web-api/src/lambdas/caseDeadline/getCaseDeadlinesForCaseLambda.ts index 0ae0f2d30bd..2b832e9e02a 100644 --- a/web-api/src/lambdas/caseDeadline/getCaseDeadlinesForCaseLambda.ts +++ b/web-api/src/lambdas/caseDeadline/getCaseDeadlinesForCaseLambda.ts @@ -8,8 +8,8 @@ import { getCaseDeadlinesForCaseInteractor } from '@web-api/business/useCases/ca * @returns {Promise<*|undefined>} the api gateway response object containing the statusCode, body, and headers */ export const getCaseDeadlinesForCaseLambda = event => - genericHandler(event, async ({ applicationContext }) => { - return await getCaseDeadlinesForCaseInteractor(applicationContext, { + genericHandler(event, async () => { + return await getCaseDeadlinesForCaseInteractor({ docketNumber: event.pathParameters.docketNumber, }); }); diff --git a/web-api/src/lambdas/caseDeadline/updateCaseDeadlineLambda.ts b/web-api/src/lambdas/caseDeadline/updateCaseDeadlineLambda.ts index 531ad482094..cbace18c722 100644 --- a/web-api/src/lambdas/caseDeadline/updateCaseDeadlineLambda.ts +++ b/web-api/src/lambdas/caseDeadline/updateCaseDeadlineLambda.ts @@ -12,9 +12,8 @@ export const updateCaseDeadlineLambda = ( event, authorizedUser: UnknownAuthUser, ): Promise => - genericHandler(event, async ({ applicationContext }) => { + genericHandler(event, async () => { return await updateCaseDeadlineInteractor( - applicationContext, { ...JSON.parse(event.body), }, diff --git a/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts index 45dd3cf49eb..df07b021af3 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts @@ -1,29 +1,21 @@ import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; -import { put } from '../../dynamodbClientService'; +import { + caseDeadlineEntity, + toKyselyNewCaseDeadline, +} from '@web-api/persistence/postgres/caseDeadlines/mapper'; +import { getDbWriter } from '@web-api/database'; -export const createCaseDeadline = ({ - applicationContext, +export const createCaseDeadline = async ({ caseDeadline, }: { - applicationContext: IApplicationContext; caseDeadline: RawCaseDeadline; }) => { - const { caseDeadlineId, docketNumber } = caseDeadline; - return Promise.all([ - put({ - Item: { - ...caseDeadline, - pk: `case-deadline|${caseDeadlineId}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - applicationContext, - }), - put({ - Item: { - pk: `case|${docketNumber}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - applicationContext, - }), - ]); + const createdCaseDeadline = await getDbWriter(writer => + writer + .insertInto('dwCaseDeadline') + .values(toKyselyNewCaseDeadline(caseDeadline)) + .returningAll() + .executeTakeFirst(), + ); + return caseDeadlineEntity(createdCaseDeadline); }; diff --git a/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts index fc25528ca4e..73756d67d70 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/deleteCaseDeadline.ts @@ -1,47 +1,14 @@ -import { get, remove } from '../../dynamodbClientService'; +import { getDbWriter } from '@web-api/database'; -/** - * deleteCaseDeadline - * - * @param {object} providers the providers object - * @param {object} providers.applicationContext the application context - * @param {string} providers.caseDeadlineId the id of the case deadline to delete - * @param {string} providers.docketNumber the docket number of the case the deadline is attached to - * @returns {Array} the promises for the persistence delete calls - */ export const deleteCaseDeadline = async ({ - applicationContext, caseDeadlineId, - docketNumber, }: { - applicationContext: IApplicationContext; caseDeadlineId: string; - docketNumber: string; }) => { - const originalCaseDeadline = await get({ - Key: { - pk: `case-deadline|${caseDeadlineId}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - applicationContext, - }); - - if (originalCaseDeadline) { - await Promise.all([ - remove({ - applicationContext, - key: { - pk: `case-deadline|${caseDeadlineId}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - }), - remove({ - applicationContext, - key: { - pk: `case|${docketNumber}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - }), - ]); - } + await getDbWriter(writer => + writer + .deleteFrom('dwCaseDeadline') + .where('caseDeadlineId', '=', caseDeadlineId) + .execute(), + ); }; diff --git a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts new file mode 100644 index 00000000000..fb69ba5d4b5 --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts @@ -0,0 +1,62 @@ +import { DEADLINE_REPORT_PAGE_SIZE } from '../../../../../shared/src/business/entities/EntityConstants'; +import { caseDeadlineEntity } from '@web-api/persistence/postgres/caseDeadlines/mapper'; +import { getDbReader } from '@web-api/database'; + +export const getCaseDeadlinesByDateRange = async ({ + endDate, + from = 0, + judge, + pageSize, + startDate, +}) => { + const size = + pageSize && pageSize <= DEADLINE_REPORT_PAGE_SIZE + ? pageSize + : DEADLINE_REPORT_PAGE_SIZE; + + const { results: caseDeadlines, total: totalCount } = await getDbReader( + async reader => { + let deadlineQuery = reader + .selectFrom('dwCaseDeadline') + .selectAll() + .where('deadlineDate', '>=', startDate) + .where('deadlineDate', '<=', endDate); + + if (judge) { + deadlineQuery = deadlineQuery.where('associatedJudge', '=', judge); + } + + deadlineQuery = deadlineQuery + .offset(from) + .limit(size) + .orderBy('deadlineDate', 'asc') + .orderBy('sortableDocketNumber', 'asc'); + + const results = await deadlineQuery.execute(); + + let countQuery = reader + .selectFrom('dwCaseDeadline') + .select(reader.fn.count('docketNumber').as('totalCount')) + .where('deadlineDate', '>=', startDate) + .where('deadlineDate', '<=', endDate); + + if (judge) { + countQuery = countQuery.where('associatedJudge', '=', judge); + } + + const total = await countQuery.executeTakeFirst(); + + return { + results, + total: total?.totalCount || 0, + }; + }, + ); + + return { + foundDeadlines: caseDeadlines.map(caseDeadline => + caseDeadlineEntity(caseDeadline), + ), + totalCount, + }; +}; diff --git a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts index 51c13a2ece9..984b1a46044 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts @@ -1,22 +1,20 @@ -import { getRecordsViaMapping } from '../helpers/getRecordsViaMapping'; +import { caseDeadlineEntity } from '@web-api/persistence/postgres/caseDeadlines/mapper'; +import { getDbReader } from '@web-api/database'; -/** - * getCaseDeadlinesByDocketNumber - * - * @param {object} providers the providers object - * @param {object} providers.applicationContext the application context - * @param {string} providers.docketNumber the docket number of the case to get the case deadlines for - * @returns {Promise} the promise of the persistence call to get the records - */ -export const getCaseDeadlinesByDocketNumber = ({ - applicationContext, +export const getCaseDeadlinesByDocketNumber = async ({ docketNumber, }: { - applicationContext: IApplicationContext; docketNumber: string; -}) => - getRecordsViaMapping({ - applicationContext, - pk: `case|${docketNumber}`, - prefix: 'case-deadline', - }); +}) => { + const caseDeadlines = await getDbReader(reader => + reader + .selectFrom('dwCaseDeadline as cd') + .leftJoin('dwCase as c', 'c.docketNumber', 'cd.docketNumber') + .where('docketNumber', '=', docketNumber) + .selectAll() + .select('cd.docketNumber') + .execute(), + ); + + return caseDeadlines.map(message => caseDeadlineEntity(message)); +}; diff --git a/web-api/src/persistence/postgres/caseDeadlines/mapper.ts b/web-api/src/persistence/postgres/caseDeadlines/mapper.ts new file mode 100644 index 00000000000..6cb6ec39958 --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/mapper.ts @@ -0,0 +1,53 @@ +import { + CaseDeadline, + RawCaseDeadline, +} from '@shared/business/entities/CaseDeadline'; +import { NewCaseDeadlineKysely } from '@web-api/database-types'; +import { transformNullToUndefined } from '@web-api/persistence/postgres/utils/transformNullToUndefined'; + +function pickFields(deadline): NewCaseDeadlineKysely { + return { + associatedJudge: deadline.associatedJudge, + associatedJudgeId: deadline.associatedJudgeId, + caseDeadlineId: deadline.caseDeadlineId, + createdAt: deadline.createdAt, + deadlineDate: deadline.deadlineDate, + description: deadline.description, + docketNumber: deadline.docketNumber, + sortableDocketNumber: deadline.sortableDocketNumber, + }; +} + +// export function toKyselyUpdateMessage( +// message: RawMessage, +// ): UpdateMessageKysely { +// return pickFields(message); +// } + +// export function toKyselyUpdateMessages( +// messages: RawMessage[], +// ): UpdateMessageKysely[] { +// return messages.map(pickFields); +// } + +export function toKyselyNewCaseDeadline( + deadline: RawCaseDeadline, +): NewCaseDeadlineKysely { + return pickFields(deadline); +} + +// export function toKyselyNewMessages( +// messages: RawMessage[], +// ): NewMessageKysely[] { +// return messages.map(pickFields); +// } + +export function caseDeadlineEntity(caseDeadline) { + return new CaseDeadline( + transformNullToUndefined({ + ...caseDeadline, + createdAt: caseDeadline.createdAt.toISOString(), + deadlineDate: caseDeadline.deadlineDate?.toISOString(), + }), + ); +} diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts new file mode 100644 index 00000000000..f7349df9ce7 --- /dev/null +++ b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts @@ -0,0 +1,30 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely): Promise { + await db.schema + .createTable('dwCaseCorrespondence') + .addColumn('correspondenceId', 'varchar', col => col.primaryKey()) + .addColumn('documentTitle', 'varchar', col => col.notNull()) + .addColumn('filedBy', 'varchar') + .addColumn('userId', 'varchar', col => col.notNull()) + .addColumn('archived', 'boolean') + .addColumn('filingDate', 'timestamptz', col => col.notNull()) + .execute(); + + await db.schema + .createTable('dwCaseDeadline') + .addColumn('caseDeadlineId', 'varchar', col => col.primaryKey()) + .addColumn('description', 'varchar', col => col.notNull()) + .addColumn('docketNumber', 'varchar', col => col.notNull()) + .addColumn('sortableDocketNumber', 'int8', col => col.notNull()) + .addColumn('associatedJudge', 'varchar', col => col.notNull()) + .addColumn('associatedJudgeId', 'varchar', col => col.notNull()) + .addColumn('createdAt', 'timestamptz', col => col.notNull()) + .addColumn('deadlineDate', 'timestamptz', col => col.notNull()) + .execute(); +} + +export async function down(db: Kysely): Promise { + await db.schema.dropTable('dwCaseCorrespondence').execute(); + await db.schema.dropTable('dwCaseDeadline').execute(); +} From a0a6557591e8dae636093a6e5cdfad63ec025109 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 12:12:26 -0600 Subject: [PATCH 03/47] 10504: remove old case deadline queries --- .../caseDeadlines/createCaseDeadline.test.ts | 38 -------- .../caseDeadlines/createCaseDeadline.ts | 29 ------ .../caseDeadlines/deleteCaseDeadline.test.ts | 58 ------------ .../caseDeadlines/deleteCaseDeadline.ts | 47 ---------- .../getCaseDeadlinesByDocketNumber.test.ts | 66 ------------- .../getCaseDeadlinesByDocketNumber.ts | 22 ----- .../getCaseDeadlinesByDateRange.test.ts | 94 ------------------- .../getCaseDeadlinesByDateRange.ts | 66 ------------- 8 files changed, 420 deletions(-) delete mode 100644 web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.test.ts delete mode 100644 web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.ts delete mode 100644 web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.test.ts delete mode 100644 web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.ts delete mode 100644 web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.test.ts delete mode 100644 web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.ts delete mode 100644 web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.test.ts delete mode 100644 web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.ts diff --git a/web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.test.ts b/web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.test.ts deleted file mode 100644 index 4697f7a5d47..00000000000 --- a/web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; -import { createCaseDeadline } from './createCaseDeadline'; - -describe('createCaseDeadline', () => { - const CASE_DEADLINE_ID = '6805d1ab-18d0-43ec-bafb-654e83405416'; - - const mockCaseDeadline = { - caseDeadlineId: CASE_DEADLINE_ID, - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'hello world', - docketNumber: '123-20', - } as any; - - it('attempts to persist the case deadline', async () => { - await createCaseDeadline({ - applicationContext, - caseDeadline: mockCaseDeadline, - }); - - expect( - applicationContext.getDocumentClient().put.mock.calls[0][0], - ).toMatchObject({ - Item: { - caseDeadlineId: CASE_DEADLINE_ID, - pk: `case-deadline|${CASE_DEADLINE_ID}`, - sk: `case-deadline|${CASE_DEADLINE_ID}`, - }, - }); - expect( - applicationContext.getDocumentClient().put.mock.calls[1][0], - ).toMatchObject({ - Item: { - pk: 'case|123-20', - sk: `case-deadline|${CASE_DEADLINE_ID}`, - }, - }); - }); -}); diff --git a/web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.ts b/web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.ts deleted file mode 100644 index 45dd3cf49eb..00000000000 --- a/web-api/src/persistence/dynamo/caseDeadlines/createCaseDeadline.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; -import { put } from '../../dynamodbClientService'; - -export const createCaseDeadline = ({ - applicationContext, - caseDeadline, -}: { - applicationContext: IApplicationContext; - caseDeadline: RawCaseDeadline; -}) => { - const { caseDeadlineId, docketNumber } = caseDeadline; - return Promise.all([ - put({ - Item: { - ...caseDeadline, - pk: `case-deadline|${caseDeadlineId}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - applicationContext, - }), - put({ - Item: { - pk: `case|${docketNumber}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - applicationContext, - }), - ]); -}; diff --git a/web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.test.ts b/web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.test.ts deleted file mode 100644 index 8804ee9a916..00000000000 --- a/web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; -import { deleteCaseDeadline } from './deleteCaseDeadline'; - -describe('deleteCaseDeadline', () => { - const CASE_DEADLINE_ID = '6805d1ab-18d0-43ec-bafb-654e83405416'; - - const mockCaseDeadline = { - caseDeadlineId: CASE_DEADLINE_ID, - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'hello world', - docketNumber: '123-20', - }; - - beforeEach(() => { - applicationContext - .getDocumentClient() - .get.mockResolvedValue({ Item: mockCaseDeadline }); - }); - - it('deletes the case deadline records', async () => { - await deleteCaseDeadline({ - applicationContext, - caseDeadlineId: CASE_DEADLINE_ID, - docketNumber: '456-20', - }); - - expect( - applicationContext.getDocumentClient().delete.mock.calls[0][0], - ).toMatchObject({ - Key: { - pk: `case-deadline|${CASE_DEADLINE_ID}`, - sk: `case-deadline|${CASE_DEADLINE_ID}`, - }, - }); - expect( - applicationContext.getDocumentClient().delete.mock.calls[1][0], - ).toMatchObject({ - Key: { - pk: 'case|456-20', - sk: `case-deadline|${CASE_DEADLINE_ID}`, - }, - }); - }); - - it('does not call delete function if original case deadline is not found', async () => { - applicationContext.getDocumentClient().get.mockResolvedValue({}); - - await deleteCaseDeadline({ - applicationContext, - caseDeadlineId: CASE_DEADLINE_ID, - docketNumber: '456-20', - }); - - expect( - applicationContext.getDocumentClient().delete, - ).not.toHaveBeenCalled(); - }); -}); diff --git a/web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.ts b/web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.ts deleted file mode 100644 index fc25528ca4e..00000000000 --- a/web-api/src/persistence/dynamo/caseDeadlines/deleteCaseDeadline.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { get, remove } from '../../dynamodbClientService'; - -/** - * deleteCaseDeadline - * - * @param {object} providers the providers object - * @param {object} providers.applicationContext the application context - * @param {string} providers.caseDeadlineId the id of the case deadline to delete - * @param {string} providers.docketNumber the docket number of the case the deadline is attached to - * @returns {Array} the promises for the persistence delete calls - */ -export const deleteCaseDeadline = async ({ - applicationContext, - caseDeadlineId, - docketNumber, -}: { - applicationContext: IApplicationContext; - caseDeadlineId: string; - docketNumber: string; -}) => { - const originalCaseDeadline = await get({ - Key: { - pk: `case-deadline|${caseDeadlineId}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - applicationContext, - }); - - if (originalCaseDeadline) { - await Promise.all([ - remove({ - applicationContext, - key: { - pk: `case-deadline|${caseDeadlineId}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - }), - remove({ - applicationContext, - key: { - pk: `case|${docketNumber}`, - sk: `case-deadline|${caseDeadlineId}`, - }, - }), - ]); - } -}; diff --git a/web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.test.ts b/web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.test.ts deleted file mode 100644 index 124facffcd8..00000000000 --- a/web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; -import { batchGet, query } from '../../dynamodbClientService'; -import { getCaseDeadlinesByDocketNumber } from './getCaseDeadlinesByDocketNumber'; - -jest.mock('../../dynamodbClientService', () => ({ - batchGet: jest.fn(), - query: jest.fn(), -})); - -const mockCaseDeadline = { - caseDeadlineId: '6805d1ab-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'hello world', - docketNumber: '123-20', -}; - -describe('getCaseDeadlinesByDocketNumber', () => { - const mockBatchGet = batchGet as jest.Mock; - const mockQuery = query as jest.Mock; - - beforeEach(() => { - mockBatchGet.mockReturnValue([ - { - ...mockCaseDeadline, - pk: `case-deadline|${mockCaseDeadline.caseDeadlineId}`, - sk: `case-deadline|${mockCaseDeadline.caseDeadlineId}`, - }, - ]); - mockQuery.mockReturnValue([ - { - pk: `case|${mockCaseDeadline.docketNumber}`, - sk: `case-deadline|${mockCaseDeadline.caseDeadlineId}`, - }, - ]); - }); - - it('should return data as received from persistence', async () => { - const result = await getCaseDeadlinesByDocketNumber({ - applicationContext, - docketNumber: mockCaseDeadline.docketNumber, - }); - expect(result).toEqual([ - { - caseDeadlineId: '6805d1ab-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'hello world', - docketNumber: '123-20', - pk: 'case-deadline|6805d1ab-18d0-43ec-bafb-654e83405416', - sk: 'case-deadline|6805d1ab-18d0-43ec-bafb-654e83405416', - }, - ]); - }); - - it('should attempt to do a batch get in the same ids that were returned in the mapping records', async () => { - await getCaseDeadlinesByDocketNumber({ - applicationContext, - docketNumber: mockCaseDeadline.docketNumber, - }); - expect(mockBatchGet.mock.calls[0][0].keys).toEqual([ - { - pk: 'case-deadline|6805d1ab-18d0-43ec-bafb-654e83405416', - sk: 'case-deadline|6805d1ab-18d0-43ec-bafb-654e83405416', - }, - ]); - }); -}); diff --git a/web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.ts b/web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.ts deleted file mode 100644 index 51c13a2ece9..00000000000 --- a/web-api/src/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { getRecordsViaMapping } from '../helpers/getRecordsViaMapping'; - -/** - * getCaseDeadlinesByDocketNumber - * - * @param {object} providers the providers object - * @param {object} providers.applicationContext the application context - * @param {string} providers.docketNumber the docket number of the case to get the case deadlines for - * @returns {Promise} the promise of the persistence call to get the records - */ -export const getCaseDeadlinesByDocketNumber = ({ - applicationContext, - docketNumber, -}: { - applicationContext: IApplicationContext; - docketNumber: string; -}) => - getRecordsViaMapping({ - applicationContext, - pk: `case|${docketNumber}`, - prefix: 'case-deadline', - }); diff --git a/web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.test.ts b/web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.test.ts deleted file mode 100644 index 70066f54342..00000000000 --- a/web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.test.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; -import { getCaseDeadlinesByDateRange } from './getCaseDeadlinesByDateRange'; -jest.mock('../searchClient'); -import { DEADLINE_REPORT_PAGE_SIZE } from '../../../../../shared/src/business/entities/EntityConstants'; -import { search } from '../searchClient'; - -describe('getCaseDeadlinesByDateRange', () => { - const START_DATE = '2019-08-25T05:00:00.000Z'; - const END_DATE = '2020-08-25T05:00:00.000Z'; - - it('returns results from the search client using default page size if one is not passed in', async () => { - (search as jest.Mock).mockReturnValue({ - results: ['some', 'matches'], - total: 2, - }); - - const results = await getCaseDeadlinesByDateRange({ - applicationContext, - endDate: END_DATE, - startDate: START_DATE, - }); - - expect(search).toHaveBeenCalledTimes(1); - expect(results).toMatchObject({ - foundDeadlines: ['some', 'matches'], - totalCount: 2, - }); - - const callParam = (search as jest.Mock).mock.calls[0][0]; - expect(callParam.searchParameters.body.size).toEqual( - DEADLINE_REPORT_PAGE_SIZE, - ); - expect(callParam.searchParameters.body.from).toEqual(0); - expect( - callParam.searchParameters.body.query.bool.filter[0].range[ - 'deadlineDate.S' - ].gte, - ).toEqual(`${START_DATE}||/h`); - expect( - callParam.searchParameters.body.query.bool.filter[0].range[ - 'deadlineDate.S' - ].lte, - ).toEqual(`${END_DATE}||/h`); - }); - - it('returns results from the search client using pageSize that is passed in if it is less than DEADLINE_REPORT_PAGE_SIZE', async () => { - await getCaseDeadlinesByDateRange({ - applicationContext, - endDate: END_DATE, - from: 20, - pageSize: DEADLINE_REPORT_PAGE_SIZE - 1, - startDate: START_DATE, - }); - - const callParam = (search as jest.Mock).mock.calls[0][0]; - expect(callParam.searchParameters.body.size).toEqual( - DEADLINE_REPORT_PAGE_SIZE - 1, - ); - expect(callParam.searchParameters.body.from).toEqual(20); - }); - - it('returns results from the search client using default DEADLINE_REPORT_PAGE_SIZE if pageSize is greater than DEADLINE_REPORT_PAGE_SIZE', async () => { - await getCaseDeadlinesByDateRange({ - applicationContext, - endDate: END_DATE, - pageSize: DEADLINE_REPORT_PAGE_SIZE + 1, - startDate: START_DATE, - }); - - const callParam = (search as jest.Mock).mock.calls[0][0]; - expect(callParam.searchParameters.body.size).toEqual( - DEADLINE_REPORT_PAGE_SIZE, - ); - }); - - it('adds judge query to search client call if judge is provided', async () => { - await getCaseDeadlinesByDateRange({ - applicationContext, - endDate: END_DATE, - judge: 'Buch', - pageSize: 1, - startDate: START_DATE, - }); - - const callParam = (search as jest.Mock).mock.calls[0][0]; - expect(callParam.searchParameters.body.query.bool.must[0]).toEqual({ - simple_query_string: { - default_operator: 'and', - fields: ['associatedJudge.S'], - query: '"Buch"', - }, - }); - }); -}); diff --git a/web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.ts b/web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.ts deleted file mode 100644 index cc1c223960d..00000000000 --- a/web-api/src/persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { DEADLINE_REPORT_PAGE_SIZE } from '../../../../../shared/src/business/entities/EntityConstants'; -import { search } from '../searchClient'; - -export const getCaseDeadlinesByDateRange = async ({ - applicationContext, - endDate, - from = 0, - judge, - pageSize, - startDate, -}) => { - const size = - pageSize && pageSize <= DEADLINE_REPORT_PAGE_SIZE - ? pageSize - : DEADLINE_REPORT_PAGE_SIZE; - - const queryArray = []; - const filterArray = [ - { - range: { - 'deadlineDate.S': { - gte: `${startDate}||/h`, - lte: `${endDate}||/h`, - }, - }, - }, - ]; - - if (judge) { - queryArray.push({ - simple_query_string: { - default_operator: 'and', - fields: ['associatedJudge.S'], - query: `"${judge}"`, - }, - }); - } - - const query = { - body: { - from, - query: { - bool: { - filter: filterArray, - must: queryArray, - }, - }, - size, - sort: [ - { 'deadlineDate.S': { order: 'asc' } }, - { 'sortableDocketNumber.N': { order: 'asc' } }, - ], - }, - index: 'efcms-case-deadline', - }; - - const { results, total } = await search({ - applicationContext, - searchParameters: query, - }); - - return { - foundDeadlines: results, - totalCount: total, - }; -}; From 8af8eddbc00cacf398d19e8d6d0d2b0126044f42 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 12:29:19 -0600 Subject: [PATCH 04/47] 10504: add seed data --- web-api/src/database-types.ts | 6 +- web-api/src/getPersistenceGateway.ts | 8 -- .../getCaseDeadlinesByDateRange.ts | 12 +-- .../0005-case-deadline-correspondence.ts | 2 +- .../utils/seed/fixtures/caseDeadlines.ts | 70 +++++++++++++++ .../persistence/postgres/utils/seed/seed.ts | 12 ++- .../storage/fixtures/seed/efcms-local.json | 85 ------------------- 7 files changed, 92 insertions(+), 103 deletions(-) create mode 100644 web-api/src/persistence/postgres/utils/seed/fixtures/caseDeadlines.ts diff --git a/web-api/src/database-types.ts b/web-api/src/database-types.ts index 387077c4e3c..d03962033a5 100644 --- a/web-api/src/database-types.ts +++ b/web-api/src/database-types.ts @@ -66,10 +66,10 @@ export type UpdateCaseCorrespondenceKysely = export interface CaseDeadlineTable { associatedJudge: string; - associatedJudgeId: string; + associatedJudgeId?: string; caseDeadlineId: string; - createdAt: string; - deadlineDate: string; + createdAt: Date; + deadlineDate: Date; description: string; docketNumber: string; sortableDocketNumber: number; diff --git a/web-api/src/getPersistenceGateway.ts b/web-api/src/getPersistenceGateway.ts index fb449d28cfb..490593a5cf1 100644 --- a/web-api/src/getPersistenceGateway.ts +++ b/web-api/src/getPersistenceGateway.ts @@ -9,7 +9,6 @@ import { bulkIndexRecords } from './persistence/elasticsearch/bulkIndexRecords'; import { caseAdvancedSearch } from './persistence/elasticsearch/caseAdvancedSearch'; import { casePublicSearch as casePublicSearchPersistence } from './persistence/elasticsearch/casePublicSearch'; import { createCase } from './persistence/dynamo/cases/createCase'; -import { createCaseDeadline } from './persistence/dynamo/caseDeadlines/createCaseDeadline'; import { createCaseTrialSortMappingRecords } from './persistence/dynamo/cases/createCaseTrialSortMappingRecords'; import { createChangeOfAddressJob } from './persistence/dynamo/jobs/ChangeOfAddress/createChangeOfAddressJob'; import { createJobStatus } from './persistence/dynamo/trialSessions/createJobStatus'; @@ -26,7 +25,6 @@ import { createTrialSession } from './persistence/dynamo/trialSessions/createTri import { createTrialSessionWorkingCopy } from './persistence/dynamo/trialSessions/createTrialSessionWorkingCopy'; import { createUserRecords } from './persistence/dynamo/users/createUserRecords'; import { decrementJobCounter } from './persistence/dynamo/trialSessions/decrementJobCounter'; -import { deleteCaseDeadline } from './persistence/dynamo/caseDeadlines/deleteCaseDeadline'; import { deleteCaseTrialSortMappingRecords } from './persistence/dynamo/cases/deleteCaseTrialSortMappingRecords'; import { deleteDocketEntry } from './persistence/dynamo/documents/deleteDocketEntry'; import { deleteDocketEntryWorksheetRecord } from '@web-api/persistence/dynamo/pendingMotion/deleteDocketEntryWorksheetRecord'; @@ -57,8 +55,6 @@ import { getAllWebSocketConnections } from './persistence/dynamo/notifications/g import { getBlockedCases } from './persistence/elasticsearch/getBlockedCases'; import { getCalendaredCasesForTrialSession } from './persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession'; import { getCaseByDocketNumber } from './persistence/dynamo/cases/getCaseByDocketNumber'; -import { getCaseDeadlinesByDateRange } from './persistence/elasticsearch/caseDeadlines/getCaseDeadlinesByDateRange'; -import { getCaseDeadlinesByDocketNumber } from './persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getCaseInventoryReport } from './persistence/elasticsearch/getCaseInventoryReport'; import { getCaseMetadataByDocketNumber } from './persistence/dynamo/cases/getCaseMetadataByDocketNumber'; import { getCaseMetadataWithCounsel } from './persistence/dynamo/cases/getCaseMetadataWithCounsel'; @@ -213,7 +209,6 @@ const gatewayMethods = { bulkDeleteRecords, bulkIndexRecords, createCase, - createCaseDeadline, createCaseTrialSortMappingRecords, createJobStatus, createNewPetitionerUser, @@ -266,7 +261,6 @@ const gatewayMethods = { createChangeOfAddressJob, createLock, decrementJobCounter, - deleteCaseDeadline, deleteCaseTrialSortMappingRecords, deleteDocketEntry, deleteDocketEntryWorksheetRecord, @@ -289,8 +283,6 @@ const gatewayMethods = { getBlockedCases, getCalendaredCasesForTrialSession, getCaseByDocketNumber, - getCaseDeadlinesByDateRange, - getCaseDeadlinesByDocketNumber, getCaseInventoryReport, getCaseMetadataByDocketNumber, getCaseMetadataWithCounsel, diff --git a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts index fb69ba5d4b5..b60f23a0a8f 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange.ts @@ -17,10 +17,12 @@ export const getCaseDeadlinesByDateRange = async ({ const { results: caseDeadlines, total: totalCount } = await getDbReader( async reader => { let deadlineQuery = reader - .selectFrom('dwCaseDeadline') + .selectFrom('dwCaseDeadline as cd') + .leftJoin('dwCase as c', 'c.docketNumber', 'cd.docketNumber') .selectAll() - .where('deadlineDate', '>=', startDate) - .where('deadlineDate', '<=', endDate); + .select('cd.docketNumber') + .where('cd.deadlineDate', '>=', startDate) + .where('cd.deadlineDate', '<=', endDate); if (judge) { deadlineQuery = deadlineQuery.where('associatedJudge', '=', judge); @@ -29,8 +31,8 @@ export const getCaseDeadlinesByDateRange = async ({ deadlineQuery = deadlineQuery .offset(from) .limit(size) - .orderBy('deadlineDate', 'asc') - .orderBy('sortableDocketNumber', 'asc'); + .orderBy('cd.deadlineDate', 'asc') + .orderBy('cd.sortableDocketNumber', 'asc'); const results = await deadlineQuery.execute(); diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts index f7349df9ce7..a29a966dc84 100644 --- a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts +++ b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts @@ -18,7 +18,7 @@ export async function up(db: Kysely): Promise { .addColumn('docketNumber', 'varchar', col => col.notNull()) .addColumn('sortableDocketNumber', 'int8', col => col.notNull()) .addColumn('associatedJudge', 'varchar', col => col.notNull()) - .addColumn('associatedJudgeId', 'varchar', col => col.notNull()) + .addColumn('associatedJudgeId', 'varchar') .addColumn('createdAt', 'timestamptz', col => col.notNull()) .addColumn('deadlineDate', 'timestamptz', col => col.notNull()) .execute(); diff --git a/web-api/src/persistence/postgres/utils/seed/fixtures/caseDeadlines.ts b/web-api/src/persistence/postgres/utils/seed/fixtures/caseDeadlines.ts new file mode 100644 index 00000000000..d01ed851dab --- /dev/null +++ b/web-api/src/persistence/postgres/utils/seed/fixtures/caseDeadlines.ts @@ -0,0 +1,70 @@ +/* eslint-disable @miovision/disallow-date/no-new-date */ + +import { NewCaseDeadlineKysely } from '@web-api/database-types'; + +export const caseDeadlines: NewCaseDeadlineKysely[] = [ + { + associatedJudge: 'Chief Judge', + caseDeadlineId: '08855730-3047-4ca6-a9e7-16ff64c9dcaa', + createdAt: new Date('2019-08-22T12:46:01.052Z'), + deadlineDate: new Date('2019-08-22T04:00:00.000Z'), + description: 'Pre-trial memorandum due', + docketNumber: '104-19', + sortableDocketNumber: 19000104, + }, + { + associatedJudge: 'Chief Judge', + caseDeadlineId: '0f5a666d-63c5-4378-9cd6-0b2ae141280f', + createdAt: new Date('2019-08-22T12:49:10.949Z'), + deadlineDate: new Date('2019-08-23T04:00:00.000Z'), + description: 'This is a test deadline', + docketNumber: '106-19', + sortableDocketNumber: 19000106, + }, + { + associatedJudge: 'Chief Judge', + caseDeadlineId: '307fd0e4-eeed-41bc-bbc3-a9555fccc231', + createdAt: new Date('2019-08-22T12:51:32.434Z'), + deadlineDate: new Date('2019-08-22T04:00:00.000Z'), + description: 'Filing fee due', + docketNumber: '107-19', + sortableDocketNumber: 19000107, + }, + { + associatedJudge: 'Chief Judge', + caseDeadlineId: '95b46eae-70f0-45df-91de-febdc610fed9', + createdAt: new Date('2019-08-22T12:47:16.905Z'), + deadlineDate: new Date('2019-08-25T04:00:00.000Z'), + description: 'Final status report due to Judge Ashford', + docketNumber: '109-19', + sortableDocketNumber: 19000109, + }, + { + associatedJudge: 'Buch', + associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', + caseDeadlineId: 'ad1ddb24-f3c4-47b4-b10e-76d1d050b2ab', + createdAt: new Date('2020-01-01T01:02:15.185-04:00'), + deadlineDate: new Date('2020-01-24T00:00:00.000-05:00'), + description: 'Due date migrated from Blackstone', + docketNumber: '1338-20', + sortableDocketNumber: 20001338, + }, + { + associatedJudge: 'Chief Judge', + caseDeadlineId: 'e7aeadd8-b0d0-4826-af31-22c0d8c6c173', + createdAt: new Date('2020-01-01T01:02:15.185-04:00'), + deadlineDate: new Date('2020-01-24T00:00:00.000-05:00'), + description: 'Due date migrated from Blackstone', + docketNumber: '152-12', + sortableDocketNumber: 12000152, + }, + { + associatedJudge: 'Chief Judge', + caseDeadlineId: 'ff22fe63-4117-42ee-a66c-8cfd2062a057', + createdAt: new Date('2019-08-22T12:47:16.905Z'), + deadlineDate: new Date('2019-08-25T04:00:00.000Z'), + description: 'Final status report due to Judge Ashford', + docketNumber: '104-19', + sortableDocketNumber: 19000104, + }, +]; diff --git a/web-api/src/persistence/postgres/utils/seed/seed.ts b/web-api/src/persistence/postgres/utils/seed/seed.ts index e716873b12a..3430358f730 100644 --- a/web-api/src/persistence/postgres/utils/seed/seed.ts +++ b/web-api/src/persistence/postgres/utils/seed/seed.ts @@ -1,14 +1,24 @@ +import { caseDeadlines } from '@web-api/persistence/postgres/utils/seed/fixtures/caseDeadlines'; import { getDbWriter } from '../../../../database'; import { messages } from './fixtures/messages'; export const seed = async () => { - await getDbWriter(writer => + const insertMessages = getDbWriter(writer => writer .insertInto('dwMessage') .values(messages) .onConflict(oc => oc.column('messageId').doNothing()) // ensure doesn't fail if exists .execute(), ); + const insertCaseDeadline = getDbWriter(writer => + writer + .insertInto('dwCaseDeadline') + .values(caseDeadlines) + .onConflict(oc => oc.column('caseDeadlineId').doNothing()) // ensure doesn't fail if exists + .execute(), + ); + + await Promise.all([insertMessages, insertCaseDeadline]); }; seed().catch; diff --git a/web-api/storage/fixtures/seed/efcms-local.json b/web-api/storage/fixtures/seed/efcms-local.json index f873badc8d6..1eb7df5a88d 100644 --- a/web-api/storage/fixtures/seed/efcms-local.json +++ b/web-api/storage/fixtures/seed/efcms-local.json @@ -100,91 +100,6 @@ "sk": "case|101-20", "pk": "case-by-docket-number|7805d1ab-18d0-43ec-bafb-654e83405416" }, - { - "associatedJudge": "Chief Judge", - "createdAt": "2019-08-22T12:46:01.052Z", - "deadlineDate": "2019-08-22T04:00:00.000Z", - "entityName": "CaseDeadline", - "sk": "case-deadline|08855730-3047-4ca6-a9e7-16ff64c9dcaa", - "caseDeadlineId": "08855730-3047-4ca6-a9e7-16ff64c9dcaa", - "sortableDocketNumber": 19000104, - "description": "Pre-trial memorandum due", - "pk": "case-deadline|08855730-3047-4ca6-a9e7-16ff64c9dcaa", - "docketNumber": "104-19" - }, - { - "associatedJudge": "Chief Judge", - "createdAt": "2019-08-22T12:49:10.949Z", - "deadlineDate": "2019-08-23T04:00:00.000Z", - "entityName": "CaseDeadline", - "sk": "case-deadline|0f5a666d-63c5-4378-9cd6-0b2ae141280f", - "caseDeadlineId": "0f5a666d-63c5-4378-9cd6-0b2ae141280f", - "sortableDocketNumber": 19000106, - "description": "This is a test deadline", - "pk": "case-deadline|0f5a666d-63c5-4378-9cd6-0b2ae141280f", - "docketNumber": "106-19" - }, - { - "associatedJudge": "Chief Judge", - "createdAt": "2019-08-22T12:51:32.434Z", - "deadlineDate": "2019-08-22T04:00:00.000Z", - "entityName": "CaseDeadline", - "sk": "case-deadline|307fd0e4-eeed-41bc-bbc3-a9555fccc231", - "caseDeadlineId": "307fd0e4-eeed-41bc-bbc3-a9555fccc231", - "sortableDocketNumber": 19000107, - "description": "Filing fee due", - "pk": "case-deadline|307fd0e4-eeed-41bc-bbc3-a9555fccc231", - "docketNumber": "107-19" - }, - { - "associatedJudge": "Chief Judge", - "createdAt": "2019-08-22T12:47:16.905Z", - "deadlineDate": "2019-08-25T04:00:00.000Z", - "entityName": "CaseDeadline", - "sk": "case-deadline|95b46eae-70f0-45df-91de-febdc610fed9", - "caseDeadlineId": "95b46eae-70f0-45df-91de-febdc610fed9", - "sortableDocketNumber": 19000109, - "description": "Final status report due to Judge Ashford", - "pk": "case-deadline|95b46eae-70f0-45df-91de-febdc610fed9", - "docketNumber": "109-19" - }, - { - "associatedJudge": "Buch", - "createdAt": "2020-01-01T01:02:15.185-04:00", - "entityName": "CaseDeadline", - "deadlineDate": "2020-01-24T00:00:00.000-05:00", - "sk": "case-deadline|ad1ddb24-f3c4-47b4-b10e-76d1d050b2ab", - "caseDeadlineId": "ad1ddb24-f3c4-47b4-b10e-76d1d050b2ab", - "sortableDocketNumber": 20001338, - "description": "Due date migrated from Blackstone", - "pk": "case-deadline|ad1ddb24-f3c4-47b4-b10e-76d1d050b2ab", - "docketNumber": "1338-20", - "associatedJudgeId": "dabbad02-18d0-43ec-bafb-654e83405416" - }, - { - "associatedJudge": "Chief Judge", - "createdAt": "2020-01-01T01:02:15.185-04:00", - "entityName": "CaseDeadline", - "deadlineDate": "2020-01-24T00:00:00.000-05:00", - "sk": "case-deadline|e7aeadd8-b0d0-4826-af31-22c0d8c6c173", - "caseDeadlineId": "e7aeadd8-b0d0-4826-af31-22c0d8c6c173", - "sortableDocketNumber": 12000152, - "description": "Due date migrated from Blackstone", - "pk": "case-deadline|e7aeadd8-b0d0-4826-af31-22c0d8c6c173", - "docketNumber": "152-12" - }, - { - "associatedJudge": "Chief Judge", - "createdAt": "2019-08-22T12:47:16.905Z", - "deadlineDate": "2019-08-25T04:00:00.000Z", - "entityName": "CaseDeadline", - "sk": "case-deadline|ff22fe63-4117-42ee-a66c-8cfd2062a057", - "caseDeadlineId": "ff22fe63-4117-42ee-a66c-8cfd2062a057", - "sortableDocketNumber": 19000104, - "description": "Final status report due to Judge Ashford", - "pk": "case-deadline|ff22fe63-4117-42ee-a66c-8cfd2062a057", - "docketNumber": "104-19" - }, { "associatedJudge": "Chief Judge", "isSealed": false, From 3d157abacd010b8fcc220389338a740fcafc2e6f Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 12:40:14 -0600 Subject: [PATCH 05/47] 10504: fix error with docket number --- .../postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts index 984b1a46044..8ccd8576d60 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts @@ -10,7 +10,7 @@ export const getCaseDeadlinesByDocketNumber = async ({ reader .selectFrom('dwCaseDeadline as cd') .leftJoin('dwCase as c', 'c.docketNumber', 'cd.docketNumber') - .where('docketNumber', '=', docketNumber) + .where('cd.docketNumber', '=', docketNumber) .selectAll() .select('cd.docketNumber') .execute(), From 1da7c2d09ad5851a6c327ca476eaa255e091ce96 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 13:22:05 -0600 Subject: [PATCH 06/47] 10504: add correspondence seed --- web-api/src/database-types.ts | 4 +++- .../0005-case-deadline-correspondence.ts | 2 ++ .../postgres/utils/seed/fixtures/correspodence.ts | 15 +++++++++++++++ .../src/persistence/postgres/utils/seed/seed.ts | 12 +++++++++++- web-api/storage/fixtures/seed/efcms-local.json | 10 ---------- 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts diff --git a/web-api/src/database-types.ts b/web-api/src/database-types.ts index d03962033a5..1fe3eb9c100 100644 --- a/web-api/src/database-types.ts +++ b/web-api/src/database-types.ts @@ -53,10 +53,12 @@ export type UpdateCaseKysely = Updateable; export interface CaseCorrespondenceTable { archived?: boolean; correspondenceId: string; + numberOfPages?: number; documentTitle: string; filedBy?: string; - filingDate: string; + filingDate: Date; userId: string; + docketNumber: string; } export type CaseCorrespondenceKysely = Selectable; diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts index a29a966dc84..7b3e6d0f3df 100644 --- a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts +++ b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts @@ -5,6 +5,8 @@ export async function up(db: Kysely): Promise { .createTable('dwCaseCorrespondence') .addColumn('correspondenceId', 'varchar', col => col.primaryKey()) .addColumn('documentTitle', 'varchar', col => col.notNull()) + .addColumn('docketNumber', 'varchar', col => col.notNull()) + .addColumn('numberOfPages', 'int8') .addColumn('filedBy', 'varchar') .addColumn('userId', 'varchar', col => col.notNull()) .addColumn('archived', 'boolean') diff --git a/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts b/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts new file mode 100644 index 00000000000..326eba0d742 --- /dev/null +++ b/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts @@ -0,0 +1,15 @@ +/* eslint-disable @miovision/disallow-date/no-new-date */ + +import { NewCaseCorrespondenceKysely } from '@web-api/database-types'; + +export const correspondence: NewCaseCorrespondenceKysely[] = [ + { + correspondenceId: 'f1aa4aa3-c214-424c-8870-d0049c5744d7', + docketNumber: '103-19', + documentTitle: 'Internal Memo', + filedBy: 'Test Petitionsclerk', + filingDate: new Date('2019-08-14T20:35:52.915Z'), + numberOfPages: 1, + userId: '3805d1ab-18d0-43ec-bafb-654e83405416', + }, +]; diff --git a/web-api/src/persistence/postgres/utils/seed/seed.ts b/web-api/src/persistence/postgres/utils/seed/seed.ts index 3430358f730..29b5ce059e1 100644 --- a/web-api/src/persistence/postgres/utils/seed/seed.ts +++ b/web-api/src/persistence/postgres/utils/seed/seed.ts @@ -1,4 +1,5 @@ import { caseDeadlines } from '@web-api/persistence/postgres/utils/seed/fixtures/caseDeadlines'; +import { correspondence } from '@web-api/persistence/postgres/utils/seed/fixtures/correspodence'; import { getDbWriter } from '../../../../database'; import { messages } from './fixtures/messages'; @@ -10,6 +11,7 @@ export const seed = async () => { .onConflict(oc => oc.column('messageId').doNothing()) // ensure doesn't fail if exists .execute(), ); + const insertCaseDeadline = getDbWriter(writer => writer .insertInto('dwCaseDeadline') @@ -18,7 +20,15 @@ export const seed = async () => { .execute(), ); - await Promise.all([insertMessages, insertCaseDeadline]); + const insertCorrespondence = getDbWriter(writer => + writer + .insertInto('dwCaseCorrespondence') + .values(correspondence) + .onConflict(oc => oc.column('correspondenceId').doNothing()) // ensure doesn't fail if exists + .execute(), + ); + + await Promise.all([insertMessages, insertCaseDeadline, insertCorrespondence]); }; seed().catch; diff --git a/web-api/storage/fixtures/seed/efcms-local.json b/web-api/storage/fixtures/seed/efcms-local.json index 1eb7df5a88d..8c4125868b4 100644 --- a/web-api/storage/fixtures/seed/efcms-local.json +++ b/web-api/storage/fixtures/seed/efcms-local.json @@ -11807,16 +11807,6 @@ "docketNumber": "103-19", "status": "New" }, - { - "numberOfPages": 1, - "filingDate": "2019-08-14T20:35:52.915Z", - "filedBy": "Test Petitionsclerk", - "sk": "correspondence|f1aa4aa3-c214-424c-8870-d0049c5744d7", - "correspondenceId": "f1aa4aa3-c214-424c-8870-d0049c5744d7", - "pk": "case|103-19", - "documentTitle": "Internal Memo", - "userId": "3805d1ab-18d0-43ec-bafb-654e83405416" - }, { "servedParties": [ { From d13d26c302481691716cc3c35d0703d99324237c Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 14:02:43 -0600 Subject: [PATCH 07/47] 10491: add case correspondence --- .../updateCaseAndAssociations.ts | 13 +++-- ...archiveCorrespondenceDocumentInteractor.ts | 4 +- .../fileCorrespondenceDocumentInteractor.ts | 4 +- .../updateCorrespondenceDocumentInteractor.ts | 4 +- web-api/src/getPersistenceGateway.ts | 2 - .../dynamo/cases/getCaseByDocketNumber.ts | 35 ++++++++----- .../updateCaseCorrespondence.test.ts | 46 ----------------- .../updateCaseCorrespondence.ts | 28 ----------- .../getCaseCorrespondenceByDocketNumber.ts | 21 ++++++++ .../postgres/correspondence/mapper.ts | 48 ++++++++++++++++++ .../updateCaseCorrespondence.ts | 49 ++++++++++--------- 11 files changed, 131 insertions(+), 123 deletions(-) delete mode 100644 web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.test.ts delete mode 100644 web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.ts create mode 100644 web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts create mode 100644 web-api/src/persistence/postgres/correspondence/mapper.ts diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index 1c133bbc7fa..7720f526397 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -11,6 +11,7 @@ import { WorkItem } from '../../../../../shared/src/business/entities/WorkItem'; import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; +import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; import diff from 'diff-arrays-of-objects'; @@ -122,6 +123,7 @@ const updateCaseMessages = async ({ * @returns {Array} the persistence functions required to complete this action */ const updateCorrespondence = ({ + // eslint-disable-next-line @typescript-eslint/no-unused-vars applicationContext, caseToUpdate, oldCase, @@ -151,13 +153,10 @@ const updateCorrespondence = ({ return validCorrespondence.map( correspondence => function updateCorrespondence_cb() { - return applicationContext - .getPersistenceGateway() - .updateCaseCorrespondence({ - applicationContext, - correspondence, - docketNumber: caseToUpdate.docketNumber, - }); + return updateCaseCorrespondence({ + correspondence, + docketNumber: caseToUpdate.docketNumber, + }); }, ); }; diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts index 758b9d52246..34f7b083646 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts @@ -6,6 +6,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const archiveCorrespondenceDocument = async ( @@ -36,8 +37,7 @@ export const archiveCorrespondenceDocument = async ( caseEntity.archiveCorrespondence(correspondenceToArchiveEntity); - await applicationContext.getPersistenceGateway().updateCaseCorrespondence({ - applicationContext, + await updateCaseCorrespondence({ correspondence: correspondenceToArchiveEntity.validate().toRawObject(), docketNumber, }); diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts index 75fdb4eacea..42af04d28dc 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts @@ -7,6 +7,7 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; /** * fileCorrespondenceDocumentInteractor @@ -58,8 +59,7 @@ export const fileCorrespondenceDocumentInteractor = async ( caseEntity.fileCorrespondence(correspondenceEntity); if (caseEntity.validate()) { - await applicationContext.getPersistenceGateway().updateCaseCorrespondence({ - applicationContext, + await updateCaseCorrespondence({ correspondence: correspondenceEntity.validate().toRawObject(), docketNumber, }); diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts index 80228e52194..8279aefaca1 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts @@ -7,6 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; export const updateCorrespondenceDocumentInteractor = async ( applicationContext: ServerApplicationContext, @@ -41,8 +42,7 @@ export const updateCorrespondenceDocumentInteractor = async ( const caseEntityRaw = caseEntity.validate().toRawObject(); - await applicationContext.getPersistenceGateway().updateCaseCorrespondence({ - applicationContext, + await updateCaseCorrespondence({ correspondence: updatedCorrespondenceEntity.validate().toRawObject(), docketNumber, }); diff --git a/web-api/src/getPersistenceGateway.ts b/web-api/src/getPersistenceGateway.ts index 490593a5cf1..625491d2f69 100644 --- a/web-api/src/getPersistenceGateway.ts +++ b/web-api/src/getPersistenceGateway.ts @@ -143,7 +143,6 @@ import { setStoredApplicationHealth } from '@web-api/persistence/dynamo/deployTa import { setTrialSessionJobStatusForCase } from './persistence/dynamo/trialSessions/setTrialSessionJobStatusForCase'; import { setTrialSessionProcessingStatus } from './persistence/dynamo/trialSessions/setTrialSessionProcessingStatus'; import { updateCase } from './persistence/dynamo/cases/updateCase'; -import { updateCaseCorrespondence } from './persistence/dynamo/correspondence/updateCaseCorrespondence'; import { updateCaseHearing } from './persistence/dynamo/trialSessions/updateCaseHearing'; import { updateCaseWorksheet } from '@web-api/persistence/dynamo/caseWorksheet/updateCaseWorksheet'; import { updateDocketEntry } from './persistence/dynamo/documents/updateDocketEntry'; @@ -237,7 +236,6 @@ const gatewayMethods = { setTrialSessionJobStatusForCase, setTrialSessionProcessingStatus, updateCase, - updateCaseCorrespondence, updateCaseHearing, updateCaseWorksheet, updateDocketEntry, diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts index 5e9a6728179..ed79df9f976 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts @@ -9,6 +9,7 @@ import { aggregateConsolidatedCaseItems, isCaseItem, } from '../helpers/aggregateCaseItems'; +import { getCaseCorrespondenceByDocketNumber } from '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber'; import { purgeDynamoKeys } from '@web-api/persistence/dynamo/helpers/purgeDynamoKeys'; import { queryFull } from '../../dynamodbClientService'; @@ -21,16 +22,21 @@ export const getCaseByDocketNumber = async ({ docketNumber: string; includeConsolidatedCases?: boolean; }): Promise => { - const caseItems = await queryFull({ - ExpressionAttributeNames: { - '#pk': 'pk', - }, - ExpressionAttributeValues: { - ':pk': `case|${docketNumber}`, - }, - KeyConditionExpression: '#pk = :pk', - applicationContext, - }); + const [caseItems, correspodenceItems] = await Promise.all([ + queryFull({ + ExpressionAttributeNames: { + '#pk': 'pk', + }, + ExpressionAttributeValues: { + ':pk': `case|${docketNumber}`, + }, + KeyConditionExpression: '#pk = :pk', + applicationContext, + }), + getCaseCorrespondenceByDocketNumber({ + docketNumber, + }), + ]); const leadDocketNumber = caseItems.find((caseItem): caseItem is CaseRecord => isCaseItem(caseItem), @@ -55,7 +61,14 @@ export const getCaseByDocketNumber = async ({ } return purgeDynamoKeys({ - ...aggregateCaseItems(caseItems), + ...aggregateCaseItems([ + ...caseItems, + ...correspodenceItems.map(correspodenceItem => ({ + ...correspodenceItem, + pk: `case|${docketNumber}`, + sk: `correspondence|${correspodenceItem.correspondenceId}`, + })), + ]), consolidatedCases, }); }; diff --git a/web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.test.ts b/web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.test.ts deleted file mode 100644 index e818aef1247..00000000000 --- a/web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.test.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Correspondence } from '../../../../../shared/src/business/entities/Correspondence'; -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; -import { updateCaseCorrespondence } from './updateCaseCorrespondence'; - -describe('updateCaseCorrespondence', () => { - let putStub; - - beforeAll(() => { - putStub = jest.fn().mockResolvedValue(null); - - applicationContext.getDocumentClient.mockReturnValue({ - put: putStub, - }); - }); - - it('should update the specified correspondence record', async () => { - const mockGuid = applicationContext.getUniqueId(); - const mockCorrespondence = new Correspondence({ - archived: false, - correspondenceId: mockGuid, - documentTitle: 'My Correspondence', - filedBy: 'Docket clerk', - userId: mockGuid, - }); - - await updateCaseCorrespondence({ - applicationContext, - correspondence: mockCorrespondence, - docketNumber: '101-20', - }); - - expect( - applicationContext.getDocumentClient().put.mock.calls[0][0], - ).toMatchObject({ - Item: { - archived: false, - correspondenceId: mockGuid, - documentTitle: 'My Correspondence', - filedBy: 'Docket clerk', - pk: 'case|101-20', - sk: `correspondence|${mockGuid}`, - userId: mockGuid, - }, - }); - }); -}); diff --git a/web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.ts b/web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.ts deleted file mode 100644 index bb583599525..00000000000 --- a/web-api/src/persistence/dynamo/correspondence/updateCaseCorrespondence.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { put } from '../../dynamodbClientService'; - -/** - * updateCaseCorrespondence - * - * @param {object} providers the providers object - * @param {object} providers.applicationContext the application context - * @param {string} providers.docketNumber the docket number of the case the correspondence is attached to - * @param {string} providers.correspondence the correspondence document to update - * @returns {Promise} resolved promise upon completion of client request - */ -export const updateCaseCorrespondence = ({ - applicationContext, - correspondence, - docketNumber, -}: { - applicationContext: IApplicationContext; - correspondence: any; - docketNumber: string; -}) => - put({ - Item: { - ...correspondence, - pk: `case|${docketNumber}`, - sk: `correspondence|${correspondence.correspondenceId}`, - }, - applicationContext, - }); diff --git a/web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts b/web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts new file mode 100644 index 00000000000..855aa135589 --- /dev/null +++ b/web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts @@ -0,0 +1,21 @@ +import { Correspondence } from '@shared/business/entities/Correspondence'; +import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/correspondence/mapper'; +import { getDbReader } from '@web-api/database'; + +export const getCaseCorrespondenceByDocketNumber = async ({ + docketNumber, +}: { + docketNumber: string; +}): Promise => { + const correspondence = await getDbReader(reader => + reader + .selectFrom('dwCaseCorrespondence as cc') + .leftJoin('dwCase as c', 'c.docketNumber', 'cc.docketNumber') + .where('cc.docketNumber', '=', docketNumber) + .selectAll() + .select('cc.docketNumber') + .execute(), + ); + + return correspondence.map(c => caseCorrespondenceEntity(c)); +}; diff --git a/web-api/src/persistence/postgres/correspondence/mapper.ts b/web-api/src/persistence/postgres/correspondence/mapper.ts new file mode 100644 index 00000000000..7b9b5aaba24 --- /dev/null +++ b/web-api/src/persistence/postgres/correspondence/mapper.ts @@ -0,0 +1,48 @@ +import { Correspondence } from '@shared/business/entities/Correspondence'; +import { transformNullToUndefined } from '@web-api/persistence/postgres/utils/transformNullToUndefined'; + +// function pickFields(deadline): NewCaseCorrespondenceKysely { +// return { +// associatedJudge: deadline.associatedJudge, +// associatedJudgeId: deadline.associatedJudgeId, +// caseDeadlineId: deadline.caseDeadlineId, +// createdAt: deadline.createdAt, +// deadlineDate: deadline.deadlineDate, +// description: deadline.description, +// docketNumber: deadline.docketNumber, +// sortableDocketNumber: deadline.sortableDocketNumber, +// }; +// } + +// export function toKyselyUpdateMessage( +// message: RawMessage, +// ): UpdateMessageKysely { +// return pickFields(message); +// } + +// export function toKyselyUpdateMessages( +// messages: RawMessage[], +// ): UpdateMessageKysely[] { +// return messages.map(pickFields); +// } + +// export function toKyselyNewCaseDeadline( +// deadline: RawCaseDeadline, +// ): NewCaseDeadlineKysely { +// return pickFields(deadline); +// } + +// export function toKyselyNewMessages( +// messages: RawMessage[], +// ): NewMessageKysely[] { +// return messages.map(pickFields); +// } + +export function caseCorrespondenceEntity(caseCorrespondence) { + return new Correspondence( + transformNullToUndefined({ + ...caseCorrespondence, + filingDate: caseCorrespondence.filingDate.toISOString(), + }), + ); +} diff --git a/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts b/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts index bb583599525..993be08eb10 100644 --- a/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts +++ b/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts @@ -1,28 +1,31 @@ -import { put } from '../../dynamodbClientService'; +import { RawCorrespondence } from '@shared/business/entities/Correspondence'; +import { calculateDate } from '@shared/business/utilities/DateHandler'; +import { getDbWriter } from '@web-api/database'; -/** - * updateCaseCorrespondence - * - * @param {object} providers the providers object - * @param {object} providers.applicationContext the application context - * @param {string} providers.docketNumber the docket number of the case the correspondence is attached to - * @param {string} providers.correspondence the correspondence document to update - * @returns {Promise} resolved promise upon completion of client request - */ -export const updateCaseCorrespondence = ({ - applicationContext, +export const updateCaseCorrespondence = async ({ correspondence, docketNumber, }: { - applicationContext: IApplicationContext; - correspondence: any; + correspondence: RawCorrespondence; docketNumber: string; -}) => - put({ - Item: { - ...correspondence, - pk: `case|${docketNumber}`, - sk: `correspondence|${correspondence.correspondenceId}`, - }, - applicationContext, - }); +}) => { + const correspondenceToUpsert = { + archived: correspondence.archived, + correspondenceId: correspondence.correspondenceId, + docketNumber, + // numberOfPages: correspondence.numberOfPages, + documentTitle: correspondence.documentTitle, + filedBy: correspondence.filedBy, + filingDate: calculateDate({ dateString: correspondence.filingDate }), + userId: correspondence.userId, + }; + await getDbWriter(writer => + writer + .insertInto('dwCaseCorrespondence') + .values(correspondenceToUpsert) + .onConflict(oc => + oc.column('correspondenceId').doUpdateSet(correspondenceToUpsert), + ) + .execute(), + ); +}; From 98dcdf6f5f191b3b6ff7bc48849bd0140b446832 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Fri, 11 Oct 2024 14:43:08 -0600 Subject: [PATCH 08/47] 10504: add case worksheets --- .../updateCaseWorksheetInteractor.ts | 4 +- .../getCaseWorksheetsByJudgeInteractor.ts | 20 +++----- web-api/src/database-types.ts | 13 +++++ web-api/src/getPersistenceGateway.ts | 4 -- .../getCaseWorksheetsByDocketNumber.ts | 23 --------- .../caseWorksheet/updateCaseWorksheet.ts | 23 --------- .../getCaseWorksheetsByDocketNumber.ts | 21 ++++++++ .../postgres/caseWorksheet/mapper.ts | 48 +++++++++++++++++++ .../caseWorksheet/updateCaseWorksheet.ts | 35 ++++++++++++++ .../postgres/correspondence/mocks.jest.ts | 13 +++++ ...case-deadline-correspondence-worksheet.ts} | 10 ++++ .../utils/seed/fixtures/caseWorksheets.ts | 9 ++++ .../persistence/postgres/utils/seed/seed.ts | 16 ++++++- .../storage/fixtures/seed/efcms-local.json | 9 +--- 14 files changed, 173 insertions(+), 75 deletions(-) delete mode 100644 web-api/src/persistence/dynamo/caseWorksheet/getCaseWorksheetsByDocketNumber.ts delete mode 100644 web-api/src/persistence/dynamo/caseWorksheet/updateCaseWorksheet.ts create mode 100644 web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts create mode 100644 web-api/src/persistence/postgres/caseWorksheet/mapper.ts create mode 100644 web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts create mode 100644 web-api/src/persistence/postgres/correspondence/mocks.jest.ts rename web-api/src/persistence/postgres/utils/migrate/migrations/{0005-case-deadline-correspondence.ts => 0005-case-deadline-correspondence-worksheet.ts} (78%) create mode 100644 web-api/src/persistence/postgres/utils/seed/fixtures/caseWorksheets.ts diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts index 92b85e1e96d..0b65ad03e07 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts @@ -9,6 +9,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { updateCaseWorksheet } from '@web-api/persistence/postgres/caseWorksheet/updateCaseWorksheet'; export const updateCaseWorksheetInteractor = async ( applicationContext: ServerApplicationContext, @@ -31,8 +32,7 @@ export const updateCaseWorksheetInteractor = async ( const rawCaseWorksheet = caseWorksheetEntity.toRawObject(); - await applicationContext.getPersistenceGateway().updateCaseWorksheet({ - applicationContext, + await updateCaseWorksheet({ caseWorksheet: rawCaseWorksheet, judgeUserId: judgeUser.userId, }); diff --git a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts index 38fe6015f59..4c62e3d5d47 100644 --- a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts +++ b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts @@ -8,6 +8,7 @@ import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWo import { ServerApplicationContext } from '@web-api/applicationContext'; import { SubmittedCAVTableFields } from '@web-api/persistence/elasticsearch/getDocketNumbersByStatusAndByJudge'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; +import { getCaseWorksheetsByDocketNumber } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; export type GetCasesByStatusAndByJudgeRequest = { statuses: string[]; @@ -71,10 +72,7 @@ const getCases = async ( }, }); - const completeCaseRecords = await attachCaseWorkSheets( - applicationContext, - allCaseRecords, - ); + const completeCaseRecords = await attachCaseWorkSheets(allCaseRecords); return completeCaseRecords; }; @@ -95,16 +93,10 @@ const calculateNumberOfConsolidatedCases = async ( }); }; -async function attachCaseWorkSheets( - applicationContext: ServerApplicationContext, - cases: SubmittedCAVTableFields[], -) { - const caseWorksheets = await applicationContext - .getPersistenceGateway() - .getCaseWorksheetsByDocketNumber({ - applicationContext, - docketNumbers: cases.map(c => c.docketNumber), - }); +async function attachCaseWorkSheets(cases: SubmittedCAVTableFields[]) { + const caseWorksheets = await getCaseWorksheetsByDocketNumber({ + docketNumbers: cases.map(c => c.docketNumber), + }); const caseWorksheetMap: Map = new Map(); caseWorksheets.forEach(caseWorksheet => caseWorksheetMap.set(caseWorksheet.docketNumber, caseWorksheet), diff --git a/web-api/src/database-types.ts b/web-api/src/database-types.ts index 1fe3eb9c100..3436cbb70f9 100644 --- a/web-api/src/database-types.ts +++ b/web-api/src/database-types.ts @@ -5,6 +5,7 @@ export interface Database { dwCase: CaseTable; dwCaseCorrespondence: CaseCorrespondenceTable; dwCaseDeadline: CaseDeadlineTable; + dwCaseWorksheet: CaseWorksheetTable; } export interface MessageTable { @@ -80,3 +81,15 @@ export interface CaseDeadlineTable { export type CaseDeadlineKysely = Selectable; export type NewCaseDeadlineKysely = Insertable; export type UpdateCaseDeadlineKysely = Updateable; + +export interface CaseWorksheetTable { + docketNumber: string; + finalBriefDueDate?: Date; + primaryIssue?: string; + statusOfMatter?: string; + judgeUserId?: string; +} + +export type CaseWorksheetKysely = Selectable; +export type NewCaseWorksheetKysely = Insertable; +export type UpdateCaseWorksheetKysely = Updateable; diff --git a/web-api/src/getPersistenceGateway.ts b/web-api/src/getPersistenceGateway.ts index 625491d2f69..b06efbc63b5 100644 --- a/web-api/src/getPersistenceGateway.ts +++ b/web-api/src/getPersistenceGateway.ts @@ -58,7 +58,6 @@ import { getCaseByDocketNumber } from './persistence/dynamo/cases/getCaseByDocke import { getCaseInventoryReport } from './persistence/elasticsearch/getCaseInventoryReport'; import { getCaseMetadataByDocketNumber } from './persistence/dynamo/cases/getCaseMetadataByDocketNumber'; import { getCaseMetadataWithCounsel } from './persistence/dynamo/cases/getCaseMetadataWithCounsel'; -import { getCaseWorksheetsByDocketNumber } from '@web-api/persistence/dynamo/caseWorksheet/getCaseWorksheetsByDocketNumber'; import { getCasesByDocketNumbers } from './persistence/dynamo/cases/getCasesByDocketNumbers'; import { getCasesByFilters } from './persistence/elasticsearch/getCasesByFilters'; import { getCasesByLeadDocketNumber } from './persistence/dynamo/cases/getCasesByLeadDocketNumber'; @@ -144,7 +143,6 @@ import { setTrialSessionJobStatusForCase } from './persistence/dynamo/trialSessi import { setTrialSessionProcessingStatus } from './persistence/dynamo/trialSessions/setTrialSessionProcessingStatus'; import { updateCase } from './persistence/dynamo/cases/updateCase'; import { updateCaseHearing } from './persistence/dynamo/trialSessions/updateCaseHearing'; -import { updateCaseWorksheet } from '@web-api/persistence/dynamo/caseWorksheet/updateCaseWorksheet'; import { updateDocketEntry } from './persistence/dynamo/documents/updateDocketEntry'; import { updateDocketEntryPendingServiceStatus } from './persistence/dynamo/documents/updateDocketEntryPendingServiceStatus'; import { updateDocketEntryProcessingStatus } from './persistence/dynamo/documents/updateDocketEntryProcessingStatus'; @@ -237,7 +235,6 @@ const gatewayMethods = { setTrialSessionProcessingStatus, updateCase, updateCaseHearing, - updateCaseWorksheet, updateDocketEntry, updateDocketEntryPendingServiceStatus, updateDocketEntryProcessingStatus, @@ -284,7 +281,6 @@ const gatewayMethods = { getCaseInventoryReport, getCaseMetadataByDocketNumber, getCaseMetadataWithCounsel, - getCaseWorksheetsByDocketNumber, getCasesByDocketNumbers, getCasesByFilters, getCasesByLeadDocketNumber, diff --git a/web-api/src/persistence/dynamo/caseWorksheet/getCaseWorksheetsByDocketNumber.ts b/web-api/src/persistence/dynamo/caseWorksheet/getCaseWorksheetsByDocketNumber.ts deleted file mode 100644 index f1c3607b544..00000000000 --- a/web-api/src/persistence/dynamo/caseWorksheet/getCaseWorksheetsByDocketNumber.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { - CaseWorksheet, - RawCaseWorksheet, -} from '@shared/business/entities/caseWorksheet/CaseWorksheet'; -import { batchGet } from '../../dynamodbClientService'; - -export const getCaseWorksheetsByDocketNumber = async ({ - applicationContext, - docketNumbers, -}: { - applicationContext: IApplicationContext; - docketNumbers: string[]; -}): Promise => { - const result = await batchGet({ - applicationContext, - keys: docketNumbers.map(docketNumber => ({ - pk: `case|${docketNumber}`, - sk: `case-worksheet|${docketNumber}`, - })), - }); - - return result.map(item => new CaseWorksheet(item).toRawObject()); -}; diff --git a/web-api/src/persistence/dynamo/caseWorksheet/updateCaseWorksheet.ts b/web-api/src/persistence/dynamo/caseWorksheet/updateCaseWorksheet.ts deleted file mode 100644 index 1e720b53a53..00000000000 --- a/web-api/src/persistence/dynamo/caseWorksheet/updateCaseWorksheet.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; -import { TDynamoRecord } from '@web-api/persistence/dynamo/dynamoTypes'; -import { put } from '../../dynamodbClientService'; - -export const updateCaseWorksheet = async ({ - applicationContext, - caseWorksheet, - judgeUserId, -}: { - applicationContext: IApplicationContext; - caseWorksheet: RawCaseWorksheet; - judgeUserId: string; -}): Promise => { - return await put({ - Item: { - gsi1pk: `judge-case-worksheet|${judgeUserId}`, - pk: `case|${caseWorksheet.docketNumber}`, - sk: `case-worksheet|${caseWorksheet.docketNumber}`, - ...caseWorksheet, - }, - applicationContext, - }); -}; diff --git a/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts b/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts new file mode 100644 index 00000000000..ad77362073e --- /dev/null +++ b/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts @@ -0,0 +1,21 @@ +import { CaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { caseWorksheetEntity } from '@web-api/persistence/postgres/caseWorksheet/mapper'; +import { getDbReader } from '@web-api/database'; + +export const getCaseWorksheetsByDocketNumber = async ({ + docketNumbers, +}: { + docketNumbers: string[]; +}): Promise => { + const caseWorksheets = await getDbReader(reader => + reader + .selectFrom('dwCaseCorrespondence') + .where('docketNumber', 'in', docketNumbers) + .selectAll() + .execute(), + ); + + return caseWorksheets.map(caseWorkSheet => + caseWorksheetEntity(caseWorkSheet), + ); +}; diff --git a/web-api/src/persistence/postgres/caseWorksheet/mapper.ts b/web-api/src/persistence/postgres/caseWorksheet/mapper.ts new file mode 100644 index 00000000000..b8366eeae49 --- /dev/null +++ b/web-api/src/persistence/postgres/caseWorksheet/mapper.ts @@ -0,0 +1,48 @@ +import { CaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { transformNullToUndefined } from '@web-api/persistence/postgres/utils/transformNullToUndefined'; + +// function pickFields(deadline): NewCaseCorrespondenceKysely { +// return { +// associatedJudge: deadline.associatedJudge, +// associatedJudgeId: deadline.associatedJudgeId, +// caseDeadlineId: deadline.caseDeadlineId, +// createdAt: deadline.createdAt, +// deadlineDate: deadline.deadlineDate, +// description: deadline.description, +// docketNumber: deadline.docketNumber, +// sortableDocketNumber: deadline.sortableDocketNumber, +// }; +// } + +// export function toKyselyUpdateMessage( +// message: RawMessage, +// ): UpdateMessageKysely { +// return pickFields(message); +// } + +// export function toKyselyUpdateMessages( +// messages: RawMessage[], +// ): UpdateMessageKysely[] { +// return messages.map(pickFields); +// } + +// export function toKyselyNewCaseDeadline( +// deadline: RawCaseDeadline, +// ): NewCaseDeadlineKysely { +// return pickFields(deadline); +// } + +// export function toKyselyNewMessages( +// messages: RawMessage[], +// ): NewMessageKysely[] { +// return messages.map(pickFields); +// } + +export function caseWorksheetEntity(caseWorksheet) { + return new CaseWorksheet( + transformNullToUndefined({ + ...caseWorksheet, + filingDate: caseWorksheet.finalBriefDueDate.toISOString(), + }), + ); +} diff --git a/web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts b/web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts new file mode 100644 index 00000000000..70df69b9bdb --- /dev/null +++ b/web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts @@ -0,0 +1,35 @@ +import { + CaseWorksheet, + RawCaseWorksheet, +} from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { calculateDate } from '@shared/business/utilities/DateHandler'; +import { getDbWriter } from '@web-api/database'; + +export const updateCaseWorksheet = async ({ + caseWorksheet, + judgeUserId, +}: { + caseWorksheet: RawCaseWorksheet; + judgeUserId: string; +}): Promise => { + const caseWorksheetToUpsert = { + docketNumber: caseWorksheet.docketNumber, + finalBriefDueDate: calculateDate({ + dateString: caseWorksheet.finalBriefDueDate, + }), + judgeUserId, + primaryIssue: caseWorksheet.primaryIssue, + statusOfMatter: caseWorksheet.statusOfMatter, + }; + const result = await getDbWriter(writer => + writer + .insertInto('dwCaseWorksheet') + .values(caseWorksheetToUpsert) + .onConflict(oc => + oc.column('docketNumber').doUpdateSet(caseWorksheetToUpsert), + ) + .execute(), + ); + + return new CaseWorksheet(result); +}; diff --git a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts new file mode 100644 index 00000000000..402649de00b --- /dev/null +++ b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts @@ -0,0 +1,13 @@ +import { mockFactory } from '@shared/test/mockFactory'; + +jest.mock('@web-api/persistence/postgres/cases/getCaseByDocketNumber', () => + mockFactory('getCaseByDocketNumber'), +); + +jest.mock('@web-api/persistence/postgres/cases/upsertCase', () => + mockFactory('upsertCase'), +); + +jest.mock('@web-api/persistence/postgres/cases/upsertCases', () => + mockFactory('upsertCases'), +); diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts similarity index 78% rename from web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts rename to web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts index 7b3e6d0f3df..f9ca78aef01 100644 --- a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence.ts +++ b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts @@ -24,9 +24,19 @@ export async function up(db: Kysely): Promise { .addColumn('createdAt', 'timestamptz', col => col.notNull()) .addColumn('deadlineDate', 'timestamptz', col => col.notNull()) .execute(); + + await db.schema + .createTable('dwCaseWorksheet') + .addColumn('docketNumber', 'varchar', col => col.primaryKey()) + .addColumn('statusOfMatter', 'varchar') + .addColumn('primaryIssue', 'varchar') + .addColumn('judgeUserId', 'varchar') + .addColumn('finalBriefDueDate', 'timestamptz') + .execute(); } export async function down(db: Kysely): Promise { await db.schema.dropTable('dwCaseCorrespondence').execute(); await db.schema.dropTable('dwCaseDeadline').execute(); + await db.schema.dropTable('dwCaseWorksheet').execute(); } diff --git a/web-api/src/persistence/postgres/utils/seed/fixtures/caseWorksheets.ts b/web-api/src/persistence/postgres/utils/seed/fixtures/caseWorksheets.ts new file mode 100644 index 00000000000..6288b987ecd --- /dev/null +++ b/web-api/src/persistence/postgres/utils/seed/fixtures/caseWorksheets.ts @@ -0,0 +1,9 @@ +import { NewCaseWorksheetKysely } from '@web-api/database-types'; + +export const caseWorksheets: NewCaseWorksheetKysely[] = [ + { + docketNumber: '400-22', + judgeUserId: 'dabbad00-18d0-43ec-bafb-654e83405416', + primaryIssue: 'Trumpet!\nThe trumpet!\nMambo Number 5!', + }, +]; diff --git a/web-api/src/persistence/postgres/utils/seed/seed.ts b/web-api/src/persistence/postgres/utils/seed/seed.ts index 29b5ce059e1..475e9a7204c 100644 --- a/web-api/src/persistence/postgres/utils/seed/seed.ts +++ b/web-api/src/persistence/postgres/utils/seed/seed.ts @@ -1,4 +1,5 @@ import { caseDeadlines } from '@web-api/persistence/postgres/utils/seed/fixtures/caseDeadlines'; +import { caseWorksheets } from '@web-api/persistence/postgres/utils/seed/fixtures/caseWorksheets'; import { correspondence } from '@web-api/persistence/postgres/utils/seed/fixtures/correspodence'; import { getDbWriter } from '../../../../database'; import { messages } from './fixtures/messages'; @@ -28,7 +29,20 @@ export const seed = async () => { .execute(), ); - await Promise.all([insertMessages, insertCaseDeadline, insertCorrespondence]); + const insertCaseWorksheet = getDbWriter(writer => + writer + .insertInto('dwCaseWorksheet') + .values(caseWorksheets) + .onConflict(oc => oc.column('docketNumber').doNothing()) // ensure doesn't fail if exists + .execute(), + ); + + await Promise.all([ + insertMessages, + insertCaseDeadline, + insertCorrespondence, + insertCaseWorksheet, + ]); }; seed().catch; diff --git a/web-api/storage/fixtures/seed/efcms-local.json b/web-api/storage/fixtures/seed/efcms-local.json index 8c4125868b4..a02e8ca20dd 100644 --- a/web-api/storage/fixtures/seed/efcms-local.json +++ b/web-api/storage/fixtures/seed/efcms-local.json @@ -30728,14 +30728,7 @@ "sentByUserId": "7805d1ab-18d0-43ec-bafb-654e83405416", "completedBy": "Test Petitionsclerk" }, - { - "sk": "case-worksheet|400-22", - "pk": "case|400-22", - "docketNumber": "400-22", - "entityName": "CaseWorksheet", - "gsi1pk": "judge-case-worksheet|dabbad00-18d0-43ec-bafb-654e83405416", - "primaryIssue": "Trumpet!\nThe trumpet!\nMambo Number 5!" - }, + { "associatedJudge": "Colvin", "isSealed": false, From 9471803973ac18db03e15fae501bd625400c319a Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 6 Nov 2024 16:33:27 -0500 Subject: [PATCH 09/47] 10504-dxox: remove case-dealine| and fix correspondence mock file and getCaseByDocketNumber.test.ts --- docs/dynamodb-access-patterns.csv | 3 -- .../test/createTestApplicationContext.ts | 4 +- .../cases/getCaseByDocketNumber.test.ts | 42 +++++++++++++------ .../dynamo/cases/getCaseByDocketNumber.ts | 8 ++-- .../postgres/correspondence/mocks.jest.ts | 13 ++---- .../storage/fixtures/seed/efcms-local.json | 30 +------------ 6 files changed, 40 insertions(+), 60 deletions(-) diff --git a/docs/dynamodb-access-patterns.csv b/docs/dynamodb-access-patterns.csv index b9ee4eac496..1b6930704b4 100644 --- a/docs/dynamodb-access-patterns.csv +++ b/docs/dynamodb-access-patterns.csv @@ -1,11 +1,8 @@ Access Scenario,PK,SK,GS1PK,GSI2PK -the case deadline object,case-deadline|${DEADLINE_ID},case-deadline|${DEADLINE_ID}, -associate a deadline with a case (mapping record),case|${CASE_ID},case-deadline|${DEADLINE_ID}, a case,case|${CASE_ID},case|${CASE_ID},leadCase|${LEAD_CASE_ID} associate an irs practitioner onto a case,case|${CASE_ID},irsPractitioner|${USER_ID},leadCase|${LEAD_CASE_ID} associate a private practitioner onto a case,case|${CASE_ID},privatePractitioner|${USER_ID},leadCase|${LEAD_CASE_ID} associate docket entry on a case,case|${CASE_ID},docket-entry|${DOCKET_ENTRY_ID}, -add correspondence to a case,case|${CASE_ID},correspondence|${CORRESPONDENCE_ID}, add a hearing to a case,case|${CASE_ID},hearing|${TRIAL_SESSION_ID}, a work item on a case,case|${CASE_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID},assigneeId|${ASSIGNEE_ID} docket number generator counter,docketNumberCounter-${YEAR},docketNumberCounter-${YEAR}, diff --git a/shared/src/business/test/createTestApplicationContext.ts b/shared/src/business/test/createTestApplicationContext.ts index d79fd34dffa..ca8286bb18a 100644 --- a/shared/src/business/test/createTestApplicationContext.ts +++ b/shared/src/business/test/createTestApplicationContext.ts @@ -79,7 +79,7 @@ import { import { getAllFeatureFlagsInteractor } from '@web-api/business/useCases/featureFlag/getAllFeatureFlagsInteractor'; import { getAllWebSocketConnections } from '@web-api/persistence/dynamo/notifications/getAllWebSocketConnections'; import { getCaseByDocketNumber } from '@web-api/persistence/dynamo/cases/getCaseByDocketNumber'; -import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber'; +import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getCaseDocumentsIdsFilteredByDocumentType } from '@shared/business/utilities/getCaseDocumentsIdsFilteredByDocumentType'; import { getConfigurationItemValue } from '@web-api/persistence/dynamo/deployTable/getConfigurationItemValue'; import { getConstants } from '@web-client/getConstants'; @@ -121,7 +121,7 @@ import { unsealDocketEntryInteractor } from '@web-api/business/useCases/docketEn import { updateCase } from '@web-api/persistence/dynamo/cases/updateCase'; import { updateCaseAndAssociations } from '@web-api/business/useCaseHelper/caseAssociation/updateCaseAndAssociations'; import { updateCaseAutomaticBlock } from '@web-api/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock'; -import { updateCaseCorrespondence } from '@web-api/persistence/dynamo/correspondence/updateCaseCorrespondence'; +import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; import { updateDocketEntry } from '@web-api/persistence/dynamo/documents/updateDocketEntry'; import { updateUserRecords } from '@web-api/persistence/dynamo/users/updateUserRecords'; import { uploadDocumentAndMakeSafeInteractor } from '@shared/business/useCases/uploadDocumentAndMakeSafeInteractor'; diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts index afc3f94a6b4..cd653efd2b3 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts @@ -1,11 +1,22 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { CASE_STATUS_TYPES, ROLES, } from '../../../../../shared/src/business/entities/EntityConstants'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +import { calculateDate } from '@shared/business/utilities/DateHandler'; +import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/correspondence/mapper'; import { getCaseByDocketNumber } from './getCaseByDocketNumber'; +import { getCaseCorrespondenceByDocketNumber as getCaseCorrespondenceByDocketNumberMock } from '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber'; + +const getCaseCorrespondenceByDocketNumber = + getCaseCorrespondenceByDocketNumberMock as jest.Mock; describe('getCaseByDocketNumber', () => { + beforeEach(() => { + (getCaseCorrespondenceByDocketNumber as jest.Mock).mockResolvedValue([]); + }); + it('should return data as received from persistence', async () => { applicationContext.getDocumentClient().query.mockResolvedValue({ Items: [ @@ -38,6 +49,21 @@ describe('getCaseByDocketNumber', () => { }); it('should return case and its associated data', async () => { + (getCaseCorrespondenceByDocketNumber as jest.Mock).mockResolvedValue([ + caseCorrespondenceEntity({ + archived: false, + correspondenceId: 'abc-124', + filingDate: calculateDate({ dateString: '2024-11-06T21:05:08.191Z' }), + }), + caseCorrespondenceEntity({ + archived: true, + correspondenceId: 'abc-123', + filingDate: calculateDate({ + dateString: '2024-11-06T21:05:08.191Z', + }), + }), + ]); + applicationContext.getDocumentClient().query.mockResolvedValue({ Items: [ { @@ -74,18 +100,6 @@ describe('getCaseByDocketNumber', () => { pk: 'case|123-20', sk: 'docket-entry|124', }, - { - archived: true, - correspondenceId: 'abc-123', - pk: 'case|123-20', - sk: 'correspondence|123', - }, - { - archived: false, - correspondenceId: 'abc-124', - pk: 'case|123-20', - sk: 'correspondence|124', - }, { name: 'Judge Fieri', pk: 'case|123-20', @@ -106,6 +120,8 @@ describe('getCaseByDocketNumber', () => { { archived: true, correspondenceId: 'abc-123', + entityName: 'Correspondence', + filingDate: '2024-11-06T21:05:08.191Z', }, ], archivedDocketEntries: [ @@ -120,6 +136,8 @@ describe('getCaseByDocketNumber', () => { { archived: false, correspondenceId: 'abc-124', + entityName: 'Correspondence', + filingDate: '2024-11-06T21:05:08.191Z', }, ], docketEntries: [ diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts index ed79df9f976..c8769c3e7b7 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts @@ -22,7 +22,7 @@ export const getCaseByDocketNumber = async ({ docketNumber: string; includeConsolidatedCases?: boolean; }): Promise => { - const [caseItems, correspodenceItems] = await Promise.all([ + const [caseItems, correspondenceItems] = await Promise.all([ queryFull({ ExpressionAttributeNames: { '#pk': 'pk', @@ -63,10 +63,10 @@ export const getCaseByDocketNumber = async ({ return purgeDynamoKeys({ ...aggregateCaseItems([ ...caseItems, - ...correspodenceItems.map(correspodenceItem => ({ - ...correspodenceItem, + ...correspondenceItems.map(correspondenceItem => ({ + ...correspondenceItem, pk: `case|${docketNumber}`, - sk: `correspondence|${correspodenceItem.correspondenceId}`, + sk: `correspondence|${correspondenceItem.correspondenceId}`, })), ]), consolidatedCases, diff --git a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts index 402649de00b..cfbfe9b05a4 100644 --- a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts +++ b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts @@ -1,13 +1,6 @@ import { mockFactory } from '@shared/test/mockFactory'; -jest.mock('@web-api/persistence/postgres/cases/getCaseByDocketNumber', () => - mockFactory('getCaseByDocketNumber'), -); - -jest.mock('@web-api/persistence/postgres/cases/upsertCase', () => - mockFactory('upsertCase'), -); - -jest.mock('@web-api/persistence/postgres/cases/upsertCases', () => - mockFactory('upsertCases'), +jest.mock( + '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber', + () => mockFactory('getCaseCorrespondenceByDocketNumber'), ); diff --git a/web-api/storage/fixtures/seed/efcms-local.json b/web-api/storage/fixtures/seed/efcms-local.json index e751bf3b0bd..21229d4949f 100644 --- a/web-api/storage/fixtures/seed/efcms-local.json +++ b/web-api/storage/fixtures/seed/efcms-local.json @@ -13501,14 +13501,6 @@ "sentByUserId": "4805d1ab-18d0-43ec-bafb-654e83405416", "completedBy": "Test Petitionsclerk1" }, - { - "sk": "case-deadline|08855730-3047-4ca6-a9e7-16ff64c9dcaa", - "pk": "case|104-19" - }, - { - "sk": "case-deadline|ff22fe63-4117-42ee-a66c-8cfd2062a057", - "pk": "case|104-19" - }, { "associatedJudge": "Chief Judge", "procedureType": "Regular", @@ -19563,10 +19555,6 @@ "sentByUserId": "5805d1ab-18d0-43ec-bafb-654e83405416", "updatedAt": "2023-08-08T17:32:21.464Z" }, - { - "sk": "case-deadline|0f5a666d-63c5-4378-9cd6-0b2ae141280f", - "pk": "case|106-19" - }, { "associatedJudge": "Chief Judge", "procedureType": "Regular", @@ -20209,10 +20197,6 @@ "sentByUserId": "7805d1ab-18d0-43ec-bafb-654e83405417", "completedBy": "Test Petitionsclerk1" }, - { - "sk": "case-deadline|307fd0e4-eeed-41bc-bbc3-a9555fccc231", - "pk": "case|107-19" - }, { "associatedJudge": "Chief Judge", "isSealed": false, @@ -21069,10 +21053,6 @@ "sentByUserId": "3805d1ab-18d0-43ec-bafb-654e83405416", "completedBy": "Test Petitionsclerk" }, - { - "sk": "case-deadline|95b46eae-70f0-45df-91de-febdc610fed9", - "pk": "case|109-19" - }, { "associatedJudge": "Chief Judge", "procedureType": "Regular", @@ -24394,10 +24374,6 @@ "sentByUserId": "3805d1ab-18d0-43ec-bafb-654e83405416", "completedBy": "Test Petitionsclerk" }, - { - "sk": "case-deadline|ad1ddb24-f3c4-47b4-b10e-76d1d050b2ab", - "pk": "case|1338-20" - }, { "associatedJudge": "Chief Judge", "isSealed": false, @@ -24813,10 +24789,6 @@ "servedAt": "2019-08-25T05:00:00.000Z", "docketNumber": "101-18" }, - { - "sk": "case-deadline|e7aeadd8-b0d0-4826-af31-22c0d8c6c173", - "pk": "case|152-12" - }, { "associatedJudge": "Chief Judge", "isSealed": false, @@ -30641,7 +30613,7 @@ "sentByUserId": "7805d1ab-18d0-43ec-bafb-654e83405416", "completedBy": "Test Petitionsclerk" }, - + { "associatedJudge": "Colvin", "isSealed": false, From 68c798ba4801ce78e889594a55a88e59b5d099c2 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 6 Nov 2024 17:46:51 -0500 Subject: [PATCH 10/47] 10504-dxox: add mocks.jest.ts files, and fix updateCaseAndAssociations.test.ts --- .../test/createTestApplicationContext.ts | 4 +- .../updateCaseAndAssociations.test.ts | 59 +++++++++---------- .../updateCaseAndAssociations.ts | 4 +- .../updateCaseWorksheetInteractor.ts | 4 +- ...archiveCorrespondenceDocumentInteractor.ts | 4 +- .../fileCorrespondenceDocumentInteractor.ts | 4 +- .../updateCorrespondenceDocumentInteractor.ts | 4 +- .../cases/getCaseByDocketNumber.test.ts | 2 +- .../postgres/caseDeadlines/mocks.jest.ts | 21 +++++++ .../postgres/caseWorksheet/mocks.jest.ts | 11 ++++ ...aseWorksheet.ts => upsertCaseWorksheet.ts} | 2 +- .../postgres/correspondence/mocks.jest.ts | 5 ++ ...ondence.ts => upsertCaseCorrespondence.ts} | 2 +- 13 files changed, 79 insertions(+), 47 deletions(-) create mode 100644 web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts create mode 100644 web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts rename web-api/src/persistence/postgres/caseWorksheet/{updateCaseWorksheet.ts => upsertCaseWorksheet.ts} (95%) rename web-api/src/persistence/postgres/correspondence/{updateCaseCorrespondence.ts => upsertCaseCorrespondence.ts} (95%) diff --git a/shared/src/business/test/createTestApplicationContext.ts b/shared/src/business/test/createTestApplicationContext.ts index ca8286bb18a..f247ddd8436 100644 --- a/shared/src/business/test/createTestApplicationContext.ts +++ b/shared/src/business/test/createTestApplicationContext.ts @@ -121,10 +121,10 @@ import { unsealDocketEntryInteractor } from '@web-api/business/useCases/docketEn import { updateCase } from '@web-api/persistence/dynamo/cases/updateCase'; import { updateCaseAndAssociations } from '@web-api/business/useCaseHelper/caseAssociation/updateCaseAndAssociations'; import { updateCaseAutomaticBlock } from '@web-api/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock'; -import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; import { updateDocketEntry } from '@web-api/persistence/dynamo/documents/updateDocketEntry'; import { updateUserRecords } from '@web-api/persistence/dynamo/users/updateUserRecords'; import { uploadDocumentAndMakeSafeInteractor } from '@shared/business/useCases/uploadDocumentAndMakeSafeInteractor'; +import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; import { validatePenaltiesInteractor } from '@shared/business/useCases/validatePenaltiesInteractor'; import { verifyCaseForUser } from '@web-api/persistence/dynamo/cases/verifyCaseForUser'; import path from 'path'; @@ -540,7 +540,7 @@ export const createTestApplicationContext = () => { updateCase: jest.fn().mockImplementation(updateCase), updateCaseCorrespondence: jest .fn() - .mockImplementation(updateCaseCorrespondence), + .mockImplementation(upsertCaseCorrespondence), updateCaseHearing: jest.fn(), updateDocketEntry: jest.fn().mockImplementation(updateDocketEntry), uploadDocument: jest.fn(), diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index e2f87d20b8d..d70d401b5f9 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -1,5 +1,6 @@ /* eslint-disable max-lines */ -import '@web-api/persistence/postgres/cases/mocks.jest'; +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; +import '@web-api/persistence/postgres/correspondence/mocks.jest'; jest.mock('@shared/business/entities/Message.ts'); jest.mock('@shared/business/entities/CaseDeadline'); jest.mock('@web-api/persistence/postgres/messages/getMessagesByDocketNumber'); @@ -18,16 +19,26 @@ import { MOCK_WORK_ITEM } from '../../../../../shared/src/test/mockWorkItem'; import { Message } from '../../../../../shared/src/business/entities/Message'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { cloneDeep } from 'lodash'; +import { createCaseDeadline as createCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { docketClerkUser } from '../../../../../shared/src/test/mockUsers'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getMessagesByDocketNumber as getMessagesByDocketNumberMock } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseAndAssociations } from './updateCaseAndAssociations'; import { updateMessage as updateMessageMock } from '@web-api/persistence/postgres/messages/updateMessage'; +import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; import { v4 as uuidv4 } from 'uuid'; const getMessagesByDocketNumber = getMessagesByDocketNumberMock as jest.Mock; const updateMessage = updateMessageMock as jest.Mock; +const createCaseDeadline = createCaseDeadlineMock as jest.Mock; + +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + +const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; + describe('updateCaseAndAssociations', () => { let updateCaseMock = jest.fn(); let validMockCase; @@ -74,6 +85,10 @@ describe('updateCaseAndAssociations', () => { .updateCase.mockImplementation(updateCaseMock); }); + beforeEach(() => { + getCaseDeadlinesByDocketNumber.mockResolvedValue([]); + }); + it('gets the old case before passing it to updateCase persistence method', async () => { const caseToUpdate = { ...validMockCase, @@ -119,11 +134,9 @@ describe('updateCaseAndAssociations', () => { }); it('does not attempt to make any update calls to persistence if any queries to persistence fail', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockRejectedValueOnce( - new Error('query problem'), - ); + getCaseDeadlinesByDocketNumber.mockRejectedValue( + new Error('query problem'), + ); await expect( updateCaseAndAssociations({ @@ -601,9 +614,7 @@ describe('updateCaseAndAssociations', () => { caseToUpdate, }); - expect( - applicationContext.getPersistenceGateway().updateCaseCorrespondence, - ).toHaveBeenCalledTimes(4); + expect(upsertCaseCorrespondence).toHaveBeenCalledTimes(4); }); }); @@ -919,21 +930,14 @@ describe('updateCaseAndAssociations', () => { }); describe('case deadlines', () => { - const mockDeadline = new CaseDeadline( - {}, - { - applicationContext, - }, - ); + const mockDeadline = new CaseDeadline({}); beforeAll(() => { applicationContext .getPersistenceGateway() .getCaseByDocketNumber.mockReturnValue(validMockCase); - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { ...mockDeadline, pk: 'abc|987', sk: 'user-case|123' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([ + { ...mockDeadline, pk: 'abc|987', sk: 'user-case|123' }, + ]); }); it('should not fetch or persist any case deadline data if associated judge is unchanged', async () => { @@ -945,10 +949,7 @@ describe('updateCaseAndAssociations', () => { authorizedUser: mockDocketClerkUser, caseToUpdate: updatedCase, }); - expect( - applicationContext.getPersistenceGateway() - .getCaseDeadlinesByDocketNumber, - ).not.toHaveBeenCalled(); + expect(getCaseDeadlinesByDocketNumber).not.toHaveBeenCalled(); expect( applicationContext.getPersistenceGateway().createCaseDeadline, ).not.toHaveBeenCalled(); @@ -965,15 +966,9 @@ describe('updateCaseAndAssociations', () => { authorizedUser: mockDocketClerkUser, caseToUpdate: updatedCase, }); - expect( - applicationContext.getPersistenceGateway() - .getCaseDeadlinesByDocketNumber, - ).toHaveBeenCalled(); + expect(getCaseDeadlinesByDocketNumber).toHaveBeenCalled(); expect(CaseDeadline.validateRawCollection).toHaveBeenCalled(); - expect( - applicationContext.getPersistenceGateway().createCaseDeadline, - ).toHaveBeenCalledWith({ - applicationContext, + expect(createCaseDeadline).toHaveBeenCalledWith({ caseDeadline: { some: 'deadline' }, }); }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index 7720f526397..cdcb42734b6 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -11,9 +11,9 @@ import { WorkItem } from '../../../../../shared/src/business/entities/WorkItem'; import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; -import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; +import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; import diff from 'diff-arrays-of-objects'; /** @@ -153,7 +153,7 @@ const updateCorrespondence = ({ return validCorrespondence.map( correspondence => function updateCorrespondence_cb() { - return updateCaseCorrespondence({ + return upsertCaseCorrespondence({ correspondence, docketNumber: caseToUpdate.docketNumber, }); diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts index 0b65ad03e07..6d763435255 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts @@ -9,7 +9,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { updateCaseWorksheet } from '@web-api/persistence/postgres/caseWorksheet/updateCaseWorksheet'; +import { upsertCaseWorksheet } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheet'; export const updateCaseWorksheetInteractor = async ( applicationContext: ServerApplicationContext, @@ -32,7 +32,7 @@ export const updateCaseWorksheetInteractor = async ( const rawCaseWorksheet = caseWorksheetEntity.toRawObject(); - await updateCaseWorksheet({ + await upsertCaseWorksheet({ caseWorksheet: rawCaseWorksheet, judgeUserId: judgeUser.userId, }); diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts index 34f7b083646..d5707d58849 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts @@ -6,7 +6,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; +import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const archiveCorrespondenceDocument = async ( @@ -37,7 +37,7 @@ export const archiveCorrespondenceDocument = async ( caseEntity.archiveCorrespondence(correspondenceToArchiveEntity); - await updateCaseCorrespondence({ + await upsertCaseCorrespondence({ correspondence: correspondenceToArchiveEntity.validate().toRawObject(), docketNumber, }); diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts index 42af04d28dc..d8e82379261 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts @@ -7,7 +7,7 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; +import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; /** * fileCorrespondenceDocumentInteractor @@ -59,7 +59,7 @@ export const fileCorrespondenceDocumentInteractor = async ( caseEntity.fileCorrespondence(correspondenceEntity); if (caseEntity.validate()) { - await updateCaseCorrespondence({ + await upsertCaseCorrespondence({ correspondence: correspondenceEntity.validate().toRawObject(), docketNumber, }); diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts index 8279aefaca1..dbbce9b5aee 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts @@ -7,7 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { updateCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/updateCaseCorrespondence'; +import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; export const updateCorrespondenceDocumentInteractor = async ( applicationContext: ServerApplicationContext, @@ -42,7 +42,7 @@ export const updateCorrespondenceDocumentInteractor = async ( const caseEntityRaw = caseEntity.validate().toRawObject(); - await updateCaseCorrespondence({ + await upsertCaseCorrespondence({ correspondence: updatedCorrespondenceEntity.validate().toRawObject(), docketNumber, }); diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts index cd653efd2b3..aed46b2b39e 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts @@ -49,7 +49,7 @@ describe('getCaseByDocketNumber', () => { }); it('should return case and its associated data', async () => { - (getCaseCorrespondenceByDocketNumber as jest.Mock).mockResolvedValue([ + getCaseCorrespondenceByDocketNumber.mockResolvedValue([ caseCorrespondenceEntity({ archived: false, correspondenceId: 'abc-124', diff --git a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts new file mode 100644 index 00000000000..e8ae452f2e8 --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts @@ -0,0 +1,21 @@ +import { mockFactory } from '@shared/test/mockFactory'; + +jest.mock( + '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline', + () => mockFactory('createCaseDeadline'), +); + +jest.mock( + '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline', + () => mockFactory('deleteCaseDeadline'), +); + +jest.mock( + '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange', + () => mockFactory('getCaseDeadlinesByDateRange'), +); + +jest.mock( + '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber', + () => mockFactory('getCaseDeadlinesByDocketNumber'), +); diff --git a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts b/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts new file mode 100644 index 00000000000..0530f7d6304 --- /dev/null +++ b/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts @@ -0,0 +1,11 @@ +import { mockFactory } from '@shared/test/mockFactory'; + +jest.mock( + '@web-api/persistence/postgres/caseWorkSheet/getCaseWorksheetsByDocketNumber', + () => mockFactory('getCaseWorksheetsByDocketNumber'), +); + +jest.mock( + '@web-api/persistence/postgres/caseWorkSheet/upsertCaseWorksheet', + () => mockFactory('upsertCaseWorksheet'), +); diff --git a/web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts b/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts similarity index 95% rename from web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts rename to web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts index 70df69b9bdb..b87a20f7ced 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/updateCaseWorksheet.ts +++ b/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts @@ -5,7 +5,7 @@ import { import { calculateDate } from '@shared/business/utilities/DateHandler'; import { getDbWriter } from '@web-api/database'; -export const updateCaseWorksheet = async ({ +export const upsertCaseWorksheet = async ({ caseWorksheet, judgeUserId, }: { diff --git a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts index cfbfe9b05a4..bc06c06fd29 100644 --- a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts +++ b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts @@ -4,3 +4,8 @@ jest.mock( '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber', () => mockFactory('getCaseCorrespondenceByDocketNumber'), ); + +jest.mock( + '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence', + () => mockFactory('upsertCaseCorrespondence'), +); diff --git a/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts similarity index 95% rename from web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts rename to web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts index 993be08eb10..aac0cbe56f7 100644 --- a/web-api/src/persistence/postgres/correspondence/updateCaseCorrespondence.ts +++ b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts @@ -2,7 +2,7 @@ import { RawCorrespondence } from '@shared/business/entities/Correspondence'; import { calculateDate } from '@shared/business/utilities/DateHandler'; import { getDbWriter } from '@web-api/database'; -export const updateCaseCorrespondence = async ({ +export const upsertCaseCorrespondence = async ({ correspondence, docketNumber, }: { From d22ec53456af4e5eca8d0b49d9b24aeaadb19857 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 6 Nov 2024 17:57:06 -0500 Subject: [PATCH 11/47] 10504-dxox: fix updatePetitionerInformationInteractor.test.ts --- shared/src/test/mockFactory.ts | 9 +++++---- .../user/updatePetitionerInformationInteractor.test.ts | 1 + .../src/persistence/postgres/caseDeadlines/mocks.jest.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shared/src/test/mockFactory.ts b/shared/src/test/mockFactory.ts index 01a97742bbf..bdd833ac4b0 100644 --- a/shared/src/test/mockFactory.ts +++ b/shared/src/test/mockFactory.ts @@ -1,7 +1,8 @@ -export const mockFactory = method => { +export const mockFactory = (method: string, returnValue: any = undefined) => { return { - [method]: jest.fn(() => - console.debug(`${method} was not implemented, using default mock`), - ), + [method]: jest.fn(() => { + console.debug(`${method} was not implemented, using default mock`); + return returnValue; + }), }; }; diff --git a/web-api/src/business/useCases/user/updatePetitionerInformationInteractor.test.ts b/web-api/src/business/useCases/user/updatePetitionerInformationInteractor.test.ts index 34bebd27fd4..9c568607fda 100644 --- a/web-api/src/business/useCases/user/updatePetitionerInformationInteractor.test.ts +++ b/web-api/src/business/useCases/user/updatePetitionerInformationInteractor.test.ts @@ -1,4 +1,5 @@ /* eslint-disable max-lines */ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { diff --git a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts index e8ae452f2e8..02201244fdb 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts @@ -12,10 +12,10 @@ jest.mock( jest.mock( '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange', - () => mockFactory('getCaseDeadlinesByDateRange'), + () => mockFactory('getCaseDeadlinesByDateRange', []), ); jest.mock( '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber', - () => mockFactory('getCaseDeadlinesByDocketNumber'), + () => mockFactory('getCaseDeadlinesByDocketNumber', []), ); From ddeea43ecb51a04795f328615ab875be1f0d39d6 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 6 Nov 2024 18:16:59 -0500 Subject: [PATCH 12/47] 10504-dxox: fix CaseDeadline.test.ts, getCaseDeadlnesInteractor.test.ts, removeCasePendingItemIteractor.test.ts --- .../business/entities/CaseDeadline.test.ts | 96 +++++++------------ .../getCaseDeadlinesInteractor.test.ts | 53 +++++----- .../removeCasePendingItemInteractor.test.ts | 15 ++- .../createClientTestApplicationContext.ts | 6 +- 4 files changed, 67 insertions(+), 103 deletions(-) diff --git a/shared/src/business/entities/CaseDeadline.test.ts b/shared/src/business/entities/CaseDeadline.test.ts index 2d87ba49618..c4ccaef0921 100644 --- a/shared/src/business/entities/CaseDeadline.test.ts +++ b/shared/src/business/entities/CaseDeadline.test.ts @@ -1,47 +1,24 @@ import { CaseDeadline } from './CaseDeadline'; -import { applicationContext } from '../test/createTestApplicationContext'; describe('CaseDeadline', () => { const DOCKET_NUMBER = '123-19'; it('should generate a sortable docket number using the docket number provided', () => { - const caseDeadline = new CaseDeadline( - { - associatedJudge: 'Judge Buch', - associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'One small step', - docketNumber: DOCKET_NUMBER, - sortableDocketNumber: undefined, - }, - { applicationContext }, - ); + const caseDeadline = new CaseDeadline({ + associatedJudge: 'Judge Buch', + associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', + deadlineDate: '2019-03-01T21:42:29.073Z', + description: 'One small step', + docketNumber: DOCKET_NUMBER, + sortableDocketNumber: undefined, + }); expect(caseDeadline.sortableDocketNumber).toEqual(2019000123); }); - describe('constructor', () => { - it('should throw an error when application context is not provided', () => { - expect( - () => - new CaseDeadline( - { - associatedJudge: 'Judge Buch', - associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'One small step', - docketNumber: DOCKET_NUMBER, - sortableDocketNumber: undefined, - }, - {} as any, - ), - ).toThrow('applicationContext must be defined'); - }); - }); - describe('validation', () => { it('should be invalid when required fields that are not defaulted in the constructor are not provided', () => { - const caseDeadline = new CaseDeadline({}, { applicationContext }); + const caseDeadline = new CaseDeadline({}); expect(caseDeadline.getFormattedValidationErrors()).toEqual({ associatedJudge: 'Associated judge is required', @@ -54,44 +31,37 @@ describe('CaseDeadline', () => { }); it('should be valid when required fields are all provided', () => { - const caseDeadline = new CaseDeadline( - { - associatedJudge: 'Judge Buch', - associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'One small step', - docketNumber: DOCKET_NUMBER, - leadDocketNumber: DOCKET_NUMBER, - }, - { applicationContext }, - ); + const caseDeadline = new CaseDeadline({ + associatedJudge: 'Judge Buch', + associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', + deadlineDate: '2019-03-01T21:42:29.073Z', + description: 'One small step', + docketNumber: DOCKET_NUMBER, + leadDocketNumber: DOCKET_NUMBER, + }); expect(caseDeadline.getFormattedValidationErrors()).toEqual(null); }); it('should be valid when all required fields are present and optional fields are not', () => { - const caseDeadline = new CaseDeadline( - { - associatedJudge: 'Judge Buch', - associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: 'One small step', - docketNumber: DOCKET_NUMBER, - leadDocketNumber: undefined, /// Optional property - }, - { applicationContext }, - ); + const caseDeadline = new CaseDeadline({ + associatedJudge: 'Judge Buch', + associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', + deadlineDate: '2019-03-01T21:42:29.073Z', + description: 'One small step', + docketNumber: DOCKET_NUMBER, + leadDocketNumber: undefined, /// Optional property + }); expect(caseDeadline.getFormattedValidationErrors()).toEqual(null); }); it('should be invalid and return a helpful message when the user provides a description that is too long', () => { - const caseDeadline = new CaseDeadline( - { - associatedJudge: 'Judge Buch', - associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', - deadlineDate: '2019-03-01T21:42:29.073Z', - description: `I got the horses in the back + const caseDeadline = new CaseDeadline({ + associatedJudge: 'Judge Buch', + associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', + deadlineDate: '2019-03-01T21:42:29.073Z', + description: `I got the horses in the back Horse tack is attached Hat is matte black Got the boots that's black to match @@ -99,10 +69,8 @@ describe('CaseDeadline', () => { You can whip your Porsche I been in the valley You ain't been up off that porch, now`, // Description can be at most 120 characters - docketNumber: DOCKET_NUMBER, - }, - { applicationContext }, - ); + docketNumber: DOCKET_NUMBER, + }); expect(caseDeadline.getFormattedValidationErrors()).toEqual({ description: diff --git a/shared/src/business/useCases/getCaseDeadlinesInteractor.test.ts b/shared/src/business/useCases/getCaseDeadlinesInteractor.test.ts index 793e9a9f31d..36ceb01b01e 100644 --- a/shared/src/business/useCases/getCaseDeadlinesInteractor.test.ts +++ b/shared/src/business/useCases/getCaseDeadlinesInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { CASE_TYPES_MAP, CONTACT_TYPES, @@ -7,12 +8,17 @@ import { } from '../entities/EntityConstants'; import { MOCK_CASE } from '../../test/mockCase'; import { applicationContext } from '../test/createTestApplicationContext'; +import { getCaseDeadlinesByDateRange as getCaseDeadlinesByDateRangeMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDateRange'; + import { getCaseDeadlinesInteractor } from './getCaseDeadlinesInteractor'; import { mockPetitionerUser, mockPetitionsClerkUser, } from '@shared/test/mockAuthUsers'; +const getCaseDeadlinesByDateRange = + getCaseDeadlinesByDateRangeMock as jest.Mock; + describe('getCaseDeadlinesInteractor', () => { const mockDeadlines = [ { @@ -86,12 +92,10 @@ describe('getCaseDeadlinesInteractor', () => { beforeEach(() => { applicationContext.environment.stage = 'local'; - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDateRange.mockReturnValue({ - foundDeadlines: mockDeadlines, - totalCount: 2, - }); + getCaseDeadlinesByDateRange.mockReturnValue({ + foundDeadlines: mockDeadlines, + totalCount: 2, + }); applicationContext .getPersistenceGateway() .getCasesByDocketNumbers.mockReturnValue(mockCases); @@ -162,10 +166,7 @@ describe('getCaseDeadlinesInteractor', () => { mockPetitionsClerkUser, ); - expect( - applicationContext.getPersistenceGateway().getCaseDeadlinesByDateRange - .mock.calls[0][0], - ).toMatchObject({ + expect(getCaseDeadlinesByDateRange.mock.calls[0][0]).toMatchObject({ endDate: END_DATE, from: 20, judge: 'Buch', @@ -221,23 +222,21 @@ describe('getCaseDeadlinesInteractor', () => { ], }, ]); - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDateRange.mockReturnValue({ - foundDeadlines: [ - ...mockDeadlines, - { - associatedJudge: 'Judge Carluzzo', - associatedJudgeId: 'dabbad03-18d0-43ec-bafb-654e83405416', - caseDeadlineId: 'c63d6904-1234-4321-8259-9f8f65824bb7', - createdAt: '2019-02-01T21:40:46.415Z', - deadlineDate: '2019-04-01T21:40:46.415Z', - description: 'Yet anotherA deadline!', - docketNumber: '2000-20', - }, - ], - totalCount: 3, - }); + getCaseDeadlinesByDateRange.mockReturnValue({ + foundDeadlines: [ + ...mockDeadlines, + { + associatedJudge: 'Judge Carluzzo', + associatedJudgeId: 'dabbad03-18d0-43ec-bafb-654e83405416', + caseDeadlineId: 'c63d6904-1234-4321-8259-9f8f65824bb7', + createdAt: '2019-02-01T21:40:46.415Z', + deadlineDate: '2019-04-01T21:40:46.415Z', + description: 'Yet anotherA deadline!', + docketNumber: '2000-20', + }, + ], + totalCount: 3, + }); const result = await getCaseDeadlinesInteractor( applicationContext, diff --git a/shared/src/business/useCases/removeCasePendingItemInteractor.test.ts b/shared/src/business/useCases/removeCasePendingItemInteractor.test.ts index 8487308a6e9..67a16b5726e 100644 --- a/shared/src/business/useCases/removeCasePendingItemInteractor.test.ts +++ b/shared/src/business/useCases/removeCasePendingItemInteractor.test.ts @@ -1,15 +1,20 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS } from '../entities/EntityConstants'; import { MOCK_CASE } from '../../test/mockCase'; import { MOCK_LOCK } from '../../test/mockLock'; import { ServiceUnavailableError } from '@web-api/errors/errors'; import { applicationContext } from '../test/createTestApplicationContext'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { mockPetitionerUser, mockPetitionsClerkUser, } from '@shared/test/mockAuthUsers'; import { removeCasePendingItemInteractor } from './removeCasePendingItemInteractor'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + describe('removeCasePendingItemInteractor', () => { let mockLock; @@ -60,10 +65,6 @@ describe('removeCasePendingItemInteractor', () => { }); it('should call updateCase with automaticBlocked=false if there are no deadlines or pending items remaining on the case', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([]); - await removeCasePendingItemInteractor( applicationContext, { @@ -84,11 +85,7 @@ describe('removeCasePendingItemInteractor', () => { }); it('should call updateCase with automaticBlocked=true and a reason and call deleteCaseTrialSortMappingRecords if there are deadlines remaining on the case', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { deadline: 'something' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([{ deadline: 'something' }]); await removeCasePendingItemInteractor( applicationContext, diff --git a/web-client/src/test/createClientTestApplicationContext.ts b/web-client/src/test/createClientTestApplicationContext.ts index 890ef12385b..678a2bc64a9 100644 --- a/web-client/src/test/createClientTestApplicationContext.ts +++ b/web-client/src/test/createClientTestApplicationContext.ts @@ -68,7 +68,7 @@ import { } from '@shared/business/utilities/generateChangeOfAddressTemplate'; import { getAllWebSocketConnections } from '@web-api/persistence/dynamo/notifications/getAllWebSocketConnections'; import { getCaseByDocketNumber } from '@web-api/persistence/dynamo/cases/getCaseByDocketNumber'; -import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/dynamo/caseDeadlines/getCaseDeadlinesByDocketNumber'; +import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getCaseDocumentsIdsFilteredByDocumentType } from '@shared/business/utilities/getCaseDocumentsIdsFilteredByDocumentType'; import { getConstants } from '@web-client/getConstants'; import { getCropBox } from '@shared/business/utilities/getCropBox'; @@ -104,10 +104,10 @@ import { setServiceIndicatorsForCase } from '@shared/business/utilities/setServi import { setupPdfDocument } from '@shared/business/utilities/setupPdfDocument'; import { unsealDocketEntryInteractor } from '@shared/proxies/editDocketEntry/unsealDocketEntryProxy'; import { updateCase } from '@web-api/persistence/dynamo/cases/updateCase'; -import { updateCaseCorrespondence } from '@web-api/persistence/dynamo/correspondence/updateCaseCorrespondence'; import { updateDocketEntry } from '@web-api/persistence/dynamo/documents/updateDocketEntry'; import { updateUserRecords } from '@web-api/persistence/dynamo/users/createNewPractitionerUser'; import { uploadDocumentAndMakeSafeInteractor } from '@shared/business/useCases/uploadDocumentAndMakeSafeInteractor'; +import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; import { validatePenaltiesInteractor } from '@shared/business/useCases/validatePenaltiesInteractor'; import { verifyCaseForUser } from '@web-api/persistence/dynamo/cases/verifyCaseForUser'; import path from 'path'; @@ -477,7 +477,7 @@ const createTestApplicationContext = () => { updateCase: jest.fn().mockImplementation(updateCase), updateCaseCorrespondence: jest .fn() - .mockImplementation(updateCaseCorrespondence), + .mockImplementation(upsertCaseCorrespondence), updateCaseHearing: jest.fn(), updateDocketEntry: jest.fn().mockImplementation(updateDocketEntry), uploadPdfFromClient: jest.fn().mockImplementation(() => ''), From b13ad2dc83bf2079f91e8eb5ea93ef56776e7e13 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 11:17:17 -0500 Subject: [PATCH 13/47] 10504-dxox: fixing a whole lotta api tests --- __TODO_10504.md | 5 +++ shared/src/test/mockCase.ts | 4 +++ .../autoGenerateDeadline.test.ts | 10 +++--- .../updateCaseAutomaticBlock.test.ts | 33 +++++++------------ .../updateCaseAndAssociations.test.ts | 1 + .../fileAndServeDocumentOnOneCase.test.ts | 3 +- .../createCaseDeadlineInteractor.test.ts | 14 ++++---- .../deleteCaseDeadlineInteractor.test.ts | 23 ++++++------- .../getCaseDeadlinesForCaseInteractor.test.ts | 18 +++++----- .../updateCaseDeadlineInteractor.test.ts | 22 +++++-------- .../updateCaseWorksheetInteractor.test.ts | 25 +++++++------- ...veCorrespondenceDocumentInteractor.test.ts | 9 ++--- ...archiveCorrespondenceDocumentInteractor.ts | 2 ++ ...leCorrespondenceDocumentInteractor.test.ts | 9 ++--- ...teCorrespondenceDocumentInteractor.test.ts | 9 ++--- ...rtIssuedDocumentInteractor.locking.test.ts | 1 + .../addPaperFilingInteractor.locking.test.ts | 1 + .../completeDocketEntryQCInteractor.test.ts | 1 + .../editPaperFilingInteractor.locking.test.ts | 1 + .../editPaperFilingInteractor.test.ts | 1 + .../sealDocketEntryInteractor.test.ts | 3 ++ .../unsealDocketEntryInteractor.test.ts | 6 ++-- .../updateDocketEntryMetaInteractor.test.ts | 1 + .../fileExternalDocumentInteractor.test.ts | 17 ++++++---- ...getCaseWorksheetsByJudgeInteractor.test.ts | 1 + .../removeCaseFromTrialInteractor.test.ts | 1 + .../setTrialSessionCalendarInteractor.test.ts | 1 + ...dateTrialSessionInteractor.locking.test.ts | 1 + ...SessionInteractor.noticeGeneration.test.ts | 1 + web-api/src/lambdas/v1/getCaseLambda.test.ts | 1 + .../v1/getDocumentDownloadUrlLambda.test.ts | 1 + web-api/src/lambdas/v2/getCaseLambda.test.ts | 1 + .../v2/getDocumentDownloadUrlLambda.test.ts | 1 + .../getCalendaredCasesForTrialSession.test.ts | 1 + .../postgres/correspondence/mocks.jest.ts | 2 +- 35 files changed, 122 insertions(+), 109 deletions(-) create mode 100644 __TODO_10504.md diff --git a/__TODO_10504.md b/__TODO_10504.md new file mode 100644 index 00000000000..eb6fe954341 --- /dev/null +++ b/__TODO_10504.md @@ -0,0 +1,5 @@ +TODO: + +- Remove pk/sk from getCaseByDocketNumber (in both 10491 and 10504) +- numberOfPages commented out in upsertCaseCorrespondence?? +- case-worksheets| -- find and remove \ No newline at end of file diff --git a/shared/src/test/mockCase.ts b/shared/src/test/mockCase.ts index 068bb79c0b7..2cc94d2e1e8 100644 --- a/shared/src/test/mockCase.ts +++ b/shared/src/test/mockCase.ts @@ -16,7 +16,11 @@ import { docketClerkUser, judgeUser } from './mockUsers'; export const MOCK_CASE: RawCase = { archivedDocketEntries: [], + associatedJudge: 'Ashford', + associatedJudgeId: '190ad132-18d0-43ec-bafb-15468e405481', + canAllowPrintableDocketRecord: false, caseCaption: 'Test Petitioner, Petitioner', + caseStatusHistory: [], caseType: CASE_TYPES_MAP.other, consolidatedCases: [], correspondence: [], diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts index 748233c601f..d113463c8c3 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts @@ -1,5 +1,8 @@ -import { applicationContext } from '../../../../shared/src/business/test/createTestApplicationContext'; +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { autoGenerateDeadline } from './autoGenerateDeadline'; +import { createCaseDeadline as createCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; + +const createCaseDeadline = createCaseDeadlineMock as jest.Mock; describe('autoGenerateDeadline', () => { it('should create a case deadline', async () => { @@ -14,9 +17,6 @@ describe('autoGenerateDeadline', () => { }, }); - expect( - applicationContext.getPersistenceGateway().createCaseDeadline.mock - .calls[0][0].caseDeadline, - ).toBeDefined(); + expect(createCaseDeadline.mock.calls[0][0].caseDeadline).toBeDefined(); }); }); diff --git a/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts b/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts index a7eb1d261b0..a8e800f3d73 100644 --- a/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts +++ b/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS, CASE_STATUS_TYPES, @@ -10,9 +11,13 @@ import { import { PENDING_DOCKET_ENTRY } from '../../../../../shared/src/test/mockDocketEntry'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { cloneDeep } from 'lodash'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseAutomaticBlock } from './updateCaseAutomaticBlock'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + describe('updateCaseAutomaticBlock', () => { let mockCase; @@ -22,9 +27,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('sets the case to automaticBlocked and calls deleteCaseTrialSortMappingRecords if it has pending documents', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([]); + getCaseDeadlinesByDocketNumber.mockReturnValue([]); mockCase.docketEntries = [PENDING_DOCKET_ENTRY]; const caseEntity = new Case(mockCase, { @@ -73,11 +76,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('does not set the case to automaticBlocked or call deleteCaseTrialSortMappingRecords if it already has a trial date', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { deadline: 'something' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([{ deadline: 'something' }]); const caseEntity = new Case( { @@ -102,11 +101,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('does not set the case to automaticBlocked or call deleteCaseTrialSortMappingRecords when the case is marked as high priority', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { deadline: 'something' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([{ deadline: 'something' }]); const caseEntity = new Case( { ...MOCK_CASE_WITHOUT_PENDING, @@ -130,9 +125,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('sets the case to not automaticBlocked but does not call createCaseTrialSortMappingRecords if the case does not have deadlines or pending items and the case is not generalDocketReadyForTrial status', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([]); + getCaseDeadlinesByDocketNumber.mockReturnValue([]); const caseEntity = new Case(MOCK_CASE_WITHOUT_PENDING, { authorizedUser: mockDocketClerkUser, @@ -154,9 +147,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('sets the case to not automaticBlocked and calls createCaseTrialSortMappingRecords if the case does not have deadlines or pending items and the case is generalDocketReadyForTrial status', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([]); + getCaseDeadlinesByDocketNumber.mockReturnValue([]); const caseEntity = new Case( { @@ -184,9 +175,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('does not call createCaseTrialSortMappingRecords if the case has no trial city', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([]); + getCaseDeadlinesByDocketNumber.mockReturnValue([]); const caseEntity = new Case( { diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index d70d401b5f9..0198dcce1c2 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -1,5 +1,6 @@ /* eslint-disable max-lines */ import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; +import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/correspondence/mocks.jest'; jest.mock('@shared/business/entities/Message.ts'); jest.mock('@shared/business/entities/CaseDeadline'); diff --git a/web-api/src/business/useCaseHelper/docketEntry/fileAndServeDocumentOnOneCase.test.ts b/web-api/src/business/useCaseHelper/docketEntry/fileAndServeDocumentOnOneCase.test.ts index bac981e91e4..1db34fc9cac 100644 --- a/web-api/src/business/useCaseHelper/docketEntry/fileAndServeDocumentOnOneCase.test.ts +++ b/web-api/src/business/useCaseHelper/docketEntry/fileAndServeDocumentOnOneCase.test.ts @@ -1,4 +1,5 @@ /* eslint-disable max-lines */ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS, COURT_ISSUED_EVENT_CODES, @@ -40,7 +41,7 @@ describe('fileAndServeDocumentOnOneCase', () => { { docketEntryId: mockDocketEntryId, docketNumber: MOCK_CASE.docketNumber, - documentType: eventCodeMap.documentType, + documentType: eventCodeMap?.documentType, eventCode, filedByRole: ROLES.judge, signedAt: createISODateString(), diff --git a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.test.ts index 839e1310de1..28f9b561dfe 100644 --- a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS, @@ -15,8 +16,12 @@ import { import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { createCaseDeadlineInteractor } from './createCaseDeadlineInteractor'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { mockPetitionsClerkUser } from '@shared/test/mockAuthUsers'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + describe('createCaseDeadlineInteractor', () => { const mockCaseDeadline = { deadlineDate: '2019-03-01T21:42:29.073Z', @@ -36,17 +41,10 @@ describe('createCaseDeadlineInteractor', () => { applicationContext.environment.stage = 'local'; - applicationContext - .getPersistenceGateway() - .createCaseDeadline.mockImplementation(v => v); applicationContext .getPersistenceGateway() .getCaseByDocketNumber.mockImplementation(() => mockCase); - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { deadline: 'something' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([{ deadline: 'something' }]); }); it('throws an error if the user is not valid or authorized', async () => { diff --git a/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.test.ts index 3524f6f2605..2c15acaebd7 100644 --- a/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/deleteCaseDeadlineInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS } from '../../../../../shared/src/business/entities/EntityConstants'; import { MOCK_CASE_WITHOUT_PENDING } from '../../../../../shared/src/test/mockCase'; @@ -8,8 +9,14 @@ import { } from '@web-api/errors/errors'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { deleteCaseDeadlineInteractor } from './deleteCaseDeadlineInteractor'; +import { deleteCaseDeadline as deleteCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { mockPetitionsClerkUser } from '@shared/test/mockAuthUsers'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; +const deleteCaseDeadline = deleteCaseDeadlineMock as jest.Mock; + describe('deleteCaseDeadlineInteractor', () => { let user; let mockCase; @@ -26,9 +33,7 @@ describe('deleteCaseDeadlineInteractor', () => { .getPersistenceGateway() .getCaseByDocketNumber.mockReturnValue(mockCase); - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockImplementation(() => mockDeadlines); + getCaseDeadlinesByDocketNumber.mockImplementation(() => mockDeadlines); }); beforeEach(() => { @@ -106,12 +111,8 @@ describe('deleteCaseDeadlineInteractor', () => { mockPetitionsClerkUser, ); - expect( - applicationContext.getPersistenceGateway().deleteCaseDeadline.mock - .calls[0][0], - ).toMatchObject({ + expect(deleteCaseDeadline.mock.calls[0][0]).toMatchObject({ caseDeadlineId: '6805d1ab-18d0-43ec-bafb-654e83405416', - docketNumber: '123-20', }); expect( applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0] @@ -139,12 +140,8 @@ describe('deleteCaseDeadlineInteractor', () => { mockPetitionsClerkUser, ); - expect( - applicationContext.getPersistenceGateway().deleteCaseDeadline.mock - .calls[0][0], - ).toMatchObject({ + expect(deleteCaseDeadline.mock.calls[0][0]).toMatchObject({ caseDeadlineId: '6805d1ab-18d0-43ec-bafb-654e83405416', - docketNumber: '123-20', }); expect( applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0] diff --git a/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.test.ts index 25e68fa89b9..9d4af097156 100644 --- a/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/getCaseDeadlinesForCaseInteractor.test.ts @@ -1,6 +1,11 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getCaseDeadlinesForCaseInteractor } from './getCaseDeadlinesForCaseInteractor'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + describe('getCaseDeadlinesForCaseInteractor', () => { const mockCaseDeadline = { associatedJudge: 'Buch', @@ -11,19 +16,14 @@ describe('getCaseDeadlinesForCaseInteractor', () => { }; it('gets the case deadlines', async () => { - applicationContext.environment.stage = 'local'; - - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([mockCaseDeadline]); + getCaseDeadlinesByDocketNumber.mockReturnValue([mockCaseDeadline]); applicationContext.getUniqueId.mockReturnValue( '6ba578e7-5736-435b-a41b-2de3eec29fe7', ); - const caseDeadlines = await getCaseDeadlinesForCaseInteractor( - applicationContext, - { docketNumber: mockCaseDeadline.docketNumber }, - ); + const caseDeadlines = await getCaseDeadlinesForCaseInteractor({ + docketNumber: mockCaseDeadline.docketNumber, + }); expect(caseDeadlines).toBeDefined(); }); diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts index 1a588295df6..ecc160e0668 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts @@ -1,8 +1,13 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +import { createCaseDeadline as createCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; +import { deleteCaseDeadline as deleteCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; import { mockPetitionsClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseDeadlineInteractor } from './updateCaseDeadlineInteractor'; +const createCaseDeadline = createCaseDeadlineMock as jest.Mock; +const deleteCaseDeadline = deleteCaseDeadlineMock as jest.Mock; + describe('updateCaseDeadlineInteractor', () => { const CASE_DEADLINE_ID = '6805d1ab-18d0-43ec-bafb-654e83405416'; @@ -18,7 +23,6 @@ describe('updateCaseDeadlineInteractor', () => { it('throws an error if the user is not valid or authorized', async () => { await expect( updateCaseDeadlineInteractor( - applicationContext, { caseDeadline: mockCaseDeadline, }, @@ -28,27 +32,17 @@ describe('updateCaseDeadlineInteractor', () => { }); it('updates a case deadline', async () => { - applicationContext.environment.stage = 'local'; - const caseDeadline = await updateCaseDeadlineInteractor( - applicationContext, { caseDeadline: mockCaseDeadline, }, mockPetitionsClerkUser, ); - expect( - applicationContext.getPersistenceGateway().deleteCaseDeadline.mock - .calls[0][0], - ).toMatchObject({ + expect(deleteCaseDeadline.mock.calls[0][0]).toMatchObject({ caseDeadlineId: CASE_DEADLINE_ID, - docketNumber: '123-20', }); - expect( - applicationContext.getPersistenceGateway().createCaseDeadline.mock - .calls[0][0], - ).toMatchObject({ + expect(createCaseDeadline.mock.calls[0][0]).toMatchObject({ caseDeadline: mockCaseDeadline, }); expect(caseDeadline).toBeDefined(); diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts index c177ffd3625..734fccb03b9 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts @@ -1,13 +1,20 @@ +import '@web-api/persistence/postgres/caseWorksheet/mocks.jest'; import { InvalidEntityError, UnauthorizedError } from '@web-api/errors/errors'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; import { judgeColvin } from '@shared/test/mockUsers'; import { mockChambersUser, mockPetitionsClerkUser, } from '@shared/test/mockAuthUsers'; import { updateCaseWorksheetInteractor } from './updateCaseWorksheetInteractor'; +import { upsertCaseWorksheet as upsertCaseWorksheetMock } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheet'; + +const getCaseWorksheetsByDocketNumber = + getCaseWorksheetsByDocketNumberMock as jest.Mock; +const upsertCaseWorksheet = upsertCaseWorksheetMock as jest.Mock; describe('updateCaseWorksheetInteractor', () => { const mockCaseWorksheet: RawCaseWorksheet = { @@ -58,9 +65,7 @@ describe('updateCaseWorksheetInteractor', () => { applicationContext .getPersistenceGateway() .getUserById.mockReturnValue(judgeColvin); - applicationContext - .getPersistenceGateway() - .getCaseWorksheet.mockResolvedValue(mockCaseWorksheet); + getCaseWorksheetsByDocketNumber.mockResolvedValue([mockCaseWorksheet]); const result = await updateCaseWorksheetInteractor( applicationContext, @@ -80,10 +85,7 @@ describe('updateCaseWorksheetInteractor', () => { expect( applicationContext.getUseCaseHelpers().getJudgeInSectionHelper, ).not.toHaveBeenCalled(); - expect( - applicationContext.getPersistenceGateway().updateCaseWorksheet, - ).toHaveBeenCalledWith({ - applicationContext: expect.anything(), + expect(upsertCaseWorksheet).toHaveBeenCalledWith({ caseWorksheet: expectedUpdatedCaseWorksheet, judgeUserId: judgeColvin.userId, }); @@ -92,9 +94,7 @@ describe('updateCaseWorksheetInteractor', () => { it('should persist the updated case worksheet when the updates are valid, using the judge`s userId in the section when the current user is a chambers user', async () => { const mockFinalBriefDueDate = '2023-08-29'; - applicationContext - .getPersistenceGateway() - .getCaseWorksheet.mockResolvedValue(mockCaseWorksheet); + getCaseWorksheetsByDocketNumber.mockResolvedValue([mockCaseWorksheet]); const result = await updateCaseWorksheetInteractor( applicationContext, @@ -117,10 +117,7 @@ describe('updateCaseWorksheetInteractor', () => { ).toEqual({ user: mockChambersUser, }); - expect( - applicationContext.getPersistenceGateway().updateCaseWorksheet, - ).toHaveBeenCalledWith({ - applicationContext: expect.anything(), + expect(upsertCaseWorksheet).toHaveBeenCalledWith({ caseWorksheet: expectedUpdatedCaseWorksheet, judgeUserId: judgeColvin.userId, }); diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts index 4c2c3c6eff6..7400d3a2685 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts @@ -1,4 +1,5 @@ import '@web-api/persistence/postgres/cases/mocks.jest'; +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { Correspondence } from '../../../../../shared/src/business/entities/Correspondence'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; @@ -7,6 +8,9 @@ import { ServiceUnavailableError } from '@web-api/errors/errors'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { archiveCorrespondenceDocumentInteractor } from './archiveCorrespondenceDocumentInteractor'; import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; +import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; + +const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; describe('archiveCorrespondenceDocumentInteractor', () => { let mockUserId = '2474e5c0-f741-4120-befa-b77378ac8bf0'; @@ -80,10 +84,7 @@ describe('archiveCorrespondenceDocumentInteractor', () => { mockDocketClerkUser, ); - expect( - applicationContext.getPersistenceGateway().updateCaseCorrespondence.mock - .calls[0][0], - ).toMatchObject({ + expect(upsertCaseCorrespondence.mock.calls[0][0]).toMatchObject({ correspondence: { ...mockCorrespondence, archived: true, diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts index d5707d58849..228f4c6a4b9 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts @@ -30,6 +30,8 @@ export const archiveCorrespondenceDocument = async ( .getPersistenceGateway() .getCaseByDocketNumber({ applicationContext, docketNumber }); + console.log(caseToUpdate); + const caseEntity = new Case(caseToUpdate, { authorizedUser }); const correspondenceToArchiveEntity = caseEntity.correspondence.find( c => c.correspondenceId === correspondenceId, diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts index c3b9005e29b..ff3e5feead8 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { CASE_TYPES_MAP, CONTACT_TYPES, @@ -13,6 +14,9 @@ import { mockDocketClerkUser, mockPetitionerUser, } from '@shared/test/mockAuthUsers'; +import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; + +const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; describe('fileCorrespondenceDocumentInteractor', () => { const mockCase = { @@ -119,10 +123,7 @@ describe('fileCorrespondenceDocumentInteractor', () => { }, docketClerkUser, ); - expect( - applicationContext.getPersistenceGateway().updateCaseCorrespondence.mock - .calls[0][0], - ).toMatchObject({ + expect(upsertCaseCorrespondence.mock.calls[0][0]).toMatchObject({ correspondence: { correspondenceId: mockCorrespondenceId, documentTitle: mockDocumentTitle, diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts index 1e3e186b510..3b96e45895b 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { CASE_TYPES_MAP, CONTACT_TYPES, @@ -13,6 +14,9 @@ import { mockPetitionerUser, } from '@shared/test/mockAuthUsers'; import { updateCorrespondenceDocumentInteractor } from './updateCorrespondenceDocumentInteractor'; +import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; + +const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; describe('updateCorrespondenceDocumentInteractor', () => { const mockDocketEntryId = 'cf105788-5d34-4451-aa8d-dfd9a851b675'; @@ -95,10 +99,7 @@ describe('updateCorrespondenceDocumentInteractor', () => { mockDocketClerkUser, ); - expect( - applicationContext.getPersistenceGateway().updateCaseCorrespondence.mock - .calls[0][0], - ).toMatchObject({ + expect(upsertCaseCorrespondence.mock.calls[0][0]).toMatchObject({ correspondence: { ...mockCorrespondence, documentTitle: 'A title that has been updated', diff --git a/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.locking.test.ts b/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.locking.test.ts index bf0bb8be536..57c0a1ece59 100644 --- a/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.locking.test.ts +++ b/web-api/src/business/useCases/courtIssuedDocument/fileAndServeCourtIssuedDocumentInteractor.locking.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; diff --git a/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.locking.test.ts b/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.locking.test.ts index 7a89260c18a..4ed71150353 100644 --- a/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.locking.test.ts +++ b/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.locking.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; diff --git a/web-api/src/business/useCases/docketEntry/completeDocketEntryQCInteractor.test.ts b/web-api/src/business/useCases/docketEntry/completeDocketEntryQCInteractor.test.ts index ea7b93fc49d..bf87592e9d3 100644 --- a/web-api/src/business/useCases/docketEntry/completeDocketEntryQCInteractor.test.ts +++ b/web-api/src/business/useCases/docketEntry/completeDocketEntryQCInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { CASE_SERVICES_SUPERVISOR_SECTION, diff --git a/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.locking.test.ts b/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.locking.test.ts index e2da173709b..4b4d654e533 100644 --- a/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.locking.test.ts +++ b/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.locking.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; diff --git a/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.test.ts b/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.test.ts index 583fdef7027..604f7e27f72 100644 --- a/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.test.ts +++ b/web-api/src/business/useCases/docketEntry/editPaperFilingInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { DOCKET_SECTION, diff --git a/web-api/src/business/useCases/docketEntry/sealDocketEntryInteractor.test.ts b/web-api/src/business/useCases/docketEntry/sealDocketEntryInteractor.test.ts index 2cdf662d0b7..16cd9503e3e 100644 --- a/web-api/src/business/useCases/docketEntry/sealDocketEntryInteractor.test.ts +++ b/web-api/src/business/useCases/docketEntry/sealDocketEntryInteractor.test.ts @@ -40,6 +40,9 @@ describe('sealDocketEntryInteractor', () => { }); it('should throw an error when the docket entry is not found', async () => { + applicationContext + .getPersistenceGateway() + .getCaseByDocketNumber.mockReturnValue(MOCK_CASE); await expect( sealDocketEntryInteractor( applicationContext, diff --git a/web-api/src/business/useCases/docketEntry/unsealDocketEntryInteractor.test.ts b/web-api/src/business/useCases/docketEntry/unsealDocketEntryInteractor.test.ts index 2cb6e29fa3b..2343ef6c088 100644 --- a/web-api/src/business/useCases/docketEntry/unsealDocketEntryInteractor.test.ts +++ b/web-api/src/business/useCases/docketEntry/unsealDocketEntryInteractor.test.ts @@ -8,6 +8,9 @@ import { unsealDocketEntryInteractor } from './unsealDocketEntryInteractor'; describe('unsealDocketEntryInteractor', () => { const answerDocketEntryId = 'e6b81f4d-1e47-423a-8caf-6d2fdc3d3859'; + applicationContext + .getPersistenceGateway() + .getCaseByDocketNumber.mockReturnValue(MOCK_CASE); it('should only allow docket clerks to unseal a docket entry', async () => { await expect( @@ -36,9 +39,6 @@ describe('unsealDocketEntryInteractor', () => { }); it('should mark the docket entry as unsealed and save', async () => { - applicationContext - .getPersistenceGateway() - .getCaseByDocketNumber.mockReturnValue(MOCK_CASE); const unsealedDocketEntry = await unsealDocketEntryInteractor( applicationContext, { diff --git a/web-api/src/business/useCases/docketEntry/updateDocketEntryMetaInteractor.test.ts b/web-api/src/business/useCases/docketEntry/updateDocketEntryMetaInteractor.test.ts index eac756bc109..132b92a592f 100644 --- a/web-api/src/business/useCases/docketEntry/updateDocketEntryMetaInteractor.test.ts +++ b/web-api/src/business/useCases/docketEntry/updateDocketEntryMetaInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '@shared/test/mockLock'; diff --git a/web-api/src/business/useCases/externalDocument/fileExternalDocumentInteractor.test.ts b/web-api/src/business/useCases/externalDocument/fileExternalDocumentInteractor.test.ts index a3b322e7501..fee0eeddd5f 100644 --- a/web-api/src/business/useCases/externalDocument/fileExternalDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/externalDocument/fileExternalDocumentInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS, @@ -15,11 +16,15 @@ import { MOCK_LOCK } from '@shared/test/mockLock'; import { ServiceUnavailableError } from '@web-api/errors/errors'; import { applicationContext } from '@shared/business/test/createTestApplicationContext'; import { fileExternalDocumentInteractor } from './fileExternalDocumentInteractor'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { mockDocketClerkUser, mockIrsPractitionerUser, } from '@shared/test/mockAuthUsers'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + describe('fileExternalDocumentInteractor', () => { const mockDocketEntryId = applicationContext.getUniqueId(); @@ -541,13 +546,11 @@ describe('fileExternalDocumentInteractor', () => { }); it('should automatically block the case with deadlines if the document filed is a tracked document and the case has a deadline', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { - deadlineDate: 'something', - }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([ + { + deadlineDate: 'something', + }, + ]); await fileExternalDocumentInteractor( applicationContext, diff --git a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts index 3e8884b3db5..6b9baec6844 100644 --- a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts +++ b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseWorksheet/mocks.jest'; import { CASE_STATUS_TYPES } from '@shared/business/entities/EntityConstants'; import { GetCasesByStatusAndByJudgeRequest, diff --git a/web-api/src/business/useCases/trialSessions/removeCaseFromTrialInteractor.test.ts b/web-api/src/business/useCases/trialSessions/removeCaseFromTrialInteractor.test.ts index c9206aa2525..19d447d8f66 100644 --- a/web-api/src/business/useCases/trialSessions/removeCaseFromTrialInteractor.test.ts +++ b/web-api/src/business/useCases/trialSessions/removeCaseFromTrialInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { diff --git a/web-api/src/business/useCases/trialSessions/setTrialSessionCalendarInteractor.test.ts b/web-api/src/business/useCases/trialSessions/setTrialSessionCalendarInteractor.test.ts index 11152d6fa2c..f093ff5f7ea 100644 --- a/web-api/src/business/useCases/trialSessions/setTrialSessionCalendarInteractor.test.ts +++ b/web-api/src/business/useCases/trialSessions/setTrialSessionCalendarInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; diff --git a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts index 59adf10045d..534823228cb 100644 --- a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts +++ b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; import { MOCK_TRIAL_INPERSON } from '../../../../../shared/src/test/mockTrial'; diff --git a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.noticeGeneration.test.ts b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.noticeGeneration.test.ts index bca313ce72d..ec9fa7b6ebf 100644 --- a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.noticeGeneration.test.ts +++ b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.noticeGeneration.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import { CASE_STATUS_TYPES, diff --git a/web-api/src/lambdas/v1/getCaseLambda.test.ts b/web-api/src/lambdas/v1/getCaseLambda.test.ts index 68181663318..36703503f4d 100644 --- a/web-api/src/lambdas/v1/getCaseLambda.test.ts +++ b/web-api/src/lambdas/v1/getCaseLambda.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { MOCK_CASE_WITH_TRIAL_SESSION } from '../../../../shared/src/test/mockCase'; import { getCaseLambda } from './getCaseLambda'; import { createTestApplicationContext as mockCreateTestApplicationContext } from '@shared/business/test/createTestApplicationContext'; diff --git a/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts b/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts index f2246fe2bd5..675bc2530ed 100644 --- a/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts +++ b/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { CASE_STATUS_TYPES } from '@shared/business/entities/EntityConstants'; import { MOCK_PETITION } from '@shared/test/mockDocketEntry'; import { getDocumentDownloadUrlLambda } from './getDocumentDownloadUrlLambda'; diff --git a/web-api/src/lambdas/v2/getCaseLambda.test.ts b/web-api/src/lambdas/v2/getCaseLambda.test.ts index 42533a60855..6ded42a2338 100644 --- a/web-api/src/lambdas/v2/getCaseLambda.test.ts +++ b/web-api/src/lambdas/v2/getCaseLambda.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { MOCK_CASE_WITH_TRIAL_SESSION } from '../../../../shared/src/test/mockCase'; import { MOCK_COMPLEX_CASE } from '../../../../shared/src/test/mockComplexCase'; import { MOCK_PRACTITIONER } from '../../../../shared/src/test/mockUsers'; diff --git a/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts b/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts index ef2c2798f5f..db2d1e4c8a9 100644 --- a/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts +++ b/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { CASE_STATUS_TYPES, Role, diff --git a/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts b/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts index 85114276df4..a091b0833ad 100644 --- a/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts +++ b/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { CASE_STATUS_TYPES } from '../../../../../shared/src/business/entities/EntityConstants'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; diff --git a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts index bc06c06fd29..944d6faf009 100644 --- a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts +++ b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts @@ -2,7 +2,7 @@ import { mockFactory } from '@shared/test/mockFactory'; jest.mock( '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber', - () => mockFactory('getCaseCorrespondenceByDocketNumber'), + () => mockFactory('getCaseCorrespondenceByDocketNumber', []), ); jest.mock( From 8cc25ac9c1efd90485a1f3a9fd3b2046300bf280 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 11:20:27 -0500 Subject: [PATCH 14/47] 10504-dxox: fix shared test --- shared/src/business/useCases/updateCaseContextInteractor.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/src/business/useCases/updateCaseContextInteractor.test.ts b/shared/src/business/useCases/updateCaseContextInteractor.test.ts index 89abb1fccc7..90d03e2de6f 100644 --- a/shared/src/business/useCases/updateCaseContextInteractor.test.ts +++ b/shared/src/business/useCases/updateCaseContextInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { CASE_STATUS_TYPES, CHIEF_JUDGE } from '../entities/EntityConstants'; From fecdc98c1f4da96e8fb19bf80fccc43bcd00fdfb Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 11:53:25 -0500 Subject: [PATCH 15/47] 10504-dxox: fix more API tests --- .../automaticBlock/updateCaseAutomaticBlock.test.ts | 6 +----- .../checkForReadyForTrialCasesInteractor.test.ts | 1 + .../docketEntry/addPaperFilingInteractor.test.ts | 11 ++++++----- .../serveCaseToIrs/serveCaseToIrsInteractor.test.ts | 1 + .../addCaseToTrialSessionInteractor.test.ts | 1 + .../deleteTrialSessionInteractor.test.ts | 1 + .../updateTrialSessionInteractor.test.ts | 2 ++ .../persistence/postgres/caseWorksheet/mocks.jest.ts | 4 ++-- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts b/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts index a8e800f3d73..7fc8c3c0566 100644 --- a/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts +++ b/web-api/src/business/useCaseHelper/automaticBlock/updateCaseAutomaticBlock.test.ts @@ -50,11 +50,7 @@ describe('updateCaseAutomaticBlock', () => { }); it('sets the case to automaticBlocked and calls deleteCaseTrialSortMappingRecords if it has deadlines', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { deadline: 'something' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([{ deadline: 'something' }]); const caseEntity = new Case(MOCK_CASE_WITHOUT_PENDING, { authorizedUser: mockDocketClerkUser, diff --git a/web-api/src/business/useCases/checkForReadyForTrialCasesInteractor.test.ts b/web-api/src/business/useCases/checkForReadyForTrialCasesInteractor.test.ts index e79f82978ac..f374bba1174 100644 --- a/web-api/src/business/useCases/checkForReadyForTrialCasesInteractor.test.ts +++ b/web-api/src/business/useCases/checkForReadyForTrialCasesInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { CASE_STATUS_TYPES } from '../../../../shared/src/business/entities/EntityConstants'; diff --git a/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.test.ts b/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.test.ts index c75373967ea..2fd0f2889d6 100644 --- a/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.test.ts +++ b/web-api/src/business/useCases/docketEntry/addPaperFilingInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { @@ -15,8 +16,12 @@ import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { addPaperFilingInteractor } from './addPaperFilingInteractor'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { docketClerkUser } from '../../../../../shared/src/test/mockUsers'; +import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; +const getCaseDeadlinesByDocketNumber = + getCaseDeadlinesByDocketNumberMock as jest.Mock; + describe('addPaperFilingInteractor', () => { const mockClientConnectionId = '987654'; const mockCase = { ...MOCK_CASE, leadDocketNumber: MOCK_CASE.docketNumber }; @@ -342,11 +347,7 @@ describe('addPaperFilingInteractor', () => { }); it('sets the case as blocked with due dates if the document filed is a tracked document type and the case has due dates', async () => { - applicationContext - .getPersistenceGateway() - .getCaseDeadlinesByDocketNumber.mockReturnValue([ - { deadline: 'something' }, - ]); + getCaseDeadlinesByDocketNumber.mockReturnValue([{ deadline: 'something' }]); await addPaperFilingInteractor( applicationContext, diff --git a/web-api/src/business/useCases/serveCaseToIrs/serveCaseToIrsInteractor.test.ts b/web-api/src/business/useCases/serveCaseToIrs/serveCaseToIrsInteractor.test.ts index 9d9b66f7671..4dfd9dec2d0 100644 --- a/web-api/src/business/useCases/serveCaseToIrs/serveCaseToIrsInteractor.test.ts +++ b/web-api/src/business/useCases/serveCaseToIrs/serveCaseToIrsInteractor.test.ts @@ -1,4 +1,5 @@ /* eslint-disable max-lines */ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { diff --git a/web-api/src/business/useCases/trialSessions/addCaseToTrialSessionInteractor.test.ts b/web-api/src/business/useCases/trialSessions/addCaseToTrialSessionInteractor.test.ts index 5d6c2cec874..72ab84b79ff 100644 --- a/web-api/src/business/useCases/trialSessions/addCaseToTrialSessionInteractor.test.ts +++ b/web-api/src/business/useCases/trialSessions/addCaseToTrialSessionInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { diff --git a/web-api/src/business/useCases/trialSessions/deleteTrialSessionInteractor.test.ts b/web-api/src/business/useCases/trialSessions/deleteTrialSessionInteractor.test.ts index 8965720fa07..7ba83a09013 100644 --- a/web-api/src/business/useCases/trialSessions/deleteTrialSessionInteractor.test.ts +++ b/web-api/src/business/useCases/trialSessions/deleteTrialSessionInteractor.test.ts @@ -1,3 +1,4 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; import '@web-api/persistence/postgres/messages/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; diff --git a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts index 0c925d36798..8a856f5f2eb 100644 --- a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts +++ b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts @@ -1,4 +1,6 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_TRIAL_INPERSON, diff --git a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts b/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts index 0530f7d6304..76a18665274 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts @@ -1,11 +1,11 @@ import { mockFactory } from '@shared/test/mockFactory'; jest.mock( - '@web-api/persistence/postgres/caseWorkSheet/getCaseWorksheetsByDocketNumber', + '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber', () => mockFactory('getCaseWorksheetsByDocketNumber'), ); jest.mock( - '@web-api/persistence/postgres/caseWorkSheet/upsertCaseWorksheet', + '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheet', () => mockFactory('upsertCaseWorksheet'), ); From 016287e17d6d9c773ab49712bce09a8d9d8faa96 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 12:50:02 -0500 Subject: [PATCH 16/47] 10504-dxox: fix a few more tests, undo a change to MOCK_CASE (which will probably cause regressions to previous-commit test fixes) --- __TODO_10504.md | 3 ++- shared/src/business/entities/cases/Case.test.ts | 7 ++++++- shared/src/business/entities/cases/Case.ts | 10 +++++----- shared/src/test/mockCase.ts | 8 ++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/__TODO_10504.md b/__TODO_10504.md index eb6fe954341..c55314b4ddd 100644 --- a/__TODO_10504.md +++ b/__TODO_10504.md @@ -2,4 +2,5 @@ TODO: - Remove pk/sk from getCaseByDocketNumber (in both 10491 and 10504) - numberOfPages commented out in upsertCaseCorrespondence?? -- case-worksheets| -- find and remove \ No newline at end of file +- case-worksheets| -- find and remove +- use of getFreshMockCase -- before, we sent undefined, so the caseStatusHistory was always fresh; now, following the type, we send in [], so that it is updated (Case.caseStatusHistory is assigned to the reference of rawCase.caseStatusHistory). Should we pass in undefined instead and change the type rule? \ No newline at end of file diff --git a/shared/src/business/entities/cases/Case.test.ts b/shared/src/business/entities/cases/Case.test.ts index 1933bc1d3e3..d810fad2478 100644 --- a/shared/src/business/entities/cases/Case.test.ts +++ b/shared/src/business/entities/cases/Case.test.ts @@ -1,4 +1,7 @@ /* eslint-disable max-lines */ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; +import '@web-api/persistence/postgres/cases/mocks.jest'; +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS, CASE_STATUS_TYPES, @@ -126,7 +129,9 @@ describe('Case entity', () => { }); it('defaults the orders to false', () => { - const myCase = new Case(MOCK_CASE, { authorizedUser: mockDocketClerkUser }); + const myCase = new Case(MOCK_CASE, { + authorizedUser: mockDocketClerkUser, + }); expect(myCase).toMatchObject({ isSealed: false, diff --git a/shared/src/business/entities/cases/Case.ts b/shared/src/business/entities/cases/Case.ts index 7187672b71e..01d777646fa 100644 --- a/shared/src/business/entities/cases/Case.ts +++ b/shared/src/business/entities/cases/Case.ts @@ -85,7 +85,7 @@ export class Case extends JoiValidationEntity { public blocked?: boolean; public blockedDate?: string; public blockedReason?: string; - public caseStatusHistory: CaseStatusChange[]; + public caseStatusHistory?: CaseStatusChange[]; public caseNote?: string; public damages?: number; public highPriority?: boolean; @@ -134,7 +134,7 @@ export class Case extends JoiValidationEntity { public noticeOfTrialDate?: string; public docketNumberWithSuffix?: string; public canAllowDocumentService?: boolean; - public canAllowPrintableDocketRecord!: boolean; + public canAllowPrintableDocketRecord?: boolean; public canDojPractitionersRepresentParty?: boolean; public archivedDocketEntries?: RawDocketEntry[]; public docketEntries: any[]; @@ -1493,7 +1493,7 @@ export class Case extends JoiValidationEntity { const date = createISODateString(); this.status = updatedCaseStatus; - this.caseStatusHistory.push({ + this.caseStatusHistory?.push({ changedBy, date, updatedCaseStatus, @@ -2144,11 +2144,11 @@ export const shouldGenerateNoticesForCase = rawCase => { /** * determines whether or not we should show the printable docket record - * @param {Object} rawCase the case we are using to determine whether we should show the printable docket record + * @param {Object} rawCase the case we are using to determine whether we should show the printable docket record * @returns {Boolean} whether or not we should show the printable docket record */ export const canAllowPrintableDocketRecord = rawCase => { - if (typeof rawCase.canAllowPrintableDocketRecord !== 'undefined') { + if (rawCase.canAllowPrintableDocketRecord !== undefined) { return rawCase.canAllowPrintableDocketRecord; } return rawCase.status !== CASE_STATUS_TYPES.new; diff --git a/shared/src/test/mockCase.ts b/shared/src/test/mockCase.ts index 2cc94d2e1e8..82d5ca8fd19 100644 --- a/shared/src/test/mockCase.ts +++ b/shared/src/test/mockCase.ts @@ -16,11 +16,11 @@ import { docketClerkUser, judgeUser } from './mockUsers'; export const MOCK_CASE: RawCase = { archivedDocketEntries: [], - associatedJudge: 'Ashford', - associatedJudgeId: '190ad132-18d0-43ec-bafb-15468e405481', - canAllowPrintableDocketRecord: false, + associatedJudge: undefined, + associatedJudgeId: undefined, + canAllowPrintableDocketRecord: undefined, caseCaption: 'Test Petitioner, Petitioner', - caseStatusHistory: [], + caseStatusHistory: undefined, caseType: CASE_TYPES_MAP.other, consolidatedCases: [], correspondence: [], From 81af9d72326476841f11d1eb3f74991c6ccdcd18 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 13:09:50 -0500 Subject: [PATCH 17/47] 10504-dxox: fix more tests, and some types --- __TODO_10504.md | 3 +-- .../entities/cases/Case.removeFromTrial.test.ts | 4 ++-- .../caseDeadline/validateCaseDeadlineInteractor.ts | 4 +--- .../calculateDaysElapsedSinceLastStatusChange.ts | 7 +++++-- .../getCaseWorksheetsByJudgeInteractor.test.ts | 14 ++++++++------ web-api/src/lambdas/migration/migration.test.ts | 13 ++++++++----- .../judgeActivityReportHelper.test.ts | 14 +++++++------- .../presenter/computeds/caseStatusHistoryHelper.ts | 4 ++-- .../src/presenter/computeds/docketRecordHelper.ts | 2 +- 9 files changed, 35 insertions(+), 30 deletions(-) diff --git a/__TODO_10504.md b/__TODO_10504.md index c55314b4ddd..eb6fe954341 100644 --- a/__TODO_10504.md +++ b/__TODO_10504.md @@ -2,5 +2,4 @@ TODO: - Remove pk/sk from getCaseByDocketNumber (in both 10491 and 10504) - numberOfPages commented out in upsertCaseCorrespondence?? -- case-worksheets| -- find and remove -- use of getFreshMockCase -- before, we sent undefined, so the caseStatusHistory was always fresh; now, following the type, we send in [], so that it is updated (Case.caseStatusHistory is assigned to the reference of rawCase.caseStatusHistory). Should we pass in undefined instead and change the type rule? \ No newline at end of file +- case-worksheets| -- find and remove \ No newline at end of file diff --git a/shared/src/business/entities/cases/Case.removeFromTrial.test.ts b/shared/src/business/entities/cases/Case.removeFromTrial.test.ts index dc50e186da8..732d6ddcb9d 100644 --- a/shared/src/business/entities/cases/Case.removeFromTrial.test.ts +++ b/shared/src/business/entities/cases/Case.removeFromTrial.test.ts @@ -40,7 +40,7 @@ describe('removeFromTrial', () => { changedBy: user, }); const indexOfLastCaseHistoryItem = - caseToUpdate.caseStatusHistory.length - 1; + caseToUpdate.caseStatusHistory!.length - 1; expect(caseToUpdate.status).toEqual( CASE_STATUS_TYPES.generalDocketReadyForTrial, @@ -51,7 +51,7 @@ describe('removeFromTrial', () => { expect(caseToUpdate.trialSessionId).toBeFalsy(); expect(caseToUpdate.trialTime).toBeFalsy(); expect( - caseToUpdate.caseStatusHistory[indexOfLastCaseHistoryItem], + caseToUpdate.caseStatusHistory![indexOfLastCaseHistoryItem], ).toMatchObject({ changedBy: user }); }); diff --git a/shared/src/business/useCases/caseDeadline/validateCaseDeadlineInteractor.ts b/shared/src/business/useCases/caseDeadline/validateCaseDeadlineInteractor.ts index df985534c88..5c2c9a8f224 100644 --- a/shared/src/business/useCases/caseDeadline/validateCaseDeadlineInteractor.ts +++ b/shared/src/business/useCases/caseDeadline/validateCaseDeadlineInteractor.ts @@ -4,9 +4,7 @@ export const validateCaseDeadlineInteractor = ( applicationContext, { caseDeadline }: { caseDeadline: RawCaseDeadline }, ): Record | null => { - const errors = new CaseDeadline(caseDeadline, { - applicationContext, - }).getFormattedValidationErrors(); + const errors = new CaseDeadline(caseDeadline).getFormattedValidationErrors(); return errors; }; diff --git a/shared/src/business/utilities/calculateDaysElapsedSinceLastStatusChange.ts b/shared/src/business/utilities/calculateDaysElapsedSinceLastStatusChange.ts index 4e4560e4804..1034153f58d 100644 --- a/shared/src/business/utilities/calculateDaysElapsedSinceLastStatusChange.ts +++ b/shared/src/business/utilities/calculateDaysElapsedSinceLastStatusChange.ts @@ -5,10 +5,13 @@ import { isEmpty } from 'lodash'; export const calculateDaysElapsedSinceLastStatusChange = ( applicationContext: IApplicationContext, individualCase: { - caseStatusHistory: CaseStatusChange[]; + caseStatusHistory?: CaseStatusChange[]; }, ): { daysElapsedSinceLastStatusChange: number; statusDate: string } => { - if (isEmpty(individualCase.caseStatusHistory)) { + if ( + !individualCase.caseStatusHistory || // Redundant, but helps typescript not complain later + isEmpty(individualCase.caseStatusHistory) + ) { return { daysElapsedSinceLastStatusChange: 0, statusDate: '' }; } diff --git a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts index 6b9baec6844..8a5a4ca39b1 100644 --- a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts +++ b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts @@ -12,12 +12,16 @@ import { import { MOCK_CASE_WORKSHEET } from '@shared/test/mockCaseWorksheet'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; import { judgeUser } from '@shared/test/mockUsers'; import { mockJudgeUser, mockPetitionsClerkUser, } from '@shared/test/mockAuthUsers'; +const getCaseWorksheetsByDocketNumber = + getCaseWorksheetsByDocketNumberMock as jest.Mock; + describe('getCaseWorksheetsByJudgeInteractor', () => { let mockGetDocketNumbersByStatusAndByJudgeResult: RawCase[] = []; @@ -53,12 +57,10 @@ describe('getCaseWorksheetsByJudgeInteractor', () => { beforeAll(() => { applicationContext.getSearchClient().count = jest.fn(); - applicationContext - .getPersistenceGateway() - .getCaseWorksheetsByDocketNumber.mockImplementation(() => [ - mockCaseWorksheet10123, - mockCaseWorksheet10223, - ]); + getCaseWorksheetsByDocketNumber.mockImplementation(() => [ + mockCaseWorksheet10123, + mockCaseWorksheet10223, + ]); }); applicationContext .getPersistenceGateway() diff --git a/web-api/src/lambdas/migration/migration.test.ts b/web-api/src/lambdas/migration/migration.test.ts index 6e335236adc..326f646de15 100644 --- a/web-api/src/lambdas/migration/migration.test.ts +++ b/web-api/src/lambdas/migration/migration.test.ts @@ -20,11 +20,14 @@ describe('migration', () => { }); it('migrates items and generates dynamodb PutRequest objects with the resulting data', async () => { - const mockCase = marshall({ - ...MOCK_CASE, - pk: `case|${MOCK_CASE.docketNumber}`, - sk: `case|${MOCK_CASE.docketNumber}`, - }); + const mockCase = marshall( + { + ...MOCK_CASE, + pk: `case|${MOCK_CASE.docketNumber}`, + sk: `case|${MOCK_CASE.docketNumber}`, + }, + { removeUndefinedValues: true }, + ); const mockItems: Record[] = [mockCase]; const mockMigrateRecords = jest.fn().mockReturnValue(mockItems); const dynamodb = new DynamoDBClient({ diff --git a/web-client/src/presenter/computeds/JudgeActivityReport/judgeActivityReportHelper.test.ts b/web-client/src/presenter/computeds/JudgeActivityReport/judgeActivityReportHelper.test.ts index 0b57a01f377..8f0804a9f80 100644 --- a/web-client/src/presenter/computeds/JudgeActivityReport/judgeActivityReportHelper.test.ts +++ b/web-client/src/presenter/computeds/JudgeActivityReport/judgeActivityReportHelper.test.ts @@ -411,7 +411,7 @@ describe('judgeActivityReportHelper', () => { ...MOCK_SUBMITTED_CASE, caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2023-05-11T14:19:28.717Z', }, ], @@ -422,7 +422,7 @@ describe('judgeActivityReportHelper', () => { ...MOCK_SUBMITTED_CASE, caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2023-05-29T14:19:28.717Z', }, ], @@ -432,7 +432,7 @@ describe('judgeActivityReportHelper', () => { ...MOCK_SUBMITTED_CASE, caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2023-05-15T14:19:28.717Z', }, ], @@ -535,7 +535,7 @@ describe('judgeActivityReportHelper', () => { associatedJudge: 'Colvin', caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2015-05-11T14:19:28.717Z', }, ], @@ -546,7 +546,7 @@ describe('judgeActivityReportHelper', () => { associatedJudge: 'Ashford', caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2023-05-11T14:19:28.717Z', }, ], @@ -557,7 +557,7 @@ describe('judgeActivityReportHelper', () => { associatedJudge: 'Colvin', caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2023-05-11T14:19:28.717Z', }, ], @@ -568,7 +568,7 @@ describe('judgeActivityReportHelper', () => { associatedJudge: 'Colvin', caseStatusHistory: [ { - ...MOCK_SUBMITTED_CASE.caseStatusHistory[0], + ...MOCK_SUBMITTED_CASE.caseStatusHistory?.[0], date: '2017-05-11T14:19:28.717Z', }, ], diff --git a/web-client/src/presenter/computeds/caseStatusHistoryHelper.ts b/web-client/src/presenter/computeds/caseStatusHistoryHelper.ts index 61de8f331fc..af005dc3b4a 100644 --- a/web-client/src/presenter/computeds/caseStatusHistoryHelper.ts +++ b/web-client/src/presenter/computeds/caseStatusHistoryHelper.ts @@ -16,12 +16,12 @@ export const caseStatusHistoryHelper = ( const caseStatusHistory = get(state.caseDetail.caseStatusHistory); return { - formattedCaseStatusHistory: caseStatusHistory.map(history => ({ + formattedCaseStatusHistory: caseStatusHistory?.map(history => ({ ...history, formattedDateChanged: applicationContext .getUtilities() .formatDateString(history.date, 'MMDDYY'), })), - isTableDisplayed: caseStatusHistory.length > 0, + isTableDisplayed: caseStatusHistory && caseStatusHistory.length > 0, }; }; diff --git a/web-client/src/presenter/computeds/docketRecordHelper.ts b/web-client/src/presenter/computeds/docketRecordHelper.ts index 5bfa18e95dc..77eca8d9661 100644 --- a/web-client/src/presenter/computeds/docketRecordHelper.ts +++ b/web-client/src/presenter/computeds/docketRecordHelper.ts @@ -9,7 +9,7 @@ export const docketRecordHelper = ( countOfDocumentsForDownload: number; showBatchDownloadControls: boolean; showEditOrSealDocketRecordEntry: boolean; - showPrintableDocketRecord: boolean; + showPrintableDocketRecord?: boolean; sortLabelTextMobile: string; } => { const permissions = get(state.permissions); From db2846a5d9d78cb1fdc0fde0dda7f24ba70dc7ce Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 16:54:37 -0500 Subject: [PATCH 18/47] 10504-dxox: remove dynamo persistence from client test application context --- .../src/test/createClientTestApplicationContext.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/web-client/src/test/createClientTestApplicationContext.ts b/web-client/src/test/createClientTestApplicationContext.ts index 678a2bc64a9..d2be92956b9 100644 --- a/web-client/src/test/createClientTestApplicationContext.ts +++ b/web-client/src/test/createClientTestApplicationContext.ts @@ -68,7 +68,6 @@ import { } from '@shared/business/utilities/generateChangeOfAddressTemplate'; import { getAllWebSocketConnections } from '@web-api/persistence/dynamo/notifications/getAllWebSocketConnections'; import { getCaseByDocketNumber } from '@web-api/persistence/dynamo/cases/getCaseByDocketNumber'; -import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getCaseDocumentsIdsFilteredByDocumentType } from '@shared/business/utilities/getCaseDocumentsIdsFilteredByDocumentType'; import { getConstants } from '@web-client/getConstants'; import { getCropBox } from '@shared/business/utilities/getCropBox'; @@ -88,7 +87,6 @@ import { getStampBoxCoordinates } from '@shared/business/utilities/getStampBoxCo import { getTextByCount } from '@shared/business/utilities/getTextByCount'; import { getTrialSessionById } from '@web-api/persistence/dynamo/trialSessions/getTrialSessionById'; import { getUserById as getUserByIdPersistence } from '@web-api/persistence/dynamo/users/getUserById'; -import { getWorkItemById as getWorkItemByIdPersistence } from '@web-api/persistence/dynamo/workitems/getWorkItemById'; import { incrementCounter } from '@web-api/persistence/dynamo/helpers/incrementCounter'; import { putWorkItemInOutbox } from '@web-api/persistence/dynamo/workitems/putWorkItemInOutbox'; import { removeItem } from '@web-client/persistence/localStorage/removeItem'; @@ -107,7 +105,6 @@ import { updateCase } from '@web-api/persistence/dynamo/cases/updateCase'; import { updateDocketEntry } from '@web-api/persistence/dynamo/documents/updateDocketEntry'; import { updateUserRecords } from '@web-api/persistence/dynamo/users/createNewPractitionerUser'; import { uploadDocumentAndMakeSafeInteractor } from '@shared/business/useCases/uploadDocumentAndMakeSafeInteractor'; -import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; import { validatePenaltiesInteractor } from '@shared/business/useCases/validatePenaltiesInteractor'; import { verifyCaseForUser } from '@web-api/persistence/dynamo/cases/verifyCaseForUser'; import path from 'path'; @@ -434,10 +431,6 @@ const createTestApplicationContext = () => { .mockImplementation(getAllWebSocketConnections), getCalendaredCasesForTrialSession: jest.fn(), getCaseByDocketNumber: jest.fn().mockImplementation(getCaseByDocketNumber), - getCaseDeadlinesByDateRange: jest.fn(), - getCaseDeadlinesByDocketNumber: jest - .fn() - .mockImplementation(getCaseDeadlinesByDocketNumber), getCasesByFilters: jest.fn(), getDispatchNotification: jest.fn(), getDocument: jest.fn(), @@ -458,8 +451,6 @@ const createTestApplicationContext = () => { getTrialSessionJobStatusForCase: jest.fn(), getUserById: jest.fn().mockImplementation(getUserByIdPersistence), getUserCaseMappingsByDocketNumber: jest.fn().mockReturnValue([]), - getWorkItemById: jest.fn().mockImplementation(getWorkItemByIdPersistence), - getWorkItemsByDocketNumber: jest.fn().mockReturnValue([]), incrementCounter, incrementKeyCount: jest.fn(), isEmailAvailable: jest.fn(), @@ -475,9 +466,6 @@ const createTestApplicationContext = () => { setPriorityOnAllWorkItems: jest.fn(), setTrialSessionJobStatusForCase: jest.fn(), updateCase: jest.fn().mockImplementation(updateCase), - updateCaseCorrespondence: jest - .fn() - .mockImplementation(upsertCaseCorrespondence), updateCaseHearing: jest.fn(), updateDocketEntry: jest.fn().mockImplementation(updateDocketEntry), uploadPdfFromClient: jest.fn().mockImplementation(() => ''), From a09c769cc0e229bf21f2891333d2e1fe8fe307a5 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 16:59:36 -0500 Subject: [PATCH 19/47] 10504-dxox: fix failing scripts test --- scripts/dynamo/fix-race-condition-served-in-drafts.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts b/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts index 5fc8fc3b3bf..bac49e19fd2 100644 --- a/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts +++ b/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts @@ -1,6 +1,8 @@ /* * @jest-environment node */ +import '@web-api/persistence/postgres/cases/mocks.jest'; + import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'; import { MOCK_DOCUMENTS } from '@shared/test/mockDocketEntry'; import { applicationContext } from '@shared/business/test/createTestApplicationContext'; From 739a7d7d405e5f9f8e1a5499b4a95714c1f0a67d Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 18:14:13 -0500 Subject: [PATCH 20/47] 10504-dxox: fix failing integration test --- shared/src/business/test/createTestApplicationContext.ts | 5 ----- .../caseWorksheet/getCaseWorksheetsByDocketNumber.ts | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/shared/src/business/test/createTestApplicationContext.ts b/shared/src/business/test/createTestApplicationContext.ts index f247ddd8436..c559cb882d5 100644 --- a/shared/src/business/test/createTestApplicationContext.ts +++ b/shared/src/business/test/createTestApplicationContext.ts @@ -79,7 +79,6 @@ import { import { getAllFeatureFlagsInteractor } from '@web-api/business/useCases/featureFlag/getAllFeatureFlagsInteractor'; import { getAllWebSocketConnections } from '@web-api/persistence/dynamo/notifications/getAllWebSocketConnections'; import { getCaseByDocketNumber } from '@web-api/persistence/dynamo/cases/getCaseByDocketNumber'; -import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getCaseDocumentsIdsFilteredByDocumentType } from '@shared/business/utilities/getCaseDocumentsIdsFilteredByDocumentType'; import { getConfigurationItemValue } from '@web-api/persistence/dynamo/deployTable/getConfigurationItemValue'; import { getConstants } from '@web-client/getConstants'; @@ -483,10 +482,6 @@ export const createTestApplicationContext = () => { .mockImplementation(getAllWebSocketConnections), getCalendaredCasesForTrialSession: jest.fn(), getCaseByDocketNumber: jest.fn().mockImplementation(getCaseByDocketNumber), - getCaseDeadlinesByDateRange: jest.fn(), - getCaseDeadlinesByDocketNumber: jest - .fn() - .mockImplementation(getCaseDeadlinesByDocketNumber), getCasesByFilters: jest.fn(), getConfigurationItemValue: jest .fn() diff --git a/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts b/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts index ad77362073e..9f0b7c81993 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts +++ b/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts @@ -1,15 +1,18 @@ import { CaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { caseWorksheetEntity } from '@web-api/persistence/postgres/caseWorksheet/mapper'; import { getDbReader } from '@web-api/database'; +import { isEmpty } from 'lodash'; export const getCaseWorksheetsByDocketNumber = async ({ docketNumbers, }: { docketNumbers: string[]; }): Promise => { + if (isEmpty(docketNumbers)) return []; + const caseWorksheets = await getDbReader(reader => reader - .selectFrom('dwCaseCorrespondence') + .selectFrom('dwCaseWorksheet') .where('docketNumber', 'in', docketNumbers) .selectAll() .execute(), From cba4b8c0b4b25f1e7c339e18706bdece90799d64 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 7 Nov 2024 20:07:23 -0500 Subject: [PATCH 21/47] 10504-dxox: null check in caseWorksheet mapper --- web-api/src/persistence/postgres/caseWorksheet/mapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-api/src/persistence/postgres/caseWorksheet/mapper.ts b/web-api/src/persistence/postgres/caseWorksheet/mapper.ts index b8366eeae49..43292d139ee 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/mapper.ts +++ b/web-api/src/persistence/postgres/caseWorksheet/mapper.ts @@ -42,7 +42,7 @@ export function caseWorksheetEntity(caseWorksheet) { return new CaseWorksheet( transformNullToUndefined({ ...caseWorksheet, - filingDate: caseWorksheet.finalBriefDueDate.toISOString(), + filingDate: caseWorksheet.finalBriefDueDate?.toISOString(), }), ); } From 3fbe127ae2018355f3323e981bbd017cfa42a32e Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Fri, 8 Nov 2024 08:04:42 -0500 Subject: [PATCH 22/47] 10504-dxox: fix integration tests failing for timezone reasons --- __TODO_10504.md | 1 - .../journey/docketClerkViewsAutoGeneratedCaseDeadline.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/__TODO_10504.md b/__TODO_10504.md index eb6fe954341..923f1b11c5c 100644 --- a/__TODO_10504.md +++ b/__TODO_10504.md @@ -2,4 +2,3 @@ TODO: - Remove pk/sk from getCaseByDocketNumber (in both 10491 and 10504) - numberOfPages commented out in upsertCaseCorrespondence?? -- case-worksheets| -- find and remove \ No newline at end of file diff --git a/web-client/integration-tests/journey/docketClerkViewsAutoGeneratedCaseDeadline.ts b/web-client/integration-tests/journey/docketClerkViewsAutoGeneratedCaseDeadline.ts index 7c67d4d47fc..31e31fb0012 100644 --- a/web-client/integration-tests/journey/docketClerkViewsAutoGeneratedCaseDeadline.ts +++ b/web-client/integration-tests/journey/docketClerkViewsAutoGeneratedCaseDeadline.ts @@ -17,7 +17,7 @@ export const docketClerkViewsAutoGeneratedCaseDeadline = ({ }); expect(caseDetail.caseDeadlines[0].deadlineDate).toEqual( - '2050-02-02T00:00:00.000-05:00', + '2050-02-02T05:00:00.000Z', ); expect(caseDetail.caseDeadlines[0].description).toEqual( expectedDeadlineDescription, From 3df68d911e9e203670be7cc8c36b892b38f60d6a Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Fri, 8 Nov 2024 09:09:49 -0500 Subject: [PATCH 23/47] 10504-dxox: fix more timezone format mismatches in tests --- web-client/integration-tests/caseWorksheetsJourney.test.ts | 2 +- .../journey/petitionsClerkViewsDeadlineReport.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web-client/integration-tests/caseWorksheetsJourney.test.ts b/web-client/integration-tests/caseWorksheetsJourney.test.ts index ced22237e7b..667a07cfbc7 100644 --- a/web-client/integration-tests/caseWorksheetsJourney.test.ts +++ b/web-client/integration-tests/caseWorksheetsJourney.test.ts @@ -299,7 +299,7 @@ describe('Case Worksheets Journey', () => { docketNumber: cerebralTest.docketNumber, status: CASE_STATUS_TYPES.cav, worksheet: { - finalBriefDueDate: '2023-08-29', + finalBriefDueDate: '2023-08-29T04:00:00.000Z', statusOfMatter: CaseWorksheet.STATUS_OF_MATTER_OPTIONS[0], }, }); diff --git a/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts b/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts index 3b95dc287f9..2e8af70cdd0 100644 --- a/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts +++ b/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts @@ -117,12 +117,12 @@ export const petitionsClerkViewsDeadlineReport = ( expect(deadlines).toMatchObject([ { associatedJudge: 'Buch', - deadlineDate: `${options.year}-01-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-01-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[0], }, { associatedJudge: 'Buch', - deadlineDate: `${options.year}-02-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-02-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[0], }, ]); From 54c0cab384f6bd428e75c0b3de35a9efd8dcb8a4 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Fri, 8 Nov 2024 13:48:35 -0500 Subject: [PATCH 24/47] 10504-dxox: change createCaseDeadline to upserCaseDeadline, and related work --- .../autoGenerateDeadline.test.ts | 6 ++--- .../useCaseHelper/autoGenerateDeadline.ts | 6 ++--- .../updateCaseAndAssociations.test.ts | 14 ++++------ .../updateCaseAndAssociations.ts | 8 +++--- .../createCaseDeadlineInteractor.ts | 6 ++--- .../updateCaseDeadlineInteractor.test.ts | 6 ++--- .../updateCaseDeadlineInteractor.ts | 6 ++--- .../caseDeadlines/createCaseDeadline.ts | 21 --------------- .../getCaseDeadlinesByDocketNumber.ts | 2 +- .../postgres/caseDeadlines/mapper.ts | 18 ------------- .../postgres/caseDeadlines/mocks.jest.ts | 4 +-- .../caseDeadlines/upsertCaseDeadline.ts | 26 +++++++++++++++++++ .../petitionsClerkViewsDeadlineReport.ts | 12 ++++----- 13 files changed, 59 insertions(+), 76 deletions(-) delete mode 100644 web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts create mode 100644 web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts index d113463c8c3..1f6456bed17 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts @@ -1,8 +1,8 @@ import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { autoGenerateDeadline } from './autoGenerateDeadline'; -import { createCaseDeadline as createCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; +import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; -const createCaseDeadline = createCaseDeadlineMock as jest.Mock; +const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; describe('autoGenerateDeadline', () => { it('should create a case deadline', async () => { @@ -17,6 +17,6 @@ describe('autoGenerateDeadline', () => { }, }); - expect(createCaseDeadline.mock.calls[0][0].caseDeadline).toBeDefined(); + expect(upsertCaseDeadline.mock.calls[0][0].caseDeadline).toBeDefined(); }); }); diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts index 4155df94b4b..4e2e93b1cc2 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts @@ -1,5 +1,5 @@ import { CaseDeadline } from '../../../../shared/src/business/entities/CaseDeadline'; -import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; +import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; export const autoGenerateDeadline = async ({ deadlineDate, @@ -15,7 +15,7 @@ export const autoGenerateDeadline = async ({ sortableDocketNumber: subjectCaseEntity.sortableDocketNumber, }); - await createCaseDeadline({ - caseDeadline: newCaseDeadline.validate().toRawObject(), + await upsertCaseDeadline({ + caseDeadlineToUpsert: newCaseDeadline.validate().toRawObject(), }); }; diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index 0198dcce1c2..04a76f877be 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -20,7 +20,6 @@ import { MOCK_WORK_ITEM } from '../../../../../shared/src/test/mockWorkItem'; import { Message } from '../../../../../shared/src/business/entities/Message'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { cloneDeep } from 'lodash'; -import { createCaseDeadline as createCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { docketClerkUser } from '../../../../../shared/src/test/mockUsers'; import { getCaseDeadlinesByDocketNumber as getCaseDeadlinesByDocketNumberMock } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getMessagesByDocketNumber as getMessagesByDocketNumberMock } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; @@ -28,12 +27,13 @@ import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseAndAssociations } from './updateCaseAndAssociations'; import { updateMessage as updateMessageMock } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; import { v4 as uuidv4 } from 'uuid'; const getMessagesByDocketNumber = getMessagesByDocketNumberMock as jest.Mock; const updateMessage = updateMessageMock as jest.Mock; -const createCaseDeadline = createCaseDeadlineMock as jest.Mock; +const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; const getCaseDeadlinesByDocketNumber = getCaseDeadlinesByDocketNumberMock as jest.Mock; @@ -198,9 +198,7 @@ describe('updateCaseAndAssociations', () => { ).not.toHaveBeenCalled(); // updateCaseDeadlines - expect( - applicationContext.getPersistenceGateway().createCaseDeadline, - ).not.toHaveBeenCalled(); + expect(upsertCaseDeadline).not.toHaveBeenCalled(); // update the case itself, final persistence call expect( @@ -951,9 +949,7 @@ describe('updateCaseAndAssociations', () => { caseToUpdate: updatedCase, }); expect(getCaseDeadlinesByDocketNumber).not.toHaveBeenCalled(); - expect( - applicationContext.getPersistenceGateway().createCaseDeadline, - ).not.toHaveBeenCalled(); + expect(upsertCaseDeadline).not.toHaveBeenCalled(); }); it('should fetch and persist case deadline data when associated judge has changed', async () => { @@ -969,7 +965,7 @@ describe('updateCaseAndAssociations', () => { }); expect(getCaseDeadlinesByDocketNumber).toHaveBeenCalled(); expect(CaseDeadline.validateRawCollection).toHaveBeenCalled(); - expect(createCaseDeadline).toHaveBeenCalledWith({ + expect(upsertCaseDeadline).toHaveBeenCalledWith({ caseDeadline: { some: 'deadline' }, }); }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index cdcb42734b6..8262ec3684b 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -8,12 +8,12 @@ import { PrivatePractitioner } from '../../../../../shared/src/business/entities import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { WorkItem } from '../../../../../shared/src/business/entities/WorkItem'; -import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber'; import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; import diff from 'diff-arrays-of-objects'; /** @@ -392,7 +392,6 @@ const updateCaseDeadlines = async ({ if (oldCase.associatedJudge === caseToUpdate.associatedJudge) { return []; } - const deadlines = await getCaseDeadlinesByDocketNumber({ docketNumber: caseToUpdate.docketNumber, }); @@ -406,8 +405,8 @@ const updateCaseDeadlines = async ({ return validCaseDeadlines.map( caseDeadline => function updateCaseDeadlines_cb() { - return createCaseDeadline({ - caseDeadline, + return upsertCaseDeadline({ + caseDeadlineToUpsert: caseDeadline, }); }, ); @@ -429,6 +428,7 @@ export const updateCaseAndAssociations = async ({ authorizedUser: UnknownAuthUser; caseToUpdate: any; }): Promise => { + console.log('updateCaseAndAssociations'); const caseEntity: Case = caseToUpdate.validate ? caseToUpdate : new Case(caseToUpdate, { diff --git a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts index 3dc26188848..b4348ba8195 100644 --- a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts @@ -7,7 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { createCaseDeadline as createDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; +import { upsertCaseDeadline as upsertDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const createCaseDeadline = async ( @@ -33,8 +33,8 @@ export const createCaseDeadline = async ( associatedJudgeId: caseEntity.associatedJudgeId, }); - await createDeadline({ - caseDeadline: newCaseDeadline.validate().toRawObject(), + await upsertDeadline({ + caseDeadlineToUpsert: newCaseDeadline.validate().toRawObject(), }); caseEntity = await applicationContext diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts index ecc160e0668..e0bfac8583f 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts @@ -1,11 +1,11 @@ import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { createCaseDeadline as createCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { deleteCaseDeadline as deleteCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; import { mockPetitionsClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseDeadlineInteractor } from './updateCaseDeadlineInteractor'; +import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; -const createCaseDeadline = createCaseDeadlineMock as jest.Mock; +const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; const deleteCaseDeadline = deleteCaseDeadlineMock as jest.Mock; describe('updateCaseDeadlineInteractor', () => { @@ -42,7 +42,7 @@ describe('updateCaseDeadlineInteractor', () => { expect(deleteCaseDeadline.mock.calls[0][0]).toMatchObject({ caseDeadlineId: CASE_DEADLINE_ID, }); - expect(createCaseDeadline.mock.calls[0][0]).toMatchObject({ + expect(upsertCaseDeadline.mock.calls[0][0]).toMatchObject({ caseDeadline: mockCaseDeadline, }); expect(caseDeadline).toBeDefined(); diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts index 2c9df8f20a1..3e9e1239494 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts @@ -5,8 +5,8 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { createCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline'; import { deleteCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; +import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; export const updateCaseDeadlineInteractor = async ( { caseDeadline }: { caseDeadline: CaseDeadline }, @@ -24,8 +24,8 @@ export const updateCaseDeadlineInteractor = async ( caseDeadlineId: caseDeadlineToUpdate.caseDeadlineId, }); - await createCaseDeadline({ - caseDeadline: caseDeadlineToUpdate, + await upsertCaseDeadline({ + caseDeadlineToUpsert: caseDeadlineToUpdate, }); return caseDeadlineToUpdate; diff --git a/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts deleted file mode 100644 index df07b021af3..00000000000 --- a/web-api/src/persistence/postgres/caseDeadlines/createCaseDeadline.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; -import { - caseDeadlineEntity, - toKyselyNewCaseDeadline, -} from '@web-api/persistence/postgres/caseDeadlines/mapper'; -import { getDbWriter } from '@web-api/database'; - -export const createCaseDeadline = async ({ - caseDeadline, -}: { - caseDeadline: RawCaseDeadline; -}) => { - const createdCaseDeadline = await getDbWriter(writer => - writer - .insertInto('dwCaseDeadline') - .values(toKyselyNewCaseDeadline(caseDeadline)) - .returningAll() - .executeTakeFirst(), - ); - return caseDeadlineEntity(createdCaseDeadline); -}; diff --git a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts index 8ccd8576d60..ed724f19116 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/getCaseDeadlinesByDocketNumber.ts @@ -16,5 +16,5 @@ export const getCaseDeadlinesByDocketNumber = async ({ .execute(), ); - return caseDeadlines.map(message => caseDeadlineEntity(message)); + return caseDeadlines.map(caseDeadline => caseDeadlineEntity(caseDeadline)); }; diff --git a/web-api/src/persistence/postgres/caseDeadlines/mapper.ts b/web-api/src/persistence/postgres/caseDeadlines/mapper.ts index 6cb6ec39958..6eea781036d 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/mapper.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/mapper.ts @@ -18,30 +18,12 @@ function pickFields(deadline): NewCaseDeadlineKysely { }; } -// export function toKyselyUpdateMessage( -// message: RawMessage, -// ): UpdateMessageKysely { -// return pickFields(message); -// } - -// export function toKyselyUpdateMessages( -// messages: RawMessage[], -// ): UpdateMessageKysely[] { -// return messages.map(pickFields); -// } - export function toKyselyNewCaseDeadline( deadline: RawCaseDeadline, ): NewCaseDeadlineKysely { return pickFields(deadline); } -// export function toKyselyNewMessages( -// messages: RawMessage[], -// ): NewMessageKysely[] { -// return messages.map(pickFields); -// } - export function caseDeadlineEntity(caseDeadline) { return new CaseDeadline( transformNullToUndefined({ diff --git a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts index 02201244fdb..01ef40c938c 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts @@ -1,8 +1,8 @@ import { mockFactory } from '@shared/test/mockFactory'; jest.mock( - '@web-api/persistence/postgres/caseDeadlines/createCaseDeadline', - () => mockFactory('createCaseDeadline'), + '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline', + () => mockFactory('upsertCaseDeadline'), ); jest.mock( diff --git a/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts new file mode 100644 index 00000000000..d60eb2d36eb --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts @@ -0,0 +1,26 @@ +import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; +import { + caseDeadlineEntity, + toKyselyNewCaseDeadline, +} from '@web-api/persistence/postgres/caseDeadlines/mapper'; +import { getDbWriter } from '@web-api/database'; + +export const upsertCaseDeadline = async ({ + caseDeadlineToUpsert, +}: { + caseDeadlineToUpsert: RawCaseDeadline; +}) => { + const caseDeadline = await getDbWriter(writer => + writer + .insertInto('dwCaseDeadline') + .values(toKyselyNewCaseDeadline(caseDeadlineToUpsert)) + .onConflict(oc => + oc + .column('caseDeadlineId') + .doUpdateSet(toKyselyNewCaseDeadline(caseDeadlineToUpsert)), + ) + .returningAll() + .executeTakeFirst(), + ); + return caseDeadlineEntity(caseDeadline); +}; diff --git a/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts b/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts index 2e8af70cdd0..ff9ee676f56 100644 --- a/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts +++ b/web-client/integration-tests/journey/petitionsClerkViewsDeadlineReport.ts @@ -63,32 +63,32 @@ export const petitionsClerkViewsDeadlineReport = ( expect(deadlines).toMatchObject([ { associatedJudge: 'Buch', - deadlineDate: `${options.year}-01-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-01-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[0], }, { associatedJudge: CHIEF_JUDGE, - deadlineDate: `${options.year}-01-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-01-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[1], }, { associatedJudge: CHIEF_JUDGE, - deadlineDate: `${options.year}-01-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-01-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[2], }, { associatedJudge: 'Buch', - deadlineDate: `${options.year}-02-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-02-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[0], }, { associatedJudge: CHIEF_JUDGE, - deadlineDate: `${options.year}-02-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-02-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[1], }, { associatedJudge: CHIEF_JUDGE, - deadlineDate: `${options.year}-02-${options.day}T00:00:00.000-05:00`, + deadlineDate: `${options.year}-02-${options.day}T05:00:00.000Z`, docketNumber: cerebralTest.createdDocketNumbers[2], }, ]); From 891ae7a7991ab66876b7d6ce655d04ea9e9620fe Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Fri, 8 Nov 2024 14:13:03 -0500 Subject: [PATCH 25/47] 10504-dxox: fix script test and api tests --- .../fix-race-condition-served-in-drafts.test.ts | 1 + .../useCaseHelper/autoGenerateDeadline.test.ts | 4 +++- .../updateCaseAndAssociations.test.ts | 2 +- .../updateCaseDeadlineInteractor.test.ts | 12 ++++-------- .../caseDeadline/updateCaseDeadlineInteractor.ts | 5 ----- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts b/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts index bac49e19fd2..32e40a19992 100644 --- a/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts +++ b/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts @@ -2,6 +2,7 @@ * @jest-environment node */ import '@web-api/persistence/postgres/cases/mocks.jest'; +import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'; import { MOCK_DOCUMENTS } from '@shared/test/mockDocketEntry'; diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts index 1f6456bed17..091e1d37ab8 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts @@ -17,6 +17,8 @@ describe('autoGenerateDeadline', () => { }, }); - expect(upsertCaseDeadline.mock.calls[0][0].caseDeadline).toBeDefined(); + expect( + upsertCaseDeadline.mock.calls[0][0].caseDeadlineToUpsert, + ).toBeDefined(); }); }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index 04a76f877be..55d2b074311 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -966,7 +966,7 @@ describe('updateCaseAndAssociations', () => { expect(getCaseDeadlinesByDocketNumber).toHaveBeenCalled(); expect(CaseDeadline.validateRawCollection).toHaveBeenCalled(); expect(upsertCaseDeadline).toHaveBeenCalledWith({ - caseDeadline: { some: 'deadline' }, + caseDeadlineToUpsert: { some: 'deadline' }, }); }); }); diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts index e0bfac8583f..81b945346a2 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts @@ -1,24 +1,23 @@ import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; +import { CaseDeadline } from '@shared/business/entities/CaseDeadline'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { deleteCaseDeadline as deleteCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; import { mockPetitionsClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseDeadlineInteractor } from './updateCaseDeadlineInteractor'; import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; -const deleteCaseDeadline = deleteCaseDeadlineMock as jest.Mock; describe('updateCaseDeadlineInteractor', () => { const CASE_DEADLINE_ID = '6805d1ab-18d0-43ec-bafb-654e83405416'; - const mockCaseDeadline = { + const mockCaseDeadline = new CaseDeadline({ associatedJudge: 'Buch', associatedJudgeId: 'dabbad02-18d0-43ec-bafb-654e83405416', caseDeadlineId: CASE_DEADLINE_ID, deadlineDate: '2019-03-01T21:42:29.073Z', description: 'hello world', docketNumber: '123-20', - } as any; + }); it('throws an error if the user is not valid or authorized', async () => { await expect( @@ -39,11 +38,8 @@ describe('updateCaseDeadlineInteractor', () => { mockPetitionsClerkUser, ); - expect(deleteCaseDeadline.mock.calls[0][0]).toMatchObject({ - caseDeadlineId: CASE_DEADLINE_ID, - }); expect(upsertCaseDeadline.mock.calls[0][0]).toMatchObject({ - caseDeadline: mockCaseDeadline, + caseDeadlineToUpsert: mockCaseDeadline, }); expect(caseDeadline).toBeDefined(); }); diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts index 3e9e1239494..ff6a22b5223 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts @@ -5,7 +5,6 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { deleteCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline'; import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; export const updateCaseDeadlineInteractor = async ( @@ -20,10 +19,6 @@ export const updateCaseDeadlineInteractor = async ( .validate() .toRawObject(); - await deleteCaseDeadline({ - caseDeadlineId: caseDeadlineToUpdate.caseDeadlineId, - }); - await upsertCaseDeadline({ caseDeadlineToUpsert: caseDeadlineToUpdate, }); From 967414b37b7504584608324959b4a82d1836bcf9 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 11 Nov 2024 10:46:57 -0500 Subject: [PATCH 26/47] 10504-dxox: remove numberOfPages, which looks like it was a spurious field in the original seed data (the entity never uses it), and clean up some commented out code; postpone changes to aggregateCaseItems until everything is moved over --- __TODO_10504.md | 4 -- web-api/src/database-types.ts | 1 - .../postgres/caseWorksheet/mapper.ts | 37 ------------------- .../postgres/correspondence/mapper.ts | 37 ------------------- .../upsertCaseCorrespondence.ts | 1 - .../utils/seed/fixtures/correspodence.ts | 1 - 6 files changed, 81 deletions(-) delete mode 100644 __TODO_10504.md diff --git a/__TODO_10504.md b/__TODO_10504.md deleted file mode 100644 index 923f1b11c5c..00000000000 --- a/__TODO_10504.md +++ /dev/null @@ -1,4 +0,0 @@ -TODO: - -- Remove pk/sk from getCaseByDocketNumber (in both 10491 and 10504) -- numberOfPages commented out in upsertCaseCorrespondence?? diff --git a/web-api/src/database-types.ts b/web-api/src/database-types.ts index 3436cbb70f9..d5021927a68 100644 --- a/web-api/src/database-types.ts +++ b/web-api/src/database-types.ts @@ -54,7 +54,6 @@ export type UpdateCaseKysely = Updateable; export interface CaseCorrespondenceTable { archived?: boolean; correspondenceId: string; - numberOfPages?: number; documentTitle: string; filedBy?: string; filingDate: Date; diff --git a/web-api/src/persistence/postgres/caseWorksheet/mapper.ts b/web-api/src/persistence/postgres/caseWorksheet/mapper.ts index 43292d139ee..212de245012 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/mapper.ts +++ b/web-api/src/persistence/postgres/caseWorksheet/mapper.ts @@ -1,43 +1,6 @@ import { CaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { transformNullToUndefined } from '@web-api/persistence/postgres/utils/transformNullToUndefined'; -// function pickFields(deadline): NewCaseCorrespondenceKysely { -// return { -// associatedJudge: deadline.associatedJudge, -// associatedJudgeId: deadline.associatedJudgeId, -// caseDeadlineId: deadline.caseDeadlineId, -// createdAt: deadline.createdAt, -// deadlineDate: deadline.deadlineDate, -// description: deadline.description, -// docketNumber: deadline.docketNumber, -// sortableDocketNumber: deadline.sortableDocketNumber, -// }; -// } - -// export function toKyselyUpdateMessage( -// message: RawMessage, -// ): UpdateMessageKysely { -// return pickFields(message); -// } - -// export function toKyselyUpdateMessages( -// messages: RawMessage[], -// ): UpdateMessageKysely[] { -// return messages.map(pickFields); -// } - -// export function toKyselyNewCaseDeadline( -// deadline: RawCaseDeadline, -// ): NewCaseDeadlineKysely { -// return pickFields(deadline); -// } - -// export function toKyselyNewMessages( -// messages: RawMessage[], -// ): NewMessageKysely[] { -// return messages.map(pickFields); -// } - export function caseWorksheetEntity(caseWorksheet) { return new CaseWorksheet( transformNullToUndefined({ diff --git a/web-api/src/persistence/postgres/correspondence/mapper.ts b/web-api/src/persistence/postgres/correspondence/mapper.ts index 7b9b5aaba24..66bfc86dd04 100644 --- a/web-api/src/persistence/postgres/correspondence/mapper.ts +++ b/web-api/src/persistence/postgres/correspondence/mapper.ts @@ -1,43 +1,6 @@ import { Correspondence } from '@shared/business/entities/Correspondence'; import { transformNullToUndefined } from '@web-api/persistence/postgres/utils/transformNullToUndefined'; -// function pickFields(deadline): NewCaseCorrespondenceKysely { -// return { -// associatedJudge: deadline.associatedJudge, -// associatedJudgeId: deadline.associatedJudgeId, -// caseDeadlineId: deadline.caseDeadlineId, -// createdAt: deadline.createdAt, -// deadlineDate: deadline.deadlineDate, -// description: deadline.description, -// docketNumber: deadline.docketNumber, -// sortableDocketNumber: deadline.sortableDocketNumber, -// }; -// } - -// export function toKyselyUpdateMessage( -// message: RawMessage, -// ): UpdateMessageKysely { -// return pickFields(message); -// } - -// export function toKyselyUpdateMessages( -// messages: RawMessage[], -// ): UpdateMessageKysely[] { -// return messages.map(pickFields); -// } - -// export function toKyselyNewCaseDeadline( -// deadline: RawCaseDeadline, -// ): NewCaseDeadlineKysely { -// return pickFields(deadline); -// } - -// export function toKyselyNewMessages( -// messages: RawMessage[], -// ): NewMessageKysely[] { -// return messages.map(pickFields); -// } - export function caseCorrespondenceEntity(caseCorrespondence) { return new Correspondence( transformNullToUndefined({ diff --git a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts index aac0cbe56f7..83e6fb9af9c 100644 --- a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts +++ b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts @@ -13,7 +13,6 @@ export const upsertCaseCorrespondence = async ({ archived: correspondence.archived, correspondenceId: correspondence.correspondenceId, docketNumber, - // numberOfPages: correspondence.numberOfPages, documentTitle: correspondence.documentTitle, filedBy: correspondence.filedBy, filingDate: calculateDate({ dateString: correspondence.filingDate }), diff --git a/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts b/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts index 326eba0d742..bb3ad51dcbf 100644 --- a/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts +++ b/web-api/src/persistence/postgres/utils/seed/fixtures/correspodence.ts @@ -9,7 +9,6 @@ export const correspondence: NewCaseCorrespondenceKysely[] = [ documentTitle: 'Internal Memo', filedBy: 'Test Petitionsclerk', filingDate: new Date('2019-08-14T20:35:52.915Z'), - numberOfPages: 1, userId: '3805d1ab-18d0-43ec-bafb-654e83405416', }, ]; From 86cca87508c571cefdd38b76471b54b6a77576cd Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 11 Nov 2024 11:21:36 -0500 Subject: [PATCH 27/47] 10504-dxox: remove numberOfPages from migration --- .../migrations/0005-case-deadline-correspondence-worksheet.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts index f9ca78aef01..7e8fa9ff575 100644 --- a/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts +++ b/web-api/src/persistence/postgres/utils/migrate/migrations/0005-case-deadline-correspondence-worksheet.ts @@ -6,7 +6,6 @@ export async function up(db: Kysely): Promise { .addColumn('correspondenceId', 'varchar', col => col.primaryKey()) .addColumn('documentTitle', 'varchar', col => col.notNull()) .addColumn('docketNumber', 'varchar', col => col.notNull()) - .addColumn('numberOfPages', 'int8') .addColumn('filedBy', 'varchar') .addColumn('userId', 'varchar', col => col.notNull()) .addColumn('archived', 'boolean') From bcab627078dace94af111e6a1a1150057c839aa8 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 12 Nov 2024 13:07:07 -0500 Subject: [PATCH 28/47] 10504-dxox: WIP using upsertCaseCorrespondences instead of upsertCaseCorrespondence and putting docketNumber on Correspondence --- __TODO_10504.txt | 7 +++++ .../business/entities/Correspondence.test.ts | 2 ++ .../src/business/entities/Correspondence.ts | 3 ++ .../cases/Case.archiveCorrespondence.test.ts | 1 + .../Case.deleteCorrespondenceById.test.ts | 1 + .../cases/Case.getCorrespondenceById.test.ts | 1 + .../cases/Case.updateCorrespondence.test.ts | 2 ++ .../entities/cases/PaperPetition.test.ts | 1 + .../test/createTestApplicationContext.ts | 8 ++--- .../updateCaseAndAssociations.test.ts | 12 ++++++-- .../updateCaseAndAssociations.ts | 7 ++--- ...veCorrespondenceDocumentInteractor.test.ts | 15 ++++------ ...archiveCorrespondenceDocumentInteractor.ts | 11 +++---- ...leCorrespondenceDocumentInteractor.test.ts | 9 +++--- .../fileCorrespondenceDocumentInteractor.ts | 10 +++---- ...teCorrespondenceDocumentInteractor.test.ts | 13 ++++---- .../updateCorrespondenceDocumentInteractor.ts | 10 +++---- .../processCorrespondences.ts | 22 ++++++++++++++ .../processMessageEntries.test.ts | 2 -- .../processMessageEntries.ts | 8 ++--- .../processStreamRecordsInteractor.ts | 1 - .../postgres/correspondence/mocks.jest.ts | 4 +-- .../upsertCaseCorrespondence.ts | 30 ------------------- .../upsertCaseCorrespondences.ts | 23 ++++++++++++++ 24 files changed, 115 insertions(+), 88 deletions(-) create mode 100644 __TODO_10504.txt create mode 100644 web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts delete mode 100644 web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts create mode 100644 web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts diff --git a/__TODO_10504.txt b/__TODO_10504.txt new file mode 100644 index 00000000000..eeb88b0e91d --- /dev/null +++ b/__TODO_10504.txt @@ -0,0 +1,7 @@ +I've put docketNumber on Correspondence because: + it makes the stream processing more efficient + it's just a sensible thing to do. +Make sure things work correctly after this change + + + diff --git a/shared/src/business/entities/Correspondence.test.ts b/shared/src/business/entities/Correspondence.test.ts index 6777ac46ea9..eb255d25bdc 100644 --- a/shared/src/business/entities/Correspondence.test.ts +++ b/shared/src/business/entities/Correspondence.test.ts @@ -4,6 +4,7 @@ describe('Correspondence', () => { const validCorrespondence: RawCorrespondence = { archived: false, correspondenceId: 'e9ab90a9-2150-4dd1-90b4-fee2097c23db', + docketNumber: '101-23', documentTitle: 'A Title', entityName: 'Correspondence', filedBy: 'Nika Manpreet', @@ -24,6 +25,7 @@ describe('Correspondence', () => { const correspondence = new Correspondence({ archived: true, correspondenceId: 'e9ab90a9-2150-4dd1-90b4-fee2097c23db', + docketNumber: '101-23', documentTitle: 'A Title', filedBy: 'A dog', filingDate: undefined, diff --git a/shared/src/business/entities/Correspondence.ts b/shared/src/business/entities/Correspondence.ts index cf1bcc303e0..e4665c01a0f 100644 --- a/shared/src/business/entities/Correspondence.ts +++ b/shared/src/business/entities/Correspondence.ts @@ -10,6 +10,7 @@ export class Correspondence extends JoiValidationEntity { public filedBy: string; public filingDate: string; public userId: string; + public docketNumber: string; constructor(rawProps) { super('Correspondence'); @@ -20,6 +21,7 @@ export class Correspondence extends JoiValidationEntity { this.filedBy = rawProps.filedBy; this.filingDate = rawProps.filingDate || createISODateString(); this.userId = rawProps.userId; + this.docketNumber = rawProps.docketNumber; } static VALIDATION_RULES = { @@ -28,6 +30,7 @@ export class Correspondence extends JoiValidationEntity { .optional() .description('A correspondence document that was archived.'), correspondenceId: JoiValidationConstants.UUID.required(), + docketNumber: JoiValidationConstants.STRING.max(10).required(), documentTitle: JoiValidationConstants.STRING.max(500).required(), filedBy: JoiValidationConstants.STRING.max(500).allow('').optional(), filingDate: JoiValidationConstants.ISO_DATE.max('now') diff --git a/shared/src/business/entities/cases/Case.archiveCorrespondence.test.ts b/shared/src/business/entities/cases/Case.archiveCorrespondence.test.ts index 152f586975e..812ad19c2ae 100644 --- a/shared/src/business/entities/cases/Case.archiveCorrespondence.test.ts +++ b/shared/src/business/entities/cases/Case.archiveCorrespondence.test.ts @@ -9,6 +9,7 @@ describe('archiveCorrespondence', () => { beforeEach(() => { correspondenceToArchive = new Correspondence({ correspondenceId: '123-abc', + docketNumber: '101-23', documentTitle: 'My Correspondence', filedBy: 'Docket clerk', }); diff --git a/shared/src/business/entities/cases/Case.deleteCorrespondenceById.test.ts b/shared/src/business/entities/cases/Case.deleteCorrespondenceById.test.ts index 49a9b14afdd..4a2b8552a5b 100644 --- a/shared/src/business/entities/cases/Case.deleteCorrespondenceById.test.ts +++ b/shared/src/business/entities/cases/Case.deleteCorrespondenceById.test.ts @@ -6,6 +6,7 @@ import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; describe('deleteCorrespondenceById', () => { const mockCorrespondence = new Correspondence({ + docketNumer: '101-23', documentTitle: 'A correpsondence', filingDate: '2025-03-01T00:00:00.000Z', userId: MOCK_USERS['a7d90c05-f6cd-442c-a168-202db587f16f'].userId, diff --git a/shared/src/business/entities/cases/Case.getCorrespondenceById.test.ts b/shared/src/business/entities/cases/Case.getCorrespondenceById.test.ts index 3880b18518e..ce9fa5e4328 100644 --- a/shared/src/business/entities/cases/Case.getCorrespondenceById.test.ts +++ b/shared/src/business/entities/cases/Case.getCorrespondenceById.test.ts @@ -7,6 +7,7 @@ describe('getCorrespondenceById', () => { it('should get a correspondence document by id', () => { const mockCorrespondence = new Correspondence({ correspondenceId: '123-abc', + docketNumber: '101-23', documentTitle: 'My Correspondence', filedBy: 'Docket clerk', }); diff --git a/shared/src/business/entities/cases/Case.updateCorrespondence.test.ts b/shared/src/business/entities/cases/Case.updateCorrespondence.test.ts index df323ad4c91..c275ad72f0d 100644 --- a/shared/src/business/entities/cases/Case.updateCorrespondence.test.ts +++ b/shared/src/business/entities/cases/Case.updateCorrespondence.test.ts @@ -7,6 +7,7 @@ describe('updateCorrespondence', () => { it('should update a correspondence document', () => { const mockCorrespondence = new Correspondence({ correspondenceId: '123-abc', + docketNumber: '101-23', documentTitle: 'My Correspondence', filedBy: 'Docket clerk', }); @@ -32,6 +33,7 @@ describe('updateCorrespondence', () => { it('should not throw an exception when the specified correspondence document is not found', () => { const mockCorrespondence = new Correspondence({ correspondenceId: '123-abc', + docketNumber: '101-23', documentTitle: 'My Correspondence', filedBy: 'Docket clerk', }); diff --git a/shared/src/business/entities/cases/PaperPetition.test.ts b/shared/src/business/entities/cases/PaperPetition.test.ts index d4af1b3d4e2..9109b94d6db 100644 --- a/shared/src/business/entities/cases/PaperPetition.test.ts +++ b/shared/src/business/entities/cases/PaperPetition.test.ts @@ -497,6 +497,7 @@ describe('paperPetition entity', () => { const mockGuid = getUniqueId(); const mockCorrespondence = new Correspondence({ correspondenceId: mockGuid, + docketNumber: '101-23', documentTitle: 'My Correspondence', filedBy: 'Docket clerk', userId: mockGuid, diff --git a/shared/src/business/test/createTestApplicationContext.ts b/shared/src/business/test/createTestApplicationContext.ts index c559cb882d5..2294c0baecb 100644 --- a/shared/src/business/test/createTestApplicationContext.ts +++ b/shared/src/business/test/createTestApplicationContext.ts @@ -123,7 +123,7 @@ import { updateCaseAutomaticBlock } from '@web-api/business/useCaseHelper/automa import { updateDocketEntry } from '@web-api/persistence/dynamo/documents/updateDocketEntry'; import { updateUserRecords } from '@web-api/persistence/dynamo/users/updateUserRecords'; import { uploadDocumentAndMakeSafeInteractor } from '@shared/business/useCases/uploadDocumentAndMakeSafeInteractor'; -import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; import { validatePenaltiesInteractor } from '@shared/business/useCases/validatePenaltiesInteractor'; import { verifyCaseForUser } from '@web-api/persistence/dynamo/cases/verifyCaseForUser'; import path from 'path'; @@ -533,13 +533,13 @@ export const createTestApplicationContext = () => { setTrialSessionJobStatusForCase: jest.fn(), setTrialSessionProcessingStatus: jest.fn(), updateCase: jest.fn().mockImplementation(updateCase), - updateCaseCorrespondence: jest - .fn() - .mockImplementation(upsertCaseCorrespondence), updateCaseHearing: jest.fn(), updateDocketEntry: jest.fn().mockImplementation(updateDocketEntry), uploadDocument: jest.fn(), uploadPdfFromClient: jest.fn().mockImplementation(() => ''), + upsertCaseCorrespondences: jest + .fn() + .mockImplementation(upsertCaseCorrespondences), verifyCaseForUser: jest.fn().mockImplementation(verifyCaseForUser), }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index 55d2b074311..a62f0de87bb 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -26,7 +26,7 @@ import { getMessagesByDocketNumber as getMessagesByDocketNumberMock } from '@web import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseAndAssociations } from './updateCaseAndAssociations'; import { updateMessage as updateMessageMock } from '@web-api/persistence/postgres/messages/updateMessage'; -import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; import { v4 as uuidv4 } from 'uuid'; @@ -38,7 +38,7 @@ const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; const getCaseDeadlinesByDocketNumber = getCaseDeadlinesByDocketNumberMock as jest.Mock; -const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; +const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; describe('updateCaseAndAssociations', () => { let updateCaseMock = jest.fn(); @@ -51,6 +51,7 @@ describe('updateCaseAndAssociations', () => { archivedCorrespondences: [ { correspondenceId: '95a84f02-23e6-4fff-9770-41f655f972a3', + docketNumber: MOCK_CASE.docketNumber, documentTitle: 'Inverted Yield Curve', filedByRole: docketClerkUser.role, userId: docketClerkUser.userId, @@ -59,6 +60,7 @@ describe('updateCaseAndAssociations', () => { correspondence: [ { correspondenceId: 'b7a6b14a-e4bd-4a20-9b6a-83674b36a162', + docketNumber: MOCK_CASE.docketNumber, documentTitle: 'Deflationary Spending', filedByRole: docketClerkUser.role, userId: docketClerkUser.userId, @@ -586,10 +588,12 @@ describe('updateCaseAndAssociations', () => { archivedCorrespondences: [ { ...validMockCase.archivedCorrespondences[0], + docketNumber: validMockCase.docketNumber, documentTitle: 'Updated Archived Correspondence', }, { correspondenceId: applicationContext.getUniqueId(), + docketNumber: validMockCase.docketNumber, documentTitle: 'New Archived Correspondence', userId: applicationContext.getUniqueId(), }, @@ -597,10 +601,12 @@ describe('updateCaseAndAssociations', () => { correspondence: [ { ...validMockCase.correspondence[0], + docketNumber: validMockCase.docketNumber, documentTitle: 'Updated Correspondence', }, { correspondenceId: applicationContext.getUniqueId(), + docketNumber: validMockCase.docketNumber, documentTitle: 'New Correspondence', userId: applicationContext.getUniqueId(), }, @@ -613,7 +619,7 @@ describe('updateCaseAndAssociations', () => { caseToUpdate, }); - expect(upsertCaseCorrespondence).toHaveBeenCalledTimes(4); + expect(upsertCaseCorrespondences).toHaveBeenCalledTimes(4); }); }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index 8262ec3684b..28184b296d0 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -12,7 +12,7 @@ import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/ca import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; -import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; import diff from 'diff-arrays-of-objects'; @@ -153,10 +153,7 @@ const updateCorrespondence = ({ return validCorrespondence.map( correspondence => function updateCorrespondence_cb() { - return upsertCaseCorrespondence({ - correspondence, - docketNumber: caseToUpdate.docketNumber, - }); + return upsertCaseCorrespondences([correspondence]); }, ); }; diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts index 7400d3a2685..bc532319ef6 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts @@ -8,9 +8,9 @@ import { ServiceUnavailableError } from '@web-api/errors/errors'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { archiveCorrespondenceDocumentInteractor } from './archiveCorrespondenceDocumentInteractor'; import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; -import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; -const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; +const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; describe('archiveCorrespondenceDocumentInteractor', () => { let mockUserId = '2474e5c0-f741-4120-befa-b77378ac8bf0'; @@ -28,6 +28,7 @@ describe('archiveCorrespondenceDocumentInteractor', () => { mockLock = undefined; mockCorrespondence = new Correspondence({ correspondenceId: mockCorrespondenceId, + docketNumber: '101-23', documentTitle: 'My Correspondence', filedBy: 'Docket clerk', userId: mockUserId, @@ -84,13 +85,9 @@ describe('archiveCorrespondenceDocumentInteractor', () => { mockDocketClerkUser, ); - expect(upsertCaseCorrespondence.mock.calls[0][0]).toMatchObject({ - correspondence: { - ...mockCorrespondence, - archived: true, - }, - docketNumber: MOCK_CASE.docketNumber, - }); + expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject([ + { ...mockCorrespondence, archived: true }, + ]); }); it('should update the case to reflect the archived correspondence', async () => { diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts index 228f4c6a4b9..858eefd59e3 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts @@ -6,7 +6,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const archiveCorrespondenceDocument = async ( @@ -30,8 +30,6 @@ export const archiveCorrespondenceDocument = async ( .getPersistenceGateway() .getCaseByDocketNumber({ applicationContext, docketNumber }); - console.log(caseToUpdate); - const caseEntity = new Case(caseToUpdate, { authorizedUser }); const correspondenceToArchiveEntity = caseEntity.correspondence.find( c => c.correspondenceId === correspondenceId, @@ -39,10 +37,9 @@ export const archiveCorrespondenceDocument = async ( caseEntity.archiveCorrespondence(correspondenceToArchiveEntity); - await upsertCaseCorrespondence({ - correspondence: correspondenceToArchiveEntity.validate().toRawObject(), - docketNumber, - }); + await upsertCaseCorrespondences([ + correspondenceToArchiveEntity.validate().toRawObject(), + ]); await applicationContext.getUseCaseHelpers().updateCaseAndAssociations({ applicationContext, diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts index ff3e5feead8..48599a30d03 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts @@ -14,9 +14,9 @@ import { mockDocketClerkUser, mockPetitionerUser, } from '@shared/test/mockAuthUsers'; -import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; -const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; +const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; describe('fileCorrespondenceDocumentInteractor', () => { const mockCase = { @@ -123,15 +123,15 @@ describe('fileCorrespondenceDocumentInteractor', () => { }, docketClerkUser, ); - expect(upsertCaseCorrespondence.mock.calls[0][0]).toMatchObject({ + expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject({ correspondence: { correspondenceId: mockCorrespondenceId, + docketNumber: mockCase.docketNumber, documentTitle: mockDocumentTitle, filedBy: docketClerkUser.name, filingDate: mockFilingDate, userId: docketClerkUser.userId, }, - docketNumber: mockCase.docketNumber, }); }); @@ -157,6 +157,7 @@ describe('fileCorrespondenceDocumentInteractor', () => { correspondence: [ { correspondenceId: mockCorrespondenceId, + docketNumber: mockCase.docketNumber, documentTitle: mockDocumentTitle, filedBy: docketClerkUser.name, filingDate: mockFilingDate, diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts index d8e82379261..c7c9c79d67f 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts @@ -7,7 +7,7 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; /** * fileCorrespondenceDocumentInteractor @@ -52,6 +52,7 @@ export const fileCorrespondenceDocumentInteractor = async ( const correspondenceEntity = new Correspondence({ ...documentMetadata, correspondenceId: primaryDocumentFileId, + docketNumber: caseToUpdate.docketNumber, filedBy: user.name, userId: user.userId, }); @@ -59,10 +60,9 @@ export const fileCorrespondenceDocumentInteractor = async ( caseEntity.fileCorrespondence(correspondenceEntity); if (caseEntity.validate()) { - await upsertCaseCorrespondence({ - correspondence: correspondenceEntity.validate().toRawObject(), - docketNumber, - }); + await upsertCaseCorrespondences([ + correspondenceEntity.validate().toRawObject(), + ]); } return caseEntity.toRawObject(); diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts index 3b96e45895b..3b688fee4ef 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts @@ -14,15 +14,18 @@ import { mockPetitionerUser, } from '@shared/test/mockAuthUsers'; import { updateCorrespondenceDocumentInteractor } from './updateCorrespondenceDocumentInteractor'; -import { upsertCaseCorrespondence as upsertCaseCorrespondenceMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; -const upsertCaseCorrespondence = upsertCaseCorrespondenceMock as jest.Mock; +const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; describe('updateCorrespondenceDocumentInteractor', () => { const mockDocketEntryId = 'cf105788-5d34-4451-aa8d-dfd9a851b675'; + const docketNumber = '123-45'; + const mockCorrespondence = new Correspondence({ correspondenceId: '74e36bf7-dcbd-4ee7-a9ec-6d7446096df8', + docketNumber, documentTitle: 'old document title', filedBy: 'docket clerk', userId: '5980d666-641d-455a-8386-18908d50c98e', @@ -35,7 +38,7 @@ describe('updateCorrespondenceDocumentInteractor', () => { docketEntries: [ { docketEntryId: mockDocketEntryId, - docketNumber: '123-45', + docketNumber, documentTitle: 'Docket Record 1', documentType: 'Order that case is assigned', eventCode: 'OAJ', @@ -48,7 +51,7 @@ describe('updateCorrespondenceDocumentInteractor', () => { userId: '2474e5c0-f741-4120-befa-b77378ac8bf0', }, ], - docketNumber: '123-45', + docketNumber, filingType: 'Myself', partyType: PARTY_TYPES.petitioner, petitioners: [ @@ -99,7 +102,7 @@ describe('updateCorrespondenceDocumentInteractor', () => { mockDocketClerkUser, ); - expect(upsertCaseCorrespondence.mock.calls[0][0]).toMatchObject({ + expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject({ correspondence: { ...mockCorrespondence, documentTitle: 'A title that has been updated', diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts index dbbce9b5aee..23b6125b16e 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts @@ -7,7 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseCorrespondence } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; export const updateCorrespondenceDocumentInteractor = async ( applicationContext: ServerApplicationContext, @@ -35,6 +35,7 @@ export const updateCorrespondenceDocumentInteractor = async ( const updatedCorrespondenceEntity = new Correspondence({ ...currentCorrespondenceDocument, + docketNumber: caseToUpdate.docketNumber, documentTitle: documentMetadata.documentTitle, }); @@ -42,10 +43,9 @@ export const updateCorrespondenceDocumentInteractor = async ( const caseEntityRaw = caseEntity.validate().toRawObject(); - await upsertCaseCorrespondence({ - correspondence: updatedCorrespondenceEntity.validate().toRawObject(), - docketNumber, - }); + await upsertCaseCorrespondences([ + updatedCorrespondenceEntity.validate().toRawObject(), + ]); return caseEntityRaw; }; diff --git a/web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts b/web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts new file mode 100644 index 00000000000..712aab0ed12 --- /dev/null +++ b/web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts @@ -0,0 +1,22 @@ +import { RawCorrespondence } from '@shared/business/entities/Correspondence'; +import { getLogger } from 'aws-xray-sdk'; +import { unmarshall } from '@aws-sdk/util-dynamodb'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; + +export const processCorrespondences = async ({ + correspondenceRecords, +}: { + correspondenceRecords: any[]; +}) => { + if (!correspondenceRecords.length) return; + + getLogger().debug( + `going to index ${correspondenceRecords.length} correspondence records`, + ); + + await upsertCaseCorrespondences( + correspondenceRecords.map(record => { + return unmarshall(record.dynamodb.NewImage) as RawCorrespondence; + }), + ); +}; diff --git a/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts b/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts index 7aa4cc46dbb..3aaabac85b6 100644 --- a/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts +++ b/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts @@ -1,5 +1,4 @@ import '@web-api/persistence/postgres/messages/mocks.jest'; -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { processMessageEntries } from './processMessageEntries'; import { upsertMessages } from '@web-api/persistence/postgres/messages/upsertMessages'; @@ -31,7 +30,6 @@ describe('processMessageEntries', () => { }; await processMessageEntries({ - applicationContext, messageRecords: [mockRepliedToMessageRecord], }); diff --git a/web-api/src/business/useCases/processStreamRecords/processMessageEntries.ts b/web-api/src/business/useCases/processStreamRecords/processMessageEntries.ts index a1d0d1ae7a5..a24b05f5905 100644 --- a/web-api/src/business/useCases/processStreamRecords/processMessageEntries.ts +++ b/web-api/src/business/useCases/processStreamRecords/processMessageEntries.ts @@ -1,20 +1,16 @@ import { RawMessage } from '@shared/business/entities/Message'; +import { getLogger } from 'aws-xray-sdk'; import { unmarshall } from '@aws-sdk/util-dynamodb'; import { upsertMessages } from '@web-api/persistence/postgres/messages/upsertMessages'; -import type { ServerApplicationContext } from '@web-api/applicationContext'; export const processMessageEntries = async ({ - applicationContext, messageRecords, }: { - applicationContext: ServerApplicationContext; messageRecords: any[]; }) => { if (!messageRecords.length) return; - applicationContext.logger.debug( - `going to index ${messageRecords.length} message records`, - ); + getLogger().debug(`going to index ${messageRecords.length} message records`); await upsertMessages( messageRecords.map(messageRecord => { diff --git a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts index 42784a7475e..500e73c268b 100644 --- a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts +++ b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts @@ -66,7 +66,6 @@ export const processStreamRecordsInteractor = async ( ); await processMessageEntries({ - applicationContext, messageRecords, }).catch(err => { applicationContext.logger.error('failed to process message records', { diff --git a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts index 944d6faf009..7078e7cb7ad 100644 --- a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts +++ b/web-api/src/persistence/postgres/correspondence/mocks.jest.ts @@ -6,6 +6,6 @@ jest.mock( ); jest.mock( - '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondence', - () => mockFactory('upsertCaseCorrespondence'), + '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences', + () => mockFactory('upsertCaseCorrespondences'), ); diff --git a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts deleted file mode 100644 index 83e6fb9af9c..00000000000 --- a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondence.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { RawCorrespondence } from '@shared/business/entities/Correspondence'; -import { calculateDate } from '@shared/business/utilities/DateHandler'; -import { getDbWriter } from '@web-api/database'; - -export const upsertCaseCorrespondence = async ({ - correspondence, - docketNumber, -}: { - correspondence: RawCorrespondence; - docketNumber: string; -}) => { - const correspondenceToUpsert = { - archived: correspondence.archived, - correspondenceId: correspondence.correspondenceId, - docketNumber, - documentTitle: correspondence.documentTitle, - filedBy: correspondence.filedBy, - filingDate: calculateDate({ dateString: correspondence.filingDate }), - userId: correspondence.userId, - }; - await getDbWriter(writer => - writer - .insertInto('dwCaseCorrespondence') - .values(correspondenceToUpsert) - .onConflict(oc => - oc.column('correspondenceId').doUpdateSet(correspondenceToUpsert), - ) - .execute(), - ); -}; diff --git a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts new file mode 100644 index 00000000000..d0dcc532e1a --- /dev/null +++ b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts @@ -0,0 +1,23 @@ +import { RawCorrespondence } from '@shared/business/entities/Correspondence'; +import { calculateDate } from '@shared/business/utilities/DateHandler'; +import { getDbWriter } from '@web-api/database'; + +export const upsertCaseCorrespondences = async ( + correspondences: RawCorrespondence[], +) => { + const correspondencesToUpsert = correspondences.map(correspondence => { + return { + ...correspondence, + filingDate: calculateDate({ dateString: correspondence.filingDate }), + }; + }); + await getDbWriter(writer => + writer + .insertInto('dwCaseCorrespondence') + .values(correspondencesToUpsert) + .onConflict(oc => + oc.column('correspondenceId').doUpdateSet(correspondencesToUpsert), + ) + .execute(), + ); +}; From 00458dc38bd80e63533c1dcc4c28241f089aae74 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 12 Nov 2024 17:39:01 -0500 Subject: [PATCH 29/47] 10504-dxox: WIP, make stream processors for deadlines, correspondences, and worksheets --- __TODO_10504.txt | 13 ++++++ .../entities/caseWorksheet/CaseWorksheet.ts | 2 + shared/src/business/entities/cases/Case.ts | 14 ++++++- ...ts => processCaseCorrespondenceEntries.ts} | 12 +++--- .../processCaseDeadlineEntries.ts | 22 ++++++++++ .../processCaseWorksheetEntries.ts | 22 ++++++++++ .../processStreamRecordsInteractor.ts | 34 ++++++++++++++++ .../processStreamUtilities.ts | 26 +++++++++++- .../postgres/caseDeadlines/mocks.jest.ts | 5 +++ .../caseDeadlines/upsertCaseDeadlines.ts | 33 +++++++++++++++ .../caseWorksheet/upsertCaseWorksheets.ts | 40 +++++++++++++++++++ .../upsertCaseCorrespondences.ts | 18 ++++++++- 12 files changed, 230 insertions(+), 11 deletions(-) rename web-api/src/business/useCases/processStreamRecords/{processCorrespondences.ts => processCaseCorrespondenceEntries.ts} (60%) create mode 100644 web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts create mode 100644 web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts create mode 100644 web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts create mode 100644 web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheets.ts diff --git a/__TODO_10504.txt b/__TODO_10504.txt index eeb88b0e91d..0230cf381cd 100644 --- a/__TODO_10504.txt +++ b/__TODO_10504.txt @@ -3,5 +3,18 @@ I've put docketNumber on Correspondence because: it's just a sensible thing to do. Make sure things work correctly after this change +-- +Is docketNumber in Case assignCorrespondences necessary? Were there some old cases, maybe, onto which we directly stored correspondences? +-- + +get rid of upsertCaseDeadline (singular) and just use upsertCaseDeadlines (plural) + +-- + +get rid of upsertCaseWorksheet (singular) and just use upsertCaseWorksheets (plural) + +-- + +check CaseWorksheet works now with judgeUserId \ No newline at end of file diff --git a/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts b/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts index f1cef882236..eef68b377ec 100644 --- a/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts +++ b/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts @@ -6,6 +6,7 @@ export class CaseWorksheet extends JoiValidationEntity { public finalBriefDueDate?: string; public primaryIssue?: string; public statusOfMatter?: string; + public judgeUserId: string; constructor(rawProps) { super('CaseWorksheet'); @@ -14,6 +15,7 @@ export class CaseWorksheet extends JoiValidationEntity { this.finalBriefDueDate = rawProps.finalBriefDueDate; this.primaryIssue = rawProps.primaryIssue; this.statusOfMatter = rawProps.statusOfMatter; + this.judgeUserId = rawProps.judgeUserId; } static STATUS_OF_MATTER_OPTIONS = [ diff --git a/shared/src/business/entities/cases/Case.ts b/shared/src/business/entities/cases/Case.ts index 01d777646fa..30fd7f45401 100644 --- a/shared/src/business/entities/cases/Case.ts +++ b/shared/src/business/entities/cases/Case.ts @@ -912,7 +912,13 @@ export class Case extends JoiValidationEntity { assignCorrespondences({ rawCase }) { if (Array.isArray(rawCase.correspondence)) { this.correspondence = rawCase.correspondence - .map(correspondence => new Correspondence(correspondence)) + .map( + correspondence => + new Correspondence({ + ...correspondence, + docketNumber: rawCase.docketNumber, + }), + ) .sort((a, b) => compareStrings(a.filingDate, b.filingDate)); } else { this.correspondence = []; @@ -920,7 +926,11 @@ export class Case extends JoiValidationEntity { if (Array.isArray(rawCase.archivedCorrespondences)) { this.archivedCorrespondences = rawCase.archivedCorrespondences.map( - correspondence => new Correspondence(correspondence), + correspondence => + new Correspondence({ + ...correspondence, + docketNumber: rawCase.docketNumber, + }), ); } else { this.archivedCorrespondences = []; diff --git a/web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts similarity index 60% rename from web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts rename to web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts index 712aab0ed12..820453321e1 100644 --- a/web-api/src/business/useCases/processStreamRecords/processCorrespondences.ts +++ b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts @@ -3,19 +3,19 @@ import { getLogger } from 'aws-xray-sdk'; import { unmarshall } from '@aws-sdk/util-dynamodb'; import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; -export const processCorrespondences = async ({ - correspondenceRecords, +export const processCaseCorrespondenceEntries = async ({ + caseCorrespondenceRecords, }: { - correspondenceRecords: any[]; + caseCorrespondenceRecords: any[]; }) => { - if (!correspondenceRecords.length) return; + if (!caseCorrespondenceRecords.length) return; getLogger().debug( - `going to index ${correspondenceRecords.length} correspondence records`, + `going to index ${caseCorrespondenceRecords.length} correspondence records`, ); await upsertCaseCorrespondences( - correspondenceRecords.map(record => { + caseCorrespondenceRecords.map(record => { return unmarshall(record.dynamodb.NewImage) as RawCorrespondence; }), ); diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts new file mode 100644 index 00000000000..b6b498ad446 --- /dev/null +++ b/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts @@ -0,0 +1,22 @@ +import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; +import { getLogger } from 'aws-xray-sdk'; +import { unmarshall } from '@aws-sdk/util-dynamodb'; +import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; + +export const processCaseDeadlineEntries = async ({ + caseDeadlineRecords, +}: { + caseDeadlineRecords: any[]; +}) => { + if (!caseDeadlineRecords.length) return; + + getLogger().debug( + `going to index ${caseDeadlineRecords.length} case deadline records`, + ); + + await upsertCaseDeadlines( + caseDeadlineRecords.map(record => { + return unmarshall(record.dynamodb.NewImage) as RawCaseDeadline; + }), + ); +}; diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts new file mode 100644 index 00000000000..a37d45d5f6d --- /dev/null +++ b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts @@ -0,0 +1,22 @@ +import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { getLogger } from 'aws-xray-sdk'; +import { unmarshall } from '@aws-sdk/util-dynamodb'; +import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets'; + +export const processCaseWorksheetEntries = async ({ + caseWorksheetRecords, +}: { + caseWorksheetRecords: any[]; +}) => { + if (!caseWorksheetRecords.length) return; + + getLogger().debug( + `going to index ${caseWorksheetRecords.length} case worksheet records`, + ); + + await upsertCaseWorksheets( + caseWorksheetRecords.map(record => { + return unmarshall(record.dynamodb.NewImage) as RawCaseWorksheet; + }), + ); +}; diff --git a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts index 500e73c268b..db638590499 100644 --- a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts +++ b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts @@ -1,6 +1,10 @@ import { ServerApplicationContext } from '@web-api/applicationContext'; +import { getLogger } from 'aws-xray-sdk'; import { partitionRecords } from './processStreamUtilities'; +import { processCaseCorrespondenceEntries } from '@web-api/business/useCases/processStreamRecords/processCaseCorrespondenceEntries'; +import { processCaseDeadlineEntries } from '@web-api/business/useCases/processStreamRecords/processCaseDeadlineEntries'; import { processCaseEntries } from './processCaseEntries'; +import { processCaseWorksheetEntries } from '@web-api/business/useCases/processStreamRecords/processCaseWorksheetEntries'; import { processCompletionMarkers } from './processCompletionMarkers'; import { processDocketEntries } from './processDocketEntries'; import { processMessageEntries } from './processMessageEntries'; @@ -15,7 +19,10 @@ export const processStreamRecordsInteractor = async ( { recordsToProcess }: { recordsToProcess: DynamoDBRecord[] }, ): Promise => { const { + caseCorrespondenceRecords, + caseDeadlineRecords, caseEntityRecords, + caseWorksheetRecords, completionMarkers, docketEntryRecords, messageRecords, @@ -92,6 +99,33 @@ export const processStreamRecordsInteractor = async ( completionMarkers, }); + await processCaseDeadlineEntries({ + caseDeadlineRecords, + }).catch(err => { + getLogger().error('failed to process case deadline records', { + err, + }); + throw err; + }); + + await processCaseWorksheetEntries({ + caseWorksheetRecords, + }).catch(err => { + getLogger().error('failed to process case correspondence records', { + err, + }); + throw err; + }); + + await processCaseCorrespondenceEntries({ + caseCorrespondenceRecords, + }).catch(err => { + getLogger().error('failed to process case correspondence records', { + err, + }); + throw err; + }); + await processOtherEntries({ applicationContext, otherRecords }).catch( err => { applicationContext.logger.error('failed to processOtherEntries', { diff --git a/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts b/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts index 16efeb1abb5..db4a9cec061 100644 --- a/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts +++ b/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts @@ -48,15 +48,39 @@ export const partitionRecords = ( record.dynamodb.NewImage.entityName.S === 'Message', ); - const [completionMarkers, otherRecords] = partition( + const [completionMarkers, nonCompletionMarkerRecords] = partition( nonMessageRecords, record => record.dynamodb?.NewImage?.entityName && record.dynamodb.NewImage.entityName.S === 'CompletionMarker', ); + const [caseDeadlines, nonCaseDeadlines] = partition( + nonCompletionMarkerRecords, + record => + record.dynamodb?.NewImage?.entityName && + record.dynamodb.NewImage.entityName.S === 'CaseDeadline', + ); + + const [caseWorksheets, nonCaseWorksheets] = partition( + nonCaseDeadlines, + record => + record.dynamodb?.NewImage?.entityName && + record.dynamodb.NewImage.entityName.S === 'CaseWorksheet', + ); + + const [caseCorrespondenceRecords, otherRecords] = partition( + nonCaseWorksheets, + record => + record.dynamodb?.NewImage?.entityName && + record.dynamodb.NewImage.entityName.S == 'Correspondence', + ); + return { + caseCorrespondenceRecords, + caseDeadlines, caseEntityRecords, + caseWorksheets, completionMarkers, docketEntryRecords, messageRecords, diff --git a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts index 01ef40c938c..f50fc684499 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts @@ -5,6 +5,11 @@ jest.mock( () => mockFactory('upsertCaseDeadline'), ); +jest.mock( + '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines', + () => mockFactory('upsertCaseDeadlines'), +); + jest.mock( '@web-api/persistence/postgres/caseDeadlines/deleteCaseDeadline', () => mockFactory('deleteCaseDeadline'), diff --git a/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts new file mode 100644 index 00000000000..eccdc50eadd --- /dev/null +++ b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts @@ -0,0 +1,33 @@ +import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; +import { + caseDeadlineEntity, + toKyselyNewCaseDeadline, +} from '@web-api/persistence/postgres/caseDeadlines/mapper'; +import { getDbWriter } from '@web-api/database'; + +export const upsertCaseDeadlines = async ( + caseDeadlinesToUpsert: RawCaseDeadline[], +) => { + const caseDeadlines = await getDbWriter(writer => + writer + .insertInto('dwCaseDeadline') + .values(caseDeadlinesToUpsert.map(cd => toKyselyNewCaseDeadline(cd))) + .onConflict(oc => + oc.column('caseDeadlineId').doUpdateSet(cd => { + return { + associatedJudge: cd.ref('excluded.associatedJudge'), + associatedJudgeId: cd.ref('excluded.associatedJudgeId'), + caseDeadlineId: cd.ref('excluded.caseDeadlineId'), + createdAt: cd.ref('excluded.createdAt'), + deadlineDate: cd.ref('excluded.deadlineDate'), + description: cd.ref('excluded.description'), + docketNumber: cd.ref('excluded.docketNumber'), + sortableDocketNumber: cd.ref('excluded.sortableDocketNumber'), + }; + }), + ) + .returningAll() + .execute(), + ); + return caseDeadlines.map(cd => caseDeadlineEntity(cd)); +}; diff --git a/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheets.ts b/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheets.ts new file mode 100644 index 00000000000..f36d4d4a513 --- /dev/null +++ b/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheets.ts @@ -0,0 +1,40 @@ +import { + CaseWorksheet, + RawCaseWorksheet, +} from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { calculateDate } from '@shared/business/utilities/DateHandler'; +import { getDbWriter } from '@web-api/database'; + +export const upsertCaseWorksheets = async ( + caseWorksheets: RawCaseWorksheet[], +): Promise => { + const caseWorksheetsToUpsert = caseWorksheets.map(cw => { + return { + docketNumber: cw.docketNumber, + finalBriefDueDate: calculateDate({ dateString: cw.finalBriefDueDate }), + judgeUserId: cw.judgeUserId, + primaryIssue: cw.primaryIssue, + statusOfMatter: cw.statusOfMatter, + }; + }); + + const results = await getDbWriter(writer => + writer + .insertInto('dwCaseWorksheet') + .values(caseWorksheetsToUpsert) + .onConflict(oc => + oc.column('docketNumber').doUpdateSet(cd => { + return { + docketNumber: cd.ref('excluded.docketNumber'), + finalBriefDueDate: cd.ref('excluded.finalBriefDueDate'), + judgeUserId: cd.ref('excluded.judgeUserId'), + primaryIssue: cd.ref('excluded.primaryIssue'), + statusOfMatter: cd.ref('excluded.statusOfMatter'), + }; + }), + ) + .execute(), + ); + + return results.map(cw => new CaseWorksheet(cw)); +}; diff --git a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts index d0dcc532e1a..42e6053bf01 100644 --- a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts +++ b/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts @@ -7,8 +7,13 @@ export const upsertCaseCorrespondences = async ( ) => { const correspondencesToUpsert = correspondences.map(correspondence => { return { - ...correspondence, + archived: correspondence.archived, + correspondenceId: correspondence.correspondenceId, + docketNumber: correspondence.docketNumber, + documentTitle: correspondence.documentTitle, + filedBy: correspondence.filedBy, filingDate: calculateDate({ dateString: correspondence.filingDate }), + userId: correspondence.userId, }; }); await getDbWriter(writer => @@ -16,7 +21,16 @@ export const upsertCaseCorrespondences = async ( .insertInto('dwCaseCorrespondence') .values(correspondencesToUpsert) .onConflict(oc => - oc.column('correspondenceId').doUpdateSet(correspondencesToUpsert), + oc.column('correspondenceId').doUpdateSet(c => { + return { + archived: c.ref('excluded.archived'), + docketNumber: c.ref('excluded.docketNumber'), + documentTitle: c.ref('excluded.documentTitle'), + filedBy: c.ref('excluded.filedBy'), + filingDate: c.ref('excluded.filingDate'), + userId: c.ref('excluded.userId'), + }; + }), ) .execute(), ); From f6875855b3f7027fe471e8f3e9a4987fdf30e800 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 13 Nov 2024 08:27:49 -0500 Subject: [PATCH 30/47] 10504-dxox: fix incorrect keys in processStreamUtilities; replace upsertCaseDeadline and upsertCaseWorksheet with more flexible upsertCaseDeadlines and upsertCaseWorksheets --- __TODO_10504.txt | 12 ++--- .../autoGenerateDeadline.test.ts | 8 ++-- .../useCaseHelper/autoGenerateDeadline.ts | 6 +-- .../updateCaseAndAssociations.test.ts | 12 ++--- .../updateCaseAndAssociations.ts | 6 +-- .../createCaseDeadlineInteractor.ts | 6 +-- .../updateCaseDeadlineInteractor.test.ts | 10 ++-- .../updateCaseDeadlineInteractor.ts | 6 +-- .../updateCaseWorksheetInteractor.test.ts | 46 ++++--------------- .../updateCaseWorksheetInteractor.ts | 13 +----- .../processCaseCorrespondenceEntries.ts | 2 +- .../processCaseDeadlineEntries.ts | 2 +- .../processCaseWorksheetEntries.ts | 2 +- .../processStreamUtilities.ts | 12 ++--- .../updateCaseWorksheetLambda.ts | 3 +- .../postgres/caseDeadlines/mocks.jest.ts | 5 -- .../caseDeadlines/upsertCaseDeadline.ts | 26 ----------- .../caseDeadlines/upsertCaseDeadlines.ts | 1 - .../postgres/caseWorksheet/mocks.jest.ts | 4 +- .../caseWorksheet/upsertCaseWorksheet.ts | 35 -------------- .../updateCaseWorksheetAction.test.ts | 8 ++++ .../updateCaseWorksheetAction.ts | 8 ++++ 22 files changed, 63 insertions(+), 170 deletions(-) delete mode 100644 web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts delete mode 100644 web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts diff --git a/__TODO_10504.txt b/__TODO_10504.txt index 0230cf381cd..f2e50262f4b 100644 --- a/__TODO_10504.txt +++ b/__TODO_10504.txt @@ -1,20 +1,14 @@ -I've put docketNumber on Correspondence because: - it makes the stream processing more efficient - it's just a sensible thing to do. -Make sure things work correctly after this change +check Correspondence works now with docketNumber (added to the entity) and update validation? -- Is docketNumber in Case assignCorrespondences necessary? Were there some old cases, maybe, onto which we directly stored correspondences? --- - -get rid of upsertCaseDeadline (singular) and just use upsertCaseDeadlines (plural) -- -get rid of upsertCaseWorksheet (singular) and just use upsertCaseWorksheets (plural) +check CaseWorksheet works now with judgeUserId (added to the entity) and update validation? -- -check CaseWorksheet works now with judgeUserId \ No newline at end of file +entityName: "CaseWorksheet" in updateCaseWorksheetAction is silly \ No newline at end of file diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts index 091e1d37ab8..8c8093fc896 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.test.ts @@ -1,8 +1,8 @@ import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import { autoGenerateDeadline } from './autoGenerateDeadline'; -import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines as upsertCaseDeadlinesMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; -const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; +const upsertCaseDeadlines = upsertCaseDeadlinesMock as jest.Mock; describe('autoGenerateDeadline', () => { it('should create a case deadline', async () => { @@ -17,8 +17,6 @@ describe('autoGenerateDeadline', () => { }, }); - expect( - upsertCaseDeadline.mock.calls[0][0].caseDeadlineToUpsert, - ).toBeDefined(); + expect(upsertCaseDeadlines.mock.calls[0][0]).toBeDefined(); }); }); diff --git a/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts b/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts index 4e2e93b1cc2..3b715490b58 100644 --- a/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts +++ b/web-api/src/business/useCaseHelper/autoGenerateDeadline.ts @@ -1,5 +1,5 @@ import { CaseDeadline } from '../../../../shared/src/business/entities/CaseDeadline'; -import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; export const autoGenerateDeadline = async ({ deadlineDate, @@ -15,7 +15,5 @@ export const autoGenerateDeadline = async ({ sortableDocketNumber: subjectCaseEntity.sortableDocketNumber, }); - await upsertCaseDeadline({ - caseDeadlineToUpsert: newCaseDeadline.validate().toRawObject(), - }); + await upsertCaseDeadlines([newCaseDeadline.validate().toRawObject()]); }; diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index a62f0de87bb..e0145d8df1a 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -27,13 +27,13 @@ import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseAndAssociations } from './updateCaseAndAssociations'; import { updateMessage as updateMessageMock } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; -import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines as upsertCaseDeadlinesMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; import { v4 as uuidv4 } from 'uuid'; const getMessagesByDocketNumber = getMessagesByDocketNumberMock as jest.Mock; const updateMessage = updateMessageMock as jest.Mock; -const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; +const upsertCaseDeadlines = upsertCaseDeadlinesMock as jest.Mock; const getCaseDeadlinesByDocketNumber = getCaseDeadlinesByDocketNumberMock as jest.Mock; @@ -200,7 +200,7 @@ describe('updateCaseAndAssociations', () => { ).not.toHaveBeenCalled(); // updateCaseDeadlines - expect(upsertCaseDeadline).not.toHaveBeenCalled(); + expect(upsertCaseDeadlines).not.toHaveBeenCalled(); // update the case itself, final persistence call expect( @@ -955,7 +955,7 @@ describe('updateCaseAndAssociations', () => { caseToUpdate: updatedCase, }); expect(getCaseDeadlinesByDocketNumber).not.toHaveBeenCalled(); - expect(upsertCaseDeadline).not.toHaveBeenCalled(); + expect(upsertCaseDeadlines).not.toHaveBeenCalled(); }); it('should fetch and persist case deadline data when associated judge has changed', async () => { @@ -971,9 +971,7 @@ describe('updateCaseAndAssociations', () => { }); expect(getCaseDeadlinesByDocketNumber).toHaveBeenCalled(); expect(CaseDeadline.validateRawCollection).toHaveBeenCalled(); - expect(upsertCaseDeadline).toHaveBeenCalledWith({ - caseDeadlineToUpsert: { some: 'deadline' }, - }); + expect(upsertCaseDeadlines).toHaveBeenCalledWith([{ some: 'deadline' }]); }); }); }); diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index 28184b296d0..1acd8ae715f 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -13,7 +13,7 @@ import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/message import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; -import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; import diff from 'diff-arrays-of-objects'; /** @@ -402,9 +402,7 @@ const updateCaseDeadlines = async ({ return validCaseDeadlines.map( caseDeadline => function updateCaseDeadlines_cb() { - return upsertCaseDeadline({ - caseDeadlineToUpsert: caseDeadline, - }); + return upsertCaseDeadlines([caseDeadline]); }, ); }; diff --git a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts index b4348ba8195..0fa4fa20322 100644 --- a/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/createCaseDeadlineInteractor.ts @@ -7,7 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseDeadline as upsertDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const createCaseDeadline = async ( @@ -33,9 +33,7 @@ export const createCaseDeadline = async ( associatedJudgeId: caseEntity.associatedJudgeId, }); - await upsertDeadline({ - caseDeadlineToUpsert: newCaseDeadline.validate().toRawObject(), - }); + await upsertCaseDeadlines([newCaseDeadline.validate().toRawObject()]); caseEntity = await applicationContext .getUseCaseHelpers() diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts index 81b945346a2..16a3b93f3bc 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.test.ts @@ -3,9 +3,9 @@ import { CaseDeadline } from '@shared/business/entities/CaseDeadline'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; import { mockPetitionsClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseDeadlineInteractor } from './updateCaseDeadlineInteractor'; -import { upsertCaseDeadline as upsertCaseDeadlineMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines as upsertCaseDeadlinesMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; -const upsertCaseDeadline = upsertCaseDeadlineMock as jest.Mock; +const upsertCaseDeadlines = upsertCaseDeadlinesMock as jest.Mock; describe('updateCaseDeadlineInteractor', () => { const CASE_DEADLINE_ID = '6805d1ab-18d0-43ec-bafb-654e83405416'; @@ -38,9 +38,9 @@ describe('updateCaseDeadlineInteractor', () => { mockPetitionsClerkUser, ); - expect(upsertCaseDeadline.mock.calls[0][0]).toMatchObject({ - caseDeadlineToUpsert: mockCaseDeadline, - }); + expect(upsertCaseDeadlines.mock.calls[0][0]).toMatchObject([ + mockCaseDeadline, + ]); expect(caseDeadline).toBeDefined(); }); }); diff --git a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts index ff6a22b5223..89c4b4acd50 100644 --- a/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts +++ b/web-api/src/business/useCases/caseDeadline/updateCaseDeadlineInteractor.ts @@ -5,7 +5,7 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseDeadline } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline'; +import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; export const updateCaseDeadlineInteractor = async ( { caseDeadline }: { caseDeadline: CaseDeadline }, @@ -19,9 +19,7 @@ export const updateCaseDeadlineInteractor = async ( .validate() .toRawObject(); - await upsertCaseDeadline({ - caseDeadlineToUpsert: caseDeadlineToUpdate, - }); + await upsertCaseDeadlines([caseDeadlineToUpdate]); return caseDeadlineToUpdate; }; diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts index 734fccb03b9..6989e7482cd 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts @@ -2,7 +2,6 @@ import '@web-api/persistence/postgres/caseWorksheet/mocks.jest'; import { InvalidEntityError, UnauthorizedError } from '@web-api/errors/errors'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; import { judgeColvin } from '@shared/test/mockUsers'; import { @@ -10,29 +9,23 @@ import { mockPetitionsClerkUser, } from '@shared/test/mockAuthUsers'; import { updateCaseWorksheetInteractor } from './updateCaseWorksheetInteractor'; -import { upsertCaseWorksheet as upsertCaseWorksheetMock } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheet'; +import { upsertCaseWorksheets as upsertCaseWorksheetsMock } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets'; const getCaseWorksheetsByDocketNumber = getCaseWorksheetsByDocketNumberMock as jest.Mock; -const upsertCaseWorksheet = upsertCaseWorksheetMock as jest.Mock; +const upsertCaseWorksheets = upsertCaseWorksheetsMock as jest.Mock; describe('updateCaseWorksheetInteractor', () => { const mockCaseWorksheet: RawCaseWorksheet = { docketNumber: '101-23', entityName: 'CaseWorksheet', + judgeUserId: judgeColvin.userId, primaryIssue: 'Don`t go chasin waterfalls', }; - beforeAll(() => { - applicationContext - .getUseCaseHelpers() - .getJudgeForUserHelper.mockReturnValue(judgeColvin); - }); - it('should throw an error when the user does not have access to the case worksheet feature', async () => { await expect( updateCaseWorksheetInteractor( - applicationContext, { worksheet: mockCaseWorksheet, }, @@ -42,13 +35,8 @@ describe('updateCaseWorksheetInteractor', () => { }); it('should throw an error when the updated case worksheet is invalid', async () => { - applicationContext - .getPersistenceGateway() - .getUserById.mockReturnValue(judgeColvin); - await expect( updateCaseWorksheetInteractor( - applicationContext, { worksheet: { ...mockCaseWorksheet, @@ -62,13 +50,9 @@ describe('updateCaseWorksheetInteractor', () => { it('should persist and return the updated case worksheet when the updates are valid', async () => { const mockFinalBriefDueDate = '2023-08-29'; - applicationContext - .getPersistenceGateway() - .getUserById.mockReturnValue(judgeColvin); getCaseWorksheetsByDocketNumber.mockResolvedValue([mockCaseWorksheet]); const result = await updateCaseWorksheetInteractor( - applicationContext, { worksheet: { ...mockCaseWorksheet, @@ -82,13 +66,9 @@ describe('updateCaseWorksheetInteractor', () => { ...mockCaseWorksheet, finalBriefDueDate: mockFinalBriefDueDate, }; - expect( - applicationContext.getUseCaseHelpers().getJudgeInSectionHelper, - ).not.toHaveBeenCalled(); - expect(upsertCaseWorksheet).toHaveBeenCalledWith({ - caseWorksheet: expectedUpdatedCaseWorksheet, - judgeUserId: judgeColvin.userId, - }); + expect(upsertCaseWorksheets).toHaveBeenCalledWith([ + expectedUpdatedCaseWorksheet, + ]); expect(result).toEqual(expectedUpdatedCaseWorksheet); }); @@ -97,7 +77,6 @@ describe('updateCaseWorksheetInteractor', () => { getCaseWorksheetsByDocketNumber.mockResolvedValue([mockCaseWorksheet]); const result = await updateCaseWorksheetInteractor( - applicationContext, { worksheet: { ...mockCaseWorksheet, @@ -111,16 +90,9 @@ describe('updateCaseWorksheetInteractor', () => { ...mockCaseWorksheet, finalBriefDueDate: mockFinalBriefDueDate, }; - expect( - applicationContext.getUseCaseHelpers().getJudgeForUserHelper.mock - .calls[0][1], - ).toEqual({ - user: mockChambersUser, - }); - expect(upsertCaseWorksheet).toHaveBeenCalledWith({ - caseWorksheet: expectedUpdatedCaseWorksheet, - judgeUserId: judgeColvin.userId, - }); + expect(upsertCaseWorksheets).toHaveBeenCalledWith([ + expectedUpdatedCaseWorksheet, + ]); expect(result).toEqual(expectedUpdatedCaseWorksheet); }); }); diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts index 6d763435255..af57393d585 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts @@ -6,13 +6,11 @@ import { ROLE_PERMISSIONS, isAuthorized, } from '../../../../../shared/src/authorization/authorizationClientService'; -import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseWorksheet } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheet'; +import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets'; export const updateCaseWorksheetInteractor = async ( - applicationContext: ServerApplicationContext, { worksheet, }: { @@ -24,18 +22,11 @@ export const updateCaseWorksheetInteractor = async ( throw new UnauthorizedError('Unauthorized'); } - const judgeUser = await applicationContext - .getUseCaseHelpers() - .getJudgeForUserHelper(applicationContext, { user: authorizedUser }); - const caseWorksheetEntity = new CaseWorksheet(worksheet).validate(); const rawCaseWorksheet = caseWorksheetEntity.toRawObject(); - await upsertCaseWorksheet({ - caseWorksheet: rawCaseWorksheet, - judgeUserId: judgeUser.userId, - }); + await upsertCaseWorksheets([rawCaseWorksheet]); return rawCaseWorksheet; }; diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts index 820453321e1..b561f2a39fc 100644 --- a/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts +++ b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts @@ -11,7 +11,7 @@ export const processCaseCorrespondenceEntries = async ({ if (!caseCorrespondenceRecords.length) return; getLogger().debug( - `going to index ${caseCorrespondenceRecords.length} correspondence records`, + `going to upsert ${caseCorrespondenceRecords.length} correspondence records`, ); await upsertCaseCorrespondences( diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts index b6b498ad446..cefd9adf977 100644 --- a/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts +++ b/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.ts @@ -11,7 +11,7 @@ export const processCaseDeadlineEntries = async ({ if (!caseDeadlineRecords.length) return; getLogger().debug( - `going to index ${caseDeadlineRecords.length} case deadline records`, + `going to upsert ${caseDeadlineRecords.length} case deadline records`, ); await upsertCaseDeadlines( diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts index a37d45d5f6d..50ab97c0cff 100644 --- a/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts +++ b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts @@ -11,7 +11,7 @@ export const processCaseWorksheetEntries = async ({ if (!caseWorksheetRecords.length) return; getLogger().debug( - `going to index ${caseWorksheetRecords.length} case worksheet records`, + `going to upsert ${caseWorksheetRecords.length} case worksheet records`, ); await upsertCaseWorksheets( diff --git a/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts b/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts index db4a9cec061..321df496759 100644 --- a/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts +++ b/web-api/src/business/useCases/processStreamRecords/processStreamUtilities.ts @@ -55,22 +55,22 @@ export const partitionRecords = ( record.dynamodb.NewImage.entityName.S === 'CompletionMarker', ); - const [caseDeadlines, nonCaseDeadlines] = partition( + const [caseDeadlineRecords, nonCaseDeadlineRecords] = partition( nonCompletionMarkerRecords, record => record.dynamodb?.NewImage?.entityName && record.dynamodb.NewImage.entityName.S === 'CaseDeadline', ); - const [caseWorksheets, nonCaseWorksheets] = partition( - nonCaseDeadlines, + const [caseWorksheetRecords, nonCaseWorksheetRecords] = partition( + nonCaseDeadlineRecords, record => record.dynamodb?.NewImage?.entityName && record.dynamodb.NewImage.entityName.S === 'CaseWorksheet', ); const [caseCorrespondenceRecords, otherRecords] = partition( - nonCaseWorksheets, + nonCaseWorksheetRecords, record => record.dynamodb?.NewImage?.entityName && record.dynamodb.NewImage.entityName.S == 'Correspondence', @@ -78,9 +78,9 @@ export const partitionRecords = ( return { caseCorrespondenceRecords, - caseDeadlines, + caseDeadlineRecords, caseEntityRecords, - caseWorksheets, + caseWorksheetRecords, completionMarkers, docketEntryRecords, messageRecords, diff --git a/web-api/src/lambdas/caseWorksheet/updateCaseWorksheetLambda.ts b/web-api/src/lambdas/caseWorksheet/updateCaseWorksheetLambda.ts index 6eac6e3aa84..1beb3e39be4 100644 --- a/web-api/src/lambdas/caseWorksheet/updateCaseWorksheetLambda.ts +++ b/web-api/src/lambdas/caseWorksheet/updateCaseWorksheetLambda.ts @@ -6,9 +6,8 @@ export const updateCaseWorksheetLambda = ( event, authorizedUser: UnknownAuthUser, ) => - genericHandler(event, async ({ applicationContext }) => { + genericHandler(event, async () => { return await updateCaseWorksheetInteractor( - applicationContext, JSON.parse(event.body), authorizedUser, ); diff --git a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts index f50fc684499..534d62e2fec 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/mocks.jest.ts @@ -1,10 +1,5 @@ import { mockFactory } from '@shared/test/mockFactory'; -jest.mock( - '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadline', - () => mockFactory('upsertCaseDeadline'), -); - jest.mock( '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines', () => mockFactory('upsertCaseDeadlines'), diff --git a/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts deleted file mode 100644 index d60eb2d36eb..00000000000 --- a/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadline.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { RawCaseDeadline } from '@shared/business/entities/CaseDeadline'; -import { - caseDeadlineEntity, - toKyselyNewCaseDeadline, -} from '@web-api/persistence/postgres/caseDeadlines/mapper'; -import { getDbWriter } from '@web-api/database'; - -export const upsertCaseDeadline = async ({ - caseDeadlineToUpsert, -}: { - caseDeadlineToUpsert: RawCaseDeadline; -}) => { - const caseDeadline = await getDbWriter(writer => - writer - .insertInto('dwCaseDeadline') - .values(toKyselyNewCaseDeadline(caseDeadlineToUpsert)) - .onConflict(oc => - oc - .column('caseDeadlineId') - .doUpdateSet(toKyselyNewCaseDeadline(caseDeadlineToUpsert)), - ) - .returningAll() - .executeTakeFirst(), - ); - return caseDeadlineEntity(caseDeadline); -}; diff --git a/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts index eccdc50eadd..0f6ba80e115 100644 --- a/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts +++ b/web-api/src/persistence/postgres/caseDeadlines/upsertCaseDeadlines.ts @@ -17,7 +17,6 @@ export const upsertCaseDeadlines = async ( return { associatedJudge: cd.ref('excluded.associatedJudge'), associatedJudgeId: cd.ref('excluded.associatedJudgeId'), - caseDeadlineId: cd.ref('excluded.caseDeadlineId'), createdAt: cd.ref('excluded.createdAt'), deadlineDate: cd.ref('excluded.deadlineDate'), description: cd.ref('excluded.description'), diff --git a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts b/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts index 76a18665274..3e9cbc1f4ba 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts @@ -6,6 +6,6 @@ jest.mock( ); jest.mock( - '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheet', - () => mockFactory('upsertCaseWorksheet'), + '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets', + () => mockFactory('upsertCaseWorksheets'), ); diff --git a/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts b/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts deleted file mode 100644 index b87a20f7ced..00000000000 --- a/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheet.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - CaseWorksheet, - RawCaseWorksheet, -} from '@shared/business/entities/caseWorksheet/CaseWorksheet'; -import { calculateDate } from '@shared/business/utilities/DateHandler'; -import { getDbWriter } from '@web-api/database'; - -export const upsertCaseWorksheet = async ({ - caseWorksheet, - judgeUserId, -}: { - caseWorksheet: RawCaseWorksheet; - judgeUserId: string; -}): Promise => { - const caseWorksheetToUpsert = { - docketNumber: caseWorksheet.docketNumber, - finalBriefDueDate: calculateDate({ - dateString: caseWorksheet.finalBriefDueDate, - }), - judgeUserId, - primaryIssue: caseWorksheet.primaryIssue, - statusOfMatter: caseWorksheet.statusOfMatter, - }; - const result = await getDbWriter(writer => - writer - .insertInto('dwCaseWorksheet') - .values(caseWorksheetToUpsert) - .onConflict(oc => - oc.column('docketNumber').doUpdateSet(caseWorksheetToUpsert), - ) - .execute(), - ); - - return new CaseWorksheet(result); -}; diff --git a/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.test.ts b/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.test.ts index e7026efb740..5dbc1a2f7d0 100644 --- a/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.test.ts +++ b/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.test.ts @@ -2,6 +2,7 @@ import { CaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorks import { MOCK_CASE } from '@shared/test/mockCase'; import { MOCK_CASE_WORKSHEET } from '@shared/test/mockCaseWorksheet'; import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext'; +import { judgeColvin } from '@shared/test/mockUsers'; import { presenter } from '../../presenter-mock'; import { runAction } from '@web-client/presenter/test.cerebral'; import { updateCaseWorksheetAction } from './updateCaseWorksheetAction'; @@ -18,12 +19,19 @@ describe('updateCaseWorksheetAction', () => { .getUseCases() .updateCaseWorksheetInteractor.mockResolvedValue(MOCK_CASE_WORKSHEET); + applicationContext + .getUseCases() + .getJudgeInSectionInteractor.mockResolvedValue({ + userId: judgeColvin.userId, + }); + const { output } = await runAction(updateCaseWorksheetAction, { modules: { presenter, }, state: { form: mockForm, + user: { section: '', userId: '' }, }, }); diff --git a/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts b/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts index 79fac5bd030..509f0942b9b 100644 --- a/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts +++ b/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts @@ -1,4 +1,5 @@ import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { getJudgeForCurrentUserAction } from '@web-client/presenter/actions/getJudgeForCurrentUserAction'; import { state } from '@web-client/presenter/app.cerebral'; export const updateCaseWorksheetAction = async ({ @@ -9,12 +10,19 @@ export const updateCaseWorksheetAction = async ({ state.form, ); + const { judgeUser } = await getJudgeForCurrentUserAction({ + applicationContext, + get, + } as ActionProps); + const updatedWorksheet = await applicationContext .getUseCases() .updateCaseWorksheetInteractor(applicationContext, { worksheet: { docketNumber, + entityName: 'CaseWorksheet', finalBriefDueDate, + judgeUserId: judgeUser.userId, primaryIssue, statusOfMatter, }, From 60114d36e6e1133a733c03e68d7a9e1da27827ca Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 13 Nov 2024 10:28:55 -0500 Subject: [PATCH 31/47] 10504-dxox: update some tests after the previous refactor --- .../validateCaseWorksheetInteractor.test.ts | 3 + shared/src/test/mockCaseWorksheet.ts | 2 + ...veCorrespondenceDocumentInteractor.test.ts | 2 +- ...leCorrespondenceDocumentInteractor.test.ts | 6 +- ...teCorrespondenceDocumentInteractor.test.ts | 7 +- .../processStreamRecordsInteractor.test.ts | 120 +++++++++++++++++- .../processStreamRecordsInteractor.ts | 25 ++-- ...dEditCaseWorksheetModalStateAction.test.ts | 2 + .../setCaseWorksheetAction.test.ts | 2 + 9 files changed, 140 insertions(+), 29 deletions(-) diff --git a/shared/src/business/useCases/caseWorksheet/validateCaseWorksheetInteractor.test.ts b/shared/src/business/useCases/caseWorksheet/validateCaseWorksheetInteractor.test.ts index 1dfd8118639..3a5ec600938 100644 --- a/shared/src/business/useCases/caseWorksheet/validateCaseWorksheetInteractor.test.ts +++ b/shared/src/business/useCases/caseWorksheet/validateCaseWorksheetInteractor.test.ts @@ -1,4 +1,5 @@ import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { judgeColvin } from '@shared/test/mockUsers'; import { validateCaseWorksheetInteractor } from './validateCaseWorksheetInteractor'; describe('validateCaseWorksheetInteractor', () => { @@ -6,6 +7,7 @@ describe('validateCaseWorksheetInteractor', () => { const mockInvalidCaseWorksheet: RawCaseWorksheet = { docketNumber: undefined as any, // Docket number is required entityName: 'CaseWorksheet', + judgeUserId: judgeColvin.userId, }; const errors = validateCaseWorksheetInteractor({ @@ -19,6 +21,7 @@ describe('validateCaseWorksheetInteractor', () => { const mockValidCaseWorksheet: RawCaseWorksheet = { docketNumber: '111-11', entityName: 'CaseWorksheet', + judgeUserId: judgeColvin.userId, }; const errors = validateCaseWorksheetInteractor({ diff --git a/shared/src/test/mockCaseWorksheet.ts b/shared/src/test/mockCaseWorksheet.ts index 1fb63e832f9..ffc3a677a82 100644 --- a/shared/src/test/mockCaseWorksheet.ts +++ b/shared/src/test/mockCaseWorksheet.ts @@ -3,11 +3,13 @@ import { RawCaseWorksheet, } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { MOCK_CASE } from '@shared/test/mockCase'; +import { judgeColvin } from '@shared/test/mockUsers'; export const MOCK_CASE_WORKSHEET: RawCaseWorksheet = { docketNumber: MOCK_CASE.docketNumber, entityName: 'CaseWorksheet', finalBriefDueDate: '2023-07-29', + judgeUserId: judgeColvin.userId, primaryIssue: 'anything', statusOfMatter: CaseWorksheet.STATUS_OF_MATTER_OPTIONS[0], }; diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts index bc532319ef6..13d28f34c3d 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts @@ -28,7 +28,7 @@ describe('archiveCorrespondenceDocumentInteractor', () => { mockLock = undefined; mockCorrespondence = new Correspondence({ correspondenceId: mockCorrespondenceId, - docketNumber: '101-23', + docketNumber: MOCK_CASE.docketNumber, documentTitle: 'My Correspondence', filedBy: 'Docket clerk', userId: mockUserId, diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts index 48599a30d03..6818b1b46b0 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts @@ -123,8 +123,8 @@ describe('fileCorrespondenceDocumentInteractor', () => { }, docketClerkUser, ); - expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject({ - correspondence: { + expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject([ + { correspondenceId: mockCorrespondenceId, docketNumber: mockCase.docketNumber, documentTitle: mockDocumentTitle, @@ -132,7 +132,7 @@ describe('fileCorrespondenceDocumentInteractor', () => { filingDate: mockFilingDate, userId: docketClerkUser.userId, }, - }); + ]); }); it('should return an updated raw case object', async () => { diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts index 3b688fee4ef..319cee77b53 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts @@ -102,13 +102,12 @@ describe('updateCorrespondenceDocumentInteractor', () => { mockDocketClerkUser, ); - expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject({ - correspondence: { + expect(upsertCaseCorrespondences.mock.calls[0][0]).toMatchObject([ + { ...mockCorrespondence, documentTitle: 'A title that has been updated', }, - docketNumber: mockCase.docketNumber, - }); + ]); }); it('should return an updated raw case object', async () => { diff --git a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.test.ts b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.test.ts index 2ee5a87fc45..d4298ad1aea 100644 --- a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.test.ts +++ b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.test.ts @@ -5,10 +5,17 @@ jest.mock('./processPractitionerMappingEntries'); jest.mock('./processRemoveEntries'); jest.mock('./processWorkItemEntries'); jest.mock('./processCaseEntries'); +jest.mock('./processCaseDeadlineEntries'); +jest.mock('./processCaseCorrespondenceEntries'); +jest.mock('./processCaseWorksheetEntries'); jest.mock('./processOtherEntries'); import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; +import { getLogger } from '@web-api/utilities/logger/getLogger'; import { partitionRecords } from './processStreamUtilities'; +import { processCaseCorrespondenceEntries } from '@web-api/business/useCases/processStreamRecords/processCaseCorrespondenceEntries'; +import { processCaseDeadlineEntries } from '@web-api/business/useCases/processStreamRecords/processCaseDeadlineEntries'; import { processCaseEntries } from './processCaseEntries'; +import { processCaseWorksheetEntries } from '@web-api/business/useCases/processStreamRecords/processCaseWorksheetEntries'; import { processDocketEntries } from './processDocketEntries'; import { processMessageEntries } from './processMessageEntries'; import { processOtherEntries } from './processOtherEntries'; @@ -17,6 +24,9 @@ import { processRemoveEntries } from './processRemoveEntries'; import { processStreamRecordsInteractor } from './processStreamRecordsInteractor'; import { processWorkItemEntries } from './processWorkItemEntries'; +const logger = getLogger(); +const errorSpy = jest.spyOn(logger, 'error'); + describe('processStreamRecordsInteractor', () => { beforeAll(() => { (processRemoveEntries as jest.Mock).mockResolvedValue([]); @@ -25,10 +35,16 @@ describe('processStreamRecordsInteractor', () => { (processWorkItemEntries as jest.Mock).mockResolvedValue([]); (processMessageEntries as jest.Mock).mockResolvedValue([]); (processPractitionerMappingEntries as jest.Mock).mockResolvedValue([]); + (processCaseDeadlineEntries as jest.Mock).mockResolvedValue([]); + (processCaseWorksheetEntries as jest.Mock).mockResolvedValue([]); + (processCaseCorrespondenceEntries as jest.Mock).mockResolvedValue([]); (processOtherEntries as jest.Mock).mockResolvedValue([]); (partitionRecords as jest.Mock).mockReturnValue({ + caseCorrespondenceRecords: [], + caseDeadlineRecords: [], caseEntityRecords: [], + caseWorksheetRecords: [], docketEntryRecords: [], irsPractitionerMappingRecords: [], otherRecords: [], @@ -61,8 +77,11 @@ describe('processStreamRecordsInteractor', () => { expect(processWorkItemEntries).not.toHaveBeenCalled(); expect(processMessageEntries).not.toHaveBeenCalled(); expect(processPractitionerMappingEntries).not.toHaveBeenCalled(); + expect(processCaseDeadlineEntries).not.toHaveBeenCalled(); + expect(processCaseWorksheetEntries).not.toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); expect(processOtherEntries).not.toHaveBeenCalled(); - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); it('should log an error, throw an exception, and halt further execution when processCaseEntries fails', async () => { @@ -81,7 +100,7 @@ describe('processStreamRecordsInteractor', () => { expect(processMessageEntries).not.toHaveBeenCalled(); expect(processPractitionerMappingEntries).not.toHaveBeenCalled(); expect(processOtherEntries).not.toHaveBeenCalled(); - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); it('should log an error, throw an exception, and halt further execution when processDocketEntries fails', async () => { @@ -99,8 +118,11 @@ describe('processStreamRecordsInteractor', () => { expect(processWorkItemEntries).not.toHaveBeenCalled(); expect(processMessageEntries).not.toHaveBeenCalled(); expect(processPractitionerMappingEntries).not.toHaveBeenCalled(); + expect(processCaseDeadlineEntries).not.toHaveBeenCalled(); + expect(processCaseWorksheetEntries).not.toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); expect(processOtherEntries).not.toHaveBeenCalled(); - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); it('should log an error, throw an exception, and halt further execution when processWorkItemEntries fails', async () => { @@ -118,8 +140,11 @@ describe('processStreamRecordsInteractor', () => { expect(processWorkItemEntries).toHaveBeenCalled(); // the one that throws an error expect(processMessageEntries).not.toHaveBeenCalled(); expect(processPractitionerMappingEntries).not.toHaveBeenCalled(); + expect(processCaseDeadlineEntries).not.toHaveBeenCalled(); + expect(processCaseWorksheetEntries).not.toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); expect(processOtherEntries).not.toHaveBeenCalled(); - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); it('should log an error, throw an exception, and halt further execution when processMessageEntries fails', async () => { @@ -137,8 +162,11 @@ describe('processStreamRecordsInteractor', () => { expect(processWorkItemEntries).toHaveBeenCalled(); expect(processMessageEntries).toHaveBeenCalled(); // the one that throws an error expect(processPractitionerMappingEntries).not.toHaveBeenCalled(); + expect(processCaseDeadlineEntries).not.toHaveBeenCalled(); + expect(processCaseWorksheetEntries).not.toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); expect(processOtherEntries).not.toHaveBeenCalled(); - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); it('should log an error, throw an exception, and halt further execution when processPractitionerMappingEntries fails', async () => { @@ -158,8 +186,83 @@ describe('processStreamRecordsInteractor', () => { expect(processWorkItemEntries).toHaveBeenCalled(); expect(processMessageEntries).toHaveBeenCalled(); expect(processPractitionerMappingEntries).toHaveBeenCalled(); // the one that throws an error + expect(processCaseDeadlineEntries).not.toHaveBeenCalled(); + expect(processCaseWorksheetEntries).not.toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); + expect(processOtherEntries).not.toHaveBeenCalled(); + expect(errorSpy).toHaveBeenCalledTimes(2); + }); + + it('should log an error, throw an exception, and halt further execution when processCaseDeadlineEntries fails', async () => { + (processCaseDeadlineEntries as jest.Mock).mockRejectedValueOnce( + new Error(), + ); + + await expect( + processStreamRecordsInteractor(applicationContext, { + recordsToProcess: [], + }), + ).rejects.toThrow(); + + expect(processRemoveEntries).toHaveBeenCalled(); + expect(processCaseEntries).toHaveBeenCalled(); + expect(processDocketEntries).toHaveBeenCalled(); + expect(processWorkItemEntries).toHaveBeenCalled(); + expect(processMessageEntries).toHaveBeenCalled(); + expect(processPractitionerMappingEntries).toHaveBeenCalled(); + expect(processCaseDeadlineEntries).toHaveBeenCalled(); // the one that throws an error + expect(processCaseWorksheetEntries).not.toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); + expect(processOtherEntries).not.toHaveBeenCalled(); + expect(errorSpy).toHaveBeenCalledTimes(2); + }); + + it('should log an error, throw an exception, and halt further execution when processCaseWorksheetEntries fails', async () => { + (processCaseWorksheetEntries as jest.Mock).mockRejectedValueOnce( + new Error(), + ); + + await expect( + processStreamRecordsInteractor(applicationContext, { + recordsToProcess: [], + }), + ).rejects.toThrow(); + + expect(processRemoveEntries).toHaveBeenCalled(); + expect(processCaseEntries).toHaveBeenCalled(); + expect(processDocketEntries).toHaveBeenCalled(); + expect(processWorkItemEntries).toHaveBeenCalled(); + expect(processMessageEntries).toHaveBeenCalled(); + expect(processPractitionerMappingEntries).toHaveBeenCalled(); + expect(processCaseDeadlineEntries).toHaveBeenCalled(); + expect(processCaseWorksheetEntries).toHaveBeenCalled(); // the one that throws an error + expect(processCaseCorrespondenceEntries).not.toHaveBeenCalled(); + expect(processOtherEntries).not.toHaveBeenCalled(); + expect(errorSpy).toHaveBeenCalledTimes(2); + }); + + it('should log an error, throw an exception, and halt further execution when processCaseCorrespondenceEntries fails', async () => { + (processCaseCorrespondenceEntries as jest.Mock).mockRejectedValueOnce( + new Error(), + ); + + await expect( + processStreamRecordsInteractor(applicationContext, { + recordsToProcess: [], + }), + ).rejects.toThrow(); + + expect(processRemoveEntries).toHaveBeenCalled(); + expect(processCaseEntries).toHaveBeenCalled(); + expect(processDocketEntries).toHaveBeenCalled(); + expect(processWorkItemEntries).toHaveBeenCalled(); + expect(processMessageEntries).toHaveBeenCalled(); + expect(processPractitionerMappingEntries).toHaveBeenCalled(); + expect(processCaseDeadlineEntries).toHaveBeenCalled(); + expect(processCaseWorksheetEntries).toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).toHaveBeenCalled(); // the one that throws an error expect(processOtherEntries).not.toHaveBeenCalled(); - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); it('should log an error, throw an exception, and halt further execution when processOtherEntries fails', async () => { @@ -177,7 +280,10 @@ describe('processStreamRecordsInteractor', () => { expect(processWorkItemEntries).toHaveBeenCalled(); expect(processMessageEntries).toHaveBeenCalled(); expect(processPractitionerMappingEntries).toHaveBeenCalled(); + expect(processCaseDeadlineEntries).toHaveBeenCalled(); + expect(processCaseWorksheetEntries).toHaveBeenCalled(); + expect(processCaseCorrespondenceEntries).toHaveBeenCalled(); expect(processOtherEntries).toHaveBeenCalled(); // the one that throws an error - expect(applicationContext.logger.error).toHaveBeenCalledTimes(2); + expect(errorSpy).toHaveBeenCalledTimes(2); }); }); diff --git a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts index db638590499..d572fadbd5b 100644 --- a/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts +++ b/web-api/src/business/useCases/processStreamRecords/processStreamRecordsInteractor.ts @@ -1,5 +1,5 @@ import { ServerApplicationContext } from '@web-api/applicationContext'; -import { getLogger } from 'aws-xray-sdk'; +import { getLogger } from '@web-api/utilities/logger/getLogger'; import { partitionRecords } from './processStreamUtilities'; import { processCaseCorrespondenceEntries } from '@web-api/business/useCases/processStreamRecords/processCaseCorrespondenceEntries'; import { processCaseDeadlineEntries } from '@web-api/business/useCases/processStreamRecords/processCaseDeadlineEntries'; @@ -37,7 +37,7 @@ export const processStreamRecordsInteractor = async ( applicationContext, removeRecords, }).catch(err => { - applicationContext.logger.error('failed to processRemoveEntries', { + getLogger().error('failed to processRemoveEntries', { err, }); throw err; @@ -47,7 +47,7 @@ export const processStreamRecordsInteractor = async ( applicationContext, caseEntityRecords, }).catch(err => { - applicationContext.logger.error('failed to processCaseEntries', { + getLogger().error('failed to processCaseEntries', { err, }); throw err; @@ -57,7 +57,7 @@ export const processStreamRecordsInteractor = async ( applicationContext, docketEntryRecords, }).catch(err => { - applicationContext.logger.error('failed to processDocketEntries', { + getLogger().error('failed to processDocketEntries', { err, }); throw err; @@ -65,7 +65,7 @@ export const processStreamRecordsInteractor = async ( await processWorkItemEntries({ applicationContext, workItemRecords }).catch( err => { - applicationContext.logger.error('failed to process workItem records', { + getLogger().error('failed to process workItem records', { err, }); throw err; @@ -75,7 +75,7 @@ export const processStreamRecordsInteractor = async ( await processMessageEntries({ messageRecords, }).catch(err => { - applicationContext.logger.error('failed to process message records', { + getLogger().error('failed to process message records', { err, }); throw err; @@ -85,12 +85,9 @@ export const processStreamRecordsInteractor = async ( applicationContext, practitionerMappingRecords, }).catch(err => { - applicationContext.logger.error( - 'failed to process practitioner mapping records', - { - err, - }, - ); + getLogger().error('failed to process practitioner mapping records', { + err, + }); throw err; }); @@ -128,14 +125,14 @@ export const processStreamRecordsInteractor = async ( await processOtherEntries({ applicationContext, otherRecords }).catch( err => { - applicationContext.logger.error('failed to processOtherEntries', { + getLogger().error('failed to processOtherEntries', { err, }); throw err; }, ); } catch (err) { - applicationContext.logger.error( + getLogger().error( 'processStreamRecordsInteractor failed to process the records', { err }, ); diff --git a/web-client/src/presenter/actions/CaseWorksheet/setAddEditCaseWorksheetModalStateAction.test.ts b/web-client/src/presenter/actions/CaseWorksheet/setAddEditCaseWorksheetModalStateAction.test.ts index d61a930d83c..0f3130d00a7 100644 --- a/web-client/src/presenter/actions/CaseWorksheet/setAddEditCaseWorksheetModalStateAction.test.ts +++ b/web-client/src/presenter/actions/CaseWorksheet/setAddEditCaseWorksheetModalStateAction.test.ts @@ -1,6 +1,7 @@ import { MOCK_CASE } from '@shared/test/mockCase'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext'; +import { judgeColvin } from '@shared/test/mockUsers'; import { presenter } from '@web-client/presenter/presenter-mock'; import { runAction } from '@web-client/presenter/test.cerebral'; import { setAddEditCaseWorksheetModalStateAction } from '@web-client/presenter/actions/CaseWorksheet/setAddEditCaseWorksheetModalStateAction'; @@ -12,6 +13,7 @@ describe('setAddEditCaseWorksheetModalStateAction', () => { const mockWorksheet: RawCaseWorksheet = { docketNumber: MOCK_CASE.docketNumber, entityName: 'CaseWorksheet', + judgeUserId: judgeColvin.userId, }; const { state } = await runAction(setAddEditCaseWorksheetModalStateAction, { diff --git a/web-client/src/presenter/actions/CaseWorksheet/setCaseWorksheetAction.test.ts b/web-client/src/presenter/actions/CaseWorksheet/setCaseWorksheetAction.test.ts index c448d338d6f..5f3a3eda50f 100644 --- a/web-client/src/presenter/actions/CaseWorksheet/setCaseWorksheetAction.test.ts +++ b/web-client/src/presenter/actions/CaseWorksheet/setCaseWorksheetAction.test.ts @@ -1,5 +1,6 @@ import { MOCK_CASE } from '@shared/test/mockCase'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { judgeColvin } from '@shared/test/mockUsers'; import { runAction } from '@web-client/presenter/test.cerebral'; import { setCaseWorksheetAction } from './setCaseWorksheetAction'; @@ -7,6 +8,7 @@ describe('setUpdatedCaseInStateAction', () => { const mockCaseWorksheet: RawCaseWorksheet = { docketNumber: MOCK_CASE.docketNumber, entityName: 'CaseWorksheet', + judgeUserId: judgeColvin.userId, primaryIssue: 'Superstition ain`t the way', }; From 037f5b8240ec18383369c1e87be268dea354b854 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 13 Nov 2024 11:46:11 -0500 Subject: [PATCH 32/47] 10504-dxox: add deletition scripts, add validation for judge id to CaseWorksheet.ts --- __TODO_10504.txt | 6 +- .../batch-delete-dynamo-items.ts | 63 +++++++++++++++++++ .../delete-case-correspondences.ts | 63 +++++++++++++++++++ .../delete-case-deadlines.ts | 62 ++++++++++++++++++ .../delete-case-worksheets.ts | 62 ++++++++++++++++++ .../delete-messages.ts | 2 +- .../entities/caseWorksheet/CaseWorksheet.ts | 1 + 7 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 scripts/run-once-scripts/postgres-migration/batch-delete-dynamo-items.ts create mode 100644 scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts create mode 100644 scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts create mode 100644 scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts rename scripts/run-once-scripts/{ => postgres-migration}/delete-messages.ts (98%) diff --git a/__TODO_10504.txt b/__TODO_10504.txt index f2e50262f4b..d3b7092a3fa 100644 --- a/__TODO_10504.txt +++ b/__TODO_10504.txt @@ -11,4 +11,8 @@ check CaseWorksheet works now with judgeUserId (added to the entity) and update -- -entityName: "CaseWorksheet" in updateCaseWorksheetAction is silly \ No newline at end of file +entityName: "CaseWorksheet" in updateCaseWorksheetAction is silly + +-- + +add missing tests \ No newline at end of file diff --git a/scripts/run-once-scripts/postgres-migration/batch-delete-dynamo-items.ts b/scripts/run-once-scripts/postgres-migration/batch-delete-dynamo-items.ts new file mode 100644 index 00000000000..60284d20ad4 --- /dev/null +++ b/scripts/run-once-scripts/postgres-migration/batch-delete-dynamo-items.ts @@ -0,0 +1,63 @@ +import { + BatchWriteCommand, + DynamoDBDocumentClient, +} from '@aws-sdk/lib-dynamodb'; + +export async function batchDeleteDynamoItems( + itemsToDelete: { DeleteRequest: { Key: { pk: string; sk: string } } }[], + client: DynamoDBDocumentClient, + tableNameInput: string, +): Promise { + const BATCH_SIZE = 25; + const RETRY_DELAY_MS = 5000; // Set the delay between retries (in milliseconds) + let totalItemsDeleted = 0; + + for (let i = 0; i < itemsToDelete.length; i += BATCH_SIZE) { + const batch = itemsToDelete.slice(i, i + BATCH_SIZE); + + const batchWriteParams = { + RequestItems: { + [tableNameInput]: batch, + }, + }; + + try { + let unprocessedItems: any[] = batch; + let retryCount = 0; + const MAX_RETRIES = 5; + + // Retry logic for unprocessed items + while (unprocessedItems.length > 0 && retryCount < MAX_RETRIES) { + const response = await client.send( + new BatchWriteCommand(batchWriteParams), + ); + + totalItemsDeleted += + unprocessedItems.length - + (response.UnprocessedItems?.[tableNameInput]?.length || 0); + + unprocessedItems = response.UnprocessedItems?.[tableNameInput] ?? []; + + if (unprocessedItems.length > 0) { + console.log( + `Retrying unprocessed items: ${unprocessedItems.length}, attempt ${retryCount + 1}`, + ); + batchWriteParams.RequestItems[tableNameInput] = unprocessedItems; + retryCount++; + + // Add delay before the next retry + await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS)); + } + } + + if (unprocessedItems.length > 0) { + console.error( + `Failed to delete ${unprocessedItems.length} items after ${MAX_RETRIES} retries.`, + ); + } + } catch (error) { + console.error('Error in batch delete:', error); + } + } + return totalItemsDeleted; +} diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts new file mode 100644 index 00000000000..2a3c4ae3f70 --- /dev/null +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -0,0 +1,63 @@ +/** + * HOW TO RUN + * + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-correspondences.ts + */ + +import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient, ScanCommandInput } from '@aws-sdk/client-dynamodb'; +import { requireEnvVars } from '../../../shared/admin-tools/util'; +import { getDbReader } from '../../../web-api/src/database'; +import { isEmpty } from 'lodash'; +import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; + +const caseCorrespondencePageSize = 10000; +const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); +const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); + +requireEnvVars(['TABLE_NAME']); + +const tableNameInput = process.env.TABLE_NAME!; + +const getCaseCorrespondencesToDelete = async (offset: number) => { + const caseCorrespondences = await getDbReader(reader => + reader + .selectFrom('dwCaseCorrespondence') + .select(['docketNumber', 'correspondenceId']) + .orderBy('correspondenceId') + .limit(caseCorrespondencePageSize) + .offset(offset) + .execute(), + ); + return caseCorrespondences; +}; + +let totalItemsDeleted = 0; + +async function main() { + let offset = 0; + let caseCorrespondencesToDelete = + await getCaseCorrespondencesToDelete(offset); + + while (!isEmpty(caseCorrespondencesToDelete)) { + const dynamoItemsToDelete = caseCorrespondencesToDelete.map(cd => ({ + DeleteRequest: { + Key: { + pk: `case|${cd.docketNumber}`, + sk: `correspondence${cd.correspondenceId}`, + }, + }, + })); + totalItemsDeleted += await batchDeleteDynamoItems( + dynamoItemsToDelete, + dynamoDbDocClient, + tableNameInput, + ); + console.log(`Total case correspondences deleted: ${totalItemsDeleted}`); + offset += caseCorrespondencePageSize; + caseCorrespondencesToDelete = await getCaseCorrespondencesToDelete(offset); + } + console.log('Done deleting case correspondences from Dynamo'); +} + +main().catch(console.error); diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts new file mode 100644 index 00000000000..d1a2ba0e8ba --- /dev/null +++ b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts @@ -0,0 +1,62 @@ +/** + * HOW TO RUN + * + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-deadlines.ts + */ + +import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; +import { requireEnvVars } from '../../../shared/admin-tools/util'; +import { getDbReader } from '../../../web-api/src/database'; +import { isEmpty } from 'lodash'; +import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; + +const caseDeadlinePageSize = 10000; +const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); +const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); + +requireEnvVars(['TABLE_NAME']); + +const tableNameInput = process.env.TABLE_NAME!; + +const getCaseDeadlinesToDelete = async (offset: number) => { + const caseDeadlines = await getDbReader(reader => + reader + .selectFrom('dwCaseDeadline') + .select(['docketNumber', 'caseDeadlineId']) + .orderBy('caseDeadlineId') + .limit(caseDeadlinePageSize) + .offset(offset) + .execute(), + ); + return caseDeadlines; +}; + +let totalItemsDeleted = 0; + +async function main() { + let offset = 0; + let caseDeadlinesToDelete = await getCaseDeadlinesToDelete(offset); + + while (!isEmpty(caseDeadlinesToDelete)) { + const dynamoItemsToDelete = caseDeadlinesToDelete.map(cd => ({ + DeleteRequest: { + Key: { + pk: `case|${cd.docketNumber}`, + sk: `case-deadline|${cd.caseDeadlineId}`, + }, + }, + })); + totalItemsDeleted += await batchDeleteDynamoItems( + dynamoItemsToDelete, + dynamoDbDocClient, + tableNameInput, + ); + console.log(`Total case deadlines deleted: ${totalItemsDeleted}`); + offset += caseDeadlinePageSize; + caseDeadlinesToDelete = await getCaseDeadlinesToDelete(offset); + } + console.log('Done deleting case deadlines from Dynamo'); +} + +main().catch(console.error); diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts new file mode 100644 index 00000000000..5d225682d29 --- /dev/null +++ b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts @@ -0,0 +1,62 @@ +/** + * HOW TO RUN + * + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-worksheets.ts + */ + +import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; +import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; +import { requireEnvVars } from '../../../shared/admin-tools/util'; +import { getDbReader } from '../../../web-api/src/database'; +import { isEmpty } from 'lodash'; +import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; + +const caseWorksheetPageSize = 10000; +const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); +const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); + +requireEnvVars(['TABLE_NAME']); + +const tableNameInput = process.env.TABLE_NAME!; + +const getCaseWorksheetsToDelete = async (offset: number) => { + const caseWorksheets = await getDbReader(reader => + reader + .selectFrom('dwCaseWorksheet') + .select(['docketNumber']) + .orderBy('docketNumber') + .limit(caseWorksheetPageSize) + .offset(offset) + .execute(), + ); + return caseWorksheets; +}; + +let totalItemsDeleted = 0; + +async function main() { + let offset = 0; + let caseWorksheetsToDelete = await getCaseWorksheetsToDelete(offset); + + while (!isEmpty(caseWorksheetsToDelete)) { + const dynamoItemsToDelete = caseWorksheetsToDelete.map(cd => ({ + DeleteRequest: { + Key: { + pk: `case|${cd.docketNumber}`, + sk: `case-worksheet|${cd.docketNumber}`, + }, + }, + })); + totalItemsDeleted += await batchDeleteDynamoItems( + dynamoItemsToDelete, + dynamoDbDocClient, + tableNameInput, + ); + console.log(`Total case worksheets deleted: ${totalItemsDeleted}`); + offset += caseWorksheetPageSize; + caseWorksheetsToDelete = await getCaseWorksheetsToDelete(offset); + } + console.log('Done deleting case worksheets from Dynamo'); +} + +main().catch(console.error); diff --git a/scripts/run-once-scripts/delete-messages.ts b/scripts/run-once-scripts/postgres-migration/delete-messages.ts similarity index 98% rename from scripts/run-once-scripts/delete-messages.ts rename to scripts/run-once-scripts/postgres-migration/delete-messages.ts index 6ed1a66b356..cc022e06f85 100644 --- a/scripts/run-once-scripts/delete-messages.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-messages.ts @@ -10,7 +10,7 @@ import { ScanCommand, } from '@aws-sdk/lib-dynamodb'; import { DynamoDBClient, ScanCommandInput } from '@aws-sdk/client-dynamodb'; -import { requireEnvVars } from '../../shared/admin-tools/util'; +import { requireEnvVars } from '../../../shared/admin-tools/util'; requireEnvVars(['TABLE_NAME']); diff --git a/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts b/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts index eef68b377ec..b399231ea8e 100644 --- a/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts +++ b/shared/src/business/entities/caseWorksheet/CaseWorksheet.ts @@ -37,6 +37,7 @@ export class CaseWorksheet extends JoiValidationEntity { .messages({ '*': 'Enter a valid due date', }), + judgeUserId: JoiValidationConstants.UUID.required(), primaryIssue: JoiValidationConstants.STRING.allow('').optional(), statusOfMatter: JoiValidationConstants.STRING.valid( ...CaseWorksheet.STATUS_OF_MATTER_OPTIONS, From 830ab53d192ec2d1e9b326356a4257fbacba5351 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 13 Nov 2024 12:40:01 -0500 Subject: [PATCH 33/47] 10504-dxox: add tests to new stream processors, and update postgres directory naming to be consistent --- ...ix-race-condition-served-in-drafts.test.ts | 2 +- .../src/business/entities/cases/Case.test.ts | 2 +- .../test/createTestApplicationContext.ts | 2 +- .../updateCaseAndAssociations.test.ts | 4 +-- .../updateCaseAndAssociations.ts | 2 +- .../updateCaseWorksheetInteractor.test.ts | 6 ++-- .../updateCaseWorksheetInteractor.ts | 2 +- ...veCorrespondenceDocumentInteractor.test.ts | 4 +-- ...archiveCorrespondenceDocumentInteractor.ts | 2 +- ...leCorrespondenceDocumentInteractor.test.ts | 4 +-- .../fileCorrespondenceDocumentInteractor.ts | 2 +- ...teCorrespondenceDocumentInteractor.test.ts | 4 +-- .../updateCorrespondenceDocumentInteractor.ts | 2 +- ...getCaseWorksheetsByJudgeInteractor.test.ts | 4 +-- .../getCaseWorksheetsByJudgeInteractor.ts | 2 +- .../processCaseCorrespondenceEntries.test.ts | 30 +++++++++++++++++++ .../processCaseCorrespondenceEntries.ts | 2 +- .../processCaseDeadlineEntries.test.ts | 30 +++++++++++++++++++ .../processCaseWorksheetEntries.test.ts | 29 ++++++++++++++++++ .../processCaseWorksheetEntries.ts | 2 +- .../processMessageEntries.test.ts | 2 -- ...dateTrialSessionInteractor.locking.test.ts | 2 +- .../updateTrialSessionInteractor.test.ts | 2 +- web-api/src/lambdas/v1/getCaseLambda.test.ts | 2 +- .../v1/getDocumentDownloadUrlLambda.test.ts | 2 +- web-api/src/lambdas/v2/getCaseLambda.test.ts | 2 +- .../v2/getDocumentDownloadUrlLambda.test.ts | 2 +- .../cases/getCaseByDocketNumber.test.ts | 6 ++-- .../dynamo/cases/getCaseByDocketNumber.ts | 2 +- .../getCalendaredCasesForTrialSession.test.ts | 2 +- .../getCaseCorrespondenceByDocketNumber.ts | 2 +- .../mapper.ts | 0 .../mocks.jest.ts | 4 +-- .../upsertCaseCorrespondences.ts | 0 .../getCaseWorksheetsByDocketNumber.ts | 2 +- .../mapper.ts | 0 .../mocks.jest.ts | 4 +-- .../upsertCaseWorksheets.ts | 0 .../actions/validateCaseWorksheetAction.ts | 9 +++++- .../CaseWorksheets/caseWorksheetsHelper.ts | 2 +- 40 files changed, 139 insertions(+), 45 deletions(-) create mode 100644 web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.test.ts create mode 100644 web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.test.ts create mode 100644 web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.test.ts rename web-api/src/persistence/postgres/{correspondence => caseCorrespondences}/getCaseCorrespondenceByDocketNumber.ts (94%) rename web-api/src/persistence/postgres/{correspondence => caseCorrespondences}/mapper.ts (100%) rename web-api/src/persistence/postgres/{correspondence => caseCorrespondences}/mocks.jest.ts (53%) rename web-api/src/persistence/postgres/{correspondence => caseCorrespondences}/upsertCaseCorrespondences.ts (100%) rename web-api/src/persistence/postgres/{caseWorksheet => caseWorksheets}/getCaseWorksheetsByDocketNumber.ts (96%) rename web-api/src/persistence/postgres/{caseWorksheet => caseWorksheets}/mapper.ts (100%) rename web-api/src/persistence/postgres/{caseWorksheet => caseWorksheets}/mocks.jest.ts (55%) rename web-api/src/persistence/postgres/{caseWorksheet => caseWorksheets}/upsertCaseWorksheets.ts (100%) diff --git a/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts b/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts index 32e40a19992..c74528237e6 100644 --- a/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts +++ b/scripts/dynamo/fix-race-condition-served-in-drafts.test.ts @@ -1,8 +1,8 @@ /* * @jest-environment node */ +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; -import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'; import { MOCK_DOCUMENTS } from '@shared/test/mockDocketEntry'; diff --git a/shared/src/business/entities/cases/Case.test.ts b/shared/src/business/entities/cases/Case.test.ts index d810fad2478..acc53f4d2b6 100644 --- a/shared/src/business/entities/cases/Case.test.ts +++ b/shared/src/business/entities/cases/Case.test.ts @@ -1,7 +1,7 @@ /* eslint-disable max-lines */ +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; -import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { AUTOMATIC_BLOCKED_REASONS, CASE_STATUS_TYPES, diff --git a/shared/src/business/test/createTestApplicationContext.ts b/shared/src/business/test/createTestApplicationContext.ts index 2294c0baecb..5d29f487eb3 100644 --- a/shared/src/business/test/createTestApplicationContext.ts +++ b/shared/src/business/test/createTestApplicationContext.ts @@ -123,7 +123,7 @@ import { updateCaseAutomaticBlock } from '@web-api/business/useCaseHelper/automa import { updateDocketEntry } from '@web-api/persistence/dynamo/documents/updateDocketEntry'; import { updateUserRecords } from '@web-api/persistence/dynamo/users/updateUserRecords'; import { uploadDocumentAndMakeSafeInteractor } from '@shared/business/useCases/uploadDocumentAndMakeSafeInteractor'; -import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; import { validatePenaltiesInteractor } from '@shared/business/useCases/validatePenaltiesInteractor'; import { verifyCaseForUser } from '@web-api/persistence/dynamo/cases/verifyCaseForUser'; import path from 'path'; diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts index e0145d8df1a..7a5f7c9ff98 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.test.ts @@ -1,7 +1,7 @@ /* eslint-disable max-lines */ +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; -import '@web-api/persistence/postgres/correspondence/mocks.jest'; jest.mock('@shared/business/entities/Message.ts'); jest.mock('@shared/business/entities/CaseDeadline'); jest.mock('@web-api/persistence/postgres/messages/getMessagesByDocketNumber'); @@ -26,7 +26,7 @@ import { getMessagesByDocketNumber as getMessagesByDocketNumberMock } from '@web import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; import { updateCaseAndAssociations } from './updateCaseAndAssociations'; import { updateMessage as updateMessageMock } from '@web-api/persistence/postgres/messages/updateMessage'; -import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; import { upsertCaseDeadlines as upsertCaseDeadlinesMock } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; import { v4 as uuidv4 } from 'uuid'; diff --git a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts index 1acd8ae715f..ebf006b1e08 100644 --- a/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts +++ b/web-api/src/business/useCaseHelper/caseAssociation/updateCaseAndAssociations.ts @@ -12,7 +12,7 @@ import { getCaseDeadlinesByDocketNumber } from '@web-api/persistence/postgres/ca import { getMessagesByDocketNumber } from '@web-api/persistence/postgres/messages/getMessagesByDocketNumber'; import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage'; import { upsertCase } from '@web-api/persistence/postgres/cases/upsertCase'; -import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; import diff from 'diff-arrays-of-objects'; diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts index 6989e7482cd..fa5a779cb76 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.test.ts @@ -1,15 +1,15 @@ -import '@web-api/persistence/postgres/caseWorksheet/mocks.jest'; +import '@web-api/persistence/postgres/caseWorksheets/mocks.jest'; import { InvalidEntityError, UnauthorizedError } from '@web-api/errors/errors'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; +import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber'; import { judgeColvin } from '@shared/test/mockUsers'; import { mockChambersUser, mockPetitionsClerkUser, } from '@shared/test/mockAuthUsers'; import { updateCaseWorksheetInteractor } from './updateCaseWorksheetInteractor'; -import { upsertCaseWorksheets as upsertCaseWorksheetsMock } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets'; +import { upsertCaseWorksheets as upsertCaseWorksheetsMock } from '@web-api/persistence/postgres/caseWorksheets/upsertCaseWorksheets'; const getCaseWorksheetsByDocketNumber = getCaseWorksheetsByDocketNumberMock as jest.Mock; diff --git a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts index af57393d585..d10d83c4d6a 100644 --- a/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts +++ b/web-api/src/business/useCases/caseWorksheet/updateCaseWorksheetInteractor.ts @@ -8,7 +8,7 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets'; +import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheets/upsertCaseWorksheets'; export const updateCaseWorksheetInteractor = async ( { diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts index 13d28f34c3d..ebc24d55b68 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.test.ts @@ -1,5 +1,5 @@ +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; -import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { Correspondence } from '../../../../../shared/src/business/entities/Correspondence'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; @@ -8,7 +8,7 @@ import { ServiceUnavailableError } from '@web-api/errors/errors'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { archiveCorrespondenceDocumentInteractor } from './archiveCorrespondenceDocumentInteractor'; import { mockDocketClerkUser } from '@shared/test/mockAuthUsers'; -import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; diff --git a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts index 858eefd59e3..e94f072e60d 100644 --- a/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/archiveCorrespondenceDocumentInteractor.ts @@ -6,7 +6,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; import { withLocking } from '@web-api/business/useCaseHelper/acquireLock'; export const archiveCorrespondenceDocument = async ( diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts index 6818b1b46b0..999302ed380 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { CASE_TYPES_MAP, CONTACT_TYPES, @@ -14,7 +14,7 @@ import { mockDocketClerkUser, mockPetitionerUser, } from '@shared/test/mockAuthUsers'; -import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; diff --git a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts index c7c9c79d67f..ff0d3140d9e 100644 --- a/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/fileCorrespondenceDocumentInteractor.ts @@ -7,7 +7,7 @@ import { } from '../../../../../shared/src/authorization/authorizationClientService'; import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; /** * fileCorrespondenceDocumentInteractor diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts index 319cee77b53..17991576586 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { CASE_TYPES_MAP, CONTACT_TYPES, @@ -14,7 +14,7 @@ import { mockPetitionerUser, } from '@shared/test/mockAuthUsers'; import { updateCorrespondenceDocumentInteractor } from './updateCorrespondenceDocumentInteractor'; -import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences as upsertCaseCorrespondencesMock } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; const upsertCaseCorrespondences = upsertCaseCorrespondencesMock as jest.Mock; diff --git a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts index 23b6125b16e..f513fb7657d 100644 --- a/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts +++ b/web-api/src/business/useCases/correspondence/updateCorrespondenceDocumentInteractor.ts @@ -7,7 +7,7 @@ import { import { ServerApplicationContext } from '@web-api/applicationContext'; import { UnauthorizedError } from '@web-api/errors/errors'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; export const updateCorrespondenceDocumentInteractor = async ( applicationContext: ServerApplicationContext, diff --git a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts index 8a5a4ca39b1..0c9272883fd 100644 --- a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts +++ b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/caseWorksheet/mocks.jest'; +import '@web-api/persistence/postgres/caseWorksheets/mocks.jest'; import { CASE_STATUS_TYPES } from '@shared/business/entities/EntityConstants'; import { GetCasesByStatusAndByJudgeRequest, @@ -12,7 +12,7 @@ import { import { MOCK_CASE_WORKSHEET } from '@shared/test/mockCaseWorksheet'; import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; -import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; +import { getCaseWorksheetsByDocketNumber as getCaseWorksheetsByDocketNumberMock } from '@web-api/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber'; import { judgeUser } from '@shared/test/mockUsers'; import { mockJudgeUser, diff --git a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts index 4c62e3d5d47..54f86d99c58 100644 --- a/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts +++ b/web-api/src/business/useCases/judgeActivityReport/getCaseWorksheetsByJudgeInteractor.ts @@ -8,7 +8,7 @@ import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWo import { ServerApplicationContext } from '@web-api/applicationContext'; import { SubmittedCAVTableFields } from '@web-api/persistence/elasticsearch/getDocketNumbersByStatusAndByJudge'; import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser'; -import { getCaseWorksheetsByDocketNumber } from '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber'; +import { getCaseWorksheetsByDocketNumber } from '@web-api/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber'; export type GetCasesByStatusAndByJudgeRequest = { statuses: string[]; diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.test.ts b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.test.ts new file mode 100644 index 00000000000..a5d5507f24b --- /dev/null +++ b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.test.ts @@ -0,0 +1,30 @@ +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; +import { processCaseCorrespondenceEntries } from '@web-api/business/useCases/processStreamRecords/processCaseCorrespondenceEntries'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; + +describe('processCaseCorrespondenceEntries', () => { + beforeEach(() => { + (upsertCaseCorrespondences as jest.Mock).mockResolvedValue(undefined); + }); + + it('should attempt to store case correspondences using the upsert method', async () => { + const mockDynamoCaseCorrespondence = { + dynamodb: { + NewImage: { + docketNumber: { + S: '123-45', + }, + entityName: { + S: 'CaseCorrespondence', + }, + }, + }, + }; + + await processCaseCorrespondenceEntries({ + caseCorrespondenceRecords: [mockDynamoCaseCorrespondence], + }); + + expect(upsertCaseCorrespondences).toHaveBeenCalled(); + }); +}); diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts index b561f2a39fc..cafa536099e 100644 --- a/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts +++ b/web-api/src/business/useCases/processStreamRecords/processCaseCorrespondenceEntries.ts @@ -1,7 +1,7 @@ import { RawCorrespondence } from '@shared/business/entities/Correspondence'; import { getLogger } from 'aws-xray-sdk'; import { unmarshall } from '@aws-sdk/util-dynamodb'; -import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences'; +import { upsertCaseCorrespondences } from '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences'; export const processCaseCorrespondenceEntries = async ({ caseCorrespondenceRecords, diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.test.ts b/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.test.ts new file mode 100644 index 00000000000..b7c0d8b0283 --- /dev/null +++ b/web-api/src/business/useCases/processStreamRecords/processCaseDeadlineEntries.test.ts @@ -0,0 +1,30 @@ +import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; +import { processCaseDeadlineEntries } from '@web-api/business/useCases/processStreamRecords/processCaseDeadlineEntries'; +import { upsertCaseDeadlines } from '@web-api/persistence/postgres/caseDeadlines/upsertCaseDeadlines'; + +describe('processCaseDeadlineEntries', () => { + beforeEach(() => { + (upsertCaseDeadlines as jest.Mock).mockResolvedValue(undefined); + }); + + it('should attempt to store case deadlines using the upsert method', async () => { + const mockDynamoCaseDeadlines = { + dynamodb: { + NewImage: { + docketNumber: { + S: '123-45', + }, + entityName: { + S: 'CaseDeadline', + }, + }, + }, + }; + + await processCaseDeadlineEntries({ + caseDeadlineRecords: [mockDynamoCaseDeadlines], + }); + + expect(upsertCaseDeadlines).toHaveBeenCalled(); + }); +}); diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.test.ts b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.test.ts new file mode 100644 index 00000000000..752549b3462 --- /dev/null +++ b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.test.ts @@ -0,0 +1,29 @@ +import '@web-api/persistence/postgres/caseWorksheets/mocks.jest'; +import { processCaseWorksheetEntries } from '@web-api/business/useCases/processStreamRecords/processCaseWorksheetEntries'; +import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheets/upsertCaseWorksheets'; +describe('processCaseWorksheetEntries', () => { + beforeEach(() => { + (upsertCaseWorksheets as jest.Mock).mockResolvedValue(undefined); + }); + + it('should attempt to store case worksheets using the upsert method', async () => { + const mockDynamoCaseWorksheets = { + dynamodb: { + NewImage: { + docketNumber: { + S: '123-45', + }, + entityName: { + S: 'CaseWorksheet', + }, + }, + }, + }; + + await processCaseWorksheetEntries({ + caseWorksheetRecords: [mockDynamoCaseWorksheets], + }); + + expect(upsertCaseWorksheets).toHaveBeenCalled(); + }); +}); diff --git a/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts index 50ab97c0cff..164c397eef1 100644 --- a/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts +++ b/web-api/src/business/useCases/processStreamRecords/processCaseWorksheetEntries.ts @@ -1,7 +1,7 @@ import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { getLogger } from 'aws-xray-sdk'; import { unmarshall } from '@aws-sdk/util-dynamodb'; -import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets'; +import { upsertCaseWorksheets } from '@web-api/persistence/postgres/caseWorksheets/upsertCaseWorksheets'; export const processCaseWorksheetEntries = async ({ caseWorksheetRecords, diff --git a/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts b/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts index 3aaabac85b6..53d2b82a15b 100644 --- a/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts +++ b/web-api/src/business/useCases/processStreamRecords/processMessageEntries.test.ts @@ -2,8 +2,6 @@ import '@web-api/persistence/postgres/messages/mocks.jest'; import { processMessageEntries } from './processMessageEntries'; import { upsertMessages } from '@web-api/persistence/postgres/messages/upsertMessages'; -jest.mock('@web-api/persistence/postgres/messages/upsertMessages'); - describe('processMessageEntries', () => { beforeEach(() => { (upsertMessages as jest.Mock).mockResolvedValue(undefined); diff --git a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts index 534823228cb..3724e9666b2 100644 --- a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts +++ b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.locking.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_LOCK } from '../../../../../shared/src/test/mockLock'; import { MOCK_TRIAL_INPERSON } from '../../../../../shared/src/test/mockTrial'; diff --git a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts index 8a856f5f2eb..b56626d29db 100644 --- a/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts +++ b/web-api/src/business/useCases/trialSessions/updateTrialSessionInteractor.test.ts @@ -1,6 +1,6 @@ +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import '@web-api/persistence/postgres/caseDeadlines/mocks.jest'; import '@web-api/persistence/postgres/cases/mocks.jest'; -import '@web-api/persistence/postgres/correspondence/mocks.jest'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { MOCK_TRIAL_INPERSON, diff --git a/web-api/src/lambdas/v1/getCaseLambda.test.ts b/web-api/src/lambdas/v1/getCaseLambda.test.ts index 36703503f4d..13164c8cb45 100644 --- a/web-api/src/lambdas/v1/getCaseLambda.test.ts +++ b/web-api/src/lambdas/v1/getCaseLambda.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { MOCK_CASE_WITH_TRIAL_SESSION } from '../../../../shared/src/test/mockCase'; import { getCaseLambda } from './getCaseLambda'; import { createTestApplicationContext as mockCreateTestApplicationContext } from '@shared/business/test/createTestApplicationContext'; diff --git a/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts b/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts index 675bc2530ed..fa546881ff5 100644 --- a/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts +++ b/web-api/src/lambdas/v1/getDocumentDownloadUrlLambda.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { CASE_STATUS_TYPES } from '@shared/business/entities/EntityConstants'; import { MOCK_PETITION } from '@shared/test/mockDocketEntry'; import { getDocumentDownloadUrlLambda } from './getDocumentDownloadUrlLambda'; diff --git a/web-api/src/lambdas/v2/getCaseLambda.test.ts b/web-api/src/lambdas/v2/getCaseLambda.test.ts index 6ded42a2338..bb391de8a62 100644 --- a/web-api/src/lambdas/v2/getCaseLambda.test.ts +++ b/web-api/src/lambdas/v2/getCaseLambda.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { MOCK_CASE_WITH_TRIAL_SESSION } from '../../../../shared/src/test/mockCase'; import { MOCK_COMPLEX_CASE } from '../../../../shared/src/test/mockComplexCase'; import { MOCK_PRACTITIONER } from '../../../../shared/src/test/mockUsers'; diff --git a/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts b/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts index db2d1e4c8a9..868c3bac0de 100644 --- a/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts +++ b/web-api/src/lambdas/v2/getDocumentDownloadUrlLambda.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { CASE_STATUS_TYPES, Role, diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts index aed46b2b39e..32391057760 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.test.ts @@ -1,13 +1,13 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { CASE_STATUS_TYPES, ROLES, } from '../../../../../shared/src/business/entities/EntityConstants'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; import { calculateDate } from '@shared/business/utilities/DateHandler'; -import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/correspondence/mapper'; +import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/caseCorrespondences/mapper'; import { getCaseByDocketNumber } from './getCaseByDocketNumber'; -import { getCaseCorrespondenceByDocketNumber as getCaseCorrespondenceByDocketNumberMock } from '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber'; +import { getCaseCorrespondenceByDocketNumber as getCaseCorrespondenceByDocketNumberMock } from '@web-api/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber'; const getCaseCorrespondenceByDocketNumber = getCaseCorrespondenceByDocketNumberMock as jest.Mock; diff --git a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts index c8769c3e7b7..28ecf6d8b9d 100644 --- a/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts +++ b/web-api/src/persistence/dynamo/cases/getCaseByDocketNumber.ts @@ -9,7 +9,7 @@ import { aggregateConsolidatedCaseItems, isCaseItem, } from '../helpers/aggregateCaseItems'; -import { getCaseCorrespondenceByDocketNumber } from '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber'; +import { getCaseCorrespondenceByDocketNumber } from '@web-api/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber'; import { purgeDynamoKeys } from '@web-api/persistence/dynamo/helpers/purgeDynamoKeys'; import { queryFull } from '../../dynamodbClientService'; diff --git a/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts b/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts index a091b0833ad..cc7ef8c8f01 100644 --- a/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts +++ b/web-api/src/persistence/dynamo/trialSessions/getCalendaredCasesForTrialSession.test.ts @@ -1,4 +1,4 @@ -import '@web-api/persistence/postgres/correspondence/mocks.jest'; +import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest'; import { CASE_STATUS_TYPES } from '../../../../../shared/src/business/entities/EntityConstants'; import { MOCK_CASE } from '../../../../../shared/src/test/mockCase'; import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext'; diff --git a/web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts b/web-api/src/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber.ts similarity index 94% rename from web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts rename to web-api/src/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber.ts index 855aa135589..3960e59a887 100644 --- a/web-api/src/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber.ts +++ b/web-api/src/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber.ts @@ -1,5 +1,5 @@ import { Correspondence } from '@shared/business/entities/Correspondence'; -import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/correspondence/mapper'; +import { caseCorrespondenceEntity } from '@web-api/persistence/postgres/caseCorrespondences/mapper'; import { getDbReader } from '@web-api/database'; export const getCaseCorrespondenceByDocketNumber = async ({ diff --git a/web-api/src/persistence/postgres/correspondence/mapper.ts b/web-api/src/persistence/postgres/caseCorrespondences/mapper.ts similarity index 100% rename from web-api/src/persistence/postgres/correspondence/mapper.ts rename to web-api/src/persistence/postgres/caseCorrespondences/mapper.ts diff --git a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts b/web-api/src/persistence/postgres/caseCorrespondences/mocks.jest.ts similarity index 53% rename from web-api/src/persistence/postgres/correspondence/mocks.jest.ts rename to web-api/src/persistence/postgres/caseCorrespondences/mocks.jest.ts index 7078e7cb7ad..ec2bf28c363 100644 --- a/web-api/src/persistence/postgres/correspondence/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseCorrespondences/mocks.jest.ts @@ -1,11 +1,11 @@ import { mockFactory } from '@shared/test/mockFactory'; jest.mock( - '@web-api/persistence/postgres/correspondence/getCaseCorrespondenceByDocketNumber', + '@web-api/persistence/postgres/caseCorrespondences/getCaseCorrespondenceByDocketNumber', () => mockFactory('getCaseCorrespondenceByDocketNumber', []), ); jest.mock( - '@web-api/persistence/postgres/correspondence/upsertCaseCorrespondences', + '@web-api/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences', () => mockFactory('upsertCaseCorrespondences'), ); diff --git a/web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts b/web-api/src/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences.ts similarity index 100% rename from web-api/src/persistence/postgres/correspondence/upsertCaseCorrespondences.ts rename to web-api/src/persistence/postgres/caseCorrespondences/upsertCaseCorrespondences.ts diff --git a/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts b/web-api/src/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber.ts similarity index 96% rename from web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts rename to web-api/src/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber.ts index 9f0b7c81993..42ab551df14 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber.ts +++ b/web-api/src/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber.ts @@ -1,5 +1,5 @@ import { CaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; -import { caseWorksheetEntity } from '@web-api/persistence/postgres/caseWorksheet/mapper'; +import { caseWorksheetEntity } from '@web-api/persistence/postgres/caseWorksheets/mapper'; import { getDbReader } from '@web-api/database'; import { isEmpty } from 'lodash'; diff --git a/web-api/src/persistence/postgres/caseWorksheet/mapper.ts b/web-api/src/persistence/postgres/caseWorksheets/mapper.ts similarity index 100% rename from web-api/src/persistence/postgres/caseWorksheet/mapper.ts rename to web-api/src/persistence/postgres/caseWorksheets/mapper.ts diff --git a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts b/web-api/src/persistence/postgres/caseWorksheets/mocks.jest.ts similarity index 55% rename from web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts rename to web-api/src/persistence/postgres/caseWorksheets/mocks.jest.ts index 3e9cbc1f4ba..ca8ecbcca30 100644 --- a/web-api/src/persistence/postgres/caseWorksheet/mocks.jest.ts +++ b/web-api/src/persistence/postgres/caseWorksheets/mocks.jest.ts @@ -1,11 +1,11 @@ import { mockFactory } from '@shared/test/mockFactory'; jest.mock( - '@web-api/persistence/postgres/caseWorksheet/getCaseWorksheetsByDocketNumber', + '@web-api/persistence/postgres/caseWorksheets/getCaseWorksheetsByDocketNumber', () => mockFactory('getCaseWorksheetsByDocketNumber'), ); jest.mock( - '@web-api/persistence/postgres/caseWorksheet/upsertCaseWorksheets', + '@web-api/persistence/postgres/caseWorksheets/upsertCaseWorksheets', () => mockFactory('upsertCaseWorksheets'), ); diff --git a/web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheets.ts b/web-api/src/persistence/postgres/caseWorksheets/upsertCaseWorksheets.ts similarity index 100% rename from web-api/src/persistence/postgres/caseWorksheet/upsertCaseWorksheets.ts rename to web-api/src/persistence/postgres/caseWorksheets/upsertCaseWorksheets.ts diff --git a/web-client/src/presenter/actions/validateCaseWorksheetAction.ts b/web-client/src/presenter/actions/validateCaseWorksheetAction.ts index fb616126163..22cc43c8a79 100644 --- a/web-client/src/presenter/actions/validateCaseWorksheetAction.ts +++ b/web-client/src/presenter/actions/validateCaseWorksheetAction.ts @@ -1,6 +1,7 @@ +import { getJudgeForCurrentUserAction } from '@web-client/presenter/actions/getJudgeForCurrentUserAction'; import { state } from '@web-client/presenter/app.cerebral'; -export const validateCaseWorksheetAction = ({ +export const validateCaseWorksheetAction = async ({ applicationContext, get, path, @@ -9,12 +10,18 @@ export const validateCaseWorksheetAction = ({ state.form, ); + const { judgeUser } = await getJudgeForCurrentUserAction({ + applicationContext, + get, + } as ActionProps); + const errors = applicationContext .getUseCases() .validateCaseWorksheetInteractor({ caseWorksheet: { docketNumber, finalBriefDueDate, + judgeUserId: judgeUser.userId, primaryIssue, statusOfMatter, }, diff --git a/web-client/src/presenter/computeds/CaseWorksheets/caseWorksheetsHelper.ts b/web-client/src/presenter/computeds/CaseWorksheets/caseWorksheetsHelper.ts index 5cbb6fdc8df..d8739628d98 100644 --- a/web-client/src/presenter/computeds/CaseWorksheets/caseWorksheetsHelper.ts +++ b/web-client/src/presenter/computeds/CaseWorksheets/caseWorksheetsHelper.ts @@ -13,7 +13,7 @@ type CaseWorksheetTableRow = { daysSinceLastStatusChange: string; caseCaption: string; docketNumber: string; - docketNumberWithSuffix: string; + docketNumberWithSuffix?: string; formattedSubmittedCavStatusDate: string; finalBriefDueDateFormatted: string; status: string; From fcbf4ba1b93352adf3497f02cc9ddb907e2f111d Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 13 Nov 2024 13:00:19 -0500 Subject: [PATCH 34/47] 10504-dxox: fix validateCaseWorksheetAction.test, and avoid passing entityName into updateCaseWorksheetAction, which is stupid --- .../actions/CaseWorksheet/updateCaseWorksheetAction.ts | 10 ++++++---- .../actions/validateCaseWorksheetAction.test.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts b/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts index 509f0942b9b..55c6a7a4717 100644 --- a/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts +++ b/web-client/src/presenter/actions/CaseWorksheet/updateCaseWorksheetAction.ts @@ -1,4 +1,7 @@ -import { RawCaseWorksheet } from '@shared/business/entities/caseWorksheet/CaseWorksheet'; +import { + CaseWorksheet, + RawCaseWorksheet, +} from '@shared/business/entities/caseWorksheet/CaseWorksheet'; import { getJudgeForCurrentUserAction } from '@web-client/presenter/actions/getJudgeForCurrentUserAction'; import { state } from '@web-client/presenter/app.cerebral'; @@ -18,14 +21,13 @@ export const updateCaseWorksheetAction = async ({ const updatedWorksheet = await applicationContext .getUseCases() .updateCaseWorksheetInteractor(applicationContext, { - worksheet: { + worksheet: new CaseWorksheet({ docketNumber, - entityName: 'CaseWorksheet', finalBriefDueDate, judgeUserId: judgeUser.userId, primaryIssue, statusOfMatter, - }, + }).toRawObject(), }); return { updatedWorksheet }; diff --git a/web-client/src/presenter/actions/validateCaseWorksheetAction.test.ts b/web-client/src/presenter/actions/validateCaseWorksheetAction.test.ts index 3b652b6a023..532cdfda452 100644 --- a/web-client/src/presenter/actions/validateCaseWorksheetAction.test.ts +++ b/web-client/src/presenter/actions/validateCaseWorksheetAction.test.ts @@ -1,5 +1,6 @@ import { MOCK_CASE } from '@shared/test/mockCase'; import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext'; +import { judgeColvin } from '@shared/test/mockUsers'; import { presenter } from '../presenter-mock'; import { runAction } from '@web-client/presenter/test.cerebral'; import { validateCaseWorksheetAction } from './validateCaseWorksheetAction'; @@ -18,6 +19,12 @@ describe('validateCaseWorksheetAction', () => { }; presenter.providers.applicationContext = applicationContext; + + applicationContext + .getUseCases() + .getJudgeInSectionInteractor.mockResolvedValue({ + userId: judgeColvin.userId, + }); }); it('should call the success path when the updated case worksheet is valid', async () => { @@ -36,6 +43,7 @@ describe('validateCaseWorksheetAction', () => { primaryIssue: 'This is a primary issue.', statusOfMatter: undefined, }, + user: { section: '', userId: '' }, }, }); @@ -64,6 +72,7 @@ describe('validateCaseWorksheetAction', () => { primaryIssue: 'This is a primary issue.', statusOfMatter: undefined, }, + user: { section: '', userId: '' }, }, }); From fee1eafec30bafaab3f1f0ec33885f3b86233d2d Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 13 Nov 2024 13:04:50 -0500 Subject: [PATCH 35/47] 10504-dxox: add 'so far' to deletion scripts --- .../postgres-migration/delete-case-correspondences.ts | 4 +++- .../postgres-migration/delete-case-deadlines.ts | 2 +- .../postgres-migration/delete-case-worksheets.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts index 2a3c4ae3f70..ef11e9d6ed8 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -53,7 +53,9 @@ async function main() { dynamoDbDocClient, tableNameInput, ); - console.log(`Total case correspondences deleted: ${totalItemsDeleted}`); + console.log( + `Total case correspondences deleted so far: ${totalItemsDeleted}`, + ); offset += caseCorrespondencePageSize; caseCorrespondencesToDelete = await getCaseCorrespondencesToDelete(offset); } diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts index d1a2ba0e8ba..6718e931f35 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts @@ -52,7 +52,7 @@ async function main() { dynamoDbDocClient, tableNameInput, ); - console.log(`Total case deadlines deleted: ${totalItemsDeleted}`); + console.log(`Total case deadlines deleted so far: ${totalItemsDeleted}`); offset += caseDeadlinePageSize; caseDeadlinesToDelete = await getCaseDeadlinesToDelete(offset); } diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts index 5d225682d29..a9ea248c8ed 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts @@ -52,7 +52,7 @@ async function main() { dynamoDbDocClient, tableNameInput, ); - console.log(`Total case worksheets deleted: ${totalItemsDeleted}`); + console.log(`Total case worksheets deleted so far: ${totalItemsDeleted}`); offset += caseWorksheetPageSize; caseWorksheetsToDelete = await getCaseWorksheetsToDelete(offset); } From 7ecc01b44b049fc11ca2618c4d94ba7f5dd834be Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 14 Nov 2024 17:20:31 -0500 Subject: [PATCH 36/47] 10504-dxox: update postgres run-once scripts to have correct HOW TO RUN; remove docketNumber argument in assignCorrespondences since the correspondences should have docketNumber already on them; remove TODO --- __TODO_10504.txt | 18 ------------------ .../delete-case-correspondences.ts | 2 +- .../delete-case-deadlines.ts | 2 +- .../delete-case-worksheets.ts | 2 +- .../postgres-migration/delete-messages.ts | 2 +- shared/src/business/entities/cases/Case.ts | 14 ++------------ 6 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 __TODO_10504.txt diff --git a/__TODO_10504.txt b/__TODO_10504.txt deleted file mode 100644 index d3b7092a3fa..00000000000 --- a/__TODO_10504.txt +++ /dev/null @@ -1,18 +0,0 @@ -check Correspondence works now with docketNumber (added to the entity) and update validation? - --- - -Is docketNumber in Case assignCorrespondences necessary? Were there some old cases, maybe, onto which we directly stored correspondences? - - --- - -check CaseWorksheet works now with judgeUserId (added to the entity) and update validation? - --- - -entityName: "CaseWorksheet" in updateCaseWorksheetAction is silly - --- - -add missing tests \ No newline at end of file diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts index ef11e9d6ed8..eb99d84fd7f 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -1,7 +1,7 @@ /** * HOW TO RUN * - * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-correspondences.ts + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts */ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts index 6718e931f35..c0dcdcd1edf 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts @@ -1,7 +1,7 @@ /** * HOW TO RUN * - * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-deadlines.ts + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts */ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts index a9ea248c8ed..3c506778c71 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts @@ -1,7 +1,7 @@ /** * HOW TO RUN * - * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-worksheets.ts + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts */ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; diff --git a/scripts/run-once-scripts/postgres-migration/delete-messages.ts b/scripts/run-once-scripts/postgres-migration/delete-messages.ts index cc022e06f85..8c5b34a9807 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-messages.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-messages.ts @@ -1,7 +1,7 @@ /** * HOW TO RUN * - * TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-messages.ts + * TABLE_NAME=testing npx ts-node --transpileOnly scripts/run-once-scripts/postgres-migration/delete-messages.ts */ import { diff --git a/shared/src/business/entities/cases/Case.ts b/shared/src/business/entities/cases/Case.ts index 30fd7f45401..01d777646fa 100644 --- a/shared/src/business/entities/cases/Case.ts +++ b/shared/src/business/entities/cases/Case.ts @@ -912,13 +912,7 @@ export class Case extends JoiValidationEntity { assignCorrespondences({ rawCase }) { if (Array.isArray(rawCase.correspondence)) { this.correspondence = rawCase.correspondence - .map( - correspondence => - new Correspondence({ - ...correspondence, - docketNumber: rawCase.docketNumber, - }), - ) + .map(correspondence => new Correspondence(correspondence)) .sort((a, b) => compareStrings(a.filingDate, b.filingDate)); } else { this.correspondence = []; @@ -926,11 +920,7 @@ export class Case extends JoiValidationEntity { if (Array.isArray(rawCase.archivedCorrespondences)) { this.archivedCorrespondences = rawCase.archivedCorrespondences.map( - correspondence => - new Correspondence({ - ...correspondence, - docketNumber: rawCase.docketNumber, - }), + correspondence => new Correspondence(correspondence), ); } else { this.archivedCorrespondences = []; From 88c1362caa1febaa210ae9ac2676e2bfb4cf5da5 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Fri, 15 Nov 2024 08:21:26 -0500 Subject: [PATCH 37/47] 10504-dxox: remove docketNumber in assignCorrespondences since it seems to be working fine that way after all --- shared/src/business/entities/cases/Case.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/shared/src/business/entities/cases/Case.ts b/shared/src/business/entities/cases/Case.ts index 30fd7f45401..01d777646fa 100644 --- a/shared/src/business/entities/cases/Case.ts +++ b/shared/src/business/entities/cases/Case.ts @@ -912,13 +912,7 @@ export class Case extends JoiValidationEntity { assignCorrespondences({ rawCase }) { if (Array.isArray(rawCase.correspondence)) { this.correspondence = rawCase.correspondence - .map( - correspondence => - new Correspondence({ - ...correspondence, - docketNumber: rawCase.docketNumber, - }), - ) + .map(correspondence => new Correspondence(correspondence)) .sort((a, b) => compareStrings(a.filingDate, b.filingDate)); } else { this.correspondence = []; @@ -926,11 +920,7 @@ export class Case extends JoiValidationEntity { if (Array.isArray(rawCase.archivedCorrespondences)) { this.archivedCorrespondences = rawCase.archivedCorrespondences.map( - correspondence => - new Correspondence({ - ...correspondence, - docketNumber: rawCase.docketNumber, - }), + correspondence => new Correspondence(correspondence), ); } else { this.archivedCorrespondences = []; From c387e5a6380cde5d4af04d2cee227c84baf88e71 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 20 Nov 2024 10:15:58 -0500 Subject: [PATCH 38/47] 10504-dxox: remove unused import --- .../postgres-migration/delete-case-correspondences.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts index eb99d84fd7f..3976cbfb066 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -5,7 +5,7 @@ */ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; -import { DynamoDBClient, ScanCommandInput } from '@aws-sdk/client-dynamodb'; +import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; import { requireEnvVars } from '../../../shared/admin-tools/util'; import { getDbReader } from '../../../web-api/src/database'; import { isEmpty } from 'lodash'; From d2066480ed982a429c1be040d1a23cfdaf6330a9 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 20 Nov 2024 10:43:40 -0500 Subject: [PATCH 39/47] 10504-dxox: readd docketNumber in assignCorrespondences, which is necessary after all --- shared/src/business/entities/cases/Case.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/shared/src/business/entities/cases/Case.ts b/shared/src/business/entities/cases/Case.ts index 01d777646fa..30fd7f45401 100644 --- a/shared/src/business/entities/cases/Case.ts +++ b/shared/src/business/entities/cases/Case.ts @@ -912,7 +912,13 @@ export class Case extends JoiValidationEntity { assignCorrespondences({ rawCase }) { if (Array.isArray(rawCase.correspondence)) { this.correspondence = rawCase.correspondence - .map(correspondence => new Correspondence(correspondence)) + .map( + correspondence => + new Correspondence({ + ...correspondence, + docketNumber: rawCase.docketNumber, + }), + ) .sort((a, b) => compareStrings(a.filingDate, b.filingDate)); } else { this.correspondence = []; @@ -920,7 +926,11 @@ export class Case extends JoiValidationEntity { if (Array.isArray(rawCase.archivedCorrespondences)) { this.archivedCorrespondences = rawCase.archivedCorrespondences.map( - correspondence => new Correspondence(correspondence), + correspondence => + new Correspondence({ + ...correspondence, + docketNumber: rawCase.docketNumber, + }), ); } else { this.archivedCorrespondences = []; From b86bed9e43dec5239f514fdcd25f967e4fc70fa6 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 3 Dec 2024 14:18:22 -0500 Subject: [PATCH 40/47] 10504-dxox: update delete script --- .../postgres-migration/delete-case-correspondences.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts index 3976cbfb066..f030a11db84 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -1,23 +1,21 @@ /** * HOW TO RUN - * * TABLE_NAME=testing npx ts-node --transpileOnly scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts */ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'; import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; -import { requireEnvVars } from '../../../shared/admin-tools/util'; import { getDbReader } from '../../../web-api/src/database'; import { isEmpty } from 'lodash'; import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; +import { environment } from '../../../web-api/src/environment'; const caseCorrespondencePageSize = 10000; const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); -requireEnvVars(['TABLE_NAME']); - -const tableNameInput = process.env.TABLE_NAME!; +// We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly +environment.nodeEnv = 'production'; const getCaseCorrespondencesToDelete = async (offset: number) => { const caseCorrespondences = await getDbReader(reader => @@ -51,7 +49,7 @@ async function main() { totalItemsDeleted += await batchDeleteDynamoItems( dynamoItemsToDelete, dynamoDbDocClient, - tableNameInput, + environment.dynamoDbTableName, ); console.log( `Total case correspondences deleted so far: ${totalItemsDeleted}`, From 1b11915d184706d9097731fbc81866dd5ab3f298 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 4 Dec 2024 10:56:01 -0500 Subject: [PATCH 41/47] 10504-dxox: update overlooked delete scripts and add CIRCLE_BRANCH var --- .../postgres-migration/delete-case-correspondences.ts | 1 + .../postgres-migration/delete-case-deadlines.ts | 9 +++++---- .../postgres-migration/delete-case-worksheets.ts | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts index f030a11db84..76a67099a15 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -16,6 +16,7 @@ const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); // We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly environment.nodeEnv = 'production'; +process.env.CIRCLE_BRANCH = 'test'; const getCaseCorrespondencesToDelete = async (offset: number) => { const caseCorrespondences = await getDbReader(reader => diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts index c0dcdcd1edf..3d8a8b9e5fd 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts @@ -10,14 +10,15 @@ import { requireEnvVars } from '../../../shared/admin-tools/util'; import { getDbReader } from '../../../web-api/src/database'; import { isEmpty } from 'lodash'; import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; +import { environment } from '../../../web-api/src/environment'; const caseDeadlinePageSize = 10000; const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); -requireEnvVars(['TABLE_NAME']); - -const tableNameInput = process.env.TABLE_NAME!; +// We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly +environment.nodeEnv = 'production'; +process.env.CIRCLE_BRANCH = 'test'; const getCaseDeadlinesToDelete = async (offset: number) => { const caseDeadlines = await getDbReader(reader => @@ -50,7 +51,7 @@ async function main() { totalItemsDeleted += await batchDeleteDynamoItems( dynamoItemsToDelete, dynamoDbDocClient, - tableNameInput, + environment.dynamoDbTableName, ); console.log(`Total case deadlines deleted so far: ${totalItemsDeleted}`); offset += caseDeadlinePageSize; diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts index 3c506778c71..56692c39503 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts @@ -10,14 +10,15 @@ import { requireEnvVars } from '../../../shared/admin-tools/util'; import { getDbReader } from '../../../web-api/src/database'; import { isEmpty } from 'lodash'; import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; +import { environment } from '../../../web-api/src/environment'; const caseWorksheetPageSize = 10000; const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); -requireEnvVars(['TABLE_NAME']); - -const tableNameInput = process.env.TABLE_NAME!; +// We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly +environment.nodeEnv = 'production'; +process.env.CIRCLE_BRANCH = 'test'; const getCaseWorksheetsToDelete = async (offset: number) => { const caseWorksheets = await getDbReader(reader => @@ -50,7 +51,7 @@ async function main() { totalItemsDeleted += await batchDeleteDynamoItems( dynamoItemsToDelete, dynamoDbDocClient, - tableNameInput, + environment.dynamoDbTableName, ); console.log(`Total case worksheets deleted so far: ${totalItemsDeleted}`); offset += caseWorksheetPageSize; From a6d1600e73fc54b171b94b9cd42987dd2e8798b2 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 4 Dec 2024 11:34:17 -0500 Subject: [PATCH 42/47] 10502-dxox: retrigger CI to fix failing test From 3ac94665ef17d937c9e7e161ac516dc8df111b8c Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 4 Dec 2024 17:07:15 -0500 Subject: [PATCH 43/47] 10504-dxox: experiment to prevent creating lots of db connections --- web-api/src/database.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/web-api/src/database.ts b/web-api/src/database.ts index e82418d026d..625ac95e057 100644 --- a/web-api/src/database.ts +++ b/web-api/src/database.ts @@ -85,21 +85,25 @@ async function createConnection({ throw new Error('token does not exist'); } - dbInstances[dbKey] = await connect({ - ...POOL, - host, - password: token, - }); + if (!dbInstances[dbKey]) { + dbInstances[dbKey] = connect({ + ...POOL, + host, + password: token, + }); + } return await cb(dbInstances[dbKey]!); } catch (err) { clearToken(region); const token = await getToken(region, host); - dbInstances[dbKey] = await connect({ - ...POOL, - host, - password: token, - }); + if (!dbInstances[dbKey]) { + dbInstances[dbKey] = connect({ + ...POOL, + host, + password: token, + }); + } return await cb(dbInstances[dbKey]!); } } From f62ed84820bcdf0ead00e97b30d29f552945904a Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 4 Dec 2024 10:56:01 -0500 Subject: [PATCH 44/47] 10504-dxox: update overlooked delete scripts and add CIRCLE_BRANCH var --- .../postgres-migration/delete-case-correspondences.ts | 1 + .../postgres-migration/delete-case-deadlines.ts | 9 +++++---- .../postgres-migration/delete-case-worksheets.ts | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts index f030a11db84..76a67099a15 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-correspondences.ts @@ -16,6 +16,7 @@ const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); // We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly environment.nodeEnv = 'production'; +process.env.CIRCLE_BRANCH = 'test'; const getCaseCorrespondencesToDelete = async (offset: number) => { const caseCorrespondences = await getDbReader(reader => diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts index c0dcdcd1edf..3d8a8b9e5fd 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-deadlines.ts @@ -10,14 +10,15 @@ import { requireEnvVars } from '../../../shared/admin-tools/util'; import { getDbReader } from '../../../web-api/src/database'; import { isEmpty } from 'lodash'; import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; +import { environment } from '../../../web-api/src/environment'; const caseDeadlinePageSize = 10000; const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); -requireEnvVars(['TABLE_NAME']); - -const tableNameInput = process.env.TABLE_NAME!; +// We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly +environment.nodeEnv = 'production'; +process.env.CIRCLE_BRANCH = 'test'; const getCaseDeadlinesToDelete = async (offset: number) => { const caseDeadlines = await getDbReader(reader => @@ -50,7 +51,7 @@ async function main() { totalItemsDeleted += await batchDeleteDynamoItems( dynamoItemsToDelete, dynamoDbDocClient, - tableNameInput, + environment.dynamoDbTableName, ); console.log(`Total case deadlines deleted so far: ${totalItemsDeleted}`); offset += caseDeadlinePageSize; diff --git a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts index 3c506778c71..56692c39503 100644 --- a/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts +++ b/scripts/run-once-scripts/postgres-migration/delete-case-worksheets.ts @@ -10,14 +10,15 @@ import { requireEnvVars } from '../../../shared/admin-tools/util'; import { getDbReader } from '../../../web-api/src/database'; import { isEmpty } from 'lodash'; import { batchDeleteDynamoItems } from './batch-delete-dynamo-items'; +import { environment } from '../../../web-api/src/environment'; const caseWorksheetPageSize = 10000; const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' }); const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient); -requireEnvVars(['TABLE_NAME']); - -const tableNameInput = process.env.TABLE_NAME!; +// We set the environment as 'production' (= "a deployed environment") to get the RDS connection to work properly +environment.nodeEnv = 'production'; +process.env.CIRCLE_BRANCH = 'test'; const getCaseWorksheetsToDelete = async (offset: number) => { const caseWorksheets = await getDbReader(reader => @@ -50,7 +51,7 @@ async function main() { totalItemsDeleted += await batchDeleteDynamoItems( dynamoItemsToDelete, dynamoDbDocClient, - tableNameInput, + environment.dynamoDbTableName, ); console.log(`Total case worksheets deleted so far: ${totalItemsDeleted}`); offset += caseWorksheetPageSize; From f7cabd704b8ff6845ae3a0495c0f5d80d4d64f16 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Wed, 4 Dec 2024 17:07:15 -0500 Subject: [PATCH 45/47] 10504-dxox: experiment to prevent creating lots of db connections --- web-api/src/database.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/web-api/src/database.ts b/web-api/src/database.ts index e82418d026d..625ac95e057 100644 --- a/web-api/src/database.ts +++ b/web-api/src/database.ts @@ -85,21 +85,25 @@ async function createConnection({ throw new Error('token does not exist'); } - dbInstances[dbKey] = await connect({ - ...POOL, - host, - password: token, - }); + if (!dbInstances[dbKey]) { + dbInstances[dbKey] = connect({ + ...POOL, + host, + password: token, + }); + } return await cb(dbInstances[dbKey]!); } catch (err) { clearToken(region); const token = await getToken(region, host); - dbInstances[dbKey] = await connect({ - ...POOL, - host, - password: token, - }); + if (!dbInstances[dbKey]) { + dbInstances[dbKey] = connect({ + ...POOL, + host, + password: token, + }); + } return await cb(dbInstances[dbKey]!); } } From 68f04f89e5b6248ca1bcea905215f43d0c175fa4 Mon Sep 17 00:00:00 2001 From: Kaitlyn Swann Date: Thu, 5 Dec 2024 08:40:46 -0700 Subject: [PATCH 46/47] 10504: Reuse existing connection if possible --- web-api/src/database.ts | 55 +++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/web-api/src/database.ts b/web-api/src/database.ts index 625ac95e057..32748fd1e2d 100644 --- a/web-api/src/database.ts +++ b/web-api/src/database.ts @@ -1,4 +1,9 @@ -import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely'; +import { + CamelCasePlugin, + CompiledQuery, + Kysely, + PostgresDialect, +} from 'kysely'; import { Database } from './database-types'; import { Pool } from 'pg'; import { Signer } from '@aws-sdk/rds-signer'; @@ -67,7 +72,7 @@ async function getToken(region: string, host: string) { return tokens[region]; } -async function createConnection({ +async function getConnection({ cb, dbKey, host, @@ -79,37 +84,51 @@ async function createConnection({ host: string; }): Promise { try { + if (dbInstances[dbKey] && (await isConnectionValid(dbInstances[dbKey]))) { + // If valid, use the existing connection + return await cb(dbInstances[dbKey]); + } + const token = await getToken(region, host); if (!token) { throw new Error('token does not exist'); } - if (!dbInstances[dbKey]) { - dbInstances[dbKey] = connect({ - ...POOL, - host, - password: token, - }); - } + dbInstances[dbKey] = connect({ + ...POOL, + host, + password: token, + }); return await cb(dbInstances[dbKey]!); } catch (err) { clearToken(region); const token = await getToken(region, host); - if (!dbInstances[dbKey]) { - dbInstances[dbKey] = connect({ - ...POOL, - host, - password: token, - }); - } + + dbInstances[dbKey] = connect({ + ...POOL, + host, + password: token, + }); + return await cb(dbInstances[dbKey]!); } } +async function isConnectionValid(db: Kysely): Promise { + try { + await db.executeQuery<{ result: 1 }>( + CompiledQuery.raw('select 1 as result', []), + ); + return true; + } catch (err) { + return false; + } +} + export function getDbReader(cb: (r: Kysely) => T): Promise { - return createConnection({ + return getConnection({ cb, dbKey: 'reader', host: @@ -121,7 +140,7 @@ export function getDbReader(cb: (r: Kysely) => T): Promise { } export function getDbWriter(cb: (r: Kysely) => T): Promise { - return createConnection({ + return getConnection({ cb, dbKey: 'writer', host: environment.rds.pool.host, From a0bbad06e27b9539f20dfc09a1d23815b4804b07 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Thu, 5 Dec 2024 11:16:17 -0500 Subject: [PATCH 47/47] 10504-dxox: fix type error --- scripts/reports/cases-closed-in-year.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/reports/cases-closed-in-year.ts b/scripts/reports/cases-closed-in-year.ts index b0c43a03639..20480a32410 100644 --- a/scripts/reports/cases-closed-in-year.ts +++ b/scripts/reports/cases-closed-in-year.ts @@ -80,7 +80,7 @@ const getAllCasesClosedInFiscalYear = async ({ const wasClosedThisFiscalYear = (c: RawCase): boolean => { let closedThisFiscalYear = false; - for (const csh of c.caseStatusHistory) { + for (const csh of c.caseStatusHistory || []) { if ( csh.date && csh.date >= BEGIN && @@ -115,7 +115,7 @@ const outputCsv = ({ .replace('Special Trial ', '') .replace('Judge ', '') || ''; const closedDateHumanized = - c.caseStatusHistory + (c.caseStatusHistory || []) .reverse() .find( csh =>