From 04652a03cb7755e54b1684d2d30ef051fc9a1900 Mon Sep 17 00:00:00 2001 From: sealDebolina <116593651+sealDebolina@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:46:47 +0000 Subject: [PATCH] Update README.md (#1698) * Update README.md * PRL-6535-sonar * PRL-6535-sonar * PRL-6535-sonar * PRL-6535-sonar * remove duplicate line --- README.md | 2 +- .../values.preview.template.yaml | 1 - config/development.yaml | 18 +- sonar-project.properties | 2 +- .../AddressLookupPostControllerBase.ts | 3 +- src/main/app/case/CaseApi.integration.test.ts | 12 +- src/main/app/case/case.ts | 4 +- src/main/app/case/definition.ts | 9 - src/main/app/controller/GetController.test.ts | 2 +- src/main/app/controller/GetController.ts | 4 +- src/main/app/form/Form.ts | 10 +- src/main/app/form/validation copy.ts | 4 - src/main/app/form/validation.ts | 32 +- src/main/app/utils/featureToggles.test.ts | 11 + src/main/app/utils/featureToggles.ts | 5 +- src/main/modules/properties-volume/index.ts | 2 +- src/main/steps/applicant/task-list/utils.ts | 2 +- .../document-upload/postController.ts | 6 +- .../navigationController.ts | 11 +- .../c100-rebuild/PageStepConfigurator.test.ts | 10 - .../c100-rebuild/PageStepConfigurator.ts | 102 -- .../steps/c100-rebuild/PreProcessCaseData.ts | 10 +- .../add-applicants/postController.ts | 42 +- .../commonConfidentialityPostController.ts | 44 +- src/main/steps/c100-rebuild/c100sequence.ts | 13 +- .../PayAndSubmitPostController.ts | 2 +- .../common/htmlSelectors.test.ts | 8 +- .../common/htmlSelectors.ts | 2 - .../helpers/InternationElementsHelper.ts | 56 +- .../helpers/courtOrderHelper.ts | 4 +- .../check-your-answers/helpers/miamHelper.ts | 6 +- .../check-your-answers/mainUtil.ts | 12 +- .../check-your-answers/util/miam.util.ts | 4 +- .../util/otherProceeding.util.ts | 42 +- .../childDetailPostController.ts | 4 +- .../childaddress/postController.test.ts | 10 +- .../childaddress/postController.ts | 2 +- .../consent-order/upload/getController.ts | 1 - .../providing-evidence/template.njk | 3 +- .../c100-rebuild/miam/navigationController.ts | 85 +- .../postController.test.ts | 196 +++ .../postController.ts | 1 - .../routeGuards.test.ts | 76 + .../c100-rebuild/miam/upload/getController.ts | 2 - .../SelectAddressPostController.test.ts | 89 ++ .../select/SelectAddressPostController.ts | 2 +- .../documentUpload/postController.ts | 47 +- .../other-proceedings/navigationController.ts | 21 +- src/main/steps/c100-rebuild/pageStepConfig.ts | 53 - .../people/AddPeoplePostContoller.ts | 4 +- .../LookupAndManualAddressPostController.ts | 4 +- .../SelectAddressPostController.test.ts | 93 ++ .../select/SelectAddressPostController.ts | 2 +- .../c100-rebuild/start/routeGuard.test.ts | 75 + .../c100-rebuild/uploadDocumentController.ts | 2 +- src/main/steps/common/common.content.ts | 13 +- .../upload-your-documents/postController.ts | 4 +- .../common/functions/mapSummaryListContent.ts | 25 - .../safety-concerns/navigationController.ts | 18 +- .../review/safetyConcernMapper.test.ts | 33 + .../review/safetyConcernMapper.ts | 48 +- .../notification-banner/index.test.ts | 12 +- .../common/yourhearings/hearings/utils.ts | 18 +- src/main/steps/constants.ts | 2 +- src/main/steps/error/error.controller.ts | 4 +- .../enter-pin/postController.ts | 2 +- .../court-proceedings/content.test.ts | 225 --- .../proceedings/court-proceedings/content.ts | 1315 ----------------- .../court-proceedings/template.njk | 8 - .../proceedings/start/content.test.ts | 87 -- .../respondent/proceedings/start/content.ts | 106 -- .../respondent/proceedings/start/template.njk | 4 - .../proceedings/summary/content.test.ts | 203 --- .../respondent/proceedings/summary/content.ts | 483 ------ .../proceedings/summary/template.njk | 5 - .../documentUpload/postController.ts | 143 +- .../proceedings/htmlSelectors.test.ts | 7 - .../proceedings/htmlSelectors.ts | 2 - .../proceedings/proceedingUtils.ts | 32 +- .../summary/postController.ts | 1 - 80 files changed, 969 insertions(+), 3100 deletions(-) delete mode 100644 src/main/app/form/validation copy.ts delete mode 100644 src/main/steps/c100-rebuild/PageStepConfigurator.test.ts delete mode 100644 src/main/steps/c100-rebuild/PageStepConfigurator.ts create mode 100644 src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.test.ts create mode 100644 src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/routeGuards.test.ts delete mode 100644 src/main/steps/c100-rebuild/pageStepConfig.ts create mode 100644 src/main/steps/c100-rebuild/start/routeGuard.test.ts delete mode 100644 src/main/steps/common/functions/mapSummaryListContent.ts delete mode 100644 src/main/steps/respondent/proceedings/court-proceedings/content.test.ts delete mode 100644 src/main/steps/respondent/proceedings/court-proceedings/content.ts delete mode 100644 src/main/steps/respondent/proceedings/court-proceedings/template.njk delete mode 100644 src/main/steps/respondent/proceedings/start/content.test.ts delete mode 100644 src/main/steps/respondent/proceedings/start/content.ts delete mode 100644 src/main/steps/respondent/proceedings/start/template.njk delete mode 100644 src/main/steps/respondent/proceedings/summary/content.test.ts delete mode 100644 src/main/steps/respondent/proceedings/summary/content.ts delete mode 100644 src/main/steps/respondent/proceedings/summary/template.njk diff --git a/README.md b/README.md index b399d8584a..d9c8134a50 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# prl-citizen-frontend +## prl-citizen-frontend Updated with Release 4.0 diff --git a/charts/prl-citizen-frontend/values.preview.template.yaml b/charts/prl-citizen-frontend/values.preview.template.yaml index 2463074214..ed7d95a431 100644 --- a/charts/prl-citizen-frontend/values.preview.template.yaml +++ b/charts/prl-citizen-frontend/values.preview.template.yaml @@ -23,7 +23,6 @@ nodejs: COS_URL: 'http://prl-cos-aat.service.core-compute-aat.internal' REASONABLE_ADJUSTMENTS: 'https://cui-ra.aat.platform.hmcts.net' FACT_URL: 'http://fact-api-aat.service.core-compute-aat.internal' - REASONABLE_ADJUSTMENTS: 'https://cui-ra.{{ .Values.global.environment }}.platform.hmcts.net' REDIS_HOST: 'prl-citizen-frontend-secondary-redis-{{ .Values.global.environment }}.redis.cache.windows.net' LAUNCH_DARKLY_OFFLINE_MODE: false C100_REBUILD_FLAG: false diff --git a/config/development.yaml b/config/development.yaml index 365fdaa787..8d58ba015d 100644 --- a/config/development.yaml +++ b/config/development.yaml @@ -7,12 +7,12 @@ services: url: 'https://api.os.uk/search/places/v1' token: POSTCODE_TOKEN authProvider: - url: 'http://rpe-service-auth-provider-demo.service.core-compute-demo.internal' + url: 'http://rpe-service-auth-provider-aat.service.core-compute-aat.internal' microservice: 'prl_citizen_frontend' secret: 'NEED TO INSERT SECRET' idam: - authorizationURL: 'https://idam-web-public.demo.platform.hmcts.net/login' - tokenURL: 'https://idam-api.demo.platform.hmcts.net/o/token' + authorizationURL: 'https://idam-web-public.aat.platform.hmcts.net/login' + tokenURL: 'https://idam-api.aat.platform.hmcts.net/o/token' clientID: 'prl-citizen-frontend' citizenClientSecret: cosApiClientSecret: @@ -21,18 +21,18 @@ services: citizen: uploadDocsEmail: UPLOAD_DOCUMENTS_EMAIL case: - url: 'http://ccd-data-store-api-demo.service.core-compute-demo.internal' + url: 'http://ccd-data-store-api-aat.service.core-compute-aat.internal' cos: - url: 'http://prl-cos-demo.service.core-compute-demo.internal' + url: 'http://prl-cos-aat.service.core-compute-aat.internal' documentManagement: - url: 'http://ccd-case-document-am-api-demo.service.core-compute-demo.internal' + url: 'http://ccd-case-document-am-api-aat.service.core-compute-aat.internal' fact: - url: 'http://fact-api-demo.service.core-compute-demo.internal' + url: 'http://fact-api-aat.service.core-compute-aat.internal' reasonableAdjustments: - url: 'https://cui-ra.demo.platform.hmcts.net' + url: 'https://cui-ra.aat.platform.hmcts.net' equalityAndDiversity: name: 'Equality and Diversity Service' - url: 'https://pcq.demo.platform.hmcts.net' + url: 'https://pcq.aat.platform.hmcts.net' path: '/service-endpoint' tokenKey: PCQ_TOKEN health: diff --git a/sonar-project.properties b/sonar-project.properties index 77116918e9..2a80ca325d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -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,src/main/steps/tasklistresponse/responseCaseSequence.ts,src/main/steps/tasklistresponse/tasklistresponseCaseSequence.ts**/__mocks__/**,src/**/content.ts,src/main/steps/applicant/applicantCaseSequence.ts,src/main/steps/respondent/respondentcaseSequence.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/tasklistresponse/summary/handler.ts,src/main/app/case/C100CaseApi.ts,src/main/steps/common/task-list/components/tasklist/utils.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 sonar.organization=hmcts sonar.cpd.typescript.minimumLines=250 sonar.cpd.javascript.minimumLines=250 diff --git a/src/main/app/address/AddressLookupPostControllerBase.ts b/src/main/app/address/AddressLookupPostControllerBase.ts index d81b15415c..fb1237a58b 100644 --- a/src/main/app/address/AddressLookupPostControllerBase.ts +++ b/src/main/app/address/AddressLookupPostControllerBase.ts @@ -28,6 +28,7 @@ export default class AddressLookupPostControllerBase extends PostController res.redirect(redirectUrl)); - } else if (!(req.body.citizenUserAddressPostcode as string).match(/^[A-Z]{1,2}\d[A-Z0-9]? ?\d[A-Z]{2}$/i)) { + } else if (!matcher.test(req.body.citizenUserAddressPostcode as string)) { req.session.errors = []; req.session.errors?.push({ propertyName: 'citizenUserAddressPostcode', diff --git a/src/main/app/case/CaseApi.integration.test.ts b/src/main/app/case/CaseApi.integration.test.ts index 461ecfb46d..3c7a2322aa 100644 --- a/src/main/app/case/CaseApi.integration.test.ts +++ b/src/main/app/case/CaseApi.integration.test.ts @@ -60,7 +60,7 @@ // const results = { // data: { // id: '1234', -// state: State.Draft, +// state: State.AWAITING_SUBMISSION_TO_HMCTS, // data: {}, // }, // }; @@ -71,7 +71,7 @@ // expect(userCase).toStrictEqual({ // id: '1234', -// state: State.Draft, +// state: State.AWAITING_SUBMISSION_TO_HMCTS, // }); // }); @@ -103,12 +103,12 @@ // test('Should retrieve the first case if two cases found', async () => { // const firstMockCase = { // id: '1', -// state: State.Draft, +// state: State.AWAITING_SUBMISSION_TO_HMCTS, // case_data: {}, // }; // // const secondMockCase = { // // id: '2', -// // state: State.Draft, +// // state: State.AWAITING_SUBMISSION_TO_HMCTS, // // case_data: {}, // // }; @@ -120,7 +120,7 @@ // expect(userCase).toStrictEqual({ // id: '1', -// state: State.Draft, +// state: State.AWAITING_SUBMISSION_TO_HMCTS, // }); // }); @@ -191,7 +191,7 @@ // mockedAxios.get.mockResolvedValue({ // data: { // id: '1234', -// state: State.Draft, +// state: State.AWAITING_SUBMISSION_TO_HMCTS, // data: {}, // }, // }); diff --git a/src/main/app/case/case.ts b/src/main/app/case/case.ts index 9823f67dc8..eb121b9d34 100644 --- a/src/main/app/case/case.ts +++ b/src/main/app/case/case.ts @@ -780,8 +780,8 @@ export interface CaseWithId extends Case { id: string; state: State; applicantTemporaryFormData?: { - TempFirstName?: string | unknown; - TempLastName?: string | unknown; + TempFirstName?: string; + TempLastName?: string; }; applicationPayOnline?: YesOrNo; legalRepresentativeForProceedings?: YesOrNo; diff --git a/src/main/app/case/definition.ts b/src/main/app/case/definition.ts index a299e668bb..24e564e2c8 100644 --- a/src/main/app/case/definition.ts +++ b/src/main/app/case/definition.ts @@ -2653,15 +2653,6 @@ export interface C1ASafteyConcernsAbuse { childrenConcernedAbout?: string[]; } -export interface PRL_C1ASafteyConcernsAbuse { - behaviourDetails?: string; - behaviourStartDate?: string; - isOngoingBehaviour?: YesNoEmpty; - seekHelpFromPersonOrAgency?: YesNoEmpty; - seekHelpDetails?: string; - childrenConcernedAbout?: string[]; -} - export interface C1ASafteyConcerns { child?: { physicalAbuse?: C1ASafteyConcernsAbuse; diff --git a/src/main/app/controller/GetController.test.ts b/src/main/app/controller/GetController.test.ts index a1a798d6e2..b74ce30cb0 100644 --- a/src/main/app/controller/GetController.test.ts +++ b/src/main/app/controller/GetController.test.ts @@ -211,7 +211,7 @@ describe('GetController', () => { const getContentMock = jest.fn().mockReturnValue({}); const controller = new GetController('page', getContentMock); - const req = mockRequest({ userCase: { state: State.Draft }, session: { errors: [] } }); + const req = mockRequest({ userCase: { state: State.AWAITING_SUBMISSION_TO_HMCTS }, session: { errors: [] } }); const res = mockResponse(); await controller.get(req, res); diff --git a/src/main/app/controller/GetController.ts b/src/main/app/controller/GetController.ts index 3798ec87bd..4e011c3cd0 100644 --- a/src/main/app/controller/GetController.ts +++ b/src/main/app/controller/GetController.ts @@ -77,7 +77,7 @@ export class GetController { ...content, sessionErrors, htmlLang: language, - caseId: req.session.userCase?.caseId || req.session.userCase?.id, + caseId: req.session.userCase?.caseId ?? req.session.userCase?.id, paymentError: req.session.paymentError, document_type, breadcrumbs: BreadcrumbController.get(req.session, language), @@ -105,7 +105,7 @@ export class GetController { // Browsers default language const negotiator = new Negotiator(req); - return negotiator.language(LanguageToggle.supportedLanguages) || 'en'; + return negotiator.language(LanguageToggle.supportedLanguages) ?? 'en'; } private getCaption(req: AppRequest) { diff --git a/src/main/app/form/Form.ts b/src/main/app/form/Form.ts index d13adb14dc..20876bba66 100644 --- a/src/main/app/form/Form.ts +++ b/src/main/app/form/Form.ts @@ -56,13 +56,13 @@ export class Form { // if there are checkboxes or options, check them for errors if (isFormOptions(field)) { - const valuesErrors = field.values.flatMap(value => this.getErrorsFromField(body, value.name || id, value)); + const valuesErrors = field.values.flatMap(value => this.getErrorsFromField(body, value.name ?? id, value)); errors.push(...valuesErrors); } // if there are subfields and the current field is selected then check for errors in the subfields else if (field.subFields) { - if (body[id] === field.value || (body[id] && body[id].includes(field.value))) { + if (body[id] === field.value || body[id]?.includes(field.value)) { const subFields = Object.entries(field.subFields); const subFieldErrors = subFields.flatMap(([subId, subField]) => this.getErrorsFromField(body, subId, subField)); @@ -122,15 +122,13 @@ export type LanguageLookup = (lang: Record) => string; type Parser = (value: Record | string[]) => void; export type LabelFormFormatter = { - text?: string | never; + text?: string; classes?: string; isPageHeading?: boolean; }; type Label = LabelFormFormatter | string | LanguageLookup; -type Warning = Label; - export type ValidationCheck = ( value: string | string[] | CaseDate | undefined, formData: Partial @@ -228,7 +226,7 @@ export interface FormInput { attributes?: Partial; validator?: ValidationCheck; parser?: Parser; - warning?: Warning; + warning?: Label; conditionalText?: Label; subFields?: Record; open?: boolean; diff --git a/src/main/app/form/validation copy.ts b/src/main/app/form/validation copy.ts deleted file mode 100644 index 91463b8b2e..0000000000 --- a/src/main/app/form/validation copy.ts +++ /dev/null @@ -1,4 +0,0 @@ -import dayjs from 'dayjs'; -import customParseFormat from 'dayjs/plugin/customParseFormat'; - -dayjs.extend(customParseFormat); diff --git a/src/main/app/form/validation.ts b/src/main/app/form/validation.ts index 2b756373ef..7454dc9759 100644 --- a/src/main/app/form/validation.ts +++ b/src/main/app/form/validation.ts @@ -13,7 +13,6 @@ export type Validator = ( export type DateValidator = (value: CaseDate | undefined) => void | string; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -export type AnyType = any; export const enum ValidationError { REQUIRED = 'required', NOT_SELECTED = 'notSelected', @@ -141,9 +140,9 @@ export const isInvalidHelpWithFeesRef: Validator = value => { if (fieldNotFilledIn) { return fieldNotFilledIn; } - + const matcher = new RegExp(/^HWF-[A-Z0-9]{3}-[A-Z0-9]{3}$/i); if (typeof value === 'string') { - if (!value.match(/^HWF-[A-Z0-9]{3}-[A-Z0-9]{3}$/i)) { + if (!matcher.test(value)) { return 'invalid'; } @@ -158,26 +157,29 @@ export const isInvalidPostcode: Validator = value => { if (fieldNotFilledIn) { return fieldNotFilledIn; } - - if (!(value as string).match(/^[A-Z]{1,2}\d[A-Z0-9]? ?\d[A-Z]{2}$/i)) { + const matcher = new RegExp(/^[A-Z]{1,2}\d[A-Z0-9]? ?\d[A-Z]{2}$/i); + if (!matcher.test(value as string)) { return 'invalid'; } }; export const isPhoneNoValid: Validator = value => { if (typeof value === 'string') { - return !value.match(/^$|^[0-9 +().-]{11,}$/) ? 'invalid' : undefined; + const matcher = new RegExp(/^$|^[0-9 +().-]{11,}$/); + return !matcher.test(value) ? 'invalid' : undefined; } }; export const isAlphaNumeric: Validator = value => { if (typeof value === 'string') { - return !value.match(/^[a-zA-Z0-9_\s]*$/) ? 'invalid' : undefined; + const matcher = new RegExp(/^[a-zA-Z0-9_\s]*$/); + return !matcher.test(value) ? 'invalid' : undefined; } }; export const isAlphaNumericWithApostrophe: Validator = value => { if (typeof value === 'string') { - return !value.match(/^[a-zA-Z0-9'_\s]*$/) ? 'invalid' : undefined; + const matcher = new RegExp(/^[a-zA-Z0-9'_\s]*$/); + return !matcher.test(value) ? 'invalid' : undefined; } }; export const isEmailValid: Validator = value => { @@ -187,13 +189,16 @@ export const isEmailValid: Validator = value => { }; export const isFieldLetters: Validator = value => { - if (!(value as string).match(/^[\p{Script=Latin}'’\-\s]*$/gu)) { + const matcher = new RegExp(/^[\p{Script=Latin}'’\-\s]*$/gu); + if (!matcher.test(value as string)) { return 'invalid'; } }; export const isValidCaseReference: Validator = value => { - if (!(value as string).match(/^\d{16}$/) && !(value as string).match(/^\d{4}-\d{4}-\d{4}-\d{4}$/)) { + const matcher = new RegExp(/^\d{4}-\d{4}-\d{4}-\d{4}$/); + const matcher1 = new RegExp(/^\d{16}$/); + if (!matcher1.test(value as string) && !matcher.test(value as string)) { return 'invalid'; } }; @@ -236,20 +241,21 @@ export const isAccessCodeValid: Validator = value => { }; export const isNumeric: Validator = value => { - if (value && !(value as string).match(/^\d+$/)) { + const matcher = new RegExp(/^\d+$/); + if (value && !matcher.test(value as string)) { return ValidationError.NOT_NUMERIC; } }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any export const isFileSizeGreaterThanMaxAllowed = (files: any): boolean => { - const { documents }: AnyType = files; + const { documents } = files; return documents.size > C100MaxFileSize; }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any export const isValidFileFormat = (files: any): boolean => { - const { documents }: AnyType = files; + const { documents } = files; const extension = documents.name.toLowerCase().split('.')[documents.name.split('.').length - 1]; return AllowedFileExtentionList.indexOf(extension) > -1; }; diff --git a/src/main/app/utils/featureToggles.test.ts b/src/main/app/utils/featureToggles.test.ts index 5bf751ec96..a01f06387b 100644 --- a/src/main/app/utils/featureToggles.test.ts +++ b/src/main/app/utils/featureToggles.test.ts @@ -31,6 +31,17 @@ describe('FeatureToggles', () => { it('should throw an error if toggle does not exist', () => { expect(() => FeatureToggles.hasAnyAuthorisedFeature([])).to.throw(Error); }); + it('should not throw an error feature names are provided', () => { + expect(FeatureToggles.hasAnyAuthorisedFeature([], ...['c100Rebuild'])).equal(false); + }); + it('should not throw an error feature names are provided -diffent array object', () => { + expect(() => FeatureToggles.hasAnyAuthorisedFeature(['c100Rebuild'], ...['testingSupport'])).not.to.throw(Error); + }); + it('should not throw an error feature names are provided -some matching array object', () => { + expect(() => + FeatureToggles.hasAnyAuthorisedFeature(['c100Rebuild', 'testingSupport'], ...['testingSupport']) + ).not.to.throw(Error); + }); }); describe('isEnabled', () => { diff --git a/src/main/app/utils/featureToggles.ts b/src/main/app/utils/featureToggles.ts index 2fd0f9f2b7..6fab093936 100644 --- a/src/main/app/utils/featureToggles.ts +++ b/src/main/app/utils/featureToggles.ts @@ -20,10 +20,7 @@ export class FeatureToggles { throw new Error('At least one feature name has to be provided'); } - return features.some( - feature => - FeatureToggles.isEnabled(feature) && authorisedFeatures !== undefined && authorisedFeatures.includes(feature) - ); + return features.some(feature => FeatureToggles.isEnabled(feature) && authorisedFeatures?.includes(feature)); } static isAnyEnabled(...featureNames: string[]): boolean { diff --git a/src/main/modules/properties-volume/index.ts b/src/main/modules/properties-volume/index.ts index 3e57534922..1ecfba1c54 100644 --- a/src/main/modules/properties-volume/index.ts +++ b/src/main/modules/properties-volume/index.ts @@ -45,7 +45,7 @@ export class PropertiesVolume { * Load a secret from the aat vault using azure cli */ private setLocalSecret(secret: string, toPath: string): void { - const result = execSync(`az keyvault secret show --vault-name prl-demo -o tsv --query value --name ${secret}`); + const result = execSync(`az keyvault secret show --vault-name prl-aat -o tsv --query value --name ${secret}`); set(config, toPath, result.toString().replace('\n', '')); } } diff --git a/src/main/steps/applicant/task-list/utils.ts b/src/main/steps/applicant/task-list/utils.ts index e7a3a18d4a..3f8f957dda 100644 --- a/src/main/steps/applicant/task-list/utils.ts +++ b/src/main/steps/applicant/task-list/utils.ts @@ -3,7 +3,7 @@ import { Applicant } from '../../../app/case/definition'; export const getApplicantAllegationsOfHarmAndViolence = (userCase: CaseWithId): boolean => { let flag = false; - if (userCase && userCase.allegationsOfHarmYesNo) { + if (userCase?.allegationsOfHarmYesNo) { flag = true; } return flag; diff --git a/src/main/steps/application-within-proceedings/document-upload/postController.ts b/src/main/steps/application-within-proceedings/document-upload/postController.ts index 575816d5ff..07455857d8 100644 --- a/src/main/steps/application-within-proceedings/document-upload/postController.ts +++ b/src/main/steps/application-within-proceedings/document-upload/postController.ts @@ -9,7 +9,7 @@ import { DocumentUploadResponse } from '../../../app/case/definition'; import { AppRequest } from '../../../app/controller/AppRequest'; import { AnyObject, PostController } from '../../../app/controller/PostController'; import { FormFields, FormFieldsFn } from '../../../app/form/Form'; -import { AnyType, isFileSizeGreaterThanMaxAllowed, isValidFileFormat } from '../../../app/form/validation'; +import { isFileSizeGreaterThanMaxAllowed, isValidFileFormat } from '../../../app/form/validation'; import { applyParms } from '../../../steps/common/url-parser'; import { APPLICATION_WITHIN_PROCEEDINGS_SUPPORTING_DOCUMENT_UPLOAD } from '../../../steps/urls'; @@ -87,7 +87,7 @@ export default class UploadDocumentController extends PostController } } - private addDocument = (sessionDocs, document) => { + private readonly addDocument = (sessionDocs, document) => { if (sessionDocs && sessionDocs.length > 0) { sessionDocs.push(document); } else { @@ -120,7 +120,7 @@ export default class UploadDocumentController extends PostController private handleError( req: AppRequest, - res: Response>, + res: Response, // eslint-disable-next-line @typescript-eslint/no-explicit-any errObj: any ) { diff --git a/src/main/steps/application-within-proceedings/navigationController.ts b/src/main/steps/application-within-proceedings/navigationController.ts index 11e4dd6234..9c3dc6cb76 100644 --- a/src/main/steps/application-within-proceedings/navigationController.ts +++ b/src/main/steps/application-within-proceedings/navigationController.ts @@ -65,7 +65,7 @@ class ApplicationWithinProceedingsNavigationController { return url; } - private getUploadApplicationNextStep = ( + private readonly getUploadApplicationNextStep = ( partyType, completedForm, applicationType, @@ -108,7 +108,7 @@ class ApplicationWithinProceedingsNavigationController { return completedForm === YesOrNo.NO ? noNextStep : yesNextStep; }; - private getAgreementForRequestNextStep = ( + private readonly getAgreementForRequestNextStep = ( partyType, agreementForRequest, applicationType, @@ -144,7 +144,12 @@ class ApplicationWithinProceedingsNavigationController { return applicationReason === AWPApplicationReason.DELAY_CANCEL_HEARING_DATE ? delayOrCancelStep : otherC2NextStep; }; - private getSupportingDocumentsNextStep = (partyType, supportingDocuments, applicationType, applicationReason) => { + private readonly getSupportingDocumentsNextStep = ( + partyType, + supportingDocuments, + applicationType, + applicationReason + ) => { const noNextStep = applicationReason === AWPApplicationReason.DELAY_CANCEL_HEARING_DATE ? (applyParms(APPLICATION_WITHIN_PROCEEDINGS_CHECK_YOUR_ANSWER, { diff --git a/src/main/steps/c100-rebuild/PageStepConfigurator.test.ts b/src/main/steps/c100-rebuild/PageStepConfigurator.test.ts deleted file mode 100644 index e782740b15..0000000000 --- a/src/main/steps/c100-rebuild/PageStepConfigurator.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import PageStepConfigurator from './PageStepConfigurator'; -import { PageSteps, PageStepsConfig } from './pageStepConfig'; -const miamGeneralReasonsConfig: PageSteps = PageStepsConfig[0]; - -describe('PageStepConfigurator', () => { - test('getSteps should return null when clearSteps is invoked', () => { - PageStepConfigurator.clearSteps(miamGeneralReasonsConfig.id); - expect(PageStepConfigurator.getSteps(miamGeneralReasonsConfig.id)).toBe(null); - }); -}); diff --git a/src/main/steps/c100-rebuild/PageStepConfigurator.ts b/src/main/steps/c100-rebuild/PageStepConfigurator.ts deleted file mode 100644 index adfd590446..0000000000 --- a/src/main/steps/c100-rebuild/PageStepConfigurator.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { Page, PageSteps, PageStepsConfig } from './pageStepConfig'; - -interface FlattenedPage extends Page { - url: string; - prev: Page; - next: Page; -} - -interface FlattenedPageSteps { - [key: string]: FlattenedPage; -} - -class PageStepConfigurator { - private pageConfig; - private pageSteps; - constructor(pageConfig: PageSteps[]) { - this.pageConfig = pageConfig; - this.pageSteps = {}; - } - - clearSteps(mainPageId) { - delete this.pageSteps[mainPageId]; - } - - deriveSteps(mainPageId: string, selectedPageSteps: string[] = []): FlattenedPageSteps | null { - this.clearSteps(mainPageId); - const filteredPage = this.pageConfig.find(_page => _page.id === mainPageId); - if (!filteredPage) { - return null; - } - const steps = selectedPageSteps.reduce((_pages, pId: string, pageIndex: number, currentArray: string[]) => { - const page = filteredPage?.steps.find(_page => _page.id === pId); - - if (page) { - const prevPageId = this.checkAndReturnPageId(currentArray[pageIndex - 1]); - const prevPage = this.checkAndReturnPage(prevPageId, filteredPage); - const nextPageId = this.checkAndReturnPageId(currentArray[pageIndex + 1]); - const nextPage = this.checkAndReturnPage(nextPageId, filteredPage); - - _pages[page.url] = { - ...page, - prev: prevPageId ? { ...prevPage } : null, - next: nextPageId ? { ...nextPage } : null, - }; - } - - return _pages; - }, {}); - const hasSteps = Object.values(steps).length; - - if (hasSteps) { - this.pageSteps[mainPageId] = steps; - } - - return hasSteps ? steps : null; - } - - getSteps(mainPageId: string, selectedPageSteps?: string[]) { - const pageSteps = this.pageSteps[mainPageId]; - if (!pageSteps && selectedPageSteps?.length) { - this.deriveSteps(mainPageId, selectedPageSteps); - } - return this.pageSteps[mainPageId] || null; - } - - getNextPage(mainPageId: string, stepPageId?: string | null, selectedPageSteps?: string[]) { - const pageSteps = this.getSteps(mainPageId, selectedPageSteps); - return this.checkPageSteps(pageSteps, mainPageId, stepPageId); - } - - private checkAndReturnPageId(pageId: string): string { - if (!pageId) { - return ''; - } - return pageId; - } - - private checkAndReturnPage(pageId: string, filteredPageParam) { - if (!pageId) { - return; - } - if (!filteredPageParam?.steps.find(_page => _page.id === pageId)) { - return {}; - } - return filteredPageParam?.steps.find(_page => _page.id === pageId); - } - - private checkPageSteps(pageStepsParam, mainPageIdParam: string, stepPageIdParam?: string | null) { - if (!pageStepsParam) { - return null; - } - if (!(mainPageIdParam && stepPageIdParam)) { - return Object.values(pageStepsParam)[0]; - } - if (!pageStepsParam[stepPageIdParam]) { - return null; - } - return pageStepsParam[stepPageIdParam].next; - } -} - -export default new PageStepConfigurator(PageStepsConfig); diff --git a/src/main/steps/c100-rebuild/PreProcessCaseData.ts b/src/main/steps/c100-rebuild/PreProcessCaseData.ts index e3c86004d2..ae49024ac5 100644 --- a/src/main/steps/c100-rebuild/PreProcessCaseData.ts +++ b/src/main/steps/c100-rebuild/PreProcessCaseData.ts @@ -91,13 +91,11 @@ class PreProcessCaseData { if (fieldValue.includes(valueConfig.value)) { // if form data value matches with the field values config value Object.assign(_caseData, this.removeEmptyValues(formData, valueConfig.subFields)); - } else { + } else if (valueConfig.subFields) { // if the field values config value is not present in form data then clean up other subfield data from caseData for the fields that has subfields - if (valueConfig.subFields) { - Object.keys(valueConfig.subFields).forEach(subField => { - delete _caseData[subField]; - }); - } + Object.keys(valueConfig.subFields).forEach(subField => { + delete _caseData[subField]; + }); } } } diff --git a/src/main/steps/c100-rebuild/applicant/add-applicants/postController.ts b/src/main/steps/c100-rebuild/applicant/add-applicants/postController.ts index 073a158e06..82487073df 100644 --- a/src/main/steps/c100-rebuild/applicant/add-applicants/postController.ts +++ b/src/main/steps/c100-rebuild/applicant/add-applicants/postController.ts @@ -30,8 +30,8 @@ export default class AddApplicantPostController extends PostController, res: Response): Promise { const { applicantFirstName, applicantLastName } = req.body; req.session.userCase.applicantTemporaryFormData = { - TempFirstName: applicantFirstName, - TempLastName: applicantLastName, + TempFirstName: applicantFirstName as string, + TempLastName: applicantLastName as string, }; const fields = typeof this.fields === 'function' ? this.fields(req.session.userCase, req) : this.fields; const form = new Form(fields); @@ -46,23 +46,21 @@ export default class AddApplicantPostController extends PostController; - private contextNavigators; + private readonly contextNavigators; private applicantData; constructor(protected readonly fields: FormFields | FormFieldsFn) { @@ -49,7 +49,7 @@ export default class ApplicantCommonConfidentialityController { } } this.request.session.userCase.appl_allApplicants = this.applicantData; - if (this.request.session.errors && this.request.session.errors.length) { + if (this.request.session.errors?.length) { return this.parent.redirect(this.request, res, this.request.originalUrl); } if (this.request.body.saveAndComeLater) { @@ -59,7 +59,7 @@ export default class ApplicantCommonConfidentialityController { } } - private CofidentialityStartDataUpdate = (applicantId: string): [] => { + private readonly CofidentialityStartDataUpdate = (applicantId: string): [] => { return this.request.session.userCase.appl_allApplicants?.map(applicant => { const applicantInformation: C100Applicant = applicant; if (applicant['id'] === applicantId) { @@ -67,21 +67,19 @@ export default class ApplicantCommonConfidentialityController { applicantInformation['start'] = this.request['body']['start'] as C100Applicant['start']; if (this.request.body['start'] === YesOrNo.NO) { applicantInformation['contactDetailsPrivate'] = []; - } else { - if ( - (this.request['body']['contactDetailsPrivate'] as []) && - this.request.body['contactDetailsPrivate'] !== '' - ) { - const contactDetailSelection = this.request['body']['contactDetailsPrivate'] as []; - applicantInformation['contactDetailsPrivate'] = contactDetailSelection.filter(details => details !== ''); - } + } else if ( + (this.request['body']['contactDetailsPrivate'] as []) && + this.request.body['contactDetailsPrivate'] !== '' + ) { + const contactDetailSelection = this.request['body']['contactDetailsPrivate'] as []; + applicantInformation['contactDetailsPrivate'] = contactDetailSelection.filter(details => details !== ''); } } return applicantInformation; }) as []; }; - private CofidentialityStartAlternativeDataUpdate = (applicantId: string): [] => { + private readonly CofidentialityStartAlternativeDataUpdate = (applicantId: string): [] => { return this.request.session.userCase.appl_allApplicants?.map(applicant => { const applicantInformation = applicant; if (applicant['id'] === applicantId) { @@ -89,23 +87,21 @@ export default class ApplicantCommonConfidentialityController { applicantInformation['contactDetailsPrivate'] = [] as string[]; if (this.request.body['startAlternative'] === YesOrNo.NO) { applicantInformation['contactDetailsPrivateAlternative'] = [] as []; - } else { - if ( - (this.request['body']['contactDetailsPrivateAlternative'] as []) && - this.request.body['contactDetailsPrivateAlternative'] !== '' - ) { - const contactDetailSelection = this.request['body']['contactDetailsPrivateAlternative'] as []; - applicantInformation['contactDetailsPrivateAlternative'] = contactDetailSelection.filter( - details => details !== '' - ); - } + } else if ( + (this.request['body']['contactDetailsPrivateAlternative'] as []) && + this.request.body['contactDetailsPrivateAlternative'] !== '' + ) { + const contactDetailSelection = this.request['body']['contactDetailsPrivateAlternative'] as []; + applicantInformation['contactDetailsPrivateAlternative'] = contactDetailSelection.filter( + details => details !== '' + ); } } return applicantInformation; }) as []; }; - private CofidentialityDetailKnownDataUpdate = (applicantId: string): [] => { + private readonly CofidentialityDetailKnownDataUpdate = (applicantId: string): [] => { return this.request.session.userCase.appl_allApplicants?.map(applicant => { const applicantInformation = applicant; if (applicant['id'] === applicantId) { diff --git a/src/main/steps/c100-rebuild/c100sequence.ts b/src/main/steps/c100-rebuild/c100sequence.ts index 411cca87d9..9217016279 100644 --- a/src/main/steps/c100-rebuild/c100sequence.ts +++ b/src/main/steps/c100-rebuild/c100sequence.ts @@ -135,7 +135,7 @@ import ChildrenDetailsNavigationController from './child-details/navigationContr import OtherChildrenDetailsNavigationController from './child-details/other-children/navigationController'; import MIAMNavigationController from './miam/navigationController'; import OtherPersonsDetailsNavigationController from './other-person-details/navigationController'; -import OtherProceedingsNavigationController from './other-proceedings/navigationController'; +import PreviousProceedingsNavigationController from './other-proceedings/navigationController'; import RespondentsDetailsNavigationController from './respondent-details/navigationController'; import ApplicantNavigationController from './applicant/navigationController'; import AddPeoplePostContoller from './people/AddPeoplePostContoller'; @@ -321,18 +321,19 @@ export const C100Sequence: Step[] = [ url: C100_OTHER_PROCEEDINGS_CURRENT_PREVIOUS, showInSection: Sections.C100, getNextStep: caseData => - OtherProceedingsNavigationController.getNextUrl(C100_OTHER_PROCEEDINGS_CURRENT_PREVIOUS, caseData), + PreviousProceedingsNavigationController.getNextUrl(C100_OTHER_PROCEEDINGS_CURRENT_PREVIOUS, caseData), }, { url: C100_OTHER_PROCEEDINGS_DETAILS, showInSection: Sections.C100, - getNextStep: caseData => OtherProceedingsNavigationController.getNextUrl(C100_OTHER_PROCEEDINGS_DETAILS, caseData), + getNextStep: caseData => + PreviousProceedingsNavigationController.getNextUrl(C100_OTHER_PROCEEDINGS_DETAILS, caseData), }, { url: C100_OTHER_PROCEEDINGS_ORDER_DETAILS, showInSection: Sections.C100, getNextStep: (caseData: Partial, req?: AppRequest): PageLink => { - return OtherProceedingsNavigationController.getNextUrl( + return PreviousProceedingsNavigationController.getNextUrl( C100_OTHER_PROCEEDINGS_ORDER_DETAILS, caseData, req!.params @@ -343,7 +344,7 @@ export const C100Sequence: Step[] = [ url: C100_OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, showInSection: Sections.C100, getNextStep: (caseData: Partial, req?: AppRequest): PageLink => { - return OtherProceedingsNavigationController.getNextUrl( + return PreviousProceedingsNavigationController.getNextUrl( C100_OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, caseData, req!.params @@ -354,7 +355,7 @@ export const C100Sequence: Step[] = [ url: C100_OTHER_PROCEEDINGS_DOCUMENT_SUMMARY, showInSection: Sections.C100, getNextStep: caseData => - OtherProceedingsNavigationController.getNextUrl(C100_OTHER_PROCEEDINGS_DOCUMENT_SUMMARY, caseData), + PreviousProceedingsNavigationController.getNextUrl(C100_OTHER_PROCEEDINGS_DOCUMENT_SUMMARY, caseData), }, { url: C100_CHILD_ADDRESS, diff --git a/src/main/steps/c100-rebuild/check-your-answers/PayAndSubmitPostController.ts b/src/main/steps/c100-rebuild/check-your-answers/PayAndSubmitPostController.ts index abe3d5dd35..713f17a2b3 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/PayAndSubmitPostController.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/PayAndSubmitPostController.ts @@ -26,7 +26,7 @@ export default class PayAndSubmitPostController extends PostController'; const BOTTOM_TOP_3 = '
'; const BOTTOM_PADDING_CLOSE = '
'; -const TOP_PADDING_CLOSE = ''; const BREAK = '
'; test('htmlSelectorpositivetest', () => { @@ -25,7 +23,6 @@ test('htmlSelectorpositivetest', () => { expect(HTML.UNORDER_LIST).toBe(UNORDER_LIST), expect(HTML.UNORDER_LIST_END).toBe(UNORDER_LIST_END), expect(HTML.NESTED_LIST_ITEM).toBe(NESTED_LIST_ITEM), - expect(HTML.NESTED_LIST_ITEM_END).toBe(NESTED_LIST_ITEM_END), expect(HTML.H4).toBe(H4), expect(HTML.H3).toBe(H3), expect(HTML.P).toBe(P), @@ -36,7 +33,6 @@ test('htmlSelectorpositivetest', () => { expect(HTML.BOTTOM_PADDING_3).toBe(BOTTOM_PADDING_3), expect(HTML.BOTTOM_TOP_3).toBe(BOTTOM_TOP_3), expect(HTML.BOTTOM_PADDING_CLOSE).toBe(BOTTOM_PADDING_CLOSE), - expect(HTML.TOP_PADDING_CLOSE).toBe(TOP_PADDING_CLOSE), expect(HTML.BREAK).toBe(BREAK); }); test('htmlSelectornegativetest', () => { @@ -44,8 +40,7 @@ test('htmlSelectornegativetest', () => { expect(HTML.LIST_ITEM_END).not.toBe(LIST_ITEM), expect(HTML.UNORDER_LIST).not.toBe(UNORDER_LIST_END), expect(HTML.UNORDER_LIST_END).not.toBe(UNORDER_LIST), - expect(HTML.NESTED_LIST_ITEM).not.toBe(NESTED_LIST_ITEM_END), - expect(HTML.NESTED_LIST_ITEM_END).not.toBe(NESTED_LIST_ITEM), + expect(HTML.NESTED_LIST_ITEM).not.toBe(LIST_ITEM_END), expect(HTML.H4).not.toBe(H4_CLOSE), expect(HTML.H3).not.toBe(H3_CLOSE), expect(HTML.P).not.toBe(P_CLOSE), @@ -56,6 +51,5 @@ test('htmlSelectornegativetest', () => { expect(HTML.BOTTOM_PADDING_3).not.toBe(BOTTOM_TOP_3), expect(HTML.BOTTOM_TOP_3).not.toBe(BOTTOM_PADDING_3), expect(HTML.BOTTOM_PADDING_CLOSE).not.toBe(BOTTOM_TOP_3), - expect(HTML.TOP_PADDING_CLOSE).not.toBe(BOTTOM_TOP_3), expect(HTML.BREAK).not.toBe(RULER); }); diff --git a/src/main/steps/c100-rebuild/check-your-answers/common/htmlSelectors.ts b/src/main/steps/c100-rebuild/check-your-answers/common/htmlSelectors.ts index 285a6a891d..fd16dc6285 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/common/htmlSelectors.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/common/htmlSelectors.ts @@ -4,7 +4,6 @@ export enum HTML { UNORDER_LIST = '
    ', UNORDER_LIST_END = '
', NESTED_LIST_ITEM = '
  • ', - NESTED_LIST_ITEM_END = '
  • ', H1 = '

    ', H1_CLOSE = '

    ', H4 = '

    ', @@ -17,7 +16,6 @@ export enum HTML { BOTTOM_PADDING_3 = '
    ', BOTTOM_TOP_3 = '
    ', BOTTOM_PADDING_CLOSE = '
    ', - TOP_PADDING_CLOSE = '
    ', BREAK = '
    ', H4_SECTION_TITLE = '

    ', STATEMENT_OF_TRUTH_H2 = "

    ", diff --git a/src/main/steps/c100-rebuild/check-your-answers/helpers/InternationElementsHelper.ts b/src/main/steps/c100-rebuild/check-your-answers/helpers/InternationElementsHelper.ts index 685d9cc16c..3d2854e7f9 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/helpers/InternationElementsHelper.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/helpers/InternationElementsHelper.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { YesOrNo } from '../../../../app/case/definition'; import { HTML } from '../common/htmlSelectors'; import { getYesNoTranslation } from '../mainUtil'; @@ -12,44 +13,35 @@ const htmlValParser = (selection, subText, keys) => { }; /* eslint-disable @typescript-eslint/no-explicit-any */ const getValueUrlByKey = (key: string, userCase: any, language: any, Urls: any, keys: any) => { + let caseDataYesNo: YesOrNo | undefined; + let caseDataDetail: string | undefined; + let url: any; switch (key) { case 'liveOutSideUk': - return { - valueHtml: htmlValParser( - getYesNoTranslation(language, userCase['ie_internationalStart'], 'ydyntTranslation'), - userCase['ie_provideDetailsStart'], - keys - ), - changeUrl: Urls['C100_INTERNATIONAL_ELEMENTS_START'], - }; + caseDataYesNo = userCase['ie_internationalStart']; + caseDataDetail = userCase['ie_provideDetailsStart']; + url = Urls['C100_INTERNATIONAL_ELEMENTS_START']; + break; case 'basedOutSideEnglandOrWales': - return { - valueHtml: htmlValParser( - getYesNoTranslation(language, userCase['ie_internationalParents'], 'ydyntTranslation'), - userCase['ie_provideDetailsParents'], - keys - ), - changeUrl: Urls['C100_INTERNATIONAL_ELEMENTS_PARENTS'], - }; + caseDataYesNo = userCase['ie_internationalParents']; + caseDataDetail = userCase['ie_provideDetailsParents']; + url = Urls['C100_INTERNATIONAL_ELEMENTS_PARENTS']; + break; case 'anotherPersonSameOrder': - return { - valueHtml: htmlValParser( - getYesNoTranslation(language, userCase['ie_internationalJurisdiction'], 'gallaiTranslation'), - userCase['ie_provideDetailsJurisdiction'], - keys - ), - changeUrl: Urls['C100_INTERNATIONAL_ELEMENTS_JURISDICTION'], - }; + caseDataYesNo = userCase['ie_internationalJurisdiction']; + caseDataDetail = userCase['ie_provideDetailsJurisdiction']; + url = Urls['C100_INTERNATIONAL_ELEMENTS_JURISDICTION']; + break; case 'otherCountryRequestInfo': - return { - valueHtml: htmlValParser( - getYesNoTranslation(language, userCase['ie_internationalRequest'], 'oesTranslation'), - userCase['ie_provideDetailsRequest'], - keys - ), - changeUrl: Urls['C100_INTERNATIONAL_ELEMENTS_REQUEST'], - }; + caseDataYesNo = userCase['ie_internationalRequest']; + caseDataDetail = userCase['ie_provideDetailsRequest']; + url = Urls['C100_INTERNATIONAL_ELEMENTS_REQUEST']; + break; } + return { + valueHtml: htmlValParser(getYesNoTranslation(language, caseDataYesNo, 'ydyntTranslation'), caseDataDetail, keys), + changeUrl: url, + }; }; export const InternationElementHelper = (userCase, keys, Urls, language) => { const summaryData = [ diff --git a/src/main/steps/c100-rebuild/check-your-answers/helpers/courtOrderHelper.ts b/src/main/steps/c100-rebuild/check-your-answers/helpers/courtOrderHelper.ts index 741d95b580..b5bf2cefcc 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/helpers/courtOrderHelper.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/helpers/courtOrderHelper.ts @@ -3,12 +3,12 @@ import { HTML } from '../common/htmlSelectors'; export const courtOrderSubFieldParser = (userCase, keys, userKey, originalListItem) => { if (userCase.hasOwnProperty(userKey)) { - let returnAbleString = HTML.NESTED_LIST_ITEM + originalListItem + HTML.NESTED_LIST_ITEM_END; + let returnAbleString = HTML.NESTED_LIST_ITEM + originalListItem + HTML.LIST_ITEM_END; returnAbleString += HTML.UNORDER_LIST; returnAbleString += userCase[userKey] .filter(field => field !== '') .map(item => { - return HTML.NESTED_LIST_ITEM + keys[item] + HTML.NESTED_LIST_ITEM_END; + return HTML.NESTED_LIST_ITEM + keys[item] + HTML.LIST_ITEM_END; }); returnAbleString += HTML.UNORDER_LIST_END; return returnAbleString; diff --git a/src/main/steps/c100-rebuild/check-your-answers/helpers/miamHelper.ts b/src/main/steps/c100-rebuild/check-your-answers/helpers/miamHelper.ts index 9c0dd3e425..a2097258e4 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/helpers/miamHelper.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/helpers/miamHelper.ts @@ -32,7 +32,7 @@ type MiamSection = { changeUrl: string; }; -InstanceOfMiamHelper.__proto__.miamExemptionParser = (userCase, keys) => { +Object.getPrototypeOf(InstanceOfMiamHelper).miamExemptionParser = (userCase, keys) => { if (userCase.hasOwnProperty('miam_nonAttendanceReasons')) { const nonAttenDanceReaseons = userCase['miam_nonAttendanceReasons'] .flatMap(reason => keys[`${reason}Head`]) @@ -182,7 +182,7 @@ export const miamParentAndChildFieldParser = ( userCase[`${sessionKey}_${nonAttendance}_subfields`] .filter(field => field !== '') .map(item => { - return HTML.NESTED_LIST_ITEM + keys[`${nonAttendance}_subFields`][item] + HTML.NESTED_LIST_ITEM_END; + return HTML.NESTED_LIST_ITEM + keys[`${nonAttendance}_subFields`][item] + HTML.LIST_ITEM_END; }) + HTML.UNORDER_LIST_END ) @@ -256,7 +256,7 @@ export const MiamHelperDynamicEnteriesMapper = ( return mapper[key]; }; -InstanceOfMiamHelper.__proto__.miamExemptionParserDynamicEnteries = ( +Object.getPrototypeOf(InstanceOfMiamHelper).miamExemptionParserDynamicEnteries = ( userCase: Partial, keys: Record, language: string diff --git a/src/main/steps/c100-rebuild/check-your-answers/mainUtil.ts b/src/main/steps/c100-rebuild/check-your-answers/mainUtil.ts index d94c4e5728..a9133508b8 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/mainUtil.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/mainUtil.ts @@ -723,9 +723,7 @@ export const SafetyConcerns = ( language ): SummaryList | undefined => { const dataForConcerns = userCase.hasOwnProperty('c1A_safetyConernAbout') - ? userCase['c1A_safetyConernAbout']?.map( - concern => HTML.NESTED_LIST_ITEM + keys[concern] + HTML.NESTED_LIST_ITEM_END - ) + ? userCase['c1A_safetyConernAbout']?.map(concern => HTML.NESTED_LIST_ITEM + keys[concern] + HTML.LIST_ITEM_END) : ''; const SummaryData = [ { @@ -765,9 +763,7 @@ export const SafetyConcerns_child = ( language ): SummaryList | undefined => { const childSafetyConcerns = userCase.hasOwnProperty('c1A_concernAboutChild') - ? userCase['c1A_concernAboutChild']?.map( - concern => HTML.NESTED_LIST_ITEM + keys[concern] + HTML.NESTED_LIST_ITEM_END - ) + ? userCase['c1A_concernAboutChild']?.map(concern => HTML.NESTED_LIST_ITEM + keys[concern] + HTML.LIST_ITEM_END) : ''; let subFields = userCase['c1A_concernAboutChild'] as ANYTYPE; subFields = subFields @@ -941,9 +937,7 @@ export const SafetyConcerns_yours = ( language ): SummaryList | undefined => { const childSafetyConcerns = userCase.hasOwnProperty('c1A_concernAboutApplicant') - ? userCase['c1A_concernAboutApplicant']?.map( - concern => HTML.NESTED_LIST_ITEM + keys[concern] + HTML.NESTED_LIST_ITEM_END - ) + ? userCase['c1A_concernAboutApplicant']?.map(concern => HTML.NESTED_LIST_ITEM + keys[concern] + HTML.LIST_ITEM_END) : ''; let subFields = userCase?.['c1A_concernAboutApplicant'] as ANYTYPE; subFields = subFields diff --git a/src/main/steps/c100-rebuild/check-your-answers/util/miam.util.ts b/src/main/steps/c100-rebuild/check-your-answers/util/miam.util.ts index 9bd32cd9af..b30517063e 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/util/miam.util.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/util/miam.util.ts @@ -17,7 +17,7 @@ import { import { cy as UrgentHearingContentCy, en as UrgentHearingContentEn } from '../../miam/urgency/content'; import { cy as validReasonCy, en as validReasonEn } from '../../miam/valid-reason/content'; export class CommonDataLoader { - static DataFormatter = (args, storage) => { + static readonly DataFormatter = (args, storage) => { let mappedData = {}; storage.forEach(element => { if (element.split('_').length > 1) { @@ -29,7 +29,7 @@ export class CommonDataLoader { return mappedData; }; - static SessionToFieldGenerator = (key: string, userCase: CaseWithId): string[] => { + static readonly SessionToFieldGenerator = (key: string, userCase: CaseWithId): string[] => { const storage: string[] = []; if (_.isArray(userCase[key])) { userCase[key].forEach(element => { diff --git a/src/main/steps/c100-rebuild/check-your-answers/util/otherProceeding.util.ts b/src/main/steps/c100-rebuild/check-your-answers/util/otherProceeding.util.ts index 6e1eaa12d8..6b71d64471 100644 --- a/src/main/steps/c100-rebuild/check-your-answers/util/otherProceeding.util.ts +++ b/src/main/steps/c100-rebuild/check-your-answers/util/otherProceeding.util.ts @@ -9,28 +9,26 @@ import { HTML } from '../common/htmlSelectors'; import { getYesNoTranslation } from '../mainUtil'; /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +export const Mapper = (key, keys) => { + switch (key) { + case 'orderDetail': + return keys['courtIssuedLabel']; + case 'caseNo': + return keys['caseNumberLabel']; + case 'orderDate': + return keys['orderDateLabel']; + case 'currentOrder': + return keys['isCurrentOrderLabel']; + case 'orderCopy': + return keys['copyOfOrderLabel']; + case 'orderEndDate': + return keys['orderEndDateLabel']; + case 'orderDocument': + return keys['copy']; + } +}; export const IndividualOrderFieldsParser = (keys, order, language) => { const newOrders = order; - const Mapper = { - ['orderDetail']: { - question: keys['courtIssuedLabel'], - }, - ['caseNo']: { - question: keys['caseNumberLabel'], - }, - ['orderDate']: { - question: keys['orderDateLabel'], - }, - ['currentOrder']: { - question: keys['isCurrentOrderLabel'], - }, - ['orderCopy']: { - question: keys['copyOfOrderLabel'], - }, - ['orderEndDate']: { - question: keys['orderEndDateLabel'], - }, - }; let Val = ''; Object.entries(newOrders).forEach((entry, index) => { const key = entry[0]; @@ -38,11 +36,11 @@ export const IndividualOrderFieldsParser = (keys, order, language) => { const rulerForLastElement = Object.entries(newOrders).length > index + 1 ? HTML.RULER : '
    '; if (key !== 'id' && key !== 'orderDocument') { if (typeof entry[1] === 'object' && entry[1] !== null) { - const keyDetails = HTML.H4 + Mapper[key]?.question + HTML.H4_CLOSE; + const keyDetails = HTML.H4 + Mapper(key, keys) + HTML.H4_CLOSE; const valueDetails = HTML.P + DATE_FORMATTOR(value, language) + HTML.P_CLOSE; Val += keyDetails + valueDetails + rulerForLastElement; } else { - const keyDetails = HTML.H4 + Mapper[key]?.question + HTML.H4_CLOSE; + const keyDetails = HTML.H4 + Mapper(key, keys) + HTML.H4_CLOSE; let valueDetails = ''; if (key === 'currentOrder') { valueDetails = HTML.P + getYesNoTranslation(language, value, 'ieTranslation') + HTML.P_CLOSE; diff --git a/src/main/steps/c100-rebuild/child-details/childDetailPostController.ts b/src/main/steps/c100-rebuild/child-details/childDetailPostController.ts index b50570a4ca..063453f0e4 100644 --- a/src/main/steps/c100-rebuild/child-details/childDetailPostController.ts +++ b/src/main/steps/c100-rebuild/child-details/childDetailPostController.ts @@ -17,8 +17,8 @@ type ContextReference = { formRef: (caseData: Partial, childId: Chil type FeatureContext = { [key: string]: ContextReference }; @autobind export default class ChildDetailsPostController { - private parent; - private featureContext: FeatureContext; + private readonly parent; + private readonly featureContext: FeatureContext; private contextReference: ContextReference; constructor(protected readonly fields: FormFields | FormFieldsFn) { diff --git a/src/main/steps/c100-rebuild/childaddress/postController.test.ts b/src/main/steps/c100-rebuild/childaddress/postController.test.ts index f12dbefcc8..72358eb14f 100644 --- a/src/main/steps/c100-rebuild/childaddress/postController.test.ts +++ b/src/main/steps/c100-rebuild/childaddress/postController.test.ts @@ -70,7 +70,7 @@ describe('C100ChildPostCodePostController', () => { req.locals.C100Api.createCase.mockResolvedValueOnce({ id: '1234', caseTypeOfApplication: 'C100', - state: State.Draft, + state: State.AWAITING_SUBMISSION_TO_HMCTS, noOfDaysRemainingToSubmitCase: '3', }); when(config.get).calledWith('allowedCourts').mockReturnValue(['Swansea Civil Justice Centre']); @@ -101,7 +101,7 @@ describe('C100ChildPostCodePostController', () => { req.locals.C100Api.createCase.mockResolvedValueOnce({ id: '1234', caseTypeOfApplication: 'C100', - state: State.Draft, + state: State.AWAITING_SUBMISSION_TO_HMCTS, noOfDaysRemainingToSubmitCase: '3', }); when(config.get).calledWith('allowedCourts').mockReturnValue(['Swansea Civil Justice Centre']); @@ -115,7 +115,7 @@ describe('C100ChildPostCodePostController', () => { expect(req.session.userCase).toEqual({ caseId: '1234', caseTypeOfApplication: 'C100', - state: State.Draft, + state: State.AWAITING_SUBMISSION_TO_HMCTS, noOfDaysRemainingToSubmitCase: '3', }); expect(res.redirect).toHaveBeenCalled(); @@ -125,7 +125,7 @@ describe('C100ChildPostCodePostController', () => { req.locals.C100Api.createCase.mockResolvedValueOnce({ id: '1234', caseTypeOfApplication: 'C100', - state: State.Draft, + state: State.AWAITING_SUBMISSION_TO_HMCTS, noOfDaysRemainingToSubmitCase: '3', }); when(config.get).calledWith('allowedCourts').mockReturnValue(['*']); @@ -141,7 +141,7 @@ describe('C100ChildPostCodePostController', () => { expect(req.session.userCase).toEqual({ caseId: '1234', caseTypeOfApplication: 'C100', - state: State.Draft, + state: State.AWAITING_SUBMISSION_TO_HMCTS, noOfDaysRemainingToSubmitCase: '3', }); expect(res.redirect).toHaveBeenCalled(); diff --git a/src/main/steps/c100-rebuild/childaddress/postController.ts b/src/main/steps/c100-rebuild/childaddress/postController.ts index d154f48377..24f8e15487 100644 --- a/src/main/steps/c100-rebuild/childaddress/postController.ts +++ b/src/main/steps/c100-rebuild/childaddress/postController.ts @@ -19,7 +19,7 @@ export default class C100ChildPostCodePostController extends PostController {% for abuseReason in listOfAbuseReasons %} -
  • {{ abuseReason.abuseEvidenceType }}
  • +
  • {{ abuseReason.abuseEvidenceType }} {% if abuseReason.abuseEvidenceReasons %}
      {% for evidence in abuseReason.abuseEvidenceReasons %} @@ -19,6 +19,7 @@ {% endfor %}
    {% endif %} +
  • {% endfor %}
    diff --git a/src/main/steps/c100-rebuild/miam/navigationController.ts b/src/main/steps/c100-rebuild/miam/navigationController.ts index 36d9b885dd..b3e23db57a 100644 --- a/src/main/steps/c100-rebuild/miam/navigationController.ts +++ b/src/main/steps/c100-rebuild/miam/navigationController.ts @@ -29,7 +29,7 @@ import { class MIAMNavigationController { protected selectedPages: MiamNonAttendReason[] = []; - private pages: Record> = { + private readonly pages: Record> = { [MiamNonAttendReason.DOMESTIC]: { url: C100_MIAM_MIAM_DOMESTIC_ABUSE, dataReference: 'miam_domesticAbuse', @@ -102,12 +102,7 @@ class MIAMNavigationController { break; } case C100_MIAM_OTHER: { - url = - caseData.miam_notAttendingReasons === Miam_notAttendingReasons.canNotAccessMediator - ? C100_MIAM_NO_ACCESS_MEDIATOR - : this.checkForAnyValidReason(caseData) - ? C100_MIAM_EXCEMPTION_SUMMARY - : C100_MIAM_GET_MEDIATOR; + url = this.navigationFromOtherScreen(caseData); break; } case C100_MIAM_NO_ACCESS_MEDIATOR: { @@ -118,15 +113,7 @@ class MIAMNavigationController { break; } case C100_MIAM_PREVIOUS_ATTENDANCE: { - if (caseData.miam_previousAttendance === Miam_previousAttendance.fourMonthsPriorAttended) { - url = applyParms(C100_MIAM_UPLOAD_EVIDENCE_FOR_ATTENDING) as PageLink; - } else if (caseData.miam_previousAttendance === Miam_previousAttendance.miamExamptionApplied) { - url = C100_MIAM_PREVIOUS_MIAM_ATTENDANCE_OR_NCDR; - } else { - url = - this.getNextPageUrl(C100_MIAM_PREVIOUS_ATTENDANCE) || - (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); - } + url = this.navigationFromPreviousAttendance(caseData); break; } case C100_MIAM_PREVIOUS_MIAM_ATTENDANCE_OR_NCDR: { @@ -142,23 +129,11 @@ class MIAMNavigationController { break; } case C100_MIAM_MIAM_DOMESTIC_ABUSE: { - if (!caseData.miam_domesticAbuse?.includes(DomesticAbuseExemptions.NONE)) { - url = applyParms(C100_MIAM_PROVIDING_DA_EVIDENCE) as PageLink; - } else { - url = - this.getNextPageUrl(currentPageUrl) ?? - (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); - } + url = this.navigationFromDomesticAbuseScreen(caseData, currentPageUrl); break; } case C100_MIAM_PROVIDING_DA_EVIDENCE: { - if (caseData.miam_canProvideDomesticAbuseEvidence === YesOrNo.YES) { - url = applyParms(C100_MIAM_UPLOAD_DA_EVIDENCE) as PageLink; - } else { - url = - this.getNextPageUrl(C100_MIAM_MIAM_DOMESTIC_ABUSE) ?? - (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); - } + url = this.navigationFromProvidingDAEvidence(caseData); break; } case C100_MIAM_UPLOAD_DA_EVIDENCE: { @@ -170,7 +145,7 @@ class MIAMNavigationController { } default: { url = - this.getNextPageUrl(currentPageUrl) || + this.getNextPageUrl(currentPageUrl) ?? (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); break; } @@ -179,13 +154,59 @@ class MIAMNavigationController { return url; } + private navigationFromDomesticAbuseScreen(caseData: Partial, currentPageUrl: PageLink): PageLink { + let url: PageLink; + if (!caseData.miam_domesticAbuse?.includes(DomesticAbuseExemptions.NONE)) { + url = applyParms(C100_MIAM_PROVIDING_DA_EVIDENCE) as PageLink; + } else { + url = + this.getNextPageUrl(currentPageUrl) ?? + (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); + } + return url; + } + + private navigationFromProvidingDAEvidence(caseData: Partial): PageLink { + let url: PageLink; + if (caseData.miam_canProvideDomesticAbuseEvidence === YesOrNo.YES) { + url = applyParms(C100_MIAM_UPLOAD_DA_EVIDENCE) as PageLink; + } else { + url = + this.getNextPageUrl(C100_MIAM_MIAM_DOMESTIC_ABUSE) ?? + (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); + } + return url; + } + + private navigationFromPreviousAttendance(caseData: Partial): PageLink { + let url: PageLink; + if (caseData.miam_previousAttendance === Miam_previousAttendance.fourMonthsPriorAttended) { + url = applyParms(C100_MIAM_UPLOAD_EVIDENCE_FOR_ATTENDING) as PageLink; + } else if (caseData.miam_previousAttendance === Miam_previousAttendance.miamExamptionApplied) { + url = C100_MIAM_PREVIOUS_MIAM_ATTENDANCE_OR_NCDR; + } else { + url = + this.getNextPageUrl(C100_MIAM_PREVIOUS_ATTENDANCE) ?? + (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); + } + return url; + } + + private navigationFromOtherScreen(caseData: Partial): PageLink { + if (caseData.miam_notAttendingReasons === Miam_notAttendingReasons.canNotAccessMediator) { + return C100_MIAM_NO_ACCESS_MEDIATOR; + } else { + return this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR; + } + } + private checkForOtherExemption(caseData: Partial, currentPageUrl: PageLink): PageLink { let url: PageLink; if (caseData?.miam_nonAttendanceReasons?.includes(MiamNonAttendReason.EXEMPT)) { url = C100_MIAM_OTHER; } else { url = - this.getNextPageUrl(currentPageUrl) || + this.getNextPageUrl(currentPageUrl) ?? (this.checkForAnyValidReason(caseData) ? C100_MIAM_EXCEMPTION_SUMMARY : C100_MIAM_GET_MEDIATOR); } return url; diff --git a/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.test.ts b/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.test.ts new file mode 100644 index 0000000000..716b71658f --- /dev/null +++ b/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.test.ts @@ -0,0 +1,196 @@ +import { mockRequest } from '../../../../../test/unit/utils/mockRequest'; +import { mockResponse } from '../../../../../test/unit/utils/mockResponse'; +import { CaseApi } from '../../../../app/case/CaseApi'; + +import MIAMAttendanceEvidenceUploadController from './postController'; + +const uploadDocumentMock = jest.spyOn(CaseApi.prototype, 'uploadDocument'); + +describe('MIAMAttendanceEvidenceUploadController > postController', () => { + let controller; + let req; + let res; + + beforeEach(() => { + controller = new MIAMAttendanceEvidenceUploadController({}); + req = mockRequest(); + res = mockResponse(); + }); + + test('should upload document and redirect', async () => { + req.body = { uploadFile: true, onlyContinue: true }; + req.files = { miam_previousAttendanceEvidenceDoc: { name: 'test.jpg', data: '', mimetype: 'text' } }; + + uploadDocumentMock.mockResolvedValue({ + status: 'Success', + document: { + document_url: 'test/1234', + document_binary_url: 'binary/test/1234', + document_filename: 'test_document', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + }); + + await controller.post(req, res); + + expect(req.session.userCase.miam_previousAttendanceEvidenceDoc).toStrictEqual({ + document_url: 'test/1234', + document_binary_url: 'binary/test/1234', + document_filename: 'test_document', + document_hash: '1234', + document_creation_date: '1/1/2024', + }); + expect(res.redirect).toHaveBeenCalledWith('/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr'); + expect(req.session.errors).toStrictEqual([]); + }); + + test('should not upload document and add error if document already present', async () => { + req.body = { uploadFile: true }; + req.files = { miam_previousAttendanceEvidenceDoc: { name: 'test.jpg', data: '', mimetype: 'text' } }; + + req.session.userCase = { + miam_previousAttendanceEvidenceDoc: { + document_url: 'test2/1234', + document_binary_url: 'binary/test2/1234', + document_filename: 'test_document_2', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + }; + + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'multipleFiles', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + + test('should not upload document and add error if no file present', async () => { + req.body = { uploadFile: true }; + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'required', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + + test('should set error when document upload status is not Success', async () => { + req.body = { uploadFile: true }; + req.files = { miam_previousAttendanceEvidenceDoc: { name: 'test.jpg', data: '', mimetype: 'text' } }; + + uploadDocumentMock.mockResolvedValue({ + status: 'Failure', + document: { + document_url: 'test2/1234', + document_binary_url: 'binary/test2/1234', + document_filename: 'test_document_2', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + }); + + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'uploadError', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + + test('should catch error when uploading document', async () => { + req.body = { uploadFile: true }; + + req.files = { miam_previousAttendanceEvidenceDoc: { name: 'test.jpg', data: '', mimetype: 'text' } }; + + uploadDocumentMock.mockRejectedValue({ + status: 'Failure', + }); + + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'uploadError', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + + test('should redirect without error when onlyContinue is true and document is present', async () => { + req.body = { onlyContinue: true }; + req.session.userCase = { + miam_previousAttendanceEvidenceDoc: { + document_url: 'test2/1234', + document_binary_url: 'binary/test2/1234', + document_filename: 'test_document_2', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + }; + + await controller.post(req, res); + + expect(res.redirect).toHaveBeenCalledWith('/dashboard'); + expect(req.session.errors).toStrictEqual([]); + }); + + test('should redirect with error when onlyContinue is true and document is not present', async () => { + req.body = { onlyContinue: true }; + + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'required', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + test('should catch error when uploading non allowed document type', async () => { + req.body = { uploadFile: true }; + + req.files = { miam_previousAttendanceEvidenceDoc: { name: 'test.rtf', data: '', mimetype: 'text' } }; + + uploadDocumentMock.mockRejectedValue({ + status: 'Failure', + }); + + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'invalidFileFormat', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + test('should catch error when uploading beyond allowed size document', async () => { + req.body = { uploadFile: true }; + + req.files = { + miam_previousAttendanceEvidenceDoc: { name: 'test.jpg', data: '', size: '3000000000000000', mimetype: 'text' }, + }; + + uploadDocumentMock.mockRejectedValue({ + status: 'Failure', + }); + + await controller.post(req, res); + + expect(req.session.errors).toStrictEqual([ + { + errorType: 'maxFileSize', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); +}); diff --git a/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.ts b/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.ts index 74902159dc..9c8b0367c8 100644 --- a/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.ts +++ b/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/postController.ts @@ -63,7 +63,6 @@ export default class MIAMAttendanceEvidenceUploadController extends PostControll try { const response = await caseApi(req.session.user, req.locals.logger).uploadDocument(formData); - if (response.status !== 'Success') { handleEvidenceDocError('uploadError', req, 'miam_previousAttendanceEvidenceDoc'); return super.redirect(req, res); diff --git a/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/routeGuards.test.ts b/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/routeGuards.test.ts new file mode 100644 index 0000000000..4661c5461c --- /dev/null +++ b/src/main/steps/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr/routeGuards.test.ts @@ -0,0 +1,76 @@ +import { mockRequest } from '../../../../../test/unit/utils/mockRequest'; +import { mockResponse } from '../../../../../test/unit/utils/mockResponse'; +import { CaseApi } from '../../../../app/case/CaseApi'; + +import { routeGuard } from './routeGuard'; + +const deleteDocumentMock = jest.spyOn(CaseApi.prototype, 'deleteDocument'); + +describe('C100-rebuild > MIAM > miam_previousAttendanceEvidenceDoc > upload-evidence > routeGuard', () => { + let req; + let res; + const next = jest.fn(); + + beforeEach(() => { + req = mockRequest(); + res = mockResponse(); + }); + + test('should delete document', async () => { + req.params.removeFileId = '1234'; + req.session.userCase.miam_previousAttendanceEvidenceDoc = [ + { + document_url: 'test2/1234', + document_binary_url: 'binary/test2/1234', + document_filename: 'test_document_2', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + ]; + + deleteDocumentMock.mockResolvedValue(); + await routeGuard.get(req, res, next); + + expect(req.session.save).toHaveBeenCalled(); + expect(req.session.userCase.miam_previousAttendanceEvidenceDoc).toStrictEqual(undefined); + expect(req.session.errors).toStrictEqual([]); + }); + + test('should catch error when deleting document', async () => { + req.params.removeFileId = '1234'; + req.session.userCase.miam_previousAttendanceEvidenceDoc = [ + { + document_url: 'test2/1234', + document_binary_url: 'binary/test2/1234', + document_filename: 'test_document_2', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + ]; + + deleteDocumentMock.mockRejectedValue({ status: 'Error' }); + await routeGuard.get(req, res, next); + + expect(res.redirect).toHaveBeenCalledWith('/c100-rebuild/miam/upload-evidence-of-attending-miam-or-ncdr'); + expect(req.session.userCase.miam_previousAttendanceEvidenceDoc).toStrictEqual([ + { + document_url: 'test2/1234', + document_binary_url: 'binary/test2/1234', + document_filename: 'test_document_2', + document_hash: '1234', + document_creation_date: '1/1/2024', + }, + ]); + expect(req.session.errors).toStrictEqual([ + { + errorType: 'deleteFile', + propertyName: 'miam_previousAttendanceEvidenceDoc', + }, + ]); + }); + + test('should call next if no removeFileId present', async () => { + await routeGuard.get(req, res, next); + expect(next).toHaveBeenCalled(); + }); +}); diff --git a/src/main/steps/c100-rebuild/miam/upload/getController.ts b/src/main/steps/c100-rebuild/miam/upload/getController.ts index 3a319ea870..921a72aa0e 100644 --- a/src/main/steps/c100-rebuild/miam/upload/getController.ts +++ b/src/main/steps/c100-rebuild/miam/upload/getController.ts @@ -5,9 +5,7 @@ import { FieldPrefix } from '../../../../app/case/case'; import { AppRequest } from '../../../../app/controller/AppRequest'; import { GetController, TranslationFn } from '../../../../app/controller/GetController'; import { C100_MIAM_UPLOAD } from '../../../urls'; -export type URL_OF_FILE_UPLOAD = string; //eslint-disable-next-line @typescript-eslint/no-explicit-any -export type AnyType = any; @autobind export default class DocumentUpload extends GetController { diff --git a/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.test.ts b/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.test.ts index b7eb36f8db..414b0c3270 100644 --- a/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.test.ts +++ b/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.test.ts @@ -140,6 +140,95 @@ describe('applicant1 > address > lookup > SelectAddressPostController', () => { generateContent(commonContent); await controller.post(req, res); + expect(res.redirect).toHaveBeenCalled(); + }); + test('should call super constructor with no params', async () => { + const mockFormContent = { + fields: {}, + } as unknown as FormContent; + const controller = new SelectAddressPostController(mockFormContent.fields); + const language = 'en'; + const req = mockRequest({ + params: { + otherPersonId: '480e8295-4c5b-4b9b-827f-f9be423ec1c5', + }, + body: { + firstName: 'Dummy ', + id: '480e8295-4c5b-4b9b-827f-f9be423ec1c5', + lastName: 'Test1', + address: { + PostCode: 'AG11NB', + AddressLine1: 'UK', + AddressLine2: 'UK1', + PostTown: 'London', + County: 'UK', + }, + selectedAddress: 2, + selectAddress: '0', + addresses: [ + { + fullAddress: 'FLAT 20, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 20, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + { + fullAddress: 'FLAT 21, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 21, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + ], + onlycontinue: true, + }, + session: { + lang: language, + addresses: [ + { + fullAddress: 'FLAT 20, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 20, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + { + fullAddress: 'FLAT 21, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 21, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + ], + userCase: { + oprs_otherPersons: [ + { + id: '480e8295-4c5b-4b9b-827f-f9be423ec1c5', + firstName: 'Dummy', + lastName: 'Test1', + address: { + PostCode: 'AG11NB', + AddressLine1: 'UK', + AddressLine2: 'UK1', + PostTown: 'London', + County: 'UK', + }, + applicantSelectedAddress: 2, + }, + ], + }, + }, + }); + delete req.params; + const res = mockResponse(); + generateContent(commonContent); + await controller.post(req, res); + expect(res.redirect).toHaveBeenCalled(); }); }); diff --git a/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.ts b/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.ts index 1f1e9376c4..ad9d7412f9 100644 --- a/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.ts +++ b/src/main/steps/c100-rebuild/other-person-details/address/select/SelectAddressPostController.ts @@ -16,7 +16,7 @@ export default class SelectAddressPostController extends PostController, res: Response): Promise { - const { otherPersonId } = req?.params; + const { otherPersonId } = req?.params ?? ''; const form = new Form(getUpdatedForm(req.session.userCase, otherPersonId).fields as FormFields); const { onlycontinue, ...formFields } = req.body; const { _csrf, ...formData } = form.getParsedBody(formFields); diff --git a/src/main/steps/c100-rebuild/other-proceedings/documentUpload/postController.ts b/src/main/steps/c100-rebuild/other-proceedings/documentUpload/postController.ts index 1bee509aca..168fc2a6ff 100644 --- a/src/main/steps/c100-rebuild/other-proceedings/documentUpload/postController.ts +++ b/src/main/steps/c100-rebuild/other-proceedings/documentUpload/postController.ts @@ -2,15 +2,14 @@ import autobind from 'autobind-decorator'; import { Response } from 'express'; import FormData from 'form-data'; -import { isNull } from 'lodash'; import { DocumentUploadResponse, caseApi } from '../../../../app/case/C100CaseApi'; import { C100OrderInterface, C100OrderTypeKeyMapper, C100OrderTypes } from '../../../../app/case/definition'; import { AppRequest } from '../../../../app/controller/AppRequest'; import { AnyObject, PostController } from '../../../../app/controller/PostController'; import { FormFields, FormFieldsFn } from '../../../../app/form/Form'; -import { isFileSizeGreaterThanMaxAllowed, isValidFileFormat } from '../../../../app/form/validation'; import { applyParms } from '../../../../steps/common/url-parser'; +import { validate } from '../../../../steps/tasklistresponse/proceedings/documentUpload/postController'; import { C100_OTHER_PROCEEDINGS_DOCUMENT_UPLOAD } from '../../../urls'; const C100OrderTypeNameMapper = { @@ -96,22 +95,7 @@ export default class UploadDocumentController extends PostController } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types public async validateFileAndUpload(files, req, res, orderType, orderId, courtOrderType, courtOrderId): Promise { - if (isNull(files) || files === undefined) { - this.uploadFileError(req, res, orderType, orderId, { - propertyName: 'document', - errorType: 'required', - }); - } else if (!isValidFileFormat(files)) { - this.uploadFileError(req, res, orderType, orderId, { - propertyName: 'document', - errorType: 'fileFormat', - }); - } else if (isFileSizeGreaterThanMaxAllowed(files)) { - this.uploadFileError(req, res, orderType, orderId, { - propertyName: 'document', - errorType: 'fileSize', - }); - } else { + if (validate(files, req, res, orderType, orderId, false)) { req.session.errors = []; const { documents }: any = files; @@ -191,31 +175,4 @@ export default class UploadDocumentController extends PostController public buildOrderTypeName(courtOrderType: C100OrderTypes): string { return C100OrderTypeNameMapper[courtOrderType].split(' ').join('_').toLowerCase(); } - - /** - * It's a function that handles errors that occur during the upload process - * @param req - AppRequest - * @param res - Response> - * @param {string} [errorMessage] - The error message to be displayed. - */ - - private uploadFileError( - req: AppRequest, - res: Response>, - orderType: string, - orderId: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - errObj: any - ) { - /** - * @Insert @Error @here - */ - req.session.errors = [errObj]; - req.session.save(err => { - if (err) { - throw err; - } - res.redirect(applyParms(C100_OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, { orderType, orderId })); - }); - } } diff --git a/src/main/steps/c100-rebuild/other-proceedings/navigationController.ts b/src/main/steps/c100-rebuild/other-proceedings/navigationController.ts index 3be8a3c0dd..843b39ee47 100644 --- a/src/main/steps/c100-rebuild/other-proceedings/navigationController.ts +++ b/src/main/steps/c100-rebuild/other-proceedings/navigationController.ts @@ -20,7 +20,7 @@ import { } from '../../urls'; import { isAnyOrderWithOrderCopy } from './util'; -class OtherProceedingsNavigationController { +class PreviousProceedingsNavigationController { private selectedOrderTypes: C100OrderTypes[] | [] = []; private orders: C100OrderInterface[] | [] = []; private orderType = ''; @@ -101,17 +101,14 @@ class OtherProceedingsNavigationController { const nextOrderType = this.getNextOrderType(); if (nextOrderType) { url = applyParms(C100_OTHER_PROCEEDINGS_ORDER_DETAILS, { orderType: nextOrderType }); + } else if (isAnyOrderWithOrderCopy(caseData?.op_otherProceedings?.order)) { + // check at last if there were any previous order types having at least an order with order copy + url = C100_OTHER_PROCEEDINGS_DOCUMENT_SUMMARY; } else { - // there is no other order type present - if (isAnyOrderWithOrderCopy(caseData?.op_otherProceedings?.order)) { - // check at last if there were any previous order types having at least an order with order copy - url = C100_OTHER_PROCEEDINGS_DOCUMENT_SUMMARY; - } else { - url = - caseData.sq_writtenAgreement === YesOrNo.NO && caseData.miam_otherProceedings === YesOrNo.YES - ? C100_TYPE_ORDER_SELECT_COURT_ORDER - : (applyParms(C1A_SAFETY_CONCERNS_CONCERN_GUIDANCE, { root: RootContext.C100_REBUILD }) as PageLink); - } + url = + caseData.sq_writtenAgreement === YesOrNo.NO && caseData.miam_otherProceedings === YesOrNo.YES + ? C100_TYPE_ORDER_SELECT_COURT_ORDER + : (applyParms(C1A_SAFETY_CONCERNS_CONCERN_GUIDANCE, { root: RootContext.C100_REBUILD }) as PageLink); } } return url; @@ -139,4 +136,4 @@ class OtherProceedingsNavigationController { } } -export default new OtherProceedingsNavigationController(); +export default new PreviousProceedingsNavigationController(); diff --git a/src/main/steps/c100-rebuild/pageStepConfig.ts b/src/main/steps/c100-rebuild/pageStepConfig.ts deleted file mode 100644 index 6691d627ee..0000000000 --- a/src/main/steps/c100-rebuild/pageStepConfig.ts +++ /dev/null @@ -1,53 +0,0 @@ -export interface Page { - id: string; - url: string; -} -export interface PageSteps extends Page { - id: string; - url: string; - steps?: Page[]; -} - -import { - C100_MIAM_CHILD_PROTECTION, - C100_MIAM_EXCEMPTION_SUMMARY, - C100_MIAM_GENERAL_REASONS, - C100_MIAM_MIAM_DOMESTIC_ABUSE, - C100_MIAM_OTHER, - C100_MIAM_PREVIOUS_ATTENDANCE, - C100_MIAM_URGENCY, -} from '../../../main/steps/urls'; -import { MiamNonAttendReason } from '../../app/case/definition'; - -export const PageStepsConfig: PageSteps[] = [ - { - id: C100_MIAM_GENERAL_REASONS, - url: C100_MIAM_GENERAL_REASONS, - steps: [ - { - id: MiamNonAttendReason.DOMESTIC, - url: C100_MIAM_MIAM_DOMESTIC_ABUSE, - }, - { - id: MiamNonAttendReason.CHILD_PROTECTION, - url: C100_MIAM_CHILD_PROTECTION, - }, - { - id: MiamNonAttendReason.URGENT, - url: C100_MIAM_URGENCY, - }, - { - id: MiamNonAttendReason.PREV_MIAM, - url: C100_MIAM_PREVIOUS_ATTENDANCE, - }, - { - id: MiamNonAttendReason.EXEMPT, - url: C100_MIAM_OTHER, - }, - { - id: MiamNonAttendReason.NONE, - url: C100_MIAM_EXCEMPTION_SUMMARY, - }, - ], - }, -]; diff --git a/src/main/steps/c100-rebuild/people/AddPeoplePostContoller.ts b/src/main/steps/c100-rebuild/people/AddPeoplePostContoller.ts index 85de77b7a6..ac81eb05a5 100644 --- a/src/main/steps/c100-rebuild/people/AddPeoplePostContoller.ts +++ b/src/main/steps/c100-rebuild/people/AddPeoplePostContoller.ts @@ -28,9 +28,9 @@ type FeatureContext = { [key: string]: ContextReference }; @autobind export default class AddPersonPostController { - private parent; + private readonly parent; private request: AppRequest; - private featureContext: FeatureContext; + private readonly featureContext: FeatureContext; private contextReference: ContextReference; constructor(protected readonly fields: FormFields | FormFieldsFn) { diff --git a/src/main/steps/c100-rebuild/people/LookupAndManualAddressPostController.ts b/src/main/steps/c100-rebuild/people/LookupAndManualAddressPostController.ts index 82280e7853..d977309735 100644 --- a/src/main/steps/c100-rebuild/people/LookupAndManualAddressPostController.ts +++ b/src/main/steps/c100-rebuild/people/LookupAndManualAddressPostController.ts @@ -20,8 +20,8 @@ type FeatureContext = { [key: string]: ContextReference }; @autobind export default class LookupAndManualAddressPostController { - private parent; - private featureContext: FeatureContext; + private readonly parent; + private readonly featureContext: FeatureContext; private contextReference: ContextReference; constructor(protected readonly fields: FormFields | FormFieldsFn) { diff --git a/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.test.ts b/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.test.ts index 5abbc0d609..5d2a22cdca 100644 --- a/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.test.ts +++ b/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.test.ts @@ -149,3 +149,96 @@ describe('respondent > address > lookup > SelectAddressPostController', () => { expect(res.redirect).toHaveBeenCalled(); }); }); + +test('should call super constructor with no params', async () => { + const mockFormContent = { + fields: {}, + } as unknown as FormContent; + const controller = new SelectAddressPostController(mockFormContent.fields); + const language = 'en'; + + const req = mockRequest({ + params: { + respondentId: undefined, + }, + body: { + firstName: 'Dummy ', + id: '480e8295-4c5b-4b9b-827f-f9be423ec1c5', + lastName: 'Test1', + selectAddress: '0', + address: { + AddressLine1: 'UK', + AddressLine2: 'UK1', + PostTown: 'London', + County: 'UK', + PostCode: 'AG11NB', + addressHistory: 'Yes', + provideDetailsOfPreviousAddresses: 'NA', + selectedAddress: 2, + }, + addresses: [ + { + fullAddress: 'FLAT 20, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 20, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + { + fullAddress: 'FLAT 21, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 21, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + ], + onlycontinue: true, + }, + session: { + lang: language, + addresses: [ + { + fullAddress: 'FLAT 20, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 20, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + { + fullAddress: 'FLAT 21, THAMES VIEW, CENTREWAY APARTMENTS, AXON PLACE, ILFORD, IG1 1NB', + street1: 'FLAT 21, THAMES VIEW, AXON PLACE', + street2: 'CENTREWAY APARTMENTS', + town: 'ILFORD', + county: 'REDBRIDGE', + postcode: 'IG1 1NB', + }, + ], + userCase: { + resp_Respondents: [ + { + firstName: 'Dummy ', + id: '480e8295-4c5b-4b9b-827f-f9be423ec1c5', + lastName: 'Test1', + address: { + AddressLine1: 'UK', + AddressLine2: 'UK1', + PostTown: 'London', + County: 'UK', + PostCode: 'AG11NB', + addressHistory: 'Yes', + provideDetailsOfPreviousAddresses: 'NA', + selectedAddress: 2, + }, + }, + ], + }, + }, + }); + delete req.params; + const res = mockResponse(); + await controller.post(req, res); + expect(res.redirect).toHaveBeenCalled(); +}); diff --git a/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.ts b/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.ts index f26c6793e2..8c417848aa 100644 --- a/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.ts +++ b/src/main/steps/c100-rebuild/respondent-details/address/select/SelectAddressPostController.ts @@ -16,7 +16,7 @@ export default class SelectAddressPostController extends PostController, res: Response): Promise { - const { respondentId } = req?.params; + const { respondentId } = req?.params ?? ''; const form = new Form(getUpdatedForm(req.session.userCase, respondentId).fields as FormFields); const { onlycontinue, ...formFields } = req.body; const { _csrf, ...formData } = form.getParsedBody(formFields); diff --git a/src/main/steps/c100-rebuild/start/routeGuard.test.ts b/src/main/steps/c100-rebuild/start/routeGuard.test.ts new file mode 100644 index 0000000000..3fa98d97c1 --- /dev/null +++ b/src/main/steps/c100-rebuild/start/routeGuard.test.ts @@ -0,0 +1,75 @@ +import axios from 'axios'; + +import { mockRequest } from '../../../../test/unit/utils/mockRequest'; +import { mockResponse } from '../../../../test/unit/utils/mockResponse'; + +import { routeGuard } from './routeGuard'; +jest.mock('axios'); + +const mockedAxios = axios as jest.Mocked; + +describe('c100Application start Route Guard', () => { + test('Should render the page when the guard validation passes', async () => { + const req = mockRequest({ + session: { + userCase: {}, + }, + }); + const res = mockResponse(); + jest.mock('../../../app/auth/service/get-service-auth-token', () => ({ + getServiceAuthToken: jest.fn(() => 'mock-service-auth-token'), + })); + mockedAxios.get.mockResolvedValueOnce({ + data: { + feeAmount: '232', + errorRetrievingResponse: '', + }, + }); + const next = jest.fn(); + await routeGuard.get(req, res, next); + expect(req.session.userCase).toEqual({ + c100ApplicationFees: '232', + }); + expect(req.session.userCase.c100ApplicationFees).toBe('232'); + expect(next).toHaveBeenCalled(); + }); + test('Should render the page when the guard validation passes with out usercase', async () => { + const req = mockRequest({ + session: { + userCase: {}, + }, + }); + const res = mockResponse(); + jest.mock('../../../app/auth/service/get-service-auth-token', () => ({ + getServiceAuthToken: jest.fn(() => 'mock-service-auth-token'), + })); + mockedAxios.get.mockResolvedValueOnce({ + data: { + feeAmount: '232', + errorRetrievingResponse: '', + }, + }); + const next = jest.fn(); + await routeGuard.get(req, res, next); + expect(req.session.userCase).toEqual({ + c100ApplicationFees: '232', + }); + expect(req.session.userCase.c100ApplicationFees).toBe('232'); + expect(next).toHaveBeenCalled(); + }); + + test('Should render the page when the guard validation fails', async () => { + const req = mockRequest(); + const res = mockResponse(); + const oldUserCase = req.session.userCase; + mockedAxios.get.mockRejectedValueOnce; + req.locals.C100Api.updateCase.mockRejectedValue({ + message: 'MOCK_ERROR', + response: { status: 500, data: 'Error' }, + }); + const next = jest.fn(); + await routeGuard.get(req, res, next); + expect(req.session.userCase).toEqual(oldUserCase); + expect(next).toHaveBeenCalled(); + }); +}); diff --git a/src/main/steps/c100-rebuild/uploadDocumentController.ts b/src/main/steps/c100-rebuild/uploadDocumentController.ts index c51a67eda3..3c8a00dc21 100644 --- a/src/main/steps/c100-rebuild/uploadDocumentController.ts +++ b/src/main/steps/c100-rebuild/uploadDocumentController.ts @@ -17,7 +17,7 @@ import { C100_CONSENT_ORDER_UPLOAD, C100_MIAM_UPLOAD } from '../urls'; PostDocumentUploader method */ @autobind export default class UploadDocumentController { - private parent; + private readonly parent; constructor(protected readonly fields: FormFields | FormFieldsFn) { this.parent = new PostController(fields); } diff --git a/src/main/steps/common/common.content.ts b/src/main/steps/common/common.content.ts index 869b53ed60..e05cef6cf8 100644 --- a/src/main/steps/common/common.content.ts +++ b/src/main/steps/common/common.content.ts @@ -134,7 +134,6 @@ export const en = { }; export const cy: typeof en = { - ...en, // @TODO delete me to get a list of missing translations phase: 'Beta', applyForChildArrangements: 'Cyfraith breifat', applyForDissolution: 'Cyfraith breifat', @@ -246,6 +245,18 @@ export const cy: typeof en = { feedback: 'Adborth', awpErrorSummaryHeading: 'Mae yna broblem', invalidDate: 'Dyddiad Annilys', + next: 'Next', + errorSendingInvite: + 'Sorry, we’re having technical problems sending your application for review. Please try again in a few minutes.', + habitualResidentHelpText1: + 'This may include working, owning property, having children in school, and your main family life taking place in England or Wales.', + habitualResidentHelpText2: + 'The examples above aren’t a complete list of what makes up habitual residence, and just because some of them apply to you doesn’t mean you’re habitually resident. If you’re not sure, you should get legal advice.', + save: 'Save', + cookiesSaved: 'Your cookie settings were saved', + additionalCookies: + 'Government services may set additional cookies and, if so, will have their own cookie policy and banner.', + goToHomepage: 'Go to homepage', }; export const generatePageContent = ({ diff --git a/src/main/steps/common/documents/upload/upload-your-documents/postController.ts b/src/main/steps/common/documents/upload/upload-your-documents/postController.ts index 41d6e49074..4ae465b84f 100644 --- a/src/main/steps/common/documents/upload/upload-your-documents/postController.ts +++ b/src/main/steps/common/documents/upload/upload-your-documents/postController.ts @@ -138,7 +138,7 @@ export default class UploadDocumentPostController extends PostController ({ - rows: values.map(v => { - const text = typeof v === 'string' ? v : `${v.firstNames} ${v.lastNames}`; - const id = typeof v === 'string' ? v : `${v.id}`; - return { - key: { - text, - }, - actions: { - items: actionItems.map(actionItem => ({ - href: `${path}?remove=${id}`, - text: actionItem, - visuallyHiddenText: text, - })), - }, - }; - }), -}); diff --git a/src/main/steps/common/safety-concerns/navigationController.ts b/src/main/steps/common/safety-concerns/navigationController.ts index 23c1051118..31eec33670 100644 --- a/src/main/steps/common/safety-concerns/navigationController.ts +++ b/src/main/steps/common/safety-concerns/navigationController.ts @@ -32,7 +32,7 @@ class SafteyConcernsNavigationController { private applicantConcerns: C1AAbuseTypes[] = []; private respondentConcerns: C1AAbuseTypes[] = []; - private pages: Record> = { + private readonly pages: Record> = { [C1ASafteyConcernsAbout.CHILDREN]: { dataReference: () => this.childConcerns, url: C1A_SAFETY_CONCERNS_CONCERNS_ABOUT_CHILD, @@ -296,19 +296,11 @@ class SafteyConcernsNavigationController { Flow-2: If there is no page left to navigate for applicant, then the next page url should be child guidelines selection page. Flow-3: If there is no page left to navigate for applicant, then the next page url should be other concerns page. */ + const urlParam = + params?.root === RootContext.C100_REBUILD ? C1ASafteyConcernsAbout.APPLICANT : C1ASafteyConcernsAbout.RESPONDENT; const returnUrl = - this.getNextPageUrl( - params?.root === RootContext.C100_REBUILD - ? C1ASafteyConcernsAbout.APPLICANT - : C1ASafteyConcernsAbout.RESPONDENT, - params?.abuseType - ) ?? - (this.checkForConcerns( - params?.root === RootContext.C100_REBUILD - ? C1ASafteyConcernsAbout.APPLICANT - : C1ASafteyConcernsAbout.RESPONDENT, - true - ) + this.getNextPageUrl(urlParam, params?.abuseType) ?? + (this.checkForConcerns(urlParam, true) ? this.getPageUrl(C1ASafteyConcernsAbout.CHILDREN, undefined, 'guidelines') : this.getPageUrl(C1ASafteyConcernsAbout.OTHER)); diff --git a/src/main/steps/common/safety-concerns/review/safetyConcernMapper.test.ts b/src/main/steps/common/safety-concerns/review/safetyConcernMapper.test.ts index 7cf9e4fac1..5de239575b 100644 --- a/src/main/steps/common/safety-concerns/review/safetyConcernMapper.test.ts +++ b/src/main/steps/common/safety-concerns/review/safetyConcernMapper.test.ts @@ -139,4 +139,37 @@ describe('SafetyConcernsMapper', () => { '{"c1A_haveSafetyConcerns":"Yes","c1A_safetyConernAbout":["children"],"c1A_concernAboutChild":["physicalAbuse","abduction"],"c1A_concernAboutRespondent":[],"c1A_keepingSafeStatement":"safe statement","c1A_supervisionAgreementDetails":"Yes, but I prefer that it is supervised","c1A_agreementOtherWaysDetails":"Yes","c1A_otherConcernsDrugs":"Yes","c1A_otherConcernsDrugsDetails":"drugs extra info","c1A_childSafetyConcerns":"Yes","c1A_childSafetyConcernsDetails":"other issues","c1A_abductionReasonOutsideUk":"adb other loc","c1A_childsCurrentLocation":"adb other loc","c1A_childrenMoreThanOnePassport":null,"c1A_possessionChildrenPassport":[],"c1A_provideOtherDetails":"other","c1A_passportOffice":"No","c1A_abductionPassportOfficeNotified":null,"c1A_previousAbductionsShortDesc":"prev abd","c1A_policeOrInvestigatorInvolved":"Yes","c1A_policeOrInvestigatorOtherDetails":"prev abd","c1A_childAbductedBefore":"Yes","c1A_safteyConcerns":{"child":{"physicalAbuse":{"behaviourDetails":"pa","behaviourStartDate":"pa","isOngoingBehaviour":"Yes","seekHelpFromPersonOrAgency":"Yes","seekHelpDetails":"pa extra","childrenConcernedAbout":["ec6e380e-5cad-4ee4-ae84-954864789916"]}},"respondent":null}}' ); }); + test('data clen up for child and respondent', async () => { + req.session.user.id = '0c09b130-2eba-4ca8-a910-1f001bac01e7'; + req.session.userCase = { + ...req.session.userCase, + c1A_safetyConernAbout: ['children', 'respondent'], + c1A_haveSafetyConcerns: 'Yes', + c1A_concernAboutRespondent: [], + c1A_concernAboutChild: [], + c1A_passportOffice: 'No', + }; + req.session.userCase.c1A_concernAboutRespondent = []; + respondents[0].value.response.respondingCitizenAoH = await prepareRequest(req.session.userCase); + expect(respondents[0].value.response.respondingCitizenAoH).toEqual( + '{"c1A_haveSafetyConcerns":"Yes","c1A_safetyConernAbout":["children","respondent"],"c1A_concernAboutChild":[],"c1A_concernAboutRespondent":[],"c1A_keepingSafeStatement":"safe statement","c1A_supervisionAgreementDetails":"Yes, but I prefer that it is supervised","c1A_agreementOtherWaysDetails":"Yes","c1A_otherConcernsDrugs":"Yes","c1A_otherConcernsDrugsDetails":"drugs extra info","c1A_childSafetyConcerns":"Yes","c1A_childSafetyConcernsDetails":"other issues","c1A_abductionReasonOutsideUk":"","c1A_childsCurrentLocation":"","c1A_childrenMoreThanOnePassport":null,"c1A_possessionChildrenPassport":[],"c1A_provideOtherDetails":"","c1A_passportOffice":null,"c1A_abductionPassportOfficeNotified":null,"c1A_previousAbductionsShortDesc":"","c1A_policeOrInvestigatorInvolved":null,"c1A_policeOrInvestigatorOtherDetails":"","c1A_childAbductedBefore":null,"c1A_safteyConcerns":{"child":{"physicalAbuse":null},"respondent":{"financialAbuse":null,"somethingElse":{"behaviourDetails":"se","behaviourStartDate":"se","isOngoingBehaviour":"No","seekHelpFromPersonOrAgency":"No","seekHelpDetails":"","childrenConcernedAbout":null}}}}' + ); + }); + test('data clen up for drug and c1A_childSafetyConcerns', async () => { + req.session.user.id = '0c09b130-2eba-4ca8-a910-1f001bac01e7'; + req.session.userCase = { + ...req.session.userCase, + c1A_safetyConernAbout: ['children', 'respondent'], + c1A_otherConcernsDrugs: 'No', + c1A_haveSafetyConcerns: 'Yes', + c1A_childSafetyConcerns: 'No', + c1A_concernAboutChild: [], + c1A_passportOffice: 'No', + }; + req.session.userCase.c1A_concernAboutRespondent = []; + respondents[0].value.response.respondingCitizenAoH = await prepareRequest(req.session.userCase); + expect(respondents[0].value.response.respondingCitizenAoH).toEqual( + '{"c1A_haveSafetyConcerns":"Yes","c1A_safetyConernAbout":["children","respondent"],"c1A_concernAboutChild":[],"c1A_concernAboutRespondent":[],"c1A_keepingSafeStatement":"safe statement","c1A_supervisionAgreementDetails":"Yes, but I prefer that it is supervised","c1A_agreementOtherWaysDetails":"Yes","c1A_otherConcernsDrugs":"No","c1A_otherConcernsDrugsDetails":null,"c1A_childSafetyConcerns":"No","c1A_childSafetyConcernsDetails":null,"c1A_abductionReasonOutsideUk":"","c1A_childsCurrentLocation":"","c1A_childrenMoreThanOnePassport":null,"c1A_possessionChildrenPassport":[],"c1A_provideOtherDetails":"","c1A_passportOffice":null,"c1A_abductionPassportOfficeNotified":null,"c1A_previousAbductionsShortDesc":"","c1A_policeOrInvestigatorInvolved":null,"c1A_policeOrInvestigatorOtherDetails":"","c1A_childAbductedBefore":null,"c1A_safteyConcerns":{"child":{"physicalAbuse":null},"respondent":{"financialAbuse":null,"somethingElse":{"behaviourDetails":"se","behaviourStartDate":"se","isOngoingBehaviour":"No","seekHelpFromPersonOrAgency":"No","seekHelpDetails":"","childrenConcernedAbout":null}}}}' + ); + }); }); diff --git a/src/main/steps/common/safety-concerns/review/safetyConcernMapper.ts b/src/main/steps/common/safety-concerns/review/safetyConcernMapper.ts index 7c85d6ca76..61a232f1ac 100644 --- a/src/main/steps/common/safety-concerns/review/safetyConcernMapper.ts +++ b/src/main/steps/common/safety-concerns/review/safetyConcernMapper.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Case } from '../../../../app/case/case'; +import { Case, CaseWithId } from '../../../../app/case/case'; import { C1AAbuseTypes, C1ASafteyConcernsAbout, YesOrNo } from '../../../../app/case/definition'; export const prepareRequest = (caseData: Partial): string => { @@ -114,41 +114,31 @@ const dataCleanUpForRespondentAbuse = ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.RESPONDENT) && !c1A_concernAboutRespondent?.includes(C1AAbuseTypes.PHYSICAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.respondent?.physicalAbuse) { - data.c1A_safteyConcerns.respondent.physicalAbuse = undefined; - } + deleteAbuseData(data, 'physicalAbuse', 'respondent'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.RESPONDENT) && !c1A_concernAboutRespondent?.includes(C1AAbuseTypes.PSYCHOLOGICAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.respondent?.psychologicalAbuse) { - data.c1A_safteyConcerns.respondent.psychologicalAbuse = undefined; - } + deleteAbuseData(data, 'psychologicalAbuse', 'respondent'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.RESPONDENT) && !c1A_concernAboutRespondent?.includes(C1AAbuseTypes.EMOTIONAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.respondent?.emotionalAbuse) { - data.c1A_safteyConcerns.respondent.emotionalAbuse = undefined; - } + deleteAbuseData(data, 'emotionalAbuse', 'respondent'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.RESPONDENT) && !c1A_concernAboutRespondent?.includes(C1AAbuseTypes.FINANCIAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.respondent?.financialAbuse) { - data.c1A_safteyConcerns.respondent.financialAbuse = undefined; - } + deleteAbuseData(data, 'financialAbuse', 'respondent'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.RESPONDENT) && !c1A_concernAboutRespondent?.includes(C1AAbuseTypes.SEXUAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.respondent?.sexualAbuse) { - data.c1A_safteyConcerns.respondent.sexualAbuse = undefined; - } + deleteAbuseData(data, 'sexualAbuse', 'respondent'); } }; @@ -161,41 +151,31 @@ const dataCleanUpForChildAbuse = ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.CHILDREN) && !c1A_concernAboutChild?.includes(C1AAbuseTypes.PHYSICAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.child?.physicalAbuse) { - data.c1A_safteyConcerns.child.physicalAbuse = undefined; - } + deleteAbuseData(data, 'physicalAbuse', 'child'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.CHILDREN) && !c1A_concernAboutChild?.includes(C1AAbuseTypes.PSYCHOLOGICAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.child?.psychologicalAbuse) { - data.c1A_safteyConcerns.child.psychologicalAbuse = undefined; - } + deleteAbuseData(data, 'psychologicalAbuse', 'child'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.CHILDREN) && !c1A_concernAboutChild?.includes(C1AAbuseTypes.EMOTIONAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.child?.emotionalAbuse) { - data.c1A_safteyConcerns.child.emotionalAbuse = undefined; - } + deleteAbuseData(data, 'emotionalAbuse', 'child'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.CHILDREN) && !c1A_concernAboutChild?.includes(C1AAbuseTypes.FINANCIAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.child?.financialAbuse) { - data.c1A_safteyConcerns.child.financialAbuse = undefined; - } + deleteAbuseData(data, 'financialAbuse', 'child'); } if ( c1A_safetyConernAbout?.includes(C1ASafteyConcernsAbout.CHILDREN) && !c1A_concernAboutChild?.includes(C1AAbuseTypes.SEXUAL_ABUSE) ) { - if (data.c1A_safteyConcerns?.child?.sexualAbuse) { - data.c1A_safteyConcerns.child.sexualAbuse = undefined; - } + deleteAbuseData(data, 'sexualAbuse', 'child'); } }; @@ -262,3 +242,9 @@ const dataCleanupForNoSafetyConcern = (c1A_haveSafetyConcerns: YesOrNo | undefin data.c1A_safteyConcerns = {}; } }; + +const deleteAbuseData = (data: Partial, abuse: string, party: string): void => { + if (data?.c1A_safteyConcerns?.[party]?.[abuse]) { + data.c1A_safteyConcerns[party][abuse] = null; + } +}; diff --git a/src/main/steps/common/task-list/components/notification-banner/index.test.ts b/src/main/steps/common/task-list/components/notification-banner/index.test.ts index 3be187a528..58c22a9f90 100644 --- a/src/main/steps/common/task-list/components/notification-banner/index.test.ts +++ b/src/main/steps/common/task-list/components/notification-banner/index.test.ts @@ -1403,7 +1403,7 @@ describe('testcase for notification Banner', () => { }, } as unknown as Respondent, ]; - data.state = State.Draft; + data.state = State.AWAITING_SUBMISSION_TO_HMCTS; data.caseTypeOfApplication = 'C100'; data.citizenNotifications = [ { @@ -1451,7 +1451,7 @@ describe('testcase for notification Banner', () => { }, } as unknown as Respondent, ]; - data.state = State.Draft; + data.state = State.AWAITING_SUBMISSION_TO_HMCTS; data.caseTypeOfApplication = 'C100'; data.citizenNotifications = [ { @@ -1500,7 +1500,7 @@ describe('testcase for notification Banner', () => { } as unknown as Respondent, ]; data.caseTypeOfApplication = 'C100'; - data.state = State.Draft; + data.state = State.AWAITING_SUBMISSION_TO_HMCTS; data.citizenNotifications = [ { id: 'CRNF2_APPLICANT_RESPONDENT', @@ -1548,7 +1548,7 @@ describe('testcase for notification Banner', () => { } as unknown as Respondent, ]; data.caseTypeOfApplication = 'C100'; - data.state = State.Draft; + data.state = State.AWAITING_SUBMISSION_TO_HMCTS; data.citizenNotifications = [ { id: 'CRNF2_APPLICANT_RESPONDENT', @@ -1611,7 +1611,7 @@ describe('testcase for notification Banner', () => { ], }, ] as unknown as CitizenApplicationPacks[]; - data.state = State.Draft; + data.state = State.AWAITING_SUBMISSION_TO_HMCTS; data.citizenNotifications = [ { id: 'CAN5_SOA_RESPONDENT', @@ -1680,7 +1680,7 @@ describe('testcase for notification Banner', () => { ], }, ] as unknown as CitizenApplicationPacks[]; - data.state = State.Draft; + data.state = State.AWAITING_SUBMISSION_TO_HMCTS; data.citizenNotifications = [ { id: 'CAN5_SOA_RESPONDENT', diff --git a/src/main/steps/common/yourhearings/hearings/utils.ts b/src/main/steps/common/yourhearings/hearings/utils.ts index 908a4caf14..d627646831 100644 --- a/src/main/steps/common/yourhearings/hearings/utils.ts +++ b/src/main/steps/common/yourhearings/hearings/utils.ts @@ -172,18 +172,16 @@ export const generateHearingScheduleDisplayText = ( const lang = preference === 'cy' ? cy : en; if (durationInDayOrHours >= 5) { return `1 ${lang.smallDay}`; - } else { - if (minutes > 0) { - if (durationInDayOrHours > 0) { - const hourText = generateHearingHourDisplayText(durationInDayOrHours, preference); - const minuteText = generateHearingMinuteDisplayText(minutes, preference); - return `${hourText} ${minuteText}`; - } else { - return generateHearingMinuteDisplayText(minutes, preference); - } + } else if (minutes > 0) { + if (durationInDayOrHours > 0) { + const hourText = generateHearingHourDisplayText(durationInDayOrHours, preference); + const minuteText = generateHearingMinuteDisplayText(minutes, preference); + return `${hourText} ${minuteText}`; } else { - return generateHearingHourDisplayText(durationInDayOrHours, preference); + return generateHearingMinuteDisplayText(minutes, preference); } + } else { + return generateHearingHourDisplayText(durationInDayOrHours, preference); } }; export const generateHearingMinuteDisplayText = (minutes: number, preference: string | undefined): string => { diff --git a/src/main/steps/constants.ts b/src/main/steps/constants.ts index 9c0e7c4369..3bb17e2c56 100644 --- a/src/main/steps/constants.ts +++ b/src/main/steps/constants.ts @@ -63,7 +63,7 @@ export const ordinalNumberMapEn = new Map([ [20, 'Twentieth'], ]); -export const ordinalNumberMapCy = new Map([ +export const ordinalNumberMapCy: typeof ordinalNumberMapEn = new Map([ [1, 'Cyntaf'], [2, 'Ail'], [3, 'Trydydd'], diff --git a/src/main/steps/error/error.controller.ts b/src/main/steps/error/error.controller.ts index ba64fd74fe..72b8dd2780 100644 --- a/src/main/steps/error/error.controller.ts +++ b/src/main/steps/error/error.controller.ts @@ -31,7 +31,7 @@ export class ErrorController { response = (error as AxiosError).response?.data as AxiosResponse>; } - req.locals.logger.error(`${stack || message || 'Internal Server Error'}`, response); + req.locals.logger.error(`${stack ?? message ?? 'Internal Server Error'}`, response); res.statusCode = (error as HTTPError)?.status || StatusCodes.INTERNAL_SERVER_ERROR; this.render(req, res); @@ -54,7 +54,7 @@ export class ErrorController { return; } - const language = (req.session?.lang || 'en') as Language; + const language = (req.session?.lang ?? 'en') as Language; const errorText = errorContent[language][res.statusCode] || errorContent[language][StatusCodes.INTERNAL_SERVER_ERROR]; const commonContent = generatePageContent({ diff --git a/src/main/steps/prl-cases/pin-activation/enter-pin/postController.ts b/src/main/steps/prl-cases/pin-activation/enter-pin/postController.ts index 5f5b88afb3..cb49d07ac7 100644 --- a/src/main/steps/prl-cases/pin-activation/enter-pin/postController.ts +++ b/src/main/steps/prl-cases/pin-activation/enter-pin/postController.ts @@ -13,7 +13,7 @@ export default class LinkCaseToAccountPostController extends PostController { + private readonly removeErrors = (req: AppRequest): FormError[] => { return req.session.errors?.length ? req.session.errors.filter(error => !['caseCode', 'accessCode'].includes(error.propertyName)) : []; diff --git a/src/main/steps/respondent/proceedings/court-proceedings/content.test.ts b/src/main/steps/respondent/proceedings/court-proceedings/content.test.ts deleted file mode 100644 index 045a5e530c..0000000000 --- a/src/main/steps/respondent/proceedings/court-proceedings/content.test.ts +++ /dev/null @@ -1,225 +0,0 @@ -import languageAssertions from '../../../../../test/unit/utils/languageAssertions'; -import { FormContent, FormFields, FormOptions } from '../../../../app/form/Form'; -import { CommonContent } from '../../../common/common.content'; - -import { generateContent } from './content'; - -const enContent = { - section: 'Current or previous proceedings', - title: 'Provide details of court cases you or the children have been involved in', - emergencyOrder: 'Emergency Protection Order', - caseno: 'Case number', - casenohint: 'For example, BS19F99999', - orderdate: 'What date was it made?', - orderDateHint: 'For example, 31 3 2015', - ordertime: 'How long was the order for?', - currentorder: 'Is this a current order?', - currentOrderYes: 'Yes', - currentOrderNo: 'No', - issueorder: 'Which court issued the order?', - supervisionOrder: 'Supervision Order', - careOrder: 'Care Order', - childAbductionOrder: 'Child Abduction', - caOrder: 'Child Arrangements Order', - financialOrder: 'Financial Order under Schedule 1 of the Children Act 1989', - nonmolestationOrder: 'Non-molestation Order', - occupationOrder: 'Occupation Order', - marraigeOrder: 'Forced Marriage Protection Order', - restrainingOrder: 'Restraining Order', - restrainingOrderhint: 'Under the Protection from Harassment Act 1997', - injuctiveOrder: 'Other Injunctive Order', - underTakingOrder: 'Undertaking in Place of an Order', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - courtOrderDontKnow: "I don't know", - saveAndContinue: 'Save and continue', - errors: { - emergencyOrderOptions: { - required: 'Please choose an option for emergency protection order', - }, - - 'emergencyOrder.orderDateDetails': { - invalidDate: 'emergency protection order date must be a real date', - incompleteDay: 'emergency protection order date must include a day', - incompleteMonth: 'emergency protection order date must include a month', - incompleteYear: 'emergency protection order date must include a year', - invalidDateInFuture: 'emergency protection order date must be in the past', - }, - - supervisionOrderOption: { - required: 'Please choose an option for supervision order', - }, - - careOrderOptions: { - required: 'Please choose an option for care order', - }, - - childAbductionOrderOption: { - required: 'Please choose an option for child abduction order', - }, - - caOrderOption: { - required: 'Please choose an option for child arrangements order', - }, - - financialOrderOption: { - required: 'Please choose an option for financial order', - }, - - nonmolestationOrderOption: { - required: 'Please choose an option for non molestation order', - }, - - occupationalOrderOptions: { - required: 'Please choose an option for occupation order', - }, - - marraigeOrderOptions: { - required: 'Please choose an option for forced marriage protection order', - }, - - restrainingOrderOptions: { - required: 'Please choose an option for restraining order', - }, - - injuctiveOrderOptions: { - required: 'Please choose an option for injunctive order', - }, - - underTakingOrderOptions: { - required: 'Please choose an option for undertaking order', - }, - }, -}; - -const cyContent = { - section: 'Achos cyfredol neu flaenorol', - title: "Darparwch fanylion am achosion llys rydych chi neu'r plant wedi bod yn rhan ohonynt", - emergencyOrder: 'Gorchymyn Diogelu Brys', - caseno: 'Rhif yr achos', - casenohint: 'Er enghraifft, BS19F99999', - orderdate: 'Pa ddyddiad gafodd ei wneud?', - orderDateHint: 'er enghraifft, 31 3 2015', - ordertime: 'Am ba mor hir gwnaethpwyd y gorchymyn?', - currentorder: 'Ai gorchymyn cyfredol yw hwn?', - currentOrderYes: 'Yes', - currentOrderNo: 'No', - issueorder: 'Pa lys a gyhoeddodd y gorchymyn?', - supervisionOrder: 'Gorchymyn Goruchwylio', - careOrder: 'Gorchymyn Gofal', - childAbductionOrder: 'Herwgydio Plant', - caOrder: 'Gorchymyn Trefniadau Plant', - financialOrder: 'Gorchymyn Ariannol o dan Atodlen 1 Deddf Plant 1989', - nonmolestationOrder: 'Gorchymyn Rhag Molestu', - occupationOrder: 'Gorchymyn Anheddu', - marraigeOrder: 'Gorchymyn Amddiffyn rhag Priodas dan Orfod', - restrainingOrder: 'Gorchymyn Atal', - restrainingOrderhint: 'Under the Protection from Harassment Act 1997', - injuctiveOrder: 'Other Injunctive Order', - underTakingOrder: 'Ymgymeriad yn lle gorchymyn', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - courtOrderDontKnow: 'Nid wyf yn gwybod', - saveAndContinue: 'Cadw a pharhau', - errors: { - emergencyOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn diogelu brys', - }, - - 'emergencyOrder.orderDateDetails': { - invalidDate: 'rhaid i ddyddiad y gorchymyn diogelu brys fod yn ddyddiad go iawn', - incompleteDay: 'rhaid i ddyddiad y gorchymyn diogelu brys gynnwys diwrnod', - incompleteMonth: 'rhaid i ddyddiad y gorchymyn diogelu brys gynnwys mis', - incompleteYear: 'rhaid i ddyddiad y gorchymyn diogelu brys gynnwys blwyddyn', - invalidDateInFuture: 'rhaid i ddyddiad y gorchymyn diogelu brys fod yn y gorffennol', - }, - - supervisionOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn goruchwylio', - }, - - careOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn gofal', - }, - - childAbductionOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn herwgydio plentyn', - }, - - caOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn trefniadau plant', - }, - - financialOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn ariannol', - }, - - nonmolestationOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn rhag molestu', - }, - - occupationalOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn anheddu', - }, - - marraigeOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn amddiffyn priodi dan orfod', - }, - - restrainingOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn atal', - }, - - injuctiveOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn gwahardd', - }, - - underTakingOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn ymgymeriad', - }, - }, -}; - -jest.mock('../../../../app/form/validation'); -/* eslint-disable @typescript-eslint/ban-types */ -describe('respondent/proceedings content', () => { - const commonContent = { language: 'en' } as CommonContent; - let generatedContent; - let form; - let fields; - beforeEach(() => { - generatedContent = generateContent(commonContent); - form = generatedContent.form as FormContent; - fields = form.fields as FormFields; - }); - - test('should return correct english content', () => { - expect(generatedContent.title).toEqual('Provide details of court cases you or the children have been involved in'); - expect(generatedContent.section).toEqual('Current or previous proceedings'); - expect(generatedContent.emergencyOrder).toEqual('Emergency Protection Order'); - }); - - // eslint-disable-next-line jest/expect-expect - test('should return correct english content Data', () => { - languageAssertions('en', enContent, () => generateContent(commonContent)); - }); - - // eslint-disable-next-line jest/expect-expect - test('should return correct welsh content', () => { - languageAssertions('cy', cyContent, () => generateContent({ ...commonContent, language: 'cy' })); - }); - - test('should contain detailsKnown field', () => { - const emergencyOrderOptions = fields.emergencyOrderOptions as FormOptions; - expect(emergencyOrderOptions.type).toBe('radios'); - expect(emergencyOrderOptions.classes).toBe('govuk-radios'); - - const underTakingOrderOptions = fields.underTakingOrderOptions as FormOptions; - expect(underTakingOrderOptions.type).toBe('radios'); - expect(underTakingOrderOptions.classes).toBe('govuk-radios'); - }); - - test('should onlyContinue continue button', () => { - expect((form.onlyContinue?.text as Function)(generatedContent)).toBe('Save and continue'); - }); -}); diff --git a/src/main/steps/respondent/proceedings/court-proceedings/content.ts b/src/main/steps/respondent/proceedings/court-proceedings/content.ts deleted file mode 100644 index 5e178c1c40..0000000000 --- a/src/main/steps/respondent/proceedings/court-proceedings/content.ts +++ /dev/null @@ -1,1315 +0,0 @@ -import { CaseDate } from '../../../../app/case/case'; -import { TranslationFn } from '../../../../app/controller/GetController'; -import { FormContent } from '../../../../app/form/Form'; -import { covertToDateObject } from '../../../../app/form/parser'; -import { isDateInputInvalid, isFieldFilledIn, isFutureDate } from '../../../../app/form/validation'; - -const en = { - section: 'Current or previous proceedings', - title: 'Provide details of court cases you or the children have been involved in', - emergencyOrder: 'Emergency Protection Order', - caseno: 'Case number', - casenohint: 'For example, BS19F99999', - orderdate: 'What date was it made?', - orderDateHint: 'For example, 31 3 2015', - ordertime: 'How long was the order for?', - currentorder: 'Is this a current order?', - currentOrderYes: 'Yes', - currentOrderNo: 'No', - issueorder: 'Which court issued the order?', - supervisionOrder: 'Supervision Order', - careOrder: 'Care Order', - childAbductionOrder: 'Child Abduction', - caOrder: 'Child Arrangements Order', - financialOrder: 'Financial Order under Schedule 1 of the Children Act 1989', - nonmolestationOrder: 'Non-molestation Order', - occupationOrder: 'Occupation Order', - marraigeOrder: 'Forced Marriage Protection Order', - restrainingOrder: 'Restraining Order', - restrainingOrderhint: 'Under the Protection from Harassment Act 1997', - injuctiveOrder: 'Other Injunctive Order', - underTakingOrder: 'Undertaking in Place of an Order', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - courtOrderDontKnow: "I don't know", - saveAndContinue: 'Save and continue', - errors: { - emergencyOrderOptions: { - required: 'Please choose an option for emergency protection order', - }, - - 'emergencyOrder.orderDateDetails': { - invalidDate: 'emergency protection order date must be a real date', - incompleteDay: 'emergency protection order date must include a day', - incompleteMonth: 'emergency protection order date must include a month', - incompleteYear: 'emergency protection order date must include a year', - invalidDateInFuture: 'emergency protection order date must be in the past', - }, - - supervisionOrderOption: { - required: 'Please choose an option for supervision order', - }, - - careOrderOptions: { - required: 'Please choose an option for care order', - }, - - childAbductionOrderOption: { - required: 'Please choose an option for child abduction order', - }, - - caOrderOption: { - required: 'Please choose an option for child arrangements order', - }, - - financialOrderOption: { - required: 'Please choose an option for financial order', - }, - - nonmolestationOrderOption: { - required: 'Please choose an option for non molestation order', - }, - - occupationalOrderOptions: { - required: 'Please choose an option for occupation order', - }, - - marraigeOrderOptions: { - required: 'Please choose an option for forced marriage protection order', - }, - - restrainingOrderOptions: { - required: 'Please choose an option for restraining order', - }, - - injuctiveOrderOptions: { - required: 'Please choose an option for injunctive order', - }, - - underTakingOrderOptions: { - required: 'Please choose an option for undertaking order', - }, - }, -}; - -const cy: typeof en = { - section: 'Achos cyfredol neu flaenorol', - title: "Darparwch fanylion am achosion llys rydych chi neu'r plant wedi bod yn rhan ohonynt", - emergencyOrder: 'Gorchymyn Diogelu Brys', - caseno: 'Rhif yr achos', - casenohint: 'Er enghraifft, BS19F99999', - orderdate: 'Pa ddyddiad gafodd ei wneud?', - orderDateHint: 'er enghraifft, 31 3 2015', - ordertime: 'Am ba mor hir gwnaethpwyd y gorchymyn?', - currentorder: 'Ai gorchymyn cyfredol yw hwn?', - currentOrderYes: 'Yes', - currentOrderNo: 'No', - issueorder: 'Pa lys a gyhoeddodd y gorchymyn?', - supervisionOrder: 'Gorchymyn Goruchwylio', - careOrder: 'Gorchymyn Gofal', - childAbductionOrder: 'Herwgydio Plant', - caOrder: 'Gorchymyn Trefniadau Plant', - financialOrder: 'Gorchymyn Ariannol o dan Atodlen 1 Deddf Plant 1989', - nonmolestationOrder: 'Gorchymyn Rhag Molestu', - occupationOrder: 'Gorchymyn Anheddu', - marraigeOrder: 'Gorchymyn Amddiffyn rhag Priodas dan Orfod', - restrainingOrder: 'Gorchymyn Atal', - restrainingOrderhint: 'Under the Protection from Harassment Act 1997', - injuctiveOrder: 'Other Injunctive Order', - underTakingOrder: 'Ymgymeriad yn lle gorchymyn', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - courtOrderDontKnow: 'Nid wyf yn gwybod', - saveAndContinue: 'Cadw a pharhau', - errors: { - emergencyOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn diogelu brys', - }, - - 'emergencyOrder.orderDateDetails': { - invalidDate: 'rhaid i ddyddiad y gorchymyn diogelu brys fod yn ddyddiad go iawn', - incompleteDay: 'rhaid i ddyddiad y gorchymyn diogelu brys gynnwys diwrnod', - incompleteMonth: 'rhaid i ddyddiad y gorchymyn diogelu brys gynnwys mis', - incompleteYear: 'rhaid i ddyddiad y gorchymyn diogelu brys gynnwys blwyddyn', - invalidDateInFuture: 'rhaid i ddyddiad y gorchymyn diogelu brys fod yn y gorffennol', - }, - - supervisionOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn goruchwylio', - }, - - careOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn gofal', - }, - - childAbductionOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn herwgydio plentyn', - }, - - caOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn trefniadau plant', - }, - - financialOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn ariannol', - }, - - nonmolestationOrderOption: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn rhag molestu', - }, - - occupationalOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn anheddu', - }, - - marraigeOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn amddiffyn priodi dan orfod', - }, - - restrainingOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn atal', - }, - - injuctiveOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn gwahardd', - }, - - underTakingOrderOptions: { - required: 'Dewiswch opsiwn ar gyfer y gorchymyn ymgymeriad', - }, - }, -}; - -const languages = { - en, - cy, -}; - -export const form: FormContent = { - fields: { - emergencyOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.emergencyOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'emergencyOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'emergencyOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('emergencyOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'emergencyOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'emergencyOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'emergencyOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - supervisionOrderOption: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.supervisionOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'supervisionOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'supervisionOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('supervisionOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'supervisionOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'supervisionOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'supervisionOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - careOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.careOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'careOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'careOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('careOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'careOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'careOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'careOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - childAbductionOrderOption: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.childAbductionOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'childAbductionOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'childAbductionOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => - covertToDateObject('childAbductionOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'childAbductionOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - currentOrderLabel: { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'childAbductionOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.label, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'childAbductionOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - caOrderOption: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.caOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'caOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'caOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('caOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'caOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'caOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'caOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - financialOrderOption: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.financialOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'financialOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'financialOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('financialOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'financialOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'financialOrder.currentOrderLabel': { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'financialOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.label, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'financialOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - nonmolestationOrderOption: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.nonmolestationOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'nonmolestationOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'nonmolestationOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => - covertToDateObject('nonmolestationOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'nonmolestationOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'nonmolestationOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'nonmolestationOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - occupationalOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.occupationOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'occupationOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'occupationOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('occupationOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'occupationOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'occupationOrder.currentOrderLabel': { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'occupationOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'occupationOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - marraigeOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.marraigeOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'marraigeOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'marraigeOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('marraigeOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'marraigeOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'marraigeOrder.currentOrderLabel': { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'marraigeOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'marraigeOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - restrainingOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.restrainingOrder, - hint: h => h.restrainingOrderhint, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'restrainingOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'restrainingOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('restrainingOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'restrainingOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'restrainingOrder.currentOrderLabel': { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'restrainingOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'restrainingOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - injuctiveOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.injuctiveOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'injuctiveOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'injuctiveOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('injuctiveOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'injuctiveOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'injuctiveOrder.currentOrderLabel': { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'injuctiveOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'injuctiveOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - underTakingOrderOptions: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.underTakingOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - subFields: { - 'underTakingOrder.caseNoDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.caseno, - hint: l => l.casenohint, - labelSize: 'm', - }, - 'underTakingOrder.orderDateDetails': { - type: 'date', - classes: 'govuk-date-input', - label: l => l.orderdate, - labelSize: 'm', - hint: l => l.orderDateHint, - values: [ - { - label: l => l.dateFormat['day'], - name: 'day', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['month'], - name: 'month', - classes: 'govuk-input--width-2', - attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - { - label: l => l.dateFormat['year'], - name: 'year', - classes: 'govuk-input--width-4', - attributes: { maxLength: 4, pattern: '[0-9]*', inputMode: 'numeric' }, - }, - ], - parser: body => covertToDateObject('underTakingOrder.orderDateDetails', body as Record), - validator: value => isDateInputInvalid(value as CaseDate) || isFutureDate(value as CaseDate), - }, - 'underTakingOrder.orderTimeDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.ordertime, - labelSize: 'm', - }, - 'underTakingOrder.currentOrderLabel': { - type: 'label', - classes: 'govuk-label', - label: l => l.currentorder, - labelSize: 'm', - }, - 'underTakingOrder.currentOrderDetails': { - type: 'radios', - classes: 'govuk-radios', - label: l => l.currentorder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.currentOrderYes, - value: 'Yes', - }, - { - label: l => l.currentOrderNo, - value: 'No', - }, - ], - }, - 'underTakingOrder.issueOrderDetails': { - type: 'text', - classes: 'govuk-label', - label: l => l.issueorder, - labelSize: 'm', - }, - }, - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - { - label: l => l.courtOrderDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - }, - onlyContinue: { - text: l => l.saveAndContinue, - }, -}; - -export const generateContent: TranslationFn = content => { - const translations = languages[content.language]; - return { - ...translations, - form, - }; -}; diff --git a/src/main/steps/respondent/proceedings/court-proceedings/template.njk b/src/main/steps/respondent/proceedings/court-proceedings/template.njk deleted file mode 100644 index f9713194de..0000000000 --- a/src/main/steps/respondent/proceedings/court-proceedings/template.njk +++ /dev/null @@ -1,8 +0,0 @@ - -{% extends "common/template.njk" %} - -{% from "govuk/components/details/macro.njk" import govukDetails %} -{% block page_content %} - {{section}} -

    {{title}}

    -{% endblock %} \ No newline at end of file diff --git a/src/main/steps/respondent/proceedings/start/content.test.ts b/src/main/steps/respondent/proceedings/start/content.test.ts deleted file mode 100644 index 8aad03ef66..0000000000 --- a/src/main/steps/respondent/proceedings/start/content.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -import languageAssertions from '../../../../../test/unit/utils/languageAssertions'; -import { FormContent, FormFields, FormOptions } from '../../../../app/form/Form'; -import { CommonContent } from '../../../common/common.content'; - -import { generateContent } from './content'; - -const enContent = { - section: 'Current or previous proceedings', - title: 'Have you or the children ever been involved in court proceedings?', - courtCase: 'Have the children been involved in a court case?', - courtCaseYes: 'Yes', - courtCaseNo: 'No', - courtCaseDontKnow: "I don't know", - courtOrder: 'Have you had a court order made for your protection?', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - saveAndContinue: 'Save and continue', - errors: { - proceedingsStart: { - required: 'Select yes if the children have been involved in a previous court case', - }, - proceedingsStartOrder: { - required: 'Select yes if you have had a court order made for your protection', - }, - }, -}; - -const cyContent = { - section: 'Achos cyfredol neu flaenorol', - title: "Ydych chi neu'r plant erioed wedi bod yn rhan o achosion llys?", - courtCase: "Ydy'r plant wedi bod yn rhan o achos llys?", - courtCaseYes: 'Yes', - courtCaseNo: 'No', - courtCaseDontKnow: 'Nid wyf yn gwybod', - courtOrder: 'A oes gorchymyn llys wedi ei wneud ar eich cyfer i’ch amddiffyn?', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - saveAndContinue: 'Cadw a pharhau', - errors: { - proceedingsStart: { - required: "Dewiswch do os yw'r plant wedi bod yn rhan o achos llys yn flaenorol", - }, - proceedingsStartOrder: { - required: 'Dewiswch oes os oes gorchymyn llys wedi ei wneud ar eich cyfer er mwyn eich diogelu chi', - }, - }, -}; - -jest.mock('../../../../app/form/validation'); -/* eslint-disable @typescript-eslint/ban-types */ -describe('respondent/proceedings content', () => { - const commonContent = { language: 'en' } as CommonContent; - let generatedContent; - let form; - let fields; - beforeEach(() => { - generatedContent = generateContent(commonContent); - form = generatedContent.form as FormContent; - fields = form.fields as FormFields; - }); - - test('should return correct english content', () => { - expect(generatedContent.title).toEqual('Have you or the children ever been involved in court proceedings?'); - expect(generatedContent.section).toEqual('Current or previous proceedings'); - expect(generatedContent.courtCase).toEqual('Have the children been involved in a court case?'); - }); - - // eslint-disable-next-line jest/expect-expect - test('should return correct english content Data', () => { - languageAssertions('en', enContent, () => generateContent(commonContent)); - }); - - // eslint-disable-next-line jest/expect-expect - test('should return correct welsh content', () => { - languageAssertions('cy', cyContent, () => generateContent({ ...commonContent, language: 'cy' })); - }); - - test('should contain detailsKnown field', () => { - const proceedingsStart = fields.proceedingsStart as FormOptions; - expect(proceedingsStart.type).toBe('radios'); - expect(proceedingsStart.classes).toBe('govuk-radios'); - }); - - test('should onlyContinue continue button', () => { - expect((form.onlyContinue?.text as Function)(generatedContent)).toBe('Save and continue'); - }); -}); diff --git a/src/main/steps/respondent/proceedings/start/content.ts b/src/main/steps/respondent/proceedings/start/content.ts deleted file mode 100644 index 6833b5cd9f..0000000000 --- a/src/main/steps/respondent/proceedings/start/content.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { TranslationFn } from '../../../../app/controller/GetController'; -import { FormContent } from '../../../../app/form/Form'; -import { isFieldFilledIn } from '../../../../app/form/validation'; - -const en = { - section: 'Current or previous proceedings', - title: 'Have you or the children ever been involved in court proceedings?', - courtCase: 'Have the children been involved in a court case?', - courtCaseYes: 'Yes', - courtCaseNo: 'No', - courtCaseDontKnow: "I don't know", - courtOrder: 'Have you had a court order made for your protection?', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - saveAndContinue: 'Save and continue', - errors: { - proceedingsStart: { - required: 'Select yes if the children have been involved in a previous court case', - }, - proceedingsStartOrder: { - required: 'Select yes if you have had a court order made for your protection', - }, - }, -}; - -const cy: typeof en = { - section: 'Achos cyfredol neu flaenorol', - title: "Ydych chi neu'r plant erioed wedi bod yn rhan o achosion llys?", - courtCase: "Ydy'r plant wedi bod yn rhan o achos llys?", - courtCaseYes: 'Yes', - courtCaseNo: 'No', - courtCaseDontKnow: 'Nid wyf yn gwybod', - courtOrder: 'A oes gorchymyn llys wedi ei wneud ar eich cyfer i’ch amddiffyn?', - courtOrderYes: 'Yes', - courtOrderNo: 'No', - saveAndContinue: 'Cadw a pharhau', - errors: { - proceedingsStart: { - required: "Dewiswch do os yw'r plant wedi bod yn rhan o achos llys yn flaenorol", - }, - proceedingsStartOrder: { - required: 'Dewiswch oes os oes gorchymyn llys wedi ei wneud ar eich cyfer er mwyn eich diogelu chi', - }, - }, -}; - -const languages = { - en, - cy, -}; - -export const form: FormContent = { - fields: { - proceedingsStart: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.courtCase, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtCaseYes, - value: 'Yes', - }, - { - label: l => l.courtCaseNo, - value: 'No', - }, - { - label: l => l.courtCaseDontKnow, - value: 'I', - }, - ], - validator: isFieldFilledIn, - }, - proceedingsStartOrder: { - type: 'radios', - classes: 'govuk-radios', - label: l => l.courtOrder, - section: l => l.section, - labelSize: 'm', - values: [ - { - label: l => l.courtOrderYes, - value: 'Yes', - }, - { - label: l => l.courtOrderNo, - value: 'No', - }, - ], - validator: isFieldFilledIn, - }, - }, - onlyContinue: { - text: l => l.saveAndContinue, - }, -}; - -export const generateContent: TranslationFn = content => { - const translations = languages[content.language]; - return { - ...translations, - form, - }; -}; diff --git a/src/main/steps/respondent/proceedings/start/template.njk b/src/main/steps/respondent/proceedings/start/template.njk deleted file mode 100644 index 29267f9775..0000000000 --- a/src/main/steps/respondent/proceedings/start/template.njk +++ /dev/null @@ -1,4 +0,0 @@ -{% extends "common/template.njk" %} - -{% from "govuk/components/details/macro.njk" import govukDetails %} - diff --git a/src/main/steps/respondent/proceedings/summary/content.test.ts b/src/main/steps/respondent/proceedings/summary/content.test.ts deleted file mode 100644 index 24c5636f8b..0000000000 --- a/src/main/steps/respondent/proceedings/summary/content.test.ts +++ /dev/null @@ -1,203 +0,0 @@ -import languageAssertions from '../../../../../test/unit/utils/languageAssertions'; -import mockUserCase from '../../../../../test/unit/utils/mockUserCase'; -import { CommonContent } from '../../../common/common.content'; - -import { generateContent } from './content'; - -const enContent = { - section: ' ', - title: 'Check your answers', - title2: 'Current or previous court cases', - sectionTitles: { - applicationDetails: '', - }, - keys: { - proceedingsStart: 'Have the children been involved in a court case?', - proceedingsStartOrder: 'Have you had a court order made for your protection?', - emergencyOrderOptions: 'Emergency Protection Order', - 'emergencyOrder.caseNoDetails': 'Case number', - 'emergencyOrder.orderDateDetails': 'What date was it made', - 'emergencyOrder.orderTimeDetails': 'How long was the order for?', - 'emergencyOrder.currentOrderDetails': 'Is this a current order?', - 'emergencyOrder.issueOrderDetails': 'Which court issued this order?', - supervisionOrderOption: 'Supervision Order', - 'supervisionOrder.caseNoDetails': 'Case number', - 'supervisionOrder.orderDateDetails': 'What date was it made', - 'supervisionOrder.orderTimeDetails': 'How long was the order for?', - 'supervisionOrder.currentOrderDetails': 'Is this a current order?', - 'supervisionOrder.issueOrderDetails': 'Which court issued this order?', - careOrderOptions: 'Care Order', - 'careOrder.caseNoDetails': 'Case number', - 'careOrder.orderDateDetails': 'What date was it made', - 'careOrder.orderTimeDetails': 'How long was the order for?', - 'careOrder.currentOrderDetails': 'Is this a current order?', - 'careOrder.issueOrderDetails': 'Which court issued this order?', - childAbductionOrderOption: 'Child Abduction', - 'childAbductionOrder.caseNoDetails': 'Case number', - 'childAbductionOrder.orderDateDetails': 'What date was it made', - 'childAbductionOrder.orderTimeDetails': 'How long was the order for?', - 'childAbductionOrder.currentOrderDetails': 'Is this a current order?', - 'childAbductionOrder.issueOrderDetails': 'Which court issued this order?', - caOrderOption: 'Child Arrangements Order', - 'caOrder.caseNoDetails': 'Case number', - 'caOrder.orderDateDetails': 'What date was it made', - 'caOrder.orderTimeDetails': 'How long was the order for?', - 'caOrder.currentOrderDetails': 'Is this a current order?', - 'caOrder.issueOrderDetails': 'Which court issued this order?', - financialOrderOption: 'Financial Order under Schedule 1 of the Children Act 1989', - 'financialOrder.caseNoDetails': 'Case number', - 'financialOrder.orderDateDetails': 'What date was it made', - 'financialOrder.orderTimeDetails': 'How long was the order for?', - 'financialOrder.currentOrderDetails': 'Is this a current order?', - 'financialOrder.issueOrderDetails': 'Which court issued this order?', - nonmolestationOrderOption: 'Non-molestation Order', - 'nonmolestationOrder.caseNoDetails': 'Case number', - 'nonmolestationOrder.orderDateDetails': 'What date was it made', - 'nonmolestationOrder.orderTimeDetails': 'How long was the order for?', - 'nonmolestationOrder.currentOrderDetails': 'Is this a current order?', - 'nonmolestationOrder.issueOrderDetails': 'Which court issued this order?', - occupationalOrderOptions: 'Occupation Order', - 'occupationOrder.caseNoDetails': 'Case number', - 'occupationOrder.orderDateDetails': 'What date was it made', - 'occupationOrder.orderTimeDetails': 'How long was the order for?', - 'occupationOrder.currentOrderDetails': 'Is this a current order?', - 'occupationOrder.issueOrderDetails': 'Which court issued this order?', - marraigeOrderOptions: 'Forced Marriage Protection Order', - 'marraigeOrder.caseNoDetails': 'Case number', - 'marraigeOrder.orderDateDetails': 'What date was it made', - 'marraigeOrder.orderTimeDetails': 'How long was the order for?', - 'marraigeOrder.currentOrderDetails': 'Is this a current order?', - 'marraigeOrder.issueOrderDetails': 'Which court issued this order?', - restrainingOrderOptions: 'Restraining Order', - 'restrainingOrder.caseNoDetails': 'Case number', - 'restrainingOrder.orderDateDetails': 'What date was it made', - 'restrainingOrder.orderTimeDetails': 'How long was the order for?', - 'restrainingOrder.currentOrderDetails': 'Is this a current order?', - 'restrainingOrder.issueOrderDetails': 'Which court issued this order?', - injuctiveOrderOptions: 'Other Injunctive Order', - 'injuctiveOrder.caseNoDetails': 'Case number', - 'injuctiveOrder.orderDateDetails': 'What date was it made', - 'injuctiveOrder.orderTimeDetails': 'How long was the order for?', - 'injuctiveOrder.currentOrderDetails': 'Is this a current order?', - 'injuctiveOrder.issueOrderDetails': 'Which court issued this order?', - underTakingOrderOptions: 'Undertaking in Place of an Order', - 'underTakingOrder.caseNoDetails': 'Case number', - 'underTakingOrder.orderDateDetails': 'What date was it made', - 'underTakingOrder.orderTimeDetails': 'How long was the order for?', - 'underTakingOrder.currentOrderDetails': 'Is this a current order?', - 'underTakingOrder.issueOrderDetails': 'Which court issued this order?', - }, - errors: {}, -}; - -const cyContent = { - section: ' ', - title: 'Gwirio eich atebion', - title2: 'Achosion llys cyfredol neu flaenorol', - sectionTitles: { - applicationDetails: '', - }, - keys: { - proceedingsStart: "Ydy'r plant wedi bod yn rhan o achos llys?", - proceedingsStartOrder: 'A oes gorchymyn llys wedi ei wneud ar eich cyfer i’ch amddiffyn?', - emergencyOrderOptions: 'Gorchymyn Diogelu Brys', - 'emergencyOrder.caseNoDetails': 'Rhif yr achos', - 'emergencyOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'emergencyOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'emergencyOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'emergencyOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - supervisionOrderOption: 'Gorchymyn Goruchwylio', - 'supervisionOrder.caseNoDetails': 'Rhif yr achos', - 'supervisionOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'supervisionOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'supervisionOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'supervisionOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - careOrderOptions: 'Gorchymyn Gofal', - 'careOrder.caseNoDetails': 'Rhif yr achos', - 'careOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'careOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'careOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'careOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - childAbductionOrderOption: 'Herwgydio Plant', - 'childAbductionOrder.caseNoDetails': 'Rhif yr achos', - 'childAbductionOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'childAbductionOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'childAbductionOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'childAbductionOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - caOrderOption: 'Gorchymyn Trefniadau Plant', - 'caOrder.caseNoDetails': 'Rhif yr achos', - 'caOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'caOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'caOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'caOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - financialOrderOption: 'Gorchymyn Ariannol o dan Atodlen 1 Deddf Plant 1989', - 'financialOrder.caseNoDetails': 'Rhif yr achos', - 'financialOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'financialOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'financialOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'financialOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - nonmolestationOrderOption: 'Gorchymyn Rhag Molestu', - 'nonmolestationOrder.caseNoDetails': 'Rhif yr achos', - 'nonmolestationOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'nonmolestationOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'nonmolestationOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'nonmolestationOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - occupationalOrderOptions: 'Gorchymyn Anheddu', - 'occupationOrder.caseNoDetails': 'Rhif yr achos', - 'occupationOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'occupationOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'occupationOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'occupationOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - marraigeOrderOptions: 'Gorchymyn Amddiffyn rhag Priodas dan Orfod', - 'marraigeOrder.caseNoDetails': 'Rhif yr achos', - 'marraigeOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'marraigeOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'marraigeOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'marraigeOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - restrainingOrderOptions: 'Gorchymyn Atal', - 'restrainingOrder.caseNoDetails': 'Rhif yr achos', - 'restrainingOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'restrainingOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'restrainingOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'restrainingOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - injuctiveOrderOptions: 'Other Injunctive Order - welsh', - 'injuctiveOrder.caseNoDetails': 'Rhif yr achos', - 'injuctiveOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'injuctiveOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'injuctiveOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'injuctiveOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - underTakingOrderOptions: 'Ymgymeriad yn lle gorchymyn', - 'underTakingOrder.caseNoDetails': 'Rhif yr achos', - 'underTakingOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'underTakingOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'underTakingOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'underTakingOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - }, - errors: {}, -}; - -jest.mock('../../../../app/form/validation'); -/* eslint-disable @typescript-eslint/ban-types */ -describe('respondent/proceedings content', () => { - const commonContent = { language: 'en', userCase: mockUserCase } as CommonContent; - let generatedContent; - beforeEach(() => { - generatedContent = generateContent(commonContent); - }); - - test('should return correct english content', () => { - expect(generatedContent.title).toEqual('Check your answers'); - expect(generatedContent.section).toEqual(' '); - expect(generatedContent.title2).toEqual('Current or previous court cases'); - }); - - // eslint-disable-next-line jest/expect-expect - test('should return correct english content Data', () => { - languageAssertions('en', enContent, () => generateContent(commonContent)); - }); - - // eslint-disable-next-line jest/expect-expect - test('should return correct welsh content', () => { - languageAssertions('cy', cyContent, () => generateContent({ ...commonContent, language: 'cy' })); - }); -}); diff --git a/src/main/steps/respondent/proceedings/summary/content.ts b/src/main/steps/respondent/proceedings/summary/content.ts deleted file mode 100644 index b29ef25b79..0000000000 --- a/src/main/steps/respondent/proceedings/summary/content.ts +++ /dev/null @@ -1,483 +0,0 @@ -import { TranslationFn } from '../../../../app/controller/GetController'; -import { FormContent } from '../../../../app/form/Form'; -import { CommonContent } from '../../../../steps/common/common.content'; -import { PROCEEDINGS_COURT_PROCEEDINGS, PROCEEDINGS_START } from '../../../../steps/urls'; -import { summaryList } from '../../../common/summary/utils'; - -export const enContent = { - section: ' ', - title: 'Check your answers', - title2: 'Current or previous court cases', - sectionTitles: { - applicationDetails: '', - }, - keys: { - proceedingsStart: 'Have the children been involved in a court case?', - proceedingsStartOrder: 'Have you had a court order made for your protection?', - emergencyOrderOptions: 'Emergency Protection Order', - 'emergencyOrder.caseNoDetails': 'Case number', - 'emergencyOrder.orderDateDetails': 'What date was it made', - 'emergencyOrder.orderTimeDetails': 'How long was the order for?', - 'emergencyOrder.currentOrderDetails': 'Is this a current order?', - 'emergencyOrder.issueOrderDetails': 'Which court issued this order?', - supervisionOrderOption: 'Supervision Order', - 'supervisionOrder.caseNoDetails': 'Case number', - 'supervisionOrder.orderDateDetails': 'What date was it made', - 'supervisionOrder.orderTimeDetails': 'How long was the order for?', - 'supervisionOrder.currentOrderDetails': 'Is this a current order?', - 'supervisionOrder.issueOrderDetails': 'Which court issued this order?', - careOrderOptions: 'Care Order', - 'careOrder.caseNoDetails': 'Case number', - 'careOrder.orderDateDetails': 'What date was it made', - 'careOrder.orderTimeDetails': 'How long was the order for?', - 'careOrder.currentOrderDetails': 'Is this a current order?', - 'careOrder.issueOrderDetails': 'Which court issued this order?', - childAbductionOrderOption: 'Child Abduction', - 'childAbductionOrder.caseNoDetails': 'Case number', - 'childAbductionOrder.orderDateDetails': 'What date was it made', - 'childAbductionOrder.orderTimeDetails': 'How long was the order for?', - 'childAbductionOrder.currentOrderDetails': 'Is this a current order?', - 'childAbductionOrder.issueOrderDetails': 'Which court issued this order?', - caOrderOption: 'Child Arrangements Order', - 'caOrder.caseNoDetails': 'Case number', - 'caOrder.orderDateDetails': 'What date was it made', - 'caOrder.orderTimeDetails': 'How long was the order for?', - 'caOrder.currentOrderDetails': 'Is this a current order?', - 'caOrder.issueOrderDetails': 'Which court issued this order?', - financialOrderOption: 'Financial Order under Schedule 1 of the Children Act 1989', - 'financialOrder.caseNoDetails': 'Case number', - 'financialOrder.orderDateDetails': 'What date was it made', - 'financialOrder.orderTimeDetails': 'How long was the order for?', - 'financialOrder.currentOrderDetails': 'Is this a current order?', - 'financialOrder.issueOrderDetails': 'Which court issued this order?', - nonmolestationOrderOption: 'Non-molestation Order', - 'nonmolestationOrder.caseNoDetails': 'Case number', - 'nonmolestationOrder.orderDateDetails': 'What date was it made', - 'nonmolestationOrder.orderTimeDetails': 'How long was the order for?', - 'nonmolestationOrder.currentOrderDetails': 'Is this a current order?', - 'nonmolestationOrder.issueOrderDetails': 'Which court issued this order?', - occupationalOrderOptions: 'Occupation Order', - 'occupationOrder.caseNoDetails': 'Case number', - 'occupationOrder.orderDateDetails': 'What date was it made', - 'occupationOrder.orderTimeDetails': 'How long was the order for?', - 'occupationOrder.currentOrderDetails': 'Is this a current order?', - 'occupationOrder.issueOrderDetails': 'Which court issued this order?', - marraigeOrderOptions: 'Forced Marriage Protection Order', - 'marraigeOrder.caseNoDetails': 'Case number', - 'marraigeOrder.orderDateDetails': 'What date was it made', - 'marraigeOrder.orderTimeDetails': 'How long was the order for?', - 'marraigeOrder.currentOrderDetails': 'Is this a current order?', - 'marraigeOrder.issueOrderDetails': 'Which court issued this order?', - restrainingOrderOptions: 'Restraining Order', - 'restrainingOrder.caseNoDetails': 'Case number', - 'restrainingOrder.orderDateDetails': 'What date was it made', - 'restrainingOrder.orderTimeDetails': 'How long was the order for?', - 'restrainingOrder.currentOrderDetails': 'Is this a current order?', - 'restrainingOrder.issueOrderDetails': 'Which court issued this order?', - injuctiveOrderOptions: 'Other Injunctive Order', - 'injuctiveOrder.caseNoDetails': 'Case number', - 'injuctiveOrder.orderDateDetails': 'What date was it made', - 'injuctiveOrder.orderTimeDetails': 'How long was the order for?', - 'injuctiveOrder.currentOrderDetails': 'Is this a current order?', - 'injuctiveOrder.issueOrderDetails': 'Which court issued this order?', - underTakingOrderOptions: 'Undertaking in Place of an Order', - 'underTakingOrder.caseNoDetails': 'Case number', - 'underTakingOrder.orderDateDetails': 'What date was it made', - 'underTakingOrder.orderTimeDetails': 'How long was the order for?', - 'underTakingOrder.currentOrderDetails': 'Is this a current order?', - 'underTakingOrder.issueOrderDetails': 'Which court issued this order?', - }, - errors: {}, -}; - -const en = (content: CommonContent) => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const userCase = content.userCase!; - - updateContent(enContent, userCase, urls); - return { - ...enContent, - language: content.language, - sections: [summaryList(enContent, userCase, urls, enContent.sectionTitles.applicationDetails, content.language)], - }; -}; - -const cyContent: typeof enContent = { - section: ' ', - title: 'Gwirio eich atebion', - title2: 'Achosion llys cyfredol neu flaenorol', - sectionTitles: { - applicationDetails: '', - }, - keys: { - proceedingsStart: "Ydy'r plant wedi bod yn rhan o achos llys?", - proceedingsStartOrder: 'A oes gorchymyn llys wedi ei wneud ar eich cyfer i’ch amddiffyn?', - emergencyOrderOptions: 'Gorchymyn Diogelu Brys', - 'emergencyOrder.caseNoDetails': 'Rhif yr achos', - 'emergencyOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'emergencyOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'emergencyOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'emergencyOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - supervisionOrderOption: 'Gorchymyn Goruchwylio', - 'supervisionOrder.caseNoDetails': 'Rhif yr achos', - 'supervisionOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'supervisionOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'supervisionOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'supervisionOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - careOrderOptions: 'Gorchymyn Gofal', - 'careOrder.caseNoDetails': 'Rhif yr achos', - 'careOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'careOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'careOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'careOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - childAbductionOrderOption: 'Herwgydio Plant', - 'childAbductionOrder.caseNoDetails': 'Rhif yr achos', - 'childAbductionOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'childAbductionOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'childAbductionOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'childAbductionOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - caOrderOption: 'Gorchymyn Trefniadau Plant', - 'caOrder.caseNoDetails': 'Rhif yr achos', - 'caOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'caOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'caOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'caOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - financialOrderOption: 'Gorchymyn Ariannol o dan Atodlen 1 Deddf Plant 1989', - 'financialOrder.caseNoDetails': 'Rhif yr achos', - 'financialOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'financialOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'financialOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'financialOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - nonmolestationOrderOption: 'Gorchymyn Rhag Molestu', - 'nonmolestationOrder.caseNoDetails': 'Rhif yr achos', - 'nonmolestationOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'nonmolestationOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'nonmolestationOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'nonmolestationOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - occupationalOrderOptions: 'Gorchymyn Anheddu', - 'occupationOrder.caseNoDetails': 'Rhif yr achos', - 'occupationOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'occupationOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'occupationOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'occupationOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - marraigeOrderOptions: 'Gorchymyn Amddiffyn rhag Priodas dan Orfod', - 'marraigeOrder.caseNoDetails': 'Rhif yr achos', - 'marraigeOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'marraigeOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'marraigeOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'marraigeOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - restrainingOrderOptions: 'Gorchymyn Atal', - 'restrainingOrder.caseNoDetails': 'Rhif yr achos', - 'restrainingOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'restrainingOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'restrainingOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'restrainingOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - injuctiveOrderOptions: 'Other Injunctive Order - welsh', - 'injuctiveOrder.caseNoDetails': 'Rhif yr achos', - 'injuctiveOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'injuctiveOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'injuctiveOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'injuctiveOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - underTakingOrderOptions: 'Ymgymeriad yn lle gorchymyn', - 'underTakingOrder.caseNoDetails': 'Rhif yr achos', - 'underTakingOrder.orderDateDetails': 'Pa ddyddiad y cafodd ei wneud?', - 'underTakingOrder.orderTimeDetails': 'Am ba mor hir gwnaethpwyd y gorchymyn?', - 'underTakingOrder.currentOrderDetails': 'Ai gorchymyn cyfredol yw hwn?', - 'underTakingOrder.issueOrderDetails': 'Pa lys a gyhoeddodd y gorchymyn hwn?', - }, - errors: {}, -}; - -const urls = { - proceedingsStart: PROCEEDINGS_START, - proceedingsStartOrder: PROCEEDINGS_START, - emergencyOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, - supervisionOrderOption: PROCEEDINGS_COURT_PROCEEDINGS, - careOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, - childAbductionOrderOption: PROCEEDINGS_COURT_PROCEEDINGS, - caOrderOption: PROCEEDINGS_COURT_PROCEEDINGS, - financialOrderOption: PROCEEDINGS_COURT_PROCEEDINGS, - nonmolestationOrderOption: PROCEEDINGS_COURT_PROCEEDINGS, - occupationalOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, - marraigeOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, - restrainingOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, - injuctiveOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, - underTakingOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS, -}; - -const cy: typeof en = (content: CommonContent) => { - const userCase = content.userCase!; - return { - ...cyContent, - language: content.language, - sections: [summaryList(enContent, userCase, urls, enContent.sectionTitles.applicationDetails, content.language)], - }; -}; - -export const form: FormContent = { - fields: {}, - submit: { - text: l => l.continue, - }, -}; - -const languages = { - en, - cy, -}; - -export const generateContent: TranslationFn = content => { - const translations = languages[content.language](content); - return { - ...translations, - form, - }; -}; - -function updateContent(enContentTemp, userCaseTemp, urlsTemp) { - if (userCaseTemp.proceedingsStart === 'No' && userCaseTemp.proceedingsStartOrder === 'No') { - clearObject(enContentTemp.keys, urlsTemp); - addProceedingsStart(enContentTemp, urlsTemp); - addProceedingsStartOrder(enContentTemp, urlsTemp); - } else if (userCaseTemp.proceedingsStart === 'Yes' || userCaseTemp.proceedingsStartOrder === 'Yes') { - if ( - userCaseTemp.emergencyOrderOptions === 'No' || - userCaseTemp.supervisionOrderOption === 'No' || - userCaseTemp.careOrderOptions === 'No' || - userCaseTemp.childAbductionOrderOption === 'No' || - userCaseTemp.caOrderOption === 'No' || - userCaseTemp.financialOrderOption === 'No' || - userCaseTemp.nonmolestationOrderOption === 'No' || - userCaseTemp.occupationalOrderOptions === 'No' || - userCaseTemp.marraigeOrderOptions === 'No' || - userCaseTemp.restrainingOrderOptions === 'No' || - userCaseTemp.injuctiveOrderOptions === 'No' || - userCaseTemp.underTakingOrderOptions === 'No' - ) { - clearObject(enContentTemp.keys, urlsTemp); - addProceedingsStart(enContentTemp, urlsTemp); - addProceedingsStartOrder(enContentTemp, urlsTemp); - addEmergencyOrder(enContentTemp, urlsTemp, userCaseTemp); - addSuperVisionOrder(enContentTemp, urlsTemp, userCaseTemp); - addCareOrder(enContentTemp, urlsTemp, userCaseTemp); - addchildAbductionOrder(enContentTemp, urlsTemp, userCaseTemp); - addCaOrder(enContentTemp, urlsTemp, userCaseTemp); - addFinancialOrder(enContentTemp, urlsTemp, userCaseTemp); - addNonmolestationOrder(enContentTemp, urlsTemp, userCaseTemp); - addOccupationOrder(enContentTemp, urlsTemp, userCaseTemp); - addMarriageOrder(enContentTemp, urlsTemp, userCaseTemp); - addRestrainingOrder(enContentTemp, urlsTemp, userCaseTemp); - addInjunctiveOrder(enContentTemp, urlsTemp, userCaseTemp); - addUndertakingOrder(enContentTemp, urlsTemp, userCaseTemp); - } - } -} - -function addProceedingsStart(enContenttemp, urlstemp) { - Object.assign(enContenttemp.keys, { proceedingsStart: 'Have the children been involved in a court case?' }); - Object.assign(urlstemp, { proceedingsStart: PROCEEDINGS_START }); -} - -function addProceedingsStartOrder(enContenttemp, urlstemp) { - Object.assign(enContenttemp.keys, { proceedingsStartOrder: 'Have you had a court order made for your protection?' }); - Object.assign(urlstemp, { proceedingsStartOrder: PROCEEDINGS_START }); -} - -function addEmergencyOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { emergencyOrderOptions: 'Emergency Protection Order' }); - Object.assign(urlstemp, { emergencyOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.emergencyOrderOptions === 'Yes') { - addEmergencyOrderSubFields(enContenttemp); - } -} - -function addEmergencyOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'emergencyOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'emergencyOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'emergencyOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'emergencyOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'emergencyOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addSuperVisionOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { supervisionOrderOption: 'Supervision Order' }); - Object.assign(urlstemp, { supervisionOrderOption: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.supervisionOrderOption === 'Yes') { - addSuperVisionOrderSubFields(enContenttemp); - } -} - -function addSuperVisionOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'supervisionOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'supervisionOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'supervisionOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'supervisionOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'supervisionOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addCareOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { careOrderOptions: 'Care Order' }); - Object.assign(urlstemp, { careOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.careOrderOptions === 'Yes') { - addCareOrderSubFields(enContenttemp); - } -} - -function addCareOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'careOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'careOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'careOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'careOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'careOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addchildAbductionOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { childAbductionOrderOption: 'Child Abduction' }); - Object.assign(urlstemp, { childAbductionOrderOption: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.childAbductionOrderOption === 'Yes') { - addchildAbductionOrderSubFields(enContenttemp); - } -} - -function addchildAbductionOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'childAbductionOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'childAbductionOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'childAbductionOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'childAbductionOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'childAbductionOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addCaOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { caOrderOption: 'Child Arrangements Order' }); - Object.assign(urlstemp, { caOrderOption: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.caOrderOption === 'Yes') { - addCaOrderSubFields(enContenttemp); - } -} -function addCaOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'caOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'caOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'caOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'caOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'careOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addFinancialOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { - financialOrderOption: 'Financial Order under Schedule 1 of the Children Act 1989', - }); - Object.assign(urlstemp, { financialOrderOption: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.financialOrderOption === 'Yes') { - addFinancialOrderSubFields(enContenttemp); - } -} - -function addFinancialOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'financialOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'financialOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'financialOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'financialOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'careOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addNonmolestationOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { nonmolestationOrderOption: 'Non-molestation Order' }); - Object.assign(urlstemp, { nonmolestationOrderOption: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.nonmolestationOrderOption === 'Yes') { - addNonmolestationOrderSubFields(enContenttemp); - } -} - -function addNonmolestationOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'nonmolestationOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'nonmolestationOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'nonmolestationOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'nonmolestationOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'nonmolestationOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addOccupationOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { occupationalOrderOptions: 'Occupation Order' }); - Object.assign(urlstemp, { occupationalOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.occupationalOrderOptions === 'Yes') { - addOccupationOrderSubFields(enContenttemp); - } -} - -function addOccupationOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'occupationOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'occupationOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'occupationOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'occupationOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'occupationOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function addMarriageOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { marraigeOrderOptions: 'Forced Marriage Protection Order' }); - Object.assign(urlstemp, { marraigeOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.marraigeOrderOptions === 'Yes') { - addMarriagerderSubFields(enContenttemp); - } -} - -function addMarriagerderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'marraigeOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'marraigeOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'marraigeOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'marraigeOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'marraigeOrder.issueOrderDetails': 'Which court issued this order?' }); -} -function addRestrainingOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { restrainingOrderOptions: 'Restraining Order' }); - Object.assign(urlstemp, { restrainingOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.restrainingOrderOptions === 'Yes') { - addRestrainingOrderSubFields(enContenttemp); - } -} - -function addRestrainingOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'restrainingOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'restrainingOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'restrainingOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'restrainingOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'restrainingOrder.issueOrderDetails': 'Which court issued this order?' }); -} -function addInjunctiveOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { injuctiveOrderOptions: 'Other Injunctive Order' }); - Object.assign(urlstemp, { injuctiveOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.injuctiveOrderOptions === 'Yes') { - addInjunctiveOrderSubFields(enContenttemp); - } -} - -function addInjunctiveOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'injuctiveOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'injuctiveOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'injuctiveOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'injuctiveOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'injuctiveOrder.issueOrderDetails': 'Which court issued this order?' }); -} -function addUndertakingOrder(enContenttemp, urlstemp, userCaseTemp) { - Object.assign(enContenttemp.keys, { underTakingOrderOptions: 'Undertaking in Place of an Order' }); - Object.assign(urlstemp, { underTakingOrderOptions: PROCEEDINGS_COURT_PROCEEDINGS }); - if (userCaseTemp.underTakingOrderOptions === 'Yes') { - addUndertakingOrderSubFields(enContenttemp); - } -} - -function addUndertakingOrderSubFields(enContenttemp) { - Object.assign(enContenttemp.keys, { 'underTakingOrder.caseNoDetails': 'Case number' }); - Object.assign(enContenttemp.keys, { 'underTakingOrder.orderDateDetails': 'What date was it made' }); - Object.assign(enContenttemp.keys, { 'underTakingOrder.orderTimeDetails': 'How long was the order for?' }); - Object.assign(enContenttemp.keys, { 'underTakingOrder.currentOrderDetails': 'Is this a current order?' }); - Object.assign(enContenttemp.keys, { 'underTakingOrder.issueOrderDetails': 'Which court issued this order?' }); -} - -function clearObject(enContenttemp, urlstemp) { - for (const key in enContenttemp) { - delete enContenttemp[key]; - } - for (const key in urlstemp) { - delete urlstemp[key]; - } -} diff --git a/src/main/steps/respondent/proceedings/summary/template.njk b/src/main/steps/respondent/proceedings/summary/template.njk deleted file mode 100644 index f95db57149..0000000000 --- a/src/main/steps/respondent/proceedings/summary/template.njk +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "common/summary/template.njk" %} -{% block page_content %} -

    {{title}}

    -

    {{title2}}

    -{% endblock %} \ No newline at end of file diff --git a/src/main/steps/tasklistresponse/proceedings/documentUpload/postController.ts b/src/main/steps/tasklistresponse/proceedings/documentUpload/postController.ts index 3895ec101c..45cf46bbdf 100644 --- a/src/main/steps/tasklistresponse/proceedings/documentUpload/postController.ts +++ b/src/main/steps/tasklistresponse/proceedings/documentUpload/postController.ts @@ -15,7 +15,7 @@ import { AnyObject, PostController } from '../../../../app/controller/PostContro import { FormFields, FormFieldsFn } from '../../../../app/form/Form'; import { isFileSizeGreaterThanMaxAllowed, isValidFileFormat } from '../../../../app/form/validation'; import { applyParms } from '../../../../steps/common/url-parser'; -import { OTHER_PROCEEDINGS_DOCUMENT_UPLOAD } from '../../../urls'; +import { C100_OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, OTHER_PROCEEDINGS_DOCUMENT_UPLOAD } from '../../../urls'; const C100OrderTypeNameMapper = { childArrangementOrder: 'Child Arrangements Order', @@ -37,7 +37,6 @@ const C100OrderTypeNameMapper = { }; //eslint-disable-next-line @typescript-eslint/no-explicit-any -export type AnyType = any; /* The UploadDocumentController class extends the PostController class and overrides the PostDocumentUploader method */ @@ -57,12 +56,12 @@ export default class UploadDocumentController extends PostController const { orderType, orderId } = requ.params; const req: AppRequest = requ; const courtOrderType = orderType as ProceedingsOrderTypes; - const courtOrderId: AnyType | undefined = orderId; + const courtOrderId: string | undefined = orderId; const orderSessionData = req.session.userCase?.otherProceedings?.order?.[ ProceedingsOrderTypeKeyMapper[courtOrderType] ] as ProceedingsOrderInterface[]; - const orderSessionDataById = orderSessionData[courtOrderId - 1]; + const orderSessionDataById = orderSessionData[(courtOrderId as unknown as number) - 1]; if (req.body.onlyContinue && this.checkIfDocumentAlreadyExist(orderSessionDataById)) { return super.redirect(req, res); @@ -88,32 +87,17 @@ export default class UploadDocumentController extends PostController return false; }; /* eslint-disable @typescript-eslint/no-explicit-any*/ - private async processNewDocument( + async processNewDocument( files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[] | undefined, - req: AppRequest, - res: Response>, + req: AppRequest, + res: Response, orderType: string, orderId: string, courtOrderType: ProceedingsOrderTypes, - courtOrderId: any - ) { - if (isNull(files) || files === undefined) { - this.uploadFileError(req, res, orderType, orderId, { - propertyName: 'document', - errorType: 'required', - }); - } else if (!isValidFileFormat(files)) { - this.uploadFileError(req, res, orderType, orderId, { - propertyName: 'document', - errorType: 'fileFormat', - }); - } else if (isFileSizeGreaterThanMaxAllowed(files)) { - this.uploadFileError(req, res, orderType, orderId, { - propertyName: 'document', - errorType: 'fileSize', - }); - } else { - const { documents }: AnyType = files; + courtOrderId: string + ): Promise { + if (validate(files, req, res, orderType, orderId, true)) { + const { documents }: any = files; const formData: FormData = new FormData(); @@ -145,11 +129,11 @@ export default class UploadDocumentController extends PostController if ( req.session.userCase?.otherProceedings?.order?.[ProceedingsOrderTypeKeyMapper[courtOrderType]][ - courtOrderId - 1 + (courtOrderId as unknown as number) - 1 ] ) { req.session.userCase.otherProceedings.order[ProceedingsOrderTypeKeyMapper[courtOrderType]][ - courtOrderId - 1 + (courtOrderId as unknown as number) - 1 ].orderDocument = documentInfo; } @@ -165,31 +149,82 @@ export default class UploadDocumentController extends PostController public buildOrderTypeName(courtOrderType: ProceedingsOrderTypes): string { return C100OrderTypeNameMapper[courtOrderType].split(' ').join('_').toLowerCase(); } - +} +export const validate = ( + files: Express.Multer.File[] | { [fieldname: string]: Express.Multer.File[] } | undefined, + req: AppRequest, + res: Response>, + orderType: string, + orderId: string, + isResponseJourney: boolean +): boolean | void => { + if (isNull(files) || files === undefined) { + return uploadFileError( + req, + res, + orderType, + orderId, + { + propertyName: 'document', + errorType: 'required', + }, + isResponseJourney + ); + } else if (!isValidFileFormat(files)) { + return uploadFileError( + req, + res, + orderType, + orderId, + { + propertyName: 'document', + errorType: 'fileFormat', + }, + isResponseJourney + ); + } else if (isFileSizeGreaterThanMaxAllowed(files)) { + return uploadFileError( + req, + res, + orderType, + orderId, + { + propertyName: 'document', + errorType: 'fileSize', + }, + isResponseJourney + ); + } else { + return true; + } +}; +/** + * It's a function that handles errors that occur during the upload process + * @param req - AppRequest + * @param res - Response> + * @param {string} [errorMessage] - The error message to be displayed. + */ +const uploadFileError = ( + req: AppRequest, + res: Response, + orderType: string, + orderId: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + errObj: any, + isResponseJourney: boolean +) => { /** - * It's a function that handles errors that occur during the upload process - * @param req - AppRequest - * @param res - Response> - * @param {string} [errorMessage] - The error message to be displayed. + * @Insert @Error @here */ - - private uploadFileError( - req: AppRequest, - res: Response>, - orderType: string, - orderId: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - errObj: any - ) { - /** - * @Insert @Error @here - */ - req.session.errors = [errObj]; - req.session.save(err => { - if (err) { - throw err; - } - res.redirect(applyParms(OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, { orderType, orderId })); - }); - } -} + req.session.errors = [errObj]; + req.session.save(err => { + if (err) { + throw err; + } + res.redirect( + isResponseJourney + ? applyParms(OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, { orderType, orderId }) + : applyParms(C100_OTHER_PROCEEDINGS_DOCUMENT_UPLOAD, { orderType, orderId }) + ); + }); +}; diff --git a/src/main/steps/tasklistresponse/proceedings/htmlSelectors.test.ts b/src/main/steps/tasklistresponse/proceedings/htmlSelectors.test.ts index 7fa5cb826b..e1ce001317 100644 --- a/src/main/steps/tasklistresponse/proceedings/htmlSelectors.test.ts +++ b/src/main/steps/tasklistresponse/proceedings/htmlSelectors.test.ts @@ -5,7 +5,6 @@ const LIST_ITEM_END = ''; const UNORDER_LIST = '
      '; const UNORDER_LIST_END = '
    '; const NESTED_LIST_ITEM = '
  • '; -const NESTED_LIST_ITEM_END = '
  • '; const H4 = '

    '; const H3 = '

    '; const P = '

    '; @@ -16,7 +15,6 @@ const RULER = '


    '; const BOTTOM_TOP_3 = '
    '; const BOTTOM_PADDING_CLOSE = '
    '; -const TOP_PADDING_CLOSE = ''; const BREAK = '
    '; test('htmlSelectorpositivetest', () => { @@ -25,7 +23,6 @@ test('htmlSelectorpositivetest', () => { expect(HTML.UNORDER_LIST).toBe(UNORDER_LIST), expect(HTML.UNORDER_LIST_END).toBe(UNORDER_LIST_END), expect(HTML.NESTED_LIST_ITEM).toBe(NESTED_LIST_ITEM), - expect(HTML.NESTED_LIST_ITEM_END).toBe(NESTED_LIST_ITEM_END), expect(HTML.H4).toBe(H4), expect(HTML.H3).toBe(H3), expect(HTML.P).toBe(P), @@ -36,7 +33,6 @@ test('htmlSelectorpositivetest', () => { expect(HTML.BOTTOM_PADDING_3).toBe(BOTTOM_PADDING_3), expect(HTML.BOTTOM_TOP_3).toBe(BOTTOM_TOP_3), expect(HTML.BOTTOM_PADDING_CLOSE).toBe(BOTTOM_PADDING_CLOSE), - expect(HTML.TOP_PADDING_CLOSE).toBe(TOP_PADDING_CLOSE), expect(HTML.BREAK).toBe(BREAK); }); test('htmlSelectornegativetest', () => { @@ -44,8 +40,6 @@ test('htmlSelectornegativetest', () => { expect(HTML.LIST_ITEM_END).not.toBe(LIST_ITEM), expect(HTML.UNORDER_LIST).not.toBe(UNORDER_LIST_END), expect(HTML.UNORDER_LIST_END).not.toBe(UNORDER_LIST), - expect(HTML.NESTED_LIST_ITEM).not.toBe(NESTED_LIST_ITEM_END), - expect(HTML.NESTED_LIST_ITEM_END).not.toBe(NESTED_LIST_ITEM), expect(HTML.H4).not.toBe(H4_CLOSE), expect(HTML.H3).not.toBe(H3_CLOSE), expect(HTML.P).not.toBe(P_CLOSE), @@ -56,6 +50,5 @@ test('htmlSelectornegativetest', () => { expect(HTML.BOTTOM_PADDING_3).not.toBe(BOTTOM_TOP_3), expect(HTML.BOTTOM_TOP_3).not.toBe(BOTTOM_PADDING_3), expect(HTML.BOTTOM_PADDING_CLOSE).not.toBe(BOTTOM_TOP_3), - expect(HTML.TOP_PADDING_CLOSE).not.toBe(BOTTOM_TOP_3), expect(HTML.BREAK).not.toBe(RULER); }); diff --git a/src/main/steps/tasklistresponse/proceedings/htmlSelectors.ts b/src/main/steps/tasklistresponse/proceedings/htmlSelectors.ts index 9913acff96..fe33d252e6 100644 --- a/src/main/steps/tasklistresponse/proceedings/htmlSelectors.ts +++ b/src/main/steps/tasklistresponse/proceedings/htmlSelectors.ts @@ -4,7 +4,6 @@ export enum HTML { UNORDER_LIST = '
      ', UNORDER_LIST_END = '
    ', NESTED_LIST_ITEM = '
  • ', - NESTED_LIST_ITEM_END = '
  • ', H1 = '

    ', H1_CLOSE = '

    ', H4 = '

    ', @@ -17,7 +16,6 @@ export enum HTML { BOTTOM_PADDING_3 = '
    ', BOTTOM_TOP_3 = '
    ', BOTTOM_PADDING_CLOSE = '
    ', - TOP_PADDING_CLOSE = '
    ', BREAK = '
    ', H4_SECTION_TITLE = '

    ', STATEMENT_OF_TRUTH_H2 = "

    ", diff --git a/src/main/steps/tasklistresponse/proceedings/proceedingUtils.ts b/src/main/steps/tasklistresponse/proceedings/proceedingUtils.ts index d7cb7c7081..bbdf56ad66 100644 --- a/src/main/steps/tasklistresponse/proceedings/proceedingUtils.ts +++ b/src/main/steps/tasklistresponse/proceedings/proceedingUtils.ts @@ -3,6 +3,7 @@ import { YesOrNo } from '../../../app/case/definition'; import { PROCEEDINGS_ORDER_DETAILS } from '../../../steps/urls'; import { getYesNoTranslation } from '../../c100-rebuild/check-your-answers/mainUtil'; +import { Mapper } from '../../c100-rebuild/check-your-answers/util/otherProceeding.util'; import { DATE_FORMATTOR } from '../../common/dateformatter'; import { applyParms } from '../../common/url-parser'; @@ -13,29 +14,6 @@ import { cy as opDetailsCyContents, en as opDetailsEnContents } from './order-de /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ export const IndividualOrderFieldsParser = (keys, order, language) => { const newOrders = order; - const Mapper = { - ['orderDetail']: { - question: keys['courtIssuedLabel'], - }, - ['caseNo']: { - question: keys['caseNumberLabel'], - }, - ['orderDate']: { - question: keys['orderDateLabel'], - }, - ['currentOrder']: { - question: keys['isCurrentOrderLabel'], - }, - ['orderCopy']: { - question: keys['copyOfOrderLabel'], - }, - ['orderEndDate']: { - question: keys['orderEndDateLabel'], - }, - ['orderDocument']: { - question: keys['copy'], - }, - }; let Val = ''; Object.entries(newOrders).forEach((entry, index) => { const key = entry[0]; @@ -43,11 +21,11 @@ export const IndividualOrderFieldsParser = (keys, order, language) => { const rulerForLastElement = Object.entries(newOrders).length > index + 1 ? HTML.RULER : '
    '; if (key !== 'id' && key !== 'orderDocument') { if (typeof entry[1] === 'object' && entry[1] !== null) { - const keyDetails = HTML.H4 + Mapper[key]?.question + HTML.H4_CLOSE; + const keyDetails = HTML.H4 + Mapper(key, keys) + HTML.H4_CLOSE; const valueDetails = HTML.P + DATE_FORMATTOR(value, language) + HTML.P_CLOSE; Val += keyDetails + valueDetails + rulerForLastElement; } else { - const keyDetails = HTML.H4 + Mapper[key]?.question + HTML.H4_CLOSE; + const keyDetails = HTML.H4 + Mapper(key, keys) + HTML.H4_CLOSE; const valueDetails = HTML.P + (value === YesOrNo.YES @@ -58,11 +36,11 @@ export const IndividualOrderFieldsParser = (keys, order, language) => { } } else if (key === 'orderDocument') { if (value !== 'undefined') { - const keyDetails = HTML.H4 + Mapper[key]?.question + HTML.H4_CLOSE; + const keyDetails = HTML.H4 + Mapper(key, keys) + HTML.H4_CLOSE; const valueDetails = HTML.P + getYesNoTranslation(language, YesOrNo.YES, 'doTranslation') + HTML.P_CLOSE; Val += keyDetails + valueDetails + rulerForLastElement; } else { - const keyDetails = HTML.H4 + Mapper[key]?.question + HTML.H4_CLOSE; + const keyDetails = HTML.H4 + Mapper(key, keys) + HTML.H4_CLOSE; const valueDetails = HTML.P + getYesNoTranslation(language, YesOrNo.NO, 'doTranslation') + HTML.P_CLOSE; Val += keyDetails + valueDetails + rulerForLastElement; } diff --git a/src/main/steps/tasklistresponse/summary/postController.ts b/src/main/steps/tasklistresponse/summary/postController.ts index 715a686815..6d7bd770be 100644 --- a/src/main/steps/tasklistresponse/summary/postController.ts +++ b/src/main/steps/tasklistresponse/summary/postController.ts @@ -37,7 +37,6 @@ export default class ResponseSummaryConfirmationPostController extends PostContr } public async submitC7Response(req: AppRequest, res: Response): Promise { - //TODO update when merged with response submission fixes const { user, userCase } = req.session; const partyDetails = getPartyDetails(userCase, user.id); const client = new CosApiClient(user.accessToken, req.locals.logger);