Skip to content

Commit

Permalink
10502: fix api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pixiwyn committed Feb 11, 2025
1 parent 0e5bcac commit 403100a
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 239 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@web-api/persistence/postgres/cases/mocks.jest';
import {
AUTO_GENERATED_DEADLINE_DOCUMENT_TYPES,
DOCKET_SECTION,
Expand All @@ -14,6 +15,9 @@ import {
import { fileAndServeCourtIssuedDocumentInteractor } from './fileAndServeCourtIssuedDocumentInteractor';
import { mockDocketClerkUser } from '@shared/test/mockAuthUsers';
import { testPdfDoc } from '../../../../../shared/src/business/test/getFakeFile';
import { getCaseByDocketNumber as getCaseByDocketNumberMock } from '@web-api/persistence/postgres/cases/getCaseByDocketNumber';

const getCaseByDocketNumber = getCaseByDocketNumberMock as jest.Mock;

let MOCK_DATE;

Expand Down Expand Up @@ -92,9 +96,7 @@ describe('fileAndServeCourtIssuedDocumentInteractor', () => {
.getPersistenceGateway()
.getUserById.mockReturnValue(docketClerkUser);

applicationContext
.getPersistenceGateway()
.getCaseByDocketNumber.mockReturnValue(caseRecord);
getCaseByDocketNumber.mockReturnValue(caseRecord);

applicationContext
.getUseCaseHelpers()
Expand Down Expand Up @@ -274,9 +276,8 @@ describe('fileAndServeCourtIssuedDocumentInteractor', () => {

caseRecord.docketEntries.push(mockAutoGeneratedDeadlineDocketEntry);

applicationContext
.getPersistenceGateway()
.getCaseByDocketNumber.mockReturnValueOnce(caseRecord)
getCaseByDocketNumber
.mockReturnValueOnce(caseRecord)
.mockReturnValueOnce(nonSubjectCaseRecord);

const mockAutoGeneratedDeadlineForm = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import {
mockPetitionerUser,
} from '@shared/test/mockAuthUsers';
import { updateMessage } from '@web-api/persistence/postgres/messages/updateMessage';
import { getCaseByDocketNumber as getCaseByDocketNumberMock } from '@web-api/persistence/postgres/cases/getCaseByDocketNumber';
import { updateCase as updateCaseMock } from '@web-api/persistence/postgres/cases/updateCase';

const getCaseByDocketNumber = getCaseByDocketNumberMock as jest.Mock;
const updateCase = updateCaseMock as jest.Mock;

/* eslint-disable max-lines */
describe('fileCourtIssuedOrderInteractor', () => {
Expand Down Expand Up @@ -101,9 +106,7 @@ describe('fileCourtIssuedOrderInteractor', () => {
}),
);

applicationContext
.getPersistenceGateway()
.getCaseByDocketNumber.mockReturnValue(caseRecord);
getCaseByDocketNumber.mockReturnValue(caseRecord);
});

it('should throw an error if not authorized', async () => {
Expand Down Expand Up @@ -140,12 +143,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries.length,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries.length,
).toEqual(4);
});

Expand Down Expand Up @@ -174,16 +174,16 @@ describe('fileCourtIssuedOrderInteractor', () => {
);

expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3].draftOrderState.documentContents,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3].draftOrderState
.documentContents,
).toBeUndefined();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3].draftOrderState.editorDelta,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3].draftOrderState
.editorDelta,
).toBeUndefined();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3].draftOrderState.richText,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3].draftOrderState
.richText,
).toBeUndefined();
});

Expand All @@ -205,16 +205,11 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(updateCase).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries.length,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries.length,
).toEqual(4);
const result =
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3];
const result = updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3];
expect(result).toMatchObject({ freeText: 'Notice to be nice' });
expect(result.signedAt).toBeTruthy();
});
Expand Down Expand Up @@ -244,12 +239,11 @@ describe('fileCourtIssuedOrderInteractor', () => {
useTempBucket: false,
});
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3].documentContents,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3]
.documentContents,
).toBeUndefined();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
documentContentsId: expect.anything(),
draftOrderState: {},
Expand Down Expand Up @@ -403,12 +397,10 @@ describe('fileCourtIssuedOrderInteractor', () => {
);

const lastDocumentIndex =
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries.length - 1;
updateCase.mock.calls[0][0].caseToUpdate.docketEntries.length - 1;

const newlyFiledDocument =
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[lastDocumentIndex];
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[lastDocumentIndex];

expect(newlyFiledDocument).toMatchObject({
isDraft: true,
Expand Down Expand Up @@ -437,9 +429,7 @@ describe('fileCourtIssuedOrderInteractor', () => {
),
).rejects.toThrow(ServiceUnavailableError);

expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).not.toHaveBeenCalled();
expect(getCaseByDocketNumber).not.toHaveBeenCalled();
});

it('should acquire and remove the lock on the case', async () => {
Expand Down Expand Up @@ -497,16 +487,12 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries.length,
updateCase.mock.calls[0][0].caseToUpdate.docketEntries.length,
).toEqual(4);
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: { freeText: 'Order to do anything' },
freeText: 'Order to do anything',
Expand All @@ -532,12 +518,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText: 'Order parties by 11/05/2024 shall file a status report.',
Expand All @@ -563,12 +546,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand Down Expand Up @@ -598,12 +578,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand Down Expand Up @@ -631,12 +608,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand Down Expand Up @@ -664,12 +638,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand Down Expand Up @@ -699,12 +670,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
mockDocketClerkUser,
);

expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand Down Expand Up @@ -736,12 +704,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
},
mockDocketClerkUser,
);
expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand Down Expand Up @@ -771,12 +736,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
},
mockDocketClerkUser,
);
expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText:
Expand All @@ -803,12 +765,9 @@ describe('fileCourtIssuedOrderInteractor', () => {
},
mockDocketClerkUser,
);
expect(getCaseByDocketNumber).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().getCaseByDocketNumber,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateCase.mock.calls[0][0]
.caseToUpdate.docketEntries[3],
updateCase.mock.calls[0][0].caseToUpdate.docketEntries[3],
).toMatchObject({
draftOrderState: {
freeText: '. Case is stricken from the current trial session.',
Expand Down
Loading

0 comments on commit 403100a

Please sign in to comment.