Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5512 test - feedback #5169

Merged
merged 10 commits into from
Jul 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import {
} from '../../../../../../helpers/fileAPetition/petitioner-creates-electronic-case';

describe('Logged In User Can See Un-Served Petition Document', () => {
before(() => {
cy.task('toggleFeatureFlag', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's get rid of this pattern when we can; we need to update all tests to be compatible with the new flow anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

flag: 'updated-petition-flow',
flagValue: false,
});

cy.reload(true);
});

after(() => {
cy.task('toggleFeatureFlag', {
flag: 'updated-petition-flow',
flagValue: true,
});
});

it('should display a preview link to ["P", "ATP", "DISC"] documents for the Petitioner that created the case', () => {
loginAsPetitioner();
petitionerCreatesElectronicCaseForBusiness().as('DOCKET_NUMBER');
Expand Down
4 changes: 2 additions & 2 deletions shared/src/business/entities/EntityConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,8 @@ export const CASE_TYPE_DESCRIPTIONS_WITH_IRS_NOTICE = {
};

export const CASE_TYPE_DESCRIPTIONS_WITHOUT_IRS_NOTICE = {
[CASE_TYPES_MAP.deficiency]: 'Notice of Deficiency',
[CASE_TYPES_MAP.cdp]: 'CDP (Lien/Levy)',
[CASE_TYPES_MAP.deficiency]: 'Deficiency',
[CASE_TYPES_MAP.cdp]: 'Collection (Lien/Levy)',
[CASE_TYPES_MAP.passport]: 'Passport',
[CASE_TYPES_MAP.innocentSpouse]: 'Innocent Spouse',
[CASE_TYPES_MAP.whistleblower]: 'Whistleblower',
Expand Down
97 changes: 15 additions & 82 deletions shared/src/business/useCases/generatePetitionPdfInteractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { generatePetitionPdfInteractor } from '@shared/business/useCases/generat
import { petitionerUser } from '@shared/test/mockUsers';

describe('generatePetitionPdfInteractor', () => {
const mockFileId = '9085265b-e8ad-4bab-9e7c-f82e847b41f9';

beforeEach(() => {
applicationContext.getCurrentUser.mockImplementation(() => petitionerUser);

Expand All @@ -16,18 +18,11 @@ describe('generatePetitionPdfInteractor', () => {
),
);

applicationContext
.getUseCaseHelpers()
.addDraftWatermarkToDocument.mockImplementation(
() =>
new Promise(resolve =>
resolve('RESULTS_addDraftWatermarkToDocument'),
),
);
applicationContext.getUniqueId.mockReturnValue(mockFileId);

applicationContext
.getUseCaseHelpers()
.saveFileAndGenerateUrl.mockImplementation(
.getPersistenceGateway()
.saveDocumentFromLambda.mockImplementation(
() => new Promise(resolve => resolve('RESULTS_saveFileAndGenerateUrl')),
);
});
Expand All @@ -40,15 +35,15 @@ describe('generatePetitionPdfInteractor', () => {
).rejects.toThrow('Unauthorized');
});

it('should generate petition and call save and generate URL', async () => {
it('should generate petition and call save document', async () => {
const results = await generatePetitionPdfInteractor(applicationContext, {
caseCaptionExtension: 'TEST_caseCaptionExtension',
caseTitle: 'TEST_caseTitle',
caseType: CASE_TYPES_MAP.deficiency,
contactPrimary: 'TEST_contactPrimary',
contactSecondary: 'TEST_contactSecondary',
hasIrsNotice: false,
irsNotices: [],
isDraft: false,
noticeIssuedDate: 'TEST_noticeIssuedDate',
partyType: 'TEST_partyType',
petitionFacts: 'TEST_petitionFacts',
Expand All @@ -63,7 +58,7 @@ describe('generatePetitionPdfInteractor', () => {
expect(petitionCalls.length).toEqual(1);
expect(petitionCalls[0][0].data).toEqual({
caseCaptionExtension: 'TEST_caseCaptionExtension',
caseDescription: 'Notice of Deficiency',
caseDescription: 'Deficiency',
caseTitle: 'TEST_caseTitle',
contactPrimary: 'TEST_contactPrimary',
contactSecondary: 'TEST_contactSecondary',
Expand All @@ -77,78 +72,15 @@ describe('generatePetitionPdfInteractor', () => {
taxYear: 'TEST_taxYear',
});

const addDraftWatermarkToDocumentCalls =
applicationContext.getUseCaseHelpers().addDraftWatermarkToDocument.mock
.calls;
expect(addDraftWatermarkToDocumentCalls.length).toEqual(0);

const saveFileAndGenerateUrlCalls =
applicationContext.getUseCaseHelpers().saveFileAndGenerateUrl.mock.calls;
expect(saveFileAndGenerateUrlCalls.length).toEqual(1);
expect(saveFileAndGenerateUrlCalls[0][0].file).toEqual(
'RESULTS_getDocumentGenerators_petition',
);
expect(saveFileAndGenerateUrlCalls[0][0].urlTtl).toEqual(60 * 60 * 24);
expect(saveFileAndGenerateUrlCalls[0][0].useTempBucket).toEqual(false);

expect(results).toEqual('RESULTS_saveFileAndGenerateUrl');
});

it('should generate petition, add watermark and call save and generate URL', async () => {
const results = await generatePetitionPdfInteractor(applicationContext, {
caseCaptionExtension: 'TEST_caseCaptionExtension',
caseTitle: 'TEST_caseTitle',
caseType: CASE_TYPES_MAP.deficiency,
contactPrimary: 'TEST_contactPrimary',
contactSecondary: 'TEST_contactSecondary',
irsNotices: [],
isDraft: true,
noticeIssuedDate: 'TEST_noticeIssuedDate',
partyType: 'TEST_partyType',
petitionFacts: 'TEST_petitionFacts',
petitionReasons: 'TEST_petitionReasons',
preferredTrialCity: 'TEST_preferredTrialCity',
procedureType: 'TEST_procedureType',
taxYear: 'TEST_taxYear',
});

const petitionCalls =
applicationContext.getDocumentGenerators().petition.mock.calls;
expect(petitionCalls.length).toEqual(1);
expect(petitionCalls[0][0].data).toEqual({
caseCaptionExtension: 'TEST_caseCaptionExtension',
caseDescription: 'Notice of Deficiency',
caseTitle: 'TEST_caseTitle',
contactPrimary: 'TEST_contactPrimary',
contactSecondary: 'TEST_contactSecondary',
irsNotices: [],
noticeIssuedDate: 'TEST_noticeIssuedDate',
partyType: 'TEST_partyType',
petitionFacts: 'TEST_petitionFacts',
petitionReasons: 'TEST_petitionReasons',
preferredTrialCity: 'TEST_preferredTrialCity',
procedureType: 'TEST_procedureType',
taxYear: 'TEST_taxYear',
});

const addDraftWatermarkToDocumentCalls =
applicationContext.getUseCaseHelpers().addDraftWatermarkToDocument.mock
applicationContext.getPersistenceGateway().saveDocumentFromLambda.mock
.calls;
expect(addDraftWatermarkToDocumentCalls.length).toEqual(1);
expect(addDraftWatermarkToDocumentCalls[0][0].pdfFile).toEqual(
'RESULTS_getDocumentGenerators_petition',
);

const saveFileAndGenerateUrlCalls =
applicationContext.getUseCaseHelpers().saveFileAndGenerateUrl.mock.calls;
expect(saveFileAndGenerateUrlCalls.length).toEqual(1);
expect(saveFileAndGenerateUrlCalls[0][0].file).toEqual(
'RESULTS_addDraftWatermarkToDocument',
expect(saveFileAndGenerateUrlCalls[0][0].document).toEqual(
'RESULTS_getDocumentGenerators_petition',
);
expect(saveFileAndGenerateUrlCalls[0][0].urlTtl).toEqual(60 * 60 * 24);
expect(saveFileAndGenerateUrlCalls[0][0].useTempBucket).toEqual(true);

expect(results).toEqual('RESULTS_saveFileAndGenerateUrl');
expect(results.fileId).toEqual(mockFileId);
});

it('should generate petition with correct irsNotice information', async () => {
Expand All @@ -161,14 +93,14 @@ describe('generatePetitionPdfInteractor', () => {
},
];

await generatePetitionPdfInteractor(applicationContext, {
const results = await generatePetitionPdfInteractor(applicationContext, {
caseCaptionExtension: 'TEST_caseCaptionExtension',
caseTitle: 'TEST_caseTitle',
caseType: CASE_TYPES_MAP.deficiency,
contactPrimary: 'TEST_contactPrimary',
contactSecondary: 'TEST_contactSecondary',
hasIrsNotice: true,
irsNotices,
isDraft: false,
noticeIssuedDate: 'TEST_noticeIssuedDate',
partyType: 'TEST_partyType',
petitionFacts: 'TEST_petitionFacts',
Expand All @@ -193,5 +125,6 @@ describe('generatePetitionPdfInteractor', () => {
},
],
});
expect(results.fileId).toEqual(mockFileId);
});
});
40 changes: 16 additions & 24 deletions shared/src/business/useCases/generatePetitionPdfInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import {
ROLE_PERMISSIONS,
isAuthorized,
} from '@shared/authorization/authorizationClientService';
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';

// TODO type for props

export const generatePetitionPdfInteractor = async (
applicationContext: IApplicationContext,
applicationContext: ServerApplicationContext,
{
caseCaptionExtension,
caseTitle,
caseType,
contactPrimary,
contactSecondary,
hasIrsNotice,
irsNotices,
isDraft,
noticeIssuedDate,
partyType,
petitionFacts,
Expand All @@ -29,16 +30,16 @@ export const generatePetitionPdfInteractor = async (
procedureType,
taxYear,
}: any,
) => {
): Promise<{ fileId: string }> => {
const user = applicationContext.getCurrentUser();

if (!isAuthorized(user, ROLE_PERMISSIONS.PETITION)) {
throw new UnauthorizedError('Unauthorized');
}

const caseDescription =
CASE_TYPE_DESCRIPTIONS_WITH_IRS_NOTICE[caseType] ||
CASE_TYPE_DESCRIPTIONS_WITHOUT_IRS_NOTICE[caseType];
const caseDescription = hasIrsNotice
? CASE_TYPE_DESCRIPTIONS_WITH_IRS_NOTICE[caseType]
: CASE_TYPE_DESCRIPTIONS_WITHOUT_IRS_NOTICE[caseType];

let pdfFile = await applicationContext.getDocumentGenerators().petition({
applicationContext,
Expand All @@ -50,9 +51,9 @@ export const generatePetitionPdfInteractor = async (
contactSecondary,
irsNotices: irsNotices.map(irsNotice => ({
...irsNotice,
caseDescription:
CASE_TYPE_DESCRIPTIONS_WITH_IRS_NOTICE[irsNotice.caseType] ||
CASE_TYPE_DESCRIPTIONS_WITHOUT_IRS_NOTICE[irsNotice.caseType],
caseDescription: hasIrsNotice
? CASE_TYPE_DESCRIPTIONS_WITH_IRS_NOTICE[irsNotice.caseType]
: CASE_TYPE_DESCRIPTIONS_WITHOUT_IRS_NOTICE[irsNotice.caseType],
noticeIssuedDateFormatted: applicationContext
.getUtilities()
.formatDateString(irsNotice.noticeIssuedDate || '', FORMATS.MMDDYY),
Expand All @@ -67,22 +68,13 @@ export const generatePetitionPdfInteractor = async (
},
});

if (isDraft) {
pdfFile = await applicationContext
.getUseCaseHelpers()
.addDraftWatermarkToDocument({
applicationContext,
pdfFile,
});
}

// 24 hrs
const urlTtl = 60 * 60 * 24;
const fileId = applicationContext.getUniqueId();

return await applicationContext.getUseCaseHelpers().saveFileAndGenerateUrl({
await applicationContext.getPersistenceGateway().saveDocumentFromLambda({
applicationContext,
file: pdfFile,
urlTtl,
useTempBucket: isDraft,
document: pdfFile,
key: fileId,
});

return { fileId };
};
3 changes: 0 additions & 3 deletions shared/src/proxies/generatePetitionPdfProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const generatePetitionPdfInteractor = (
contactPrimary,
contactSecondary,
irsNotices,
isDraft,
noticeIssuedDate,
partyType,
petitionFacts,
Expand All @@ -20,7 +19,6 @@ export const generatePetitionPdfInteractor = (
}: any,
): Promise<{
fileId: string;
url: string;
}> => {
return post({
applicationContext,
Expand All @@ -31,7 +29,6 @@ export const generatePetitionPdfInteractor = (
contactPrimary,
contactSecondary,
irsNotices,
isDraft,
noticeIssuedDate,
partyType,
petitionFacts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('generatePetitionPdfAction', () => {
expect(results.output).toEqual(undefined);
});

it('should generate the petition, save id in state and return URL when petition is auto generated and current step is not 5', async () => {
it('should generate the petition and save id in state when petition is auto generated', async () => {
const results = await runAction(generatePetitionPdfAction, {
modules: {
presenter,
Expand All @@ -57,17 +57,13 @@ describe('generatePetitionPdfAction', () => {
petitionProp: 'TEST_PROP',
petitionType: PETITION_TYPES.autoGenerated,
},
stepIndicatorInfo: {
currentStep: 6,
},
},
});

const generatePetitionPdfInteractorCalls =
applicationContext.getUseCases().generatePetitionPdfInteractor.mock.calls;
expect(generatePetitionPdfInteractorCalls.length).toEqual(1);
expect(generatePetitionPdfInteractorCalls[0][1]).toEqual({
isDraft: false,
noticeIssuedDate: 'RESULTS_formatDateString',
petitionFileId: undefined,
petitionProp: 'TEST_PROP',
Expand All @@ -80,47 +76,8 @@ describe('generatePetitionPdfAction', () => {
expect(formatDateStringCalls[0][0]).toEqual('TEST_noticeIssuedDate');
expect(formatDateStringCalls[0][1]).toEqual(FORMATS.MMDDYY);

expect(results.output).toEqual({ pdfUrl: 'TEST_URL' });
expect(results.state.petitionFormatted.petitionFileId).toEqual(
'TEST_FILE_ID',
);
});

it('should generate the petition, not save id in state and return URL when petition is auto generated and current step is 5', async () => {
const results = await runAction(generatePetitionPdfAction, {
modules: {
presenter,
},
state: {
petitionFormatted: {
petitionFileId: undefined,
petitionProp: 'TEST_PROP',
petitionType: PETITION_TYPES.autoGenerated,
},
stepIndicatorInfo: {
currentStep: 5,
},
},
});

const generatePetitionPdfInteractorCalls =
applicationContext.getUseCases().generatePetitionPdfInteractor.mock.calls;
expect(generatePetitionPdfInteractorCalls.length).toEqual(1);
expect(generatePetitionPdfInteractorCalls[0][1]).toEqual({
isDraft: true,
noticeIssuedDate: 'RESULTS_formatDateString',
petitionFileId: undefined,
petitionProp: 'TEST_PROP',
petitionType: 'autoGenerated',
});

const formatDateStringCalls =
applicationContext.getUtilities().formatDateString.mock.calls;
expect(formatDateStringCalls.length).toEqual(1);
expect(formatDateStringCalls[0][0]).toEqual('');
expect(formatDateStringCalls[0][1]).toEqual(FORMATS.MMDDYY);

expect(results.output).toEqual({ pdfUrl: 'TEST_URL' });
expect(results.state.petitionFormatted.petitionFileId).toEqual(undefined);
});
});
Loading
Loading