Skip to content

Commit

Permalink
Merge branch '10522-story' into 1522-test
Browse files Browse the repository at this point in the history
  • Loading branch information
John Cruz committed Jan 10, 2025
2 parents 45be917 + 6f2349b commit f698d15
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 15 deletions.
1 change: 1 addition & 0 deletions shared/src/business/test/createTestApplicationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ export const createTestApplicationContext = () => {
docketRecord: jest.fn().mockImplementation(getFakeFile),
entryOfAppearance: jest.fn().mockImplementation(getFakeFile),
noticeOfChangeOfTrialJudge: jest.fn().mockImplementation(getFakeFile),
noticeOfChangeOfTrialLocation: jest.fn().mockImplementation(getFakeFile),
noticeOfChangeToInPersonProceeding: jest
.fn()
.mockImplementation(getFakeFile),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { RawTrialSession } from '@shared/business/entities/trialSessions/TrialSession';
import { applicationContext } from '@shared/business/test/createTestApplicationContext';
import { generateNoticeOfChangeOfTrialLocationInteractor } from '@web-api/business/useCases/trialSessions/generateNoticeOfChangeOfTrialLocationInteractor';

describe('generateNoticeOfChangeOfTrialLocationInteractor', () => {
const TEST_DOCKET_NUMBER = 'TEST_DOCKET_NUMBER';
const MOCKED_CASE = {
caseCaption:
'Virginia Vincent, Deceased, Virginia Vincent, Surviving Spouse, Petitioner',
docketNumber: TEST_DOCKET_NUMBER,
} as RawCase;

const MOCK_ARRAY_BUFFER = 'MOCK_ARRAY_BUFFER';

beforeEach(() => {
applicationContext
.getPersistenceGateway()
.getCaseByDocketNumber.mockReturnValue(MOCKED_CASE);

applicationContext
.getDocumentGenerators()
.noticeOfChangeOfTrialLocation.mockReturnValue(MOCK_ARRAY_BUFFER);
});

it('should call the generatePDF method with correct params', async () => {
const PREVIOUS_TRIAL_SESSION = {
trialSessionId: 'PREVIOUS',
} as RawTrialSession;
const UPDATED_TRIAL_SESSION = {
trialSessionId: 'UPDATED',
} as RawTrialSession;

const results = await generateNoticeOfChangeOfTrialLocationInteractor(
applicationContext,
{
docketNumber: TEST_DOCKET_NUMBER,
previousTrialSession: PREVIOUS_TRIAL_SESSION,
updatedTrialSession: UPDATED_TRIAL_SESSION,
},
);

expect(results).toEqual(MOCK_ARRAY_BUFFER);

const getCaseByDocketNumberCalls =
applicationContext.getPersistenceGateway().getCaseByDocketNumber.mock
.calls;
expect(getCaseByDocketNumberCalls.length).toEqual(1);
expect(getCaseByDocketNumberCalls[0][0].docketNumber).toEqual(
TEST_DOCKET_NUMBER,
);

const noticeOfChangeOfTrialLocationCalls =
applicationContext.getDocumentGenerators().noticeOfChangeOfTrialLocation
.mock.calls;
expect(noticeOfChangeOfTrialLocationCalls.length).toEqual(1);
expect(noticeOfChangeOfTrialLocationCalls[0][0].data).toEqual({
caseCaptionExtension: 'Petitioner',
caseTitle:
'Virginia Vincent, Deceased, Virginia Vincent, Surviving Spouse',
docketNumberWithSuffix: undefined,
previousTrialSession: PREVIOUS_TRIAL_SESSION,
updatedTrialSession: UPDATED_TRIAL_SESSION,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import {
SESSION_TYPES,
TRIAL_SESSION_PROCEEDING_TYPES,
} from '@shared/business/entities/EntityConstants';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { applicationContext } from '@shared/business/test/createTestApplicationContext';
import { cloneDeep } from 'lodash';
import { judgeUser, trialClerkUser } from '@shared/test/mockUsers';
import {
mockDocketClerkUser,
mockPetitionerUser,
} from '@shared/test/mockAuthUsers';
import { mockDocketClerkUser } from '@shared/test/mockAuthUsers';
import { updateTrialSessionInteractor } from './updateTrialSessionInteractor';

describe('updateTrialSessionInteractor', () => {
Expand All @@ -32,17 +30,39 @@ describe('updateTrialSessionInteractor', () => {
.updateTrialSession.mockImplementation(trial => trial.trialSession);
});

it('should throw an error when the user is not unauthorized to update a trial session', async () => {
it('should throw an error when the trial session is not found', async () => {
await expect(
updateTrialSessionInteractor(
applicationContext,
{
clientConnectionId: '123',
trialSession: MOCK_TRIAL_REMOTE,
},
mockPetitionerUser,
undefined,
),
).rejects.toThrow();
).rejects.toThrow(
`Trial session ${MOCK_TRIAL_REMOTE.trialSessionId} was not found.`,
);
});

it('should throw an error when the user is not unauthorized to update a trial session', async () => {
applicationContext
.getPersistenceGateway()
.getTrialSessionById.mockResolvedValue({
...MOCK_TRIAL_REMOTE,
startDate: '1776-12-01',
});

await expect(
updateTrialSessionInteractor(
applicationContext,
{
clientConnectionId: '123',
trialSession: { ...MOCK_TRIAL_REMOTE, startDate: '1776-12-01' },
},
undefined as UnknownAuthUser,
),
).rejects.toThrow('Unauthorized');
});

it('should throw an error when the trial session start date is in the past', async () => {
Expand Down Expand Up @@ -558,6 +578,8 @@ describe('updateTrialSessionInteractor', () => {
});
applicationContext.getUseCaseHelpers().setNoticeOfChangeOfTrialJudge =
jest.fn();
applicationContext.getUseCaseHelpers().setNoticeOfChangeOfTrialLocation =
jest.fn();
applicationContext.getUseCaseHelpers().setNoticeOfChangeToInPersonProceeding =
jest.fn();
applicationContext.getUseCaseHelpers().setNoticeOfChangeToRemoteProceeding =
Expand Down Expand Up @@ -601,6 +623,27 @@ describe('updateTrialSessionInteractor', () => {
).toEqual('Notice of Change of Trial Judge');
});

it('should be generated when the location has changed', async () => {
desiredTrialSession.address1 = 'UPDATED ADDRESS 1';

await updateTrialSessionInteractor(
applicationContext,
{
clientConnectionId: '123',
trialSession: desiredTrialSession,
},
mockDocketClerkUser,
);

expect(
applicationContext.getUseCaseHelpers().setNoticeOfChangeOfTrialLocation,
).toHaveBeenCalled();
expect(
applicationContext.getPersistenceGateway().updateTrialSession.mock
.calls[0][0].trialSessionToUpdate.paperServicePdfs[0].title,
).toEqual('Notice of Change of Trial Location');
});

it('should be generated when the proceeding type has changed to remote', async () => {
desiredTrialSession.proceedingType =
TRIAL_SESSION_PROCEEDING_TYPES.inPerson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@ export const updateTrialSession = async (
throw new UnauthorizedError('Unauthorized');
}

const currentTrialSession = await applicationContext
const currentTrialSession = (await applicationContext
.getPersistenceGateway()
.getTrialSessionById({
applicationContext,
trialSessionId: trialSession.trialSessionId!,
});

if (!currentTrialSession) {
throw new NotFoundError(
`Trial session ${trialSession.trialSessionId} was not found.`,
);
}
}))!;

if (
currentTrialSession.startDate <
Expand Down Expand Up @@ -185,10 +179,12 @@ export const updateTrialSession = async (
file: paperServicePdfData,
fileNamePrefix: 'paper-service-pdf/',
}));

const paperServicePdfName = getPaperServicePdfName({
shouldIssueNoticeOfChangeOfTrialJudge,
shouldSetNoticeOfChangeToInPersonProceeding,
shouldSetNoticeOfChangeToRemoteProceeding,
shouldSetNoticeOfTrialSessionLocationChange,
});

updatedTrialSessionEntity.addPaperServicePdf(fileId, paperServicePdfName);
Expand Down Expand Up @@ -373,17 +369,21 @@ const getPaperServicePdfName = ({
shouldIssueNoticeOfChangeOfTrialJudge,
shouldSetNoticeOfChangeToInPersonProceeding,
shouldSetNoticeOfChangeToRemoteProceeding,
shouldSetNoticeOfTrialSessionLocationChange,
}: {
shouldSetNoticeOfChangeToRemoteProceeding: boolean;
shouldSetNoticeOfChangeToInPersonProceeding: boolean;
shouldIssueNoticeOfChangeOfTrialJudge: boolean;
shouldSetNoticeOfTrialSessionLocationChange: boolean;
}): string => {
if (shouldIssueNoticeOfChangeOfTrialJudge) {
return 'Notice of Change of Trial Judge';
} else if (shouldSetNoticeOfChangeToInPersonProceeding) {
return 'Notice of Change to In Person Proceeding';
} else if (shouldSetNoticeOfChangeToRemoteProceeding) {
return 'Notice of Change to Remote Proceeding';
} else if (shouldSetNoticeOfTrialSessionLocationChange) {
return 'Notice of Change of Trial Location';
} else {
return 'Notice of Change';
}
Expand Down

0 comments on commit f698d15

Please sign in to comment.