Skip to content

Commit

Permalink
Bat uat contigency (#1721)
Browse files Browse the repository at this point in the history
* PRL-6778

* PRL-6778

* 6778

* 6784

* 6782+5898

* lint

* 6810

* 6782

* 6782

* feat(6783): Add access control for AWP (#1723)

* PRL-6812

* PRL-6812

---------

Co-authored-by: vivek-sekhar <111058132+vivek-sekhar@users.noreply.github.com>
  • Loading branch information
sealDebolina and vivek-sekhar authored Dec 20, 2024
1 parent 6d3f60d commit a754dee
Show file tree
Hide file tree
Showing 34 changed files with 234 additions and 182 deletions.
6 changes: 3 additions & 3 deletions config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ services:
citizen:
uploadDocsEmail: UPLOAD_DOCUMENTS_EMAIL
case:
url: 'https://ccd-data-store-api-prl-ccd-definitions-pr-2518.preview.platform.hmcts.net'
url: 'http://ccd-data-store-api-aat.service.core-compute-aat.internal'
cos:
url: 'https://prl-cos-pr-2906.preview.platform.hmcts.net'
url: 'http://prl-cos-aat.service.core-compute-aat.internal'
documentManagement:
url: 'https://ccd-case-document-am-api-prl-ccd-definitions-pr-2518.preview.platform.hmcts.net'
url: 'http://ccd-case-document-am-api-aat.service.core-compute-aat.internal'
fact:
url: 'http://fact-api-aat.service.core-compute-aat.internal'
reasonableAdjustments:
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sonar.tests=src/test/
sonar.test.exclusions=src/**/*.njk
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.exclusions=src/**/*.test.ts,**/__mocks__/**,src/**/*content.ts,src/main/steps/common/task-list/components/tasklist/config/*.ts,src/main/steps/common/task-list/components/notification-banner/*/*.ts,src/main/steps/common/task-list/components/side-links/config/*.ts,src/main/steps/common/task-list/components/side-links/content.ts
sonar.exclusions=src/**/*.test.ts,**/__mocks__/**,src/**/*content.ts,src/main/steps/common/task-list/components/tasklist/config/*.ts,src/main/steps/common/task-list/components/notification-banner/*/*.ts,src/main/steps/common/task-list/components/side-links/config/*.ts,src/main/steps/common/task-list/components/side-links/content.ts,src/main/steps/application-within-proceedings/routeGuard.ts
sonar.organization=hmcts
sonar.cpd.typescript.minimumLines=250
sonar.cpd.javascript.minimumLines=250
Expand Down
4 changes: 3 additions & 1 deletion src/main/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PaymentHandler, PaymentValidationHandler } from './modules/payments/pay
import { RAProvider } from './modules/reasonable-adjustments';
import { StepWithContent, getStepsWithContent, stepsWithContent } from './steps/';
import UploadDocumentController from './steps/application-within-proceedings/document-upload/postController';
import { routeGuard } from './steps/application-within-proceedings/routeGuard';
import { processAWPApplication } from './steps/application-within-proceedings/utils';
import CaseDataController from './steps/common/CaseDataController';
import DownloadDocumentController from './steps/common/documents/download/DownloadDocumentController';
Expand All @@ -24,6 +25,7 @@ import {
APPLICANT_CHECK_ANSWERS,
APPLICATION_WITHIN_PROCEEDINGS_PAYMENT_CALLBACK,
APPLICATION_WITHIN_PROCEEDINGS_SUPPORTING_DOCUMENT_UPLOAD,
AWP,
C100_RETRIVE_CASE,
CA_RESPONDENT_GENERATE_C7_DRAFT,
CONSENT_TO_APPLICATION,
Expand Down Expand Up @@ -99,7 +101,7 @@ export class Routes {
);
app.get(DOWNLOAD_DOCUMENT_BY_TYPE, errorHandler(new DownloadDocumentController().download));
app.get(DOWNLOAD_DOCUMENT, errorHandler(new DownloadDocumentController().download));

app.get(`*/${AWP}/*`, errorHandler(routeGuard.get));
//C100 related routes
app.post(CREATE_DRAFT, errorHandler(TSDraftController.post));
app.post(`${CREATE_DRAFT}/createC100Draft`, errorHandler(TSDraftController.createTSC100Draft));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const en = {
errors: {
paymentError: {
title: 'There is a problem',
defaultPaymentError: 'Your application is not submitted. Please try again',
defaultPaymentError: 'Your application is not submitted. Please try again.',
applicationNotSubmitted:
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court',
paymentUnsuccessful: 'Your payment was unsuccessful. Make the payment again and resubmit your application',
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court.',
paymentUnsuccessful: 'Your payment was unsuccessful. Make the payment again and resubmit your application.',
},
},
};
Expand All @@ -53,11 +53,11 @@ const cy = {
errors: {
paymentError: {
title: 'Mae yna broblem',
defaultPaymentError: 'Nid yw eich cais wedi’i gyflwyno. Rhowch gynnig arall arni',
defaultPaymentError: 'Nid yw eich cais wedi’i gyflwyno. Rhowch gynnig arall arni.',
applicationNotSubmitted:
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court (welsh)',
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court (welsh).',
paymentUnsuccessful:
'Your payment was unsuccessful. Make the payment again and resubmit your application (welsh)',
'Your payment was unsuccessful. Make the payment again and resubmit your application (welsh).',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export const en = {
errors: {
paymentError: {
title: 'There is a problem',
defaultPaymentError: 'Your application is not submitted. Please try again',
defaultPaymentError: 'Your application is not submitted. Please try again.',
applicationNotSubmitted:
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court',
paymentUnsuccessful: 'Your payment was unsuccessful. Make the payment again and resubmit your application',
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court.',
paymentUnsuccessful: 'Your payment was unsuccessful. Make the payment again and resubmit your application.',
},
},
};
Expand All @@ -52,11 +52,11 @@ export const cy = {
errors: {
paymentError: {
title: 'Mae yna broblem',
defaultPaymentError: 'Nid yw eich cais wedi’i gyflwyno. Rhowch gynnig arall arni',
defaultPaymentError: 'Nid yw eich cais wedi’i gyflwyno. Rhowch gynnig arall arni.',
applicationNotSubmitted:
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court (welsh)',
'Your payment was successful but you need to resubmit your application. If you are unable to submit the application, please contact the court (welsh).',
paymentUnsuccessful:
'Your payment was unsuccessful. Make the payment again and resubmit your application (welsh)',
'Your payment was unsuccessful. Make the payment again and resubmit your application (welsh).',
},
},
};
Expand Down
25 changes: 25 additions & 0 deletions src/main/steps/application-within-proceedings/routeGuard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { NextFunction, Response } from 'express';

import { AppRequest } from '../../app/controller/AppRequest';
import { isRepresentedBySolicotor } from '../../steps/common/task-list/utils';
import { applyParms } from '../../steps/common/url-parser';
import { DASHBOARD_URL, FETCH_CASE_DETAILS } from '../../steps/urls';

export const routeGuard = {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
get: async (req: AppRequest, res: Response, next: NextFunction) => {
try {
if (!req.session?.userCase?.id) {
return res.redirect(DASHBOARD_URL);
}

if (isRepresentedBySolicotor(req.session.userCase, req.session.user.id)) {
return res.redirect(applyParms(FETCH_CASE_DETAILS, { caseId: req.session.userCase.id }));
}

next();
} catch (error) {
return res.redirect('/error');
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('ConfirmContactDetailsPostController', () => {
expect(retrieveByCaseIdMock).toBeCalled;
expect(updateCaserMock).toBeCalled;
expect(prepareRequest(req.session.userCase)).toStrictEqual(prepare);
expect(res.redirect).toHaveBeenLastCalledWith('/applicant/contact-preference/confirmation');
expect(res.redirect).toHaveBeenLastCalledWith('/applicant/contact-preference/review');
});
test('Should redirect C100 applicant after choosing digital preference', async () => {
req.session.user.id = '0c09b130-2eba-4ca8-a910-1f001bac01e6';
Expand All @@ -255,7 +255,7 @@ describe('ConfirmContactDetailsPostController', () => {
expect(retrieveByCaseIdMock).toBeCalled;
expect(updateCaserMock).toBeCalled;
expect(prepareRequest(req.session.userCase)).toStrictEqual(prepare);
expect(res.redirect).toHaveBeenLastCalledWith('/applicant/contact-preference/confirmation');
expect(res.redirect).toHaveBeenLastCalledWith('/applicant/contact-preference/review');
});

test('Should redirect C100 respondent after choosing post preference', async () => {
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('ConfirmContactDetailsPostController', () => {
expect(retrieveByCaseIdMock).toBeCalled;
expect(updateCaserMock).toBeCalled;
expect(prepareRequest(req.session.userCase)).toStrictEqual(prepare);
expect(res.redirect).toHaveBeenLastCalledWith('/respondent/contact-preference/confirmation');
expect(res.redirect).toHaveBeenLastCalledWith('/respondent/contact-preference/review');
});

test('Should redirect C100 respondent after choosing digital preference', async () => {
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('ConfirmContactDetailsPostController', () => {
expect(retrieveByCaseIdMock).toBeCalled;
expect(updateCaserMock).toBeCalled;
expect(prepareRequest(req.session.userCase)).toStrictEqual(prepare);
expect(res.redirect).toHaveBeenLastCalledWith('/respondent/contact-preference/confirmation');
expect(res.redirect).toHaveBeenLastCalledWith('/respondent/contact-preference/review');
});

test('Should not update the userCase for safety concerns when updateCaseData API is throwing error', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { prepareContactPreferenceRequest } from '../../../../steps/common/contac
import { applyParms } from '../../../../steps/common/url-parser';
import { getCasePartyType } from '../../../../steps/prl-cases/dashboard/utils';
import { getPartyDetails, mapDataInSession } from '../../../../steps/tasklistresponse/utils';
import {
CONTACT_PREFERENCE_CONFIRMATION,
PARTY_TASKLIST,
PageLink,
RESPOND_TO_APPLICATION,
} from '../../../../steps/urls';
import { PARTY_TASKLIST, PageLink, RESPOND_TO_APPLICATION, REVIEW_CONTACT_PREFERENCE } from '../../../../steps/urls';

import {
mapConfirmContactDetails,
Expand All @@ -42,7 +37,7 @@ export class ConfirmContactDetailsPostController extends PostController<AnyObjec
const getRedirectUrl = (partyType: PartyType, req: AppRequest<AnyObject>): PageLink => {
let redirectUrl;
if (req.session.applicationSettings?.navFromContactPreferences) {
redirectUrl = applyParms(CONTACT_PREFERENCE_CONFIRMATION, { partyType });
redirectUrl = applyParms(REVIEW_CONTACT_PREFERENCE, { partyType }) as PageLink;
} else if (req.session.applicationSettings?.navfromRespondToApplication) {
redirectUrl = RESPOND_TO_APPLICATION;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const en = {
title: 'Read the information to make sure it is correct, and add any missing details',
contactdetailpriv:
'if you do not want to share your contact details with the other person in the case,update the section',
contactdetailprivlinktext: 'keeping your contact details private',
contactdetailprivlinktext: 'keep your details private',
sectionTitles: {
applicationDetails: 'Application details',
},
Expand All @@ -33,7 +33,7 @@ const cy: typeof en = {
title: 'Darllenwch yr wybodaeth i wneud yn siŵr ei bod yn gywir, ac ychwanegwch unrhyw fanylion sydd ar goll',
contactdetailpriv:
'Os nad ydych eisiau rhannu eich manylion cyswllt gyda’r unigolyn arall yn yr achos, diweddarwch yr adran',
contactdetailprivlinktext: 'Cadw eich manylion cyswllt yn breifat',
contactdetailprivlinktext: 'Cadw eich manylion yn breifat',
sectionTitles: {
applicationDetails: 'Manylion y cais',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const enContent = {
title: 'Read the information to make sure it is correct, and add any missing details',
contactdetailpriv:
'if you do not want to share your contact details with the other person in the case,update the section',
contactdetailprivlinktext: 'keeping your contact details private',
contactdetailprivlinktext: 'keep your details private',
link: '',
sectionTitles: {
applicationDetails: 'Application details',
Expand Down Expand Up @@ -64,7 +64,7 @@ export const cyContent: typeof enContent = {
title: 'Darllenwch yr wybodaeth i wneud yn siŵr ei bod yn gywir, ac ychwanegwch unrhyw fanylion sydd ar goll',
contactdetailpriv:
'Os nad ydych eisiau rhannu eich manylion cyswllt gyda’r unigolyn arall yn yr achos, diweddarwch yr adran',
contactdetailprivlinktext: 'Cadw eich manylion cyswllt yn breifat',
contactdetailprivlinktext: 'Cadw eich manylion yn breifat',
link: '',
sectionTitles: {
applicationDetails: 'Manylion y cais',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FormFields } from '../../../../app/form/Form';
import ReviewContactPreferencePostController from './ReviewContactPreferencePostController';

const updateCaserMock = jest.spyOn(CosApiClient.prototype, 'updateCaseData');
const retrieveByCaseIdMock = jest.spyOn(CosApiClient.prototype, 'retrieveByCaseId');
let partyDetails;

describe('ContactPreferencesPostController', () => {
Expand Down Expand Up @@ -59,7 +58,7 @@ describe('ContactPreferencesPostController', () => {
firstName: 'testuser',
lastName: 'Citizen',
email: 'abc@example.net',
dateOfBirth: '03-20-2023',
dateOfBirth: '2023-11-12',
phoneNumber: '7755664466',
placeOfBirth: 'BPP',
previousName: 'test',
Expand Down Expand Up @@ -131,12 +130,9 @@ describe('ContactPreferencesPostController', () => {
caseTypeOfApplication: 'C100',
};
req.body.onlycontinue = true;
retrieveByCaseIdMock.mockResolvedValue(req.session.userCase);
updateCaserMock.mockResolvedValue(req.session.userCase);
});

afterEach(() => {
retrieveByCaseIdMock.mockClear();
updateCaserMock.mockClear();
});

Expand Down Expand Up @@ -185,65 +181,22 @@ describe('ContactPreferencesPostController', () => {

test('Should update the userCase for contact preferences when updateCaseData API is success', async () => {
req.session.userCase.applicants[0].value.contactPreferences = 'post';
req.body.partyContactPreference = 'post';
req.session.userCase.caseTypeOfApplication = 'C100';
req.session.userCase.id = '0c09b130-2eba-4ca8-a910-1f001bac01e6';
req.session.user.id = '123';
updateCaserMock.mockResolvedValue(req.session.userCase);

await controller.post(req, res);
await new Promise(process.nextTick);

expect(req.session.userCase.contactPreferences).toEqual('post');
expect(res.redirect).toHaveBeenCalledWith('/applicant/contact-preference/confirmation');
});

test('Should update the userCase for contact preferences when updateCaseData API is success for digital', async () => {
req.session.userCase.applicants[0].value.contactPreferences = 'email';
req.body.partyContactPreference = 'email';
req.session.userCase.caseTypeOfApplication = 'C100';
req.session.userCase.id = '0c09b130-2eba-4ca8-a910-1f001bac01e6';
req.session.user.id = '123';
updateCaserMock.mockResolvedValue(req.session.userCase);

await controller.post(req, res);
await new Promise(process.nextTick);

expect(req.session.userCase.contactPreferences).toEqual('email');
expect(res.redirect).toHaveBeenCalledWith('/applicant/contact-preference/confirmation');
});

test('Should update the userCase for contact preferences when updateCaseData API is success for respondent', async () => {
req.session.userCase.respondents[0].value.contactPreferences = 'post';
req.body.partyContactPreference = 'post';
req.session.userCase.caseTypeOfApplication = 'C100';
req.session.user.id = '8e87fde0-bab4-4701-abbe-2d277ca38fr5';
req.session.userCase.id = '0c09b130-2eba-4ca8-a910-1f001bac01e6';
updateCaserMock.mockResolvedValue(req.session.userCase);

await controller.post(req, res);
await new Promise(process.nextTick);

expect(req.session.userCase.contactPreferences).toEqual('post');
expect(res.redirect).toHaveBeenCalledWith('/respondent/contact-preference/confirmation');
expect(res.redirect).toHaveBeenCalledWith('/applicant/contact-preference/review');
});

test('Should update the userCase for contact preferences when updateCaseData API is success for email for respondent', async () => {
req.session.userCase.applicants[0].value.contactPreferences = 'email';
test('Should not update the userCase for contact preferences when updateCaseData API is throwing error', async () => {
req.session.userCase.applicants[0].value.contactPreferences = 'post';
req.body.partyContactPreference = 'email';
req.session.userCase.caseTypeOfApplication = 'C100';
req.session.user.id = '8e87fde0-bab4-4701-abbe-2d277ca38fr5';
req.session.userCase.id = '0c09b130-2eba-4ca8-a910-1f001bac01e6';
updateCaserMock.mockResolvedValue(req.session.userCase);

await controller.post(req, res);
await new Promise(process.nextTick);

expect(req.session.userCase.contactPreferences).toEqual('email');
expect(res.redirect).toHaveBeenCalledWith('/respondent/contact-preference/confirmation');
});

test('Should not update the userCase for contact preferences when updateCaseData API is throwing error', async () => {
req.session.user.id = '123';
updateCaserMock.mockRejectedValue({ message: 'MOCK_ERROR', response: { status: 500, data: 'Error' } });
await expect(controller.post(req, res)).rejects.toThrow(
'ReviewContactPreferencePostController - error when saving contact preferences and redirecting'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import autobind from 'autobind-decorator';
import type { Response } from 'express';

import { AppRequest } from '../../../../app/controller/AppRequest';
import { AnyObject, PostController } from '../../../../app/controller/PostController';
import { Form, FormFields, FormFieldsFn } from '../../../../app/form/Form';
import { applyParms } from '../../../../steps/common/url-parser';
import { getCasePartyType } from '../../../../steps/prl-cases/dashboard/utils';
import { getPartyDetails } from '../../../../steps/tasklistresponse/utils';
import { PageLink, REVIEW_CONTACT_PREFERENCE } from '../../../../steps/urls';
import { saveAndRedirectContactDetailsAndPreference } from '../../confirm-contact-details/checkanswers/ConfirmContactDetailsPostController';

@autobind
export default class ReviewContactPreferencePostController extends PostController<AnyObject> {
constructor(protected readonly fields: FormFields | FormFieldsFn) {
super(fields);
}

public async post(req: AppRequest<AnyObject>, res: Response): Promise<void> {
const fields = typeof this.fields === 'function' ? this.fields(req.session.userCase, req) : this.fields;
const form = new Form(fields);
const { _csrf, ...formData } = form.getParsedBody(req.body);
const { user, userCase } = req.session;
Object.assign(userCase, formData);
req.session.applicationSettings = { ...req.session.applicationSettings, navFromContactPreferences: true };
const partyType = getCasePartyType(userCase, user.id);
const partyDetailsContactPreference = getPartyDetails(userCase, user.id)?.contactPreferences;
if (userCase.partyContactPreference !== partyDetailsContactPreference) {
try {
await saveAndRedirectContactDetailsAndPreference(req, res);
} catch (error) {
throw new Error(
'ReviewContactPreferencePostController - error when saving contact preferences and redirecting'
);
}
} else {
req.session.save(() => {
res.redirect(applyParms(REVIEW_CONTACT_PREFERENCE, { partyType }) as PageLink);
});
}
}
}
Loading

0 comments on commit a754dee

Please sign in to comment.