From 463b1fcc9ccab592c9ede9d74e62a7890baea605 Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Tue, 28 Jan 2025 17:37:34 +0000 Subject: [PATCH 1/5] feat(DTFS2-7781): add eligibility page to amendment journeys --- .../change-both-cover-end-date-and-facility-value.spec.js | 4 +++- .../journeys/change-cover-end-date-with-BRD-journey.spec.js | 4 +++- .../journeys/change-cover-end-date-with-FED-journey.spec.js | 4 +++- .../amendments/journeys/change-facility-value-journey.spec.js | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js index f7f429b20a..25d1fcbcfd 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js @@ -93,8 +93,10 @@ context('Amendments - Change both cover end date and facility value - full journ cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); + cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.clickContinueButton(); - // TODO DTFS2-7524: add steps for effective from date + cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); // TODO DTFS2-7519: add steps for check your answer page }); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js index 54f42b65ad..24d3e61d1e 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js @@ -88,8 +88,10 @@ context('Amendments - Change cover end date with bank review date - full journey cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); + cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.clickContinueButton(); - // TODO DTFS2-7524: add steps for effective from date + cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); // TODO DTFS2-7519: add steps for check your answer page }); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js index d466da703f..4fccf559b5 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js @@ -87,8 +87,10 @@ context('Amendments - Change cover end date with facility end date - full journe cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); + cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.clickContinueButton(); - // TODO DTFS2-7524: add steps for effective from date + cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); // TODO DTFS2-7519: add steps for check your answer page }); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js index 96de7bf1ac..736e2c9823 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js @@ -72,8 +72,10 @@ context('Amendments - change facility value - full journey', () => { cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); + cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.clickContinueButton(); - // TODO DTFS2-7524: add steps for effective from date + cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); // TODO DTFS2-7519: add steps for check your answer page }); From b582db7ebc4ca0b8b34f167e9b143a2d6533037d Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Wed, 29 Jan 2025 09:28:06 +0000 Subject: [PATCH 2/5] feat(DTFS2-7781): add page e2e test (WIP) --- .../e2e/pages/amendments/effective-from.js | 12 ++ .../amendments/pages/effective-date.spec.js | 131 ++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js create mode 100644 e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js diff --git a/e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js b/e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js new file mode 100644 index 0000000000..65cd0ac053 --- /dev/null +++ b/e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js @@ -0,0 +1,12 @@ +const effectiveFrom = { + effectiveFromDay: () => cy.get('[data-cy="effective-from-day"]'), + effectiveFromMonth: () => cy.get('[data-cy="effective-from-month"]'), + effectiveFromYear: () => cy.get('[data-cy="effective-from-year"]'), + errorSummary: () => cy.get('[data-cy="error-summary"]'), + effectiveFromInlineError: () => cy.get('[data-cy="effective-from-inline-error"]'), + pageHeading: () => cy.get('[data-cy="page-heading"]'), + backLink: () => cy.get('[data-cy="back-link"]'), + cancelLink: () => cy.get('[data-cy="cancel-link"]'), +}; + +module.exports = effectiveFrom; diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js new file mode 100644 index 0000000000..8be5029808 --- /dev/null +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js @@ -0,0 +1,131 @@ +import relative from '../../../../relativeURL'; +import MOCK_USERS from '../../../../../../../e2e-fixtures/portal-users.fixture'; +import { MOCK_APPLICATION_AIN_DRAFT } from '../../../../../../../e2e-fixtures/gef/mocks/mock-deals'; +import { anIssuedCashFacility } from '../../../../../../../e2e-fixtures/mock-gef-facilities'; +import { applicationPreview } from '../../../../../../../gef/cypress/e2e/pages'; +import whatDoYouNeedToChange from '../../../../../../../gef/cypress/e2e/pages/amendments/what-do-you-need-to-change'; +import facilityValue from '../../../../../../../gef/cypress/e2e/pages/amendments/facility-value'; +import eligibility from '../../../../../../../gef/cypress/e2e/pages/amendments/eligibility'; +import effectiveFrom from '../../../../../../../gef/cypress/e2e/pages/amendments/effective-from'; +import { twoDaysAgo, twoMonths, yesterday } from '../../../../../../../e2e-fixtures/dateConstants'; + +const { BANK1_MAKER1 } = MOCK_USERS; + +context('Amendments - Date amendment effective from - page tests', () => { + /** + * @type {string} + */ + let dealId; + + /** + * @type {string} + */ + let facilityId; + /** + * @type {string} + */ + let amendmentId; + + before(() => { + cy.insertOneGefDeal(MOCK_APPLICATION_AIN_DRAFT, BANK1_MAKER1).then((insertedDeal) => { + dealId = insertedDeal._id; + + cy.updateGefDeal(dealId, MOCK_APPLICATION_AIN_DRAFT, BANK1_MAKER1); + + cy.createGefFacilities(dealId, [anIssuedCashFacility({ facilityEndDateEnabled: true })], BANK1_MAKER1).then((createdFacility) => { + facilityId = createdFacility.details._id; + + cy.makerLoginSubmitGefDealForReview(insertedDeal); + cy.checkerLoginSubmitGefDealToUkef(insertedDeal); + + cy.clearSessionCookies(); + cy.login(BANK1_MAKER1); + cy.saveSession(); + cy.visit(relative(`/gef/application-details/${dealId}`)); + + applicationPreview.makeAChangeButton(facilityId).click(); + + cy.url().then((url) => { + const urlSplit = url.split('/'); + + amendmentId = urlSplit[9]; + }); + + whatDoYouNeedToChange.facilityValueCheckbox().click(); + cy.clickContinueButton(); + cy.keyboardInput(facilityValue.facilityValue(), '10000'); + cy.clickContinueButton(); + eligibility.allTrueRadioButtons().click({ multiple: true }); + cy.clickContinueButton(); + }); + }); + }); + + after(() => { + cy.clearCookies(); + cy.clearSessionCookies(); + }); + + beforeEach(() => { + cy.clearSessionCookies(); + cy.login(BANK1_MAKER1); + cy.visit(relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); + }); + + it('should render key features of the page', () => { + effectiveFrom.pageHeading().contains('Date amendment effective from'); + effectiveFrom.backLink(); + effectiveFrom.cancelLink(); + }); + + it('should render an error if no date is provided', () => { + cy.clickContinueButton(); + + effectiveFrom.errorSummary().should('be.visible'); + effectiveFrom.errorSummary().contains('Enter the date amendment effective from'); + + effectiveFrom.effectiveFromInlineError().should('be.visible'); + effectiveFrom.effectiveFromInlineError().contains('Enter the date amendment effective from'); + }); + + const effectiveFromErrorTestCases = [ + { + description: 'the date amendment effective from consists of invalid characters', + dateFieldInput: { day: 'aa', month: '11', year: '2025' }, + expectedErrorMessage: 'date amendment effective from must be a real date', + }, + { + description: 'the date amendment effective from is missing a field', + dateFieldInput: { day: '2', month: '', year: '2025' }, + expectedErrorMessage: 'date amendment effective from must include a month', + }, + { + description: 'the date amendment effective from is greater than 30 days in the future', + dateFieldInput: twoMonths, + expectedErrorMessage: `You entered an amendment date more than 30 days from now. Amendments must be effective within the next 30 days - come back later or use the Schedule 8 form`, + }, + { + description: 'the date amendment effective from is before the cover start date', + dateFieldInput: twoDaysAgo, + expectedErrorMessage: `Date amendment effective from cannot be before the cover start date ${yesterday.d_MMMM_yyyy}`, + }, + ]; + + effectiveFromErrorTestCases.forEach(({ description, dateFieldInput, expectedErrorMessage }) => { + it(`should render an error on the bank review date page if ${description}`, () => { + cy.completeDateFormFields({ idPrefix: 'bank-review-date', ...dateFieldInput }); + cy.clickContinueButton(); + + effectiveFrom.errorSummary().should('be.visible'); + effectiveFrom.errorSummary().contains(expectedErrorMessage); + effectiveFrom.effectiveFromInlineError().should('be.visible'); + effectiveFrom.effectiveFromInlineError().contains(expectedErrorMessage); + }); + }); + + it('should navigate to cancel page when cancel is clicked', () => { + eligibility.cancelLink().click(); + + cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`)); + }); +}); From 6c94f0f077a0879c0e59ee6bf3b9d1e50b30d516 Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Thu, 30 Jan 2025 16:52:59 +0000 Subject: [PATCH 3/5] feat(DTFS2-7781): fix typo in e2e test --- .../e2e/journeys/portal/amendments/pages/effective-date.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js index 8be5029808..abbacaf7cc 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js @@ -113,7 +113,7 @@ context('Amendments - Date amendment effective from - page tests', () => { effectiveFromErrorTestCases.forEach(({ description, dateFieldInput, expectedErrorMessage }) => { it(`should render an error on the bank review date page if ${description}`, () => { - cy.completeDateFormFields({ idPrefix: 'bank-review-date', ...dateFieldInput }); + cy.completeDateFormFields({ idPrefix: 'effective-from', ...dateFieldInput }); cy.clickContinueButton(); effectiveFrom.errorSummary().should('be.visible'); From 08b936697586d493b05cfd7d7765da4411afa139 Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Mon, 3 Feb 2025 12:42:26 +0000 Subject: [PATCH 4/5] feat(DTFS2-7781): rename effectiveFrom to effectiveDate --- ...est.ts => effective-date.post.api-test.ts} | 66 +++++------ ...st.ts => effective-date.component-test.ts} | 26 ++--- ...rom.test.ts => get-effective-date.test.ts} | 56 +++++----- ...ffective-from.ts => get-effective-date.ts} | 14 +-- ...om.test.ts => post-effective-date.test.ts} | 104 +++++++++--------- ...fective-from.ts => post-effective-date.ts} | 36 +++--- .../effective-date/validation.test.ts | 72 ++++++------ .../amendments/effective-date/validation.ts | 30 ++--- .../routes/facilities/amendments/index.ts | 8 +- ...-model.ts => effective-date-view-model.ts} | 4 +- ...{effective-from.njk => effective-date.njk} | 28 ++--- gef-ui/test-helpers/mock-amendment.ts | 4 +- .../src/constants/portal/date-validation.ts | 4 +- libs/common/src/schemas/portal-amendment.ts | 2 +- 14 files changed, 227 insertions(+), 227 deletions(-) rename gef-ui/api-tests/amendments/{effective-from.post.api-test.ts => effective-date.post.api-test.ts} (79%) rename gef-ui/component-tests/partials/amendments/{effective-from.component-test.ts => effective-date.component-test.ts} (75%) rename gef-ui/server/controllers/amendments/effective-date/{get-effective-from.test.ts => get-effective-date.test.ts} (87%) rename gef-ui/server/controllers/amendments/effective-date/{get-effective-from.ts => get-effective-date.ts} (85%) rename gef-ui/server/controllers/amendments/effective-date/{post-effective-from.test.ts => post-effective-date.test.ts} (73%) rename gef-ui/server/controllers/amendments/effective-date/{post-effective-from.ts => post-effective-date.ts} (65%) rename gef-ui/server/types/view-models/amendments/{effective-from-view-model.ts => effective-date-view-model.ts} (77%) rename gef-ui/templates/partials/amendments/{effective-from.njk => effective-date.njk} (80%) diff --git a/gef-ui/api-tests/amendments/effective-from.post.api-test.ts b/gef-ui/api-tests/amendments/effective-date.post.api-test.ts similarity index 79% rename from gef-ui/api-tests/amendments/effective-from.post.api-test.ts rename to gef-ui/api-tests/amendments/effective-date.post.api-test.ts index a8864b4378..3aa7d33cf1 100644 --- a/gef-ui/api-tests/amendments/effective-from.post.api-test.ts +++ b/gef-ui/api-tests/amendments/effective-date.post.api-test.ts @@ -55,7 +55,7 @@ describe(`POST ${url}`, () => { .withDealId(dealId) .withFacilityId(facilityId) .withAmendmentId(amendmentId) - .withEffectiveFrom(getUnixTime(today)) + .withEffectiveDate(getUnixTime(today)) .build(), ); }); @@ -74,9 +74,9 @@ describe(`POST ${url}`, () => { it('should redirect to /not-found', async () => { // Arrange const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -96,9 +96,9 @@ describe(`POST ${url}`, () => { it('should redirect to /not-found', async () => { // Arrange const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -119,9 +119,9 @@ describe(`POST ${url}`, () => { makeRequestWithHeaders: (headers: Headers) => post( { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }, headers, ).to(url), @@ -134,9 +134,9 @@ describe(`POST ${url}`, () => { mockGetFacility.mockResolvedValue({ details: undefined }); const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -151,9 +151,9 @@ describe(`POST ${url}`, () => { mockGetApplication.mockResolvedValue(undefined); const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -164,9 +164,9 @@ describe(`POST ${url}`, () => { expect(response.headers.location).toEqual('/not-found'); }); - it('should render date amendment effective from page with errors if effective from is invalid', async () => { + it('should render date amendment effective date page with errors if effective date is invalid', async () => { // Arrange - const body = { 'effective-from-day': '1000', 'effective-from-month': '100', 'effective-from-year': '100' }; + const body = { 'effective-date-day': '1000', 'effective-date-month': '100', 'effective-date-year': '100' }; // Act const response = await postWithSessionCookie(body, sessionCookie); @@ -177,9 +177,9 @@ describe(`POST ${url}`, () => { expect(response.text).toContain('Date amendment effective from must be a real date'); }); - it('should render date amendment effective from page with errors if effective from is not provided', async () => { + it('should render date amendment effective date page with errors if effective date is not provided', async () => { // Arrange - const body = { 'effective-from-day': '', 'effective-from-month': '', 'effective-from-year': '' }; + const body = { 'effective-date-day': '', 'effective-date-month': '', 'effective-date-year': '' }; // Act const response = await postWithSessionCookie(body, sessionCookie); @@ -190,12 +190,12 @@ describe(`POST ${url}`, () => { expect(response.text).toContain('Enter the date amendment effective from'); }); - it('should redirect to the next page if the effective from is valid', async () => { + it('should redirect to the next page if the effective date is valid', async () => { // Arrange const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -213,9 +213,9 @@ describe(`POST ${url}`, () => { mockGetApplication.mockRejectedValue(new Error('test error')); const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -231,9 +231,9 @@ describe(`POST ${url}`, () => { mockGetFacility.mockRejectedValue(new Error('test error')); const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act @@ -249,9 +249,9 @@ describe(`POST ${url}`, () => { mockUpdateAmendment.mockRejectedValue(new Error('test error')); const body = { - 'effective-from-day': format(today, 'd'), - 'effective-from-month': format(today, 'M'), - 'effective-from-year': format(today, 'yyyy'), + 'effective-date-day': format(today, 'd'), + 'effective-date-month': format(today, 'M'), + 'effective-date-year': format(today, 'yyyy'), }; // Act diff --git a/gef-ui/component-tests/partials/amendments/effective-from.component-test.ts b/gef-ui/component-tests/partials/amendments/effective-date.component-test.ts similarity index 75% rename from gef-ui/component-tests/partials/amendments/effective-from.component-test.ts rename to gef-ui/component-tests/partials/amendments/effective-date.component-test.ts index ac19e54a39..d5338e5441 100644 --- a/gef-ui/component-tests/partials/amendments/effective-from.component-test.ts +++ b/gef-ui/component-tests/partials/amendments/effective-date.component-test.ts @@ -1,22 +1,22 @@ import { FACILITY_TYPE } from '@ukef/dtfs2-common'; import { validationErrorHandler } from '../../../server/utils/helpers'; import pageRenderer from '../../pageRenderer'; -import { EffectiveFromViewModel } from '../../../server/types/view-models/amendments/effective-from-view-model'; +import { EffectiveDateViewModel } from '../../../server/types/view-models/amendments/effective-date-view-model'; -const page = 'partials/amendments/effective-from.njk'; +const page = 'partials/amendments/effective-date.njk'; const render = pageRenderer(page); describe(page, () => { const previousPage = 'previousPage'; const cancelUrl = 'cancelUrl'; - const effectiveFrom = { day: '14', month: '2', year: '2024' }; + const effectiveDate = { day: '14', month: '2', year: '2024' }; const exporterName = 'exporterName'; const facilityType = FACILITY_TYPE.CASH; - const params: EffectiveFromViewModel = { + const params: EffectiveDateViewModel = { previousPage, cancelUrl, - effectiveFrom, + effectiveDate, exporterName, facilityType, }; @@ -33,12 +33,12 @@ describe(page, () => { wrapper.expectLink('[data-cy="back-link"]').toLinkTo(previousPage, 'Back'); }); - it(`should render the effective from input`, () => { + it(`should render the effective date input`, () => { const wrapper = render(params); - wrapper.expectInput('[data-cy="effective-from-day"]').toHaveValue(effectiveFrom.day); - wrapper.expectInput('[data-cy="effective-from-month"]').toHaveValue(effectiveFrom.month); - wrapper.expectInput('[data-cy="effective-from-year"]').toHaveValue(effectiveFrom.year); + wrapper.expectInput('[data-cy="effective-date-day"]').toHaveValue(effectiveDate.day); + wrapper.expectInput('[data-cy="effective-date-month"]').toHaveValue(effectiveDate.month); + wrapper.expectInput('[data-cy="effective-date-year"]').toHaveValue(effectiveDate.year); }); it(`should render the error summary if an error exists`, () => { @@ -46,7 +46,7 @@ describe(page, () => { const paramsWithErrors = { ...params, - errors: validationErrorHandler({ errMsg, errRef: 'effectiveFrom' }), + errors: validationErrorHandler({ errMsg, errRef: 'effectiveDate' }), }; const wrapper = render(paramsWithErrors); @@ -65,18 +65,18 @@ describe(page, () => { const paramsWithErrors = { ...params, - errors: validationErrorHandler({ errMsg, errRef: 'effectiveFrom' }), + errors: validationErrorHandler({ errMsg, errRef: 'effectiveDate' }), }; const wrapper = render(paramsWithErrors); - wrapper.expectText('[data-cy="effective-from-inline-error"]').toContain(errMsg); + wrapper.expectText('[data-cy="effective-date-inline-error"]').toContain(errMsg); }); it(`should not render the inline error if there is no error`, () => { const wrapper = render(params); - wrapper.expectText('[data-cy="effective-from-inline-error"]').notToExist(); + wrapper.expectText('[data-cy="effective-date-inline-error"]').notToExist(); }); it(`should render the continue button`, () => { diff --git a/gef-ui/server/controllers/amendments/effective-date/get-effective-from.test.ts b/gef-ui/server/controllers/amendments/effective-date/get-effective-date.test.ts similarity index 87% rename from gef-ui/server/controllers/amendments/effective-date/get-effective-from.test.ts rename to gef-ui/server/controllers/amendments/effective-date/get-effective-date.test.ts index efe32068eb..412dfa5926 100644 --- a/gef-ui/server/controllers/amendments/effective-date/get-effective-from.test.ts +++ b/gef-ui/server/controllers/amendments/effective-date/get-effective-date.test.ts @@ -8,9 +8,9 @@ import { aPortalSessionUser, DEAL_STATUS, DEAL_SUBMISSION_TYPE, PORTAL_LOGIN_STA import { format, getUnixTime } from 'date-fns'; import { HttpStatusCode } from 'axios'; import { createMocks } from 'node-mocks-http'; -import { getEffectiveFrom, GetEffectiveDateRequest } from './get-effective-from'; +import { getEffectiveDate, GetEffectiveDateRequest } from './get-effective-date'; import { MOCK_BASIC_DEAL } from '../../../utils/mocks/mock-applications'; -import { EffectiveFromViewModel } from '../../../types/view-models/amendments/effective-from-view-model'; +import { EffectiveDateViewModel } from '../../../types/view-models/amendments/effective-date-view-model'; import { MOCK_UNISSUED_FACILITY, MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities'; import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment'; import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments'; @@ -40,7 +40,7 @@ const getHttpMocks = () => const mockDeal = { ...MOCK_BASIC_DEAL, submissionType: DEAL_SUBMISSION_TYPE.AIN, status: DEAL_STATUS.UKEF_ACKNOWLEDGED }; -describe('getEffectiveFrom', () => { +describe('getEffectiveDate', () => { let amendment: PortalFacilityAmendmentWithUkefId; beforeEach(() => { @@ -66,7 +66,7 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(getApplicationMock).toHaveBeenCalledTimes(1); @@ -78,7 +78,7 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(getFacilityMock).toHaveBeenCalledTimes(1); @@ -90,44 +90,44 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(getAmendmentMock).toHaveBeenCalledTimes(1); expect(getAmendmentMock).toHaveBeenCalledWith({ facilityId, amendmentId, userToken: req.session.userToken }); }); - it('should render the correct template when the amendment does not have an existing effectiveFrom', async () => { + it('should render the correct template when the amendment does not have an existing effectiveDate', async () => { // Arrange const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert - const expectedRenderData: EffectiveFromViewModel = { + const expectedRenderData: EffectiveDateViewModel = { exporterName: MOCK_BASIC_DEAL.exporter.companyName, facilityType: MOCK_ISSUED_FACILITY.details.type, cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }), previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.EFFECTIVE_DATE, amendment), - effectiveFrom: undefined, + effectiveDate: undefined, }; expect(res._getStatusCode()).toEqual(HttpStatusCode.Ok); - expect(res._getRenderView()).toEqual('partials/amendments/effective-from.njk'); + expect(res._getRenderView()).toEqual('partials/amendments/effective-date.njk'); expect(res._getRenderData()).toEqual(expectedRenderData); expect(console.error).toHaveBeenCalledTimes(0); }); - it('should render the correct template when the amendment has an existing effectiveFrom', async () => { + it('should render the correct template when the amendment has an existing effectiveDate', async () => { // Arrange - const effectiveFrom = new Date(); + const effectiveDate = new Date(); amendment = new PortalFacilityAmendmentWithUkefIdMockBuilder() .withDealId(dealId) .withFacilityId(facilityId) .withAmendmentId(amendmentId) - .withEffectiveFrom(getUnixTime(effectiveFrom)) + .withEffectiveDate(getUnixTime(effectiveDate)) .build(); getAmendmentMock.mockResolvedValue(amendment); @@ -135,23 +135,23 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert - const expectedRenderData: EffectiveFromViewModel = { + const expectedRenderData: EffectiveDateViewModel = { exporterName: MOCK_BASIC_DEAL.exporter.companyName, facilityType: MOCK_ISSUED_FACILITY.details.type, cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }), previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.EFFECTIVE_DATE, amendment), - effectiveFrom: { - day: format(effectiveFrom, 'd'), - month: format(effectiveFrom, 'M'), - year: format(effectiveFrom, 'yyyy'), + effectiveDate: { + day: format(effectiveDate, 'd'), + month: format(effectiveDate, 'M'), + year: format(effectiveDate, 'yyyy'), }, }; expect(res._getStatusCode()).toEqual(HttpStatusCode.Ok); - expect(res._getRenderView()).toEqual('partials/amendments/effective-from.njk'); + expect(res._getRenderView()).toEqual('partials/amendments/effective-date.njk'); expect(res._getRenderData()).toEqual(expectedRenderData); expect(console.error).toHaveBeenCalledTimes(0); }); @@ -162,7 +162,7 @@ describe('getEffectiveFrom', () => { getFacilityMock.mockResolvedValue({ details: undefined }); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -177,7 +177,7 @@ describe('getEffectiveFrom', () => { getApplicationMock.mockResolvedValue(undefined); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -192,7 +192,7 @@ describe('getEffectiveFrom', () => { getAmendmentMock.mockResolvedValue(undefined); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -207,7 +207,7 @@ describe('getEffectiveFrom', () => { getFacilityMock.mockResolvedValue(MOCK_UNISSUED_FACILITY); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -223,7 +223,7 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getRenderView()).toEqual('partials/problem-with-service.njk'); @@ -238,7 +238,7 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getRenderView()).toEqual('partials/problem-with-service.njk'); @@ -253,7 +253,7 @@ describe('getEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await getEffectiveFrom(req, res); + await getEffectiveDate(req, res); // Assert expect(res._getRenderView()).toEqual('partials/problem-with-service.njk'); diff --git a/gef-ui/server/controllers/amendments/effective-date/get-effective-from.ts b/gef-ui/server/controllers/amendments/effective-date/get-effective-date.ts similarity index 85% rename from gef-ui/server/controllers/amendments/effective-date/get-effective-from.ts rename to gef-ui/server/controllers/amendments/effective-date/get-effective-date.ts index 3e691242ae..4568d21dd1 100644 --- a/gef-ui/server/controllers/amendments/effective-date/get-effective-from.ts +++ b/gef-ui/server/controllers/amendments/effective-date/get-effective-date.ts @@ -7,7 +7,7 @@ import { userCanAmendFacility } from '../../../utils/facility-amendments.helper. import { getAmendmentsUrl, getPreviousPage } from '../helpers/navigation.helper.ts'; import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments.ts'; import { convertDateToDayMonthYearInput } from '../helpers/dates.helper.ts'; -import { EffectiveFromViewModel } from '../../../types/view-models/amendments/effective-from-view-model.ts'; +import { EffectiveDateViewModel } from '../../../types/view-models/amendments/effective-date-view-model.ts'; export type GetEffectiveDateRequest = CustomExpressRequest<{ params: { dealId: string; facilityId: string; amendmentId: string }; @@ -18,7 +18,7 @@ export type GetEffectiveDateRequest = CustomExpressRequest<{ * @param req - the request object * @param res - the response object */ -export const getEffectiveFrom = async (req: GetEffectiveDateRequest, res: Response) => { +export const getEffectiveDate = async (req: GetEffectiveDateRequest, res: Response) => { try { const { dealId, facilityId, amendmentId } = req.params; const { userToken, user } = asLoggedInUserSession(req.session); @@ -43,19 +43,19 @@ export const getEffectiveFrom = async (req: GetEffectiveDateRequest, res: Respon return res.redirect('/not-found'); } - const effectiveFrom: DayMonthYearInput | undefined = amendment.effectiveFrom - ? convertDateToDayMonthYearInput(fromUnixTime(amendment.effectiveFrom)) + const effectiveDate: DayMonthYearInput | undefined = amendment.effectiveDate + ? convertDateToDayMonthYearInput(fromUnixTime(amendment.effectiveDate)) : undefined; - const viewModel: EffectiveFromViewModel = { + const viewModel: EffectiveDateViewModel = { exporterName: deal.exporter.companyName, facilityType: facility.type, cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }), previousPage: getPreviousPage(PORTAL_AMENDMENT_PAGES.EFFECTIVE_DATE, amendment), - effectiveFrom, + effectiveDate, }; - return res.render('partials/amendments/effective-from.njk', viewModel); + return res.render('partials/amendments/effective-date.njk', viewModel); } catch (error) { console.error('Error getting amendments effective date page %o', error); return res.render('partials/problem-with-service.njk'); diff --git a/gef-ui/server/controllers/amendments/effective-date/post-effective-from.test.ts b/gef-ui/server/controllers/amendments/effective-date/post-effective-date.test.ts similarity index 73% rename from gef-ui/server/controllers/amendments/effective-date/post-effective-from.test.ts rename to gef-ui/server/controllers/amendments/effective-date/post-effective-date.test.ts index 14619f5ebe..7e772b5f64 100644 --- a/gef-ui/server/controllers/amendments/effective-date/post-effective-from.test.ts +++ b/gef-ui/server/controllers/amendments/effective-date/post-effective-date.test.ts @@ -17,16 +17,16 @@ import { DayMonthYearInput, } from '@ukef/dtfs2-common'; import { getCoverStartDateOrToday } from '../../../utils/get-cover-start-date-or-today.ts'; -import { MOCK_BASIC_DEAL } from '../../../utils/mocks/mock-applications'; -import { MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities'; -import { validationErrorHandler } from '../../../utils/helpers'; -import { getNextPage } from '../helpers/navigation.helper'; -import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments'; -import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment'; -import { ValidationError } from '../../../types/validation-error'; -import { postEffectiveFrom, PostEffectiveFromRequest } from './post-effective-from'; -import { EffectiveFromViewModel } from '../../../types/view-models/amendments/effective-from-view-model'; -import { validateAndParseEffectiveFrom } from './validation.ts'; +import { MOCK_BASIC_DEAL } from '../../../utils/mocks/mock-applications.js'; +import { MOCK_ISSUED_FACILITY } from '../../../utils/mocks/mock-facilities.js'; +import { validationErrorHandler } from '../../../utils/helpers.js'; +import { getNextPage } from '../helpers/navigation.helper.ts'; +import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments.ts'; +import { PortalFacilityAmendmentWithUkefIdMockBuilder } from '../../../../test-helpers/mock-amendment.ts'; +import { ValidationError } from '../../../types/validation-error.ts'; +import { postEffectiveDate, PostEffectiveDateRequest } from './post-effective-date.ts'; +import { EffectiveDateViewModel } from '../../../types/view-models/amendments/effective-date-view-model'; +import { validateAndParseEffectiveDate } from './validation.ts'; jest.mock('../../../services/api', () => ({ getApplication: getApplicationMock, @@ -47,8 +47,8 @@ const userToken = 'userToken'; const today = startOfDay(new Date()); -const getHttpMocks = (effectiveFromDayMonthYear: DayMonthYearInput = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }) => - httpMocks.createMocks({ +const getHttpMocks = (effectiveDateDayMonthYear: DayMonthYearInput = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }) => + httpMocks.createMocks({ params: { dealId, facilityId, @@ -61,15 +61,15 @@ const getHttpMocks = (effectiveFromDayMonthYear: DayMonthYearInput = { day: form }, body: { previousPage, - 'effective-from-day': effectiveFromDayMonthYear.day, - 'effective-from-month': effectiveFromDayMonthYear.month, - 'effective-from-year': effectiveFromDayMonthYear.year, + 'effective-date-day': effectiveDateDayMonthYear.day, + 'effective-date-month': effectiveDateDayMonthYear.month, + 'effective-date-year': effectiveDateDayMonthYear.year, }, }); const mockDeal = { ...MOCK_BASIC_DEAL, submissionType: DEAL_SUBMISSION_TYPE.AIN, status: DEAL_STATUS.UKEF_ACKNOWLEDGED }; -describe('postEffectiveFrom', () => { +describe('postEffectiveDate', () => { let amendment: PortalFacilityAmendmentWithUkefId; beforeEach(() => { @@ -83,7 +83,7 @@ describe('postEffectiveFrom', () => { .withDealId(dealId) .withFacilityId(facilityId) .withAmendmentId(amendmentId) - .withEffectiveFrom(getUnixTime(today)) + .withEffectiveDate(getUnixTime(today)) .build(); getApplicationMock.mockResolvedValue(mockDeal); @@ -96,7 +96,7 @@ describe('postEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(getApplicationMock).toHaveBeenCalledTimes(1); @@ -108,94 +108,94 @@ describe('postEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(getFacilityMock).toHaveBeenCalledTimes(1); expect(getFacilityMock).toHaveBeenCalledWith({ facilityId, userToken: req.session.userToken }); }); - it('should not call updateAmendment if the effectiveFrom is invalid', async () => { + it('should not call updateAmendment if the effectiveDate is invalid', async () => { // Arrange - const effectiveFromDayMonthYear = { + const effectiveDateDayMonthYear = { day: '100', month: '100', year: '100', }; - const { req, res } = getHttpMocks(effectiveFromDayMonthYear); + const { req, res } = getHttpMocks(effectiveDateDayMonthYear); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(updateAmendmentMock).toHaveBeenCalledTimes(0); }); - it('should render the page with validation errors if effectiveFrom is invalid', async () => { + it('should render the page with validation errors if effectiveDate is invalid', async () => { // Arrange - const effectiveFromDayMonthYear = { + const effectiveDateDayMonthYear = { day: '100', month: '100', year: '100', }; - const { req, res } = getHttpMocks(effectiveFromDayMonthYear); + const { req, res } = getHttpMocks(effectiveDateDayMonthYear); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert - const expectedRenderData: EffectiveFromViewModel = { + const expectedRenderData: EffectiveDateViewModel = { exporterName: mockDeal.exporter.companyName, cancelUrl: `/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/cancel`, facilityType: MOCK_ISSUED_FACILITY.details.type, previousPage, errors: validationErrorHandler( ( - validateAndParseEffectiveFrom(effectiveFromDayMonthYear, getCoverStartDateOrToday(MOCK_ISSUED_FACILITY.details)) as { + validateAndParseEffectiveDate(effectiveDateDayMonthYear, getCoverStartDateOrToday(MOCK_ISSUED_FACILITY.details)) as { errors: ValidationError[]; } ).errors, ), - effectiveFrom: effectiveFromDayMonthYear, + effectiveDate: effectiveDateDayMonthYear, }; expect(res._getStatusCode()).toEqual(HttpStatusCode.Ok); - expect(res._getRenderView()).toEqual('partials/amendments/effective-from.njk'); + expect(res._getRenderView()).toEqual('partials/amendments/effective-date.njk'); expect(res._getRenderData()).toEqual(expectedRenderData); }); - it('should call updateAmendment if the effectiveFrom is valid', async () => { + it('should call updateAmendment if the effectiveDate is valid', async () => { // Arrange - const effectiveFromDayMonthYear = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }; - const { req, res } = getHttpMocks(effectiveFromDayMonthYear); + const effectiveDateDayMonthYear = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }; + const { req, res } = getHttpMocks(effectiveDateDayMonthYear); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(updateAmendmentMock).toHaveBeenCalledTimes(1); - expect(updateAmendmentMock).toHaveBeenCalledWith({ facilityId, amendmentId, update: { effectiveFrom: getUnixTime(today) }, userToken }); + expect(updateAmendmentMock).toHaveBeenCalledWith({ facilityId, amendmentId, update: { effectiveDate: getUnixTime(today) }, userToken }); }); - it('should not call console.error if the effectiveFrom is valid', async () => { + it('should not call console.error if the effectiveDate is valid', async () => { // Arrange - const effectiveFromDayMonthYear = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }; - const { req, res } = getHttpMocks(effectiveFromDayMonthYear); + const effectiveDateDayMonthYear = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }; + const { req, res } = getHttpMocks(effectiveDateDayMonthYear); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(console.error).toHaveBeenCalledTimes(0); }); - it('should redirect to the next page if effectiveFrom is valid', async () => { + it('should redirect to the next page if effectiveDate is valid', async () => { // Arrange - const effectiveFromDayMonthYear = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }; - const { req, res } = getHttpMocks(effectiveFromDayMonthYear); + const effectiveDateDayMonthYear = { day: format(today, 'd'), month: format(today, 'M'), year: format(today, 'yyyy') }; + const { req, res } = getHttpMocks(effectiveDateDayMonthYear); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -208,7 +208,7 @@ describe('postEffectiveFrom', () => { getFacilityMock.mockResolvedValue({ details: undefined }); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -223,7 +223,7 @@ describe('postEffectiveFrom', () => { getApplicationMock.mockResolvedValue(undefined); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(res._getStatusCode()).toEqual(HttpStatusCode.Found); @@ -239,12 +239,12 @@ describe('postEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(res._getRenderView()).toEqual('partials/problem-with-service.njk'); expect(console.error).toHaveBeenCalledTimes(1); - expect(console.error).toHaveBeenCalledWith('Error posting amendments effective from page %o', mockError); + expect(console.error).toHaveBeenCalledWith('Error posting amendments effective date page %o', mockError); }); it('should render `problem with service` if getFacility throws an error', async () => { @@ -254,12 +254,12 @@ describe('postEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(res._getRenderView()).toEqual('partials/problem-with-service.njk'); expect(console.error).toHaveBeenCalledTimes(1); - expect(console.error).toHaveBeenCalledWith('Error posting amendments effective from page %o', mockError); + expect(console.error).toHaveBeenCalledWith('Error posting amendments effective date page %o', mockError); }); it('should render `problem with service` if updateAmendment throws an error', async () => { @@ -269,11 +269,11 @@ describe('postEffectiveFrom', () => { const { req, res } = getHttpMocks(); // Act - await postEffectiveFrom(req, res); + await postEffectiveDate(req, res); // Assert expect(res._getRenderView()).toEqual('partials/problem-with-service.njk'); expect(console.error).toHaveBeenCalledTimes(1); - expect(console.error).toHaveBeenCalledWith('Error posting amendments effective from page %o', mockError); + expect(console.error).toHaveBeenCalledWith('Error posting amendments effective date page %o', mockError); }); }); diff --git a/gef-ui/server/controllers/amendments/effective-date/post-effective-from.ts b/gef-ui/server/controllers/amendments/effective-date/post-effective-date.ts similarity index 65% rename from gef-ui/server/controllers/amendments/effective-date/post-effective-from.ts rename to gef-ui/server/controllers/amendments/effective-date/post-effective-date.ts index 0c659c9331..293b3e1d46 100644 --- a/gef-ui/server/controllers/amendments/effective-date/post-effective-from.ts +++ b/gef-ui/server/controllers/amendments/effective-date/post-effective-date.ts @@ -1,20 +1,20 @@ import { CustomExpressRequest, DayMonthYearInput } from '@ukef/dtfs2-common'; import { Response } from 'express'; import * as api from '../../../services/api'; -import { EffectiveFromViewModel } from '../../../types/view-models/amendments/effective-from-view-model'; +import { EffectiveDateViewModel } from '../../../types/view-models/amendments/effective-date-view-model'; import { asLoggedInUserSession } from '../../../utils/express-session'; import { getAmendmentsUrl, getNextPage } from '../helpers/navigation.helper'; import { PORTAL_AMENDMENT_PAGES } from '../../../constants/amendments'; import { validationErrorHandler } from '../../../utils/helpers'; -import { getCoverStartDateOrToday } from '../../../utils/get-cover-start-date-or-today.ts'; -import { validateAndParseEffectiveFrom } from './validation.ts'; +import { getCoverStartDateOrToday } from '../../../utils/get-cover-start-date-or-today'; +import { validateAndParseEffectiveDate } from './validation'; -export type PostEffectiveFromRequest = CustomExpressRequest<{ +export type PostEffectiveDateRequest = CustomExpressRequest<{ params: { dealId: string; facilityId: string; amendmentId: string }; reqBody: { - 'effective-from-day': string; - 'effective-from-month': string; - 'effective-from-year': string; + 'effective-date-day': string; + 'effective-date-month': string; + 'effective-date-year': string; previousPage: string; }; }>; @@ -24,16 +24,16 @@ export type PostEffectiveFromRequest = CustomExpressRequest<{ * @param req - the request object * @param res - the response object */ -export const postEffectiveFrom = async (req: PostEffectiveFromRequest, res: Response) => { +export const postEffectiveDate = async (req: PostEffectiveDateRequest, res: Response) => { try { const { dealId, facilityId, amendmentId } = req.params; const { previousPage } = req.body; const { userToken } = asLoggedInUserSession(req.session); - const effectiveFromDayMonthYear: DayMonthYearInput = { - day: req.body['effective-from-day'], - month: req.body['effective-from-month'], - year: req.body['effective-from-year'], + const effectiveDateDayMonthYear: DayMonthYearInput = { + day: req.body['effective-date-day'], + month: req.body['effective-date-month'], + year: req.body['effective-date-year'], }; const deal = await api.getApplication({ dealId, userToken }); @@ -44,28 +44,28 @@ export const postEffectiveFrom = async (req: PostEffectiveFromRequest, res: Resp return res.redirect('/not-found'); } - const validationErrorsOrValue = validateAndParseEffectiveFrom(effectiveFromDayMonthYear, getCoverStartDateOrToday(facility)); + const validationErrorsOrValue = validateAndParseEffectiveDate(effectiveDateDayMonthYear, getCoverStartDateOrToday(facility)); if ('errors' in validationErrorsOrValue) { - const viewModel: EffectiveFromViewModel = { + const viewModel: EffectiveDateViewModel = { exporterName: deal.exporter.companyName, facilityType: facility.type, cancelUrl: getAmendmentsUrl({ dealId, facilityId, amendmentId, page: PORTAL_AMENDMENT_PAGES.CANCEL }), previousPage, - effectiveFrom: effectiveFromDayMonthYear, + effectiveDate: effectiveDateDayMonthYear, errors: validationErrorHandler(validationErrorsOrValue.errors), }; - return res.render('partials/amendments/effective-from.njk', viewModel); + return res.render('partials/amendments/effective-date.njk', viewModel); } - const update = { effectiveFrom: validationErrorsOrValue.value }; + const update = { effectiveDate: validationErrorsOrValue.value }; const amendment = await api.updateAmendment({ facilityId, amendmentId, update, userToken }); return res.redirect(getNextPage(PORTAL_AMENDMENT_PAGES.EFFECTIVE_DATE, amendment)); } catch (error) { - console.error('Error posting amendments effective from page %o', error); + console.error('Error posting amendments effective date page %o', error); return res.render('partials/problem-with-service.njk'); } }; diff --git a/gef-ui/server/controllers/amendments/effective-date/validation.test.ts b/gef-ui/server/controllers/amendments/effective-date/validation.test.ts index 86567d6d8d..acf50f5d05 100644 --- a/gef-ui/server/controllers/amendments/effective-date/validation.test.ts +++ b/gef-ui/server/controllers/amendments/effective-date/validation.test.ts @@ -2,25 +2,25 @@ import { applyStandardValidationAndParseDateInput, DayMonthYearInput, DATE_FORMATS, - AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE, - AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST, + AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE, + AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST, } from '@ukef/dtfs2-common'; import { add, format, sub, getUnixTime, startOfDay } from 'date-fns'; -import { validateAndParseEffectiveFrom } from './validation'; +import { validateAndParseEffectiveDate } from './validation'; import { mapValidationError } from '../../../utils/map-validation-error'; const valueName = 'date amendment effective from'; -const valueRef = 'effectiveFrom'; +const valueRef = 'effectiveDate'; const today = startOfDay(new Date()); -const getFormattedDate = (effectiveFrom: Date): DayMonthYearInput => { +const getFormattedDate = (effectiveDate: Date): DayMonthYearInput => { return { - day: format(effectiveFrom, 'd'), - month: format(effectiveFrom, 'M'), - year: format(effectiveFrom, 'yyyy'), + day: format(effectiveDate, 'd'), + month: format(effectiveDate, 'M'), + year: format(effectiveDate, 'yyyy'), }; }; -describe('validateAndParseEffectiveFrom', () => { +describe('validateAndParseEffectiveDate', () => { afterAll(() => { jest.resetAllMocks(); }); @@ -34,7 +34,7 @@ describe('validateAndParseEffectiveFrom', () => { }; // Act - const response = validateAndParseEffectiveFrom(dayMonthYear, today); + const response = validateAndParseEffectiveDate(dayMonthYear, today); // Assert expect(response).toEqual({ @@ -44,11 +44,11 @@ describe('validateAndParseEffectiveFrom', () => { it('should return error if date is before cover start date', () => { // Arrange - const effectiveFrom = today; + const effectiveDate = today; const coverStartDate = add(today, { days: 1 }); // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(effectiveFrom), coverStartDate); + const result = validateAndParseEffectiveDate(getFormattedDate(effectiveDate), coverStartDate); // Assert expect(result).toEqual({ @@ -56,39 +56,39 @@ describe('validateAndParseEffectiveFrom', () => { { errRef: valueRef, errMsg: `Date amendment effective from cannot be before the cover start date ${format(coverStartDate, DATE_FORMATS.D_MMMM_YYYY)}`, - subFieldErrorRefs: ['effectiveFrom-day', 'effectiveFrom-month', 'effectiveFrom-year'], + subFieldErrorRefs: ['effectiveDate-day', 'effectiveDate-month', 'effectiveDate-year'], }, ], }); }); - it(`should return error if date is more than ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE} days in the future`, () => { + it(`should return error if date is more than ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE} days in the future`, () => { // Arrange - const effectiveFrom = add(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE + 1 }); + const effectiveDate = add(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE + 1 }); const coverStartDate = add(today, { days: 1 }); // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(effectiveFrom), coverStartDate); + const result = validateAndParseEffectiveDate(getFormattedDate(effectiveDate), coverStartDate); // Assert expect(result).toEqual({ errors: [ { errRef: valueRef, - errMsg: `You entered an amendment date more than ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE} days from now. Amendments must be effective within the next ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE} days - come back later or use the Schedule 8 form`, - subFieldErrorRefs: ['effectiveFrom-day', 'effectiveFrom-month', 'effectiveFrom-year'], + errMsg: `You entered an amendment date more than ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE} days from now. Amendments must be effective within the next ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE} days - come back later or use the Schedule 8 form`, + subFieldErrorRefs: ['effectiveDate-day', 'effectiveDate-month', 'effectiveDate-year'], }, ], }); }); - it(`should return error if date is more than ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST} days in the past`, () => { + it(`should return error if date is more than ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST} days in the past`, () => { // Arrange - const effectiveFrom = sub(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST + 1 }); + const effectiveDate = sub(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST + 1 }); const coverStartDate = sub(today, { years: 1 }); // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(effectiveFrom), coverStartDate); + const result = validateAndParseEffectiveDate(getFormattedDate(effectiveDate), coverStartDate); // Assert expect(result).toEqual({ @@ -96,28 +96,28 @@ describe('validateAndParseEffectiveFrom', () => { { errRef: valueRef, errMsg: `The date entered is invalid. Please ensure the date entered does not exceed the allowable timeframe`, - subFieldErrorRefs: ['effectiveFrom-day', 'effectiveFrom-month', 'effectiveFrom-year'], + subFieldErrorRefs: ['effectiveDate-day', 'effectiveDate-month', 'effectiveDate-year'], }, ], }); }); - it(`should return effective from date if it is valid`, () => { + it(`should return effective date date if it is valid`, () => { // Arrange - const effectiveFrom = today; + const effectiveDate = today; const coverStartDate = sub(today, { years: 1 }); // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(effectiveFrom), coverStartDate); + const result = validateAndParseEffectiveDate(getFormattedDate(effectiveDate), coverStartDate); // Assert expect(result).toEqual({ - value: getUnixTime(effectiveFrom), + value: getUnixTime(effectiveDate), }); }); - it('should return effective from date if it is the same as the cover start date', () => { + it('should return effective date date if it is the same as the cover start date', () => { // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(today), today); + const result = validateAndParseEffectiveDate(getFormattedDate(today), today); // Assert expect(result).toEqual({ @@ -125,29 +125,29 @@ describe('validateAndParseEffectiveFrom', () => { }); }); - it(`should return effective from date if it is exactly ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST} days in the past`, () => { + it(`should return effective date date if it is exactly ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST} days in the past`, () => { // Arrange - const effectiveFrom = sub(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST }); + const effectiveDate = sub(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST }); const coverStartDate = sub(today, { years: 1 }); // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(effectiveFrom), coverStartDate); + const result = validateAndParseEffectiveDate(getFormattedDate(effectiveDate), coverStartDate); // Assert expect(result).toEqual({ - value: getUnixTime(effectiveFrom), + value: getUnixTime(effectiveDate), }); }); - it(`should return effective from date if it is exactly ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE} days in the future`, () => { + it(`should return effective date date if it is exactly ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE} days in the future`, () => { // Arrange - const effectiveFrom = add(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE }); + const effectiveDate = add(today, { days: AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE }); const coverStartDate = add(today, { days: 1 }); // Act - const result = validateAndParseEffectiveFrom(getFormattedDate(effectiveFrom), coverStartDate); + const result = validateAndParseEffectiveDate(getFormattedDate(effectiveDate), coverStartDate); // Assert expect(result).toEqual({ - value: getUnixTime(effectiveFrom), + value: getUnixTime(effectiveDate), }); }); }); diff --git a/gef-ui/server/controllers/amendments/effective-date/validation.ts b/gef-ui/server/controllers/amendments/effective-date/validation.ts index 114a66ad89..07c7001894 100644 --- a/gef-ui/server/controllers/amendments/effective-date/validation.ts +++ b/gef-ui/server/controllers/amendments/effective-date/validation.ts @@ -3,8 +3,8 @@ import { applyStandardValidationAndParseDateInput, DayMonthYearInput, DATE_FORMATS, - AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST, - AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE, + AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST, + AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE, } from '@ukef/dtfs2-common'; import { add, sub, isAfter, isBefore, startOfDay, format, getUnixTime } from 'date-fns'; import { ErrorsOrValue } from '../../../types/errors-or-value'; @@ -16,8 +16,8 @@ import { mapValidationError } from '../../../utils/map-validation-error'; * @param params.coverStartDate - The cover start date as Date * @returns the value or errors depending on the validation result */ -export const validateAndParseEffectiveFrom = (dayMonthYear: DayMonthYearInput, coverStartDate: Date): ErrorsOrValue => { - const errRef = 'effectiveFrom'; +export const validateAndParseEffectiveDate = (dayMonthYear: DayMonthYearInput, coverStartDate: Date): ErrorsOrValue => { + const errRef = 'effectiveDate'; const variableDisplayName = 'date amendment effective from'; const formattingErrorsOrDate = applyStandardValidationAndParseDateInput(dayMonthYear, variableDisplayName, errRef); @@ -28,46 +28,46 @@ export const validateAndParseEffectiveFrom = (dayMonthYear: DayMonthYearInput, c }; } - const effectiveFrom = formattingErrorsOrDate.parsedDate; + const effectiveDate = formattingErrorsOrDate.parsedDate; const now = startOfDay(new Date()); - const earliestEffectiveFromDate = sub(now, { days: AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST }); - const latestEffectiveFromDate = add(now, { days: AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE }); + const earliestEffectiveDateDate = sub(now, { days: AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST }); + const latestEffectiveDateDate = add(now, { days: AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE }); - if (isBefore(effectiveFrom, coverStartDate)) { + if (isBefore(effectiveDate, coverStartDate)) { return { errors: [ { errRef, errMsg: `Date amendment effective from cannot be before the cover start date ${format(coverStartDate, DATE_FORMATS.D_MMMM_YYYY)}`, - subFieldErrorRefs: ['effectiveFrom-day', 'effectiveFrom-month', 'effectiveFrom-year'], + subFieldErrorRefs: ['effectiveDate-day', 'effectiveDate-month', 'effectiveDate-year'], }, ], }; } - if (isBefore(effectiveFrom, earliestEffectiveFromDate)) { + if (isBefore(effectiveDate, earliestEffectiveDateDate)) { return { errors: [ { errRef, errMsg: `The date entered is invalid. Please ensure the date entered does not exceed the allowable timeframe`, - subFieldErrorRefs: ['effectiveFrom-day', 'effectiveFrom-month', 'effectiveFrom-year'], + subFieldErrorRefs: ['effectiveDate-day', 'effectiveDate-month', 'effectiveDate-year'], }, ], }; } - if (isAfter(effectiveFrom, latestEffectiveFromDate)) { + if (isAfter(effectiveDate, latestEffectiveDateDate)) { return { errors: [ { errRef, - errMsg: `You entered an amendment date more than ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE} days from now. Amendments must be effective within the next ${AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE} days - come back later or use the Schedule 8 form`, - subFieldErrorRefs: ['effectiveFrom-day', 'effectiveFrom-month', 'effectiveFrom-year'], + errMsg: `You entered an amendment date more than ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE} days from now. Amendments must be effective within the next ${AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE} days - come back later or use the Schedule 8 form`, + subFieldErrorRefs: ['effectiveDate-day', 'effectiveDate-month', 'effectiveDate-year'], }, ], }; } - return { value: getUnixTime(effectiveFrom) }; + return { value: getUnixTime(effectiveDate) }; }; diff --git a/gef-ui/server/routes/facilities/amendments/index.ts b/gef-ui/server/routes/facilities/amendments/index.ts index 622111e89f..b80a5292d8 100644 --- a/gef-ui/server/routes/facilities/amendments/index.ts +++ b/gef-ui/server/routes/facilities/amendments/index.ts @@ -20,8 +20,8 @@ import { getBankReviewDate } from '../../../controllers/amendments/bank-review-d import { postBankReviewDate } from '../../../controllers/amendments/bank-review-date/post-bank-review-date.ts'; import { getEligibility } from '../../../controllers/amendments/eligibility-criteria/get-eligibility.ts'; import { postEligibility } from '../../../controllers/amendments/eligibility-criteria/post-eligibility.ts'; -import { getEffectiveFrom } from '../../../controllers/amendments/effective-date/get-effective-from.ts'; -import { postEffectiveFrom } from '../../../controllers/amendments/effective-date/post-effective-from.ts'; +import { getEffectiveDate } from '../../../controllers/amendments/effective-date/get-effective-date.ts'; +import { postEffectiveDate } from '../../../controllers/amendments/effective-date/post-effective-date.ts'; const { WHAT_DO_YOU_NEED_TO_CHANGE, @@ -92,7 +92,7 @@ router router .route(`/application-details/:dealId/facilities/:facilityId/amendments/:amendmentId/${EFFECTIVE_DATE}`) .all([validatePortalFacilityAmendmentsEnabled, validateToken, validateBank, validateRole({ role: [MAKER] })]) - .get(getEffectiveFrom) - .post(postEffectiveFrom); + .get(getEffectiveDate) + .post(postEffectiveDate); export default router; diff --git a/gef-ui/server/types/view-models/amendments/effective-from-view-model.ts b/gef-ui/server/types/view-models/amendments/effective-date-view-model.ts similarity index 77% rename from gef-ui/server/types/view-models/amendments/effective-from-view-model.ts rename to gef-ui/server/types/view-models/amendments/effective-date-view-model.ts index 6709173ac0..9cb6d21c9a 100644 --- a/gef-ui/server/types/view-models/amendments/effective-from-view-model.ts +++ b/gef-ui/server/types/view-models/amendments/effective-date-view-model.ts @@ -1,11 +1,11 @@ import { DayMonthYearInput, FacilityType } from '@ukef/dtfs2-common'; import { ViewModelErrors } from '../view-model-errors'; -export type EffectiveFromViewModel = { +export type EffectiveDateViewModel = { exporterName: string; facilityType: FacilityType; previousPage: string; cancelUrl: string; errors?: ViewModelErrors | null; - effectiveFrom?: DayMonthYearInput; + effectiveDate?: DayMonthYearInput; }; diff --git a/gef-ui/templates/partials/amendments/effective-from.njk b/gef-ui/templates/partials/amendments/effective-date.njk similarity index 80% rename from gef-ui/templates/partials/amendments/effective-from.njk rename to gef-ui/templates/partials/amendments/effective-date.njk index 05c430b7e0..1e0672df57 100644 --- a/gef-ui/templates/partials/amendments/effective-from.njk +++ b/gef-ui/templates/partials/amendments/effective-date.njk @@ -50,8 +50,8 @@ {{ govukDateInput({ - id: "effectiveFrom", - namePrefix: "effective-from", + id: "effectiveDate", + namePrefix: "effective-date", fieldset: { legend: { html: headingHtml @@ -60,35 +60,35 @@ hint: { html: hintHtml }, - errorMessage: errors and errors.fieldErrors.effectiveFrom and { - text: errors.fieldErrors.effectiveFrom.text, + errorMessage: errors and errors.fieldErrors.effectiveDate and { + text: errors.fieldErrors.effectiveDate.text, attributes: { - 'data-cy': 'effective-from-inline-error' + 'data-cy': 'effective-date-inline-error' } }, items: [ { - classes: (errors.fieldErrors['effectiveFrom-day'] and "govuk-input--width-2 govuk-input--error") or "govuk-input--width-2", + classes: (errors.fieldErrors['effectiveDate-day'] and "govuk-input--width-2 govuk-input--error") or "govuk-input--width-2", name: "day", - value: effectiveFrom.day, + value: effectiveDate.day, attributes: { - 'data-cy': 'effective-from-day' + 'data-cy': 'effective-date-day' } }, { - classes: (errors.fieldErrors['effectiveFrom-month'] and "govuk-input--width-2 govuk-input--error") or "govuk-input--width-2", + classes: (errors.fieldErrors['effectiveDate-month'] and "govuk-input--width-2 govuk-input--error") or "govuk-input--width-2", name: "month", - value: effectiveFrom.month, + value: effectiveDate.month, attributes: { - 'data-cy': 'effective-from-month' + 'data-cy': 'effective-date-month' } }, { - classes: (errors.fieldErrors['effectiveFrom-year'] and "govuk-input--width-4 govuk-input--error") or "govuk-input--width-4", + classes: (errors.fieldErrors['effectiveDate-year'] and "govuk-input--width-4 govuk-input--error") or "govuk-input--width-4", name: "year", - value: effectiveFrom.year, + value: effectiveDate.year, attributes: { - 'data-cy': 'effective-from-year' + 'data-cy': 'effective-date-year' } } ] diff --git a/gef-ui/test-helpers/mock-amendment.ts b/gef-ui/test-helpers/mock-amendment.ts index 74743b8589..a54da9498d 100644 --- a/gef-ui/test-helpers/mock-amendment.ts +++ b/gef-ui/test-helpers/mock-amendment.ts @@ -101,8 +101,8 @@ export class PortalFacilityAmendmentWithUkefIdMockBuilder { return this; } - public withEffectiveFrom(effectiveFrom: UnixTimestampSeconds) { - this.amendment.effectiveFrom = effectiveFrom; + public withEffectiveDate(effectiveDate: UnixTimestampSeconds) { + this.amendment.effectiveDate = effectiveDate; return this; } diff --git a/libs/common/src/constants/portal/date-validation.ts b/libs/common/src/constants/portal/date-validation.ts index 9794802e6e..69a905a420 100644 --- a/libs/common/src/constants/portal/date-validation.ts +++ b/libs/common/src/constants/portal/date-validation.ts @@ -5,6 +5,6 @@ export const COVER_END_DATE_MAXIMUM_YEARS_IN_FUTURE = 6 as const; export const FACILITY_END_DATE_MAXIMUM_YEARS_IN_FUTURE = 6 as const; /** The value is defined as part of a business requirement */ -export const AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_FUTURE = 30 as const; +export const AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_FUTURE = 30 as const; /** The value is defined as part of a business requirement */ -export const AMENDMENT_MAXIMUM_EFFECTIVE_FROM_DAYS_IN_PAST = 16 as const; +export const AMENDMENT_MAXIMUM_EFFECTIVE_DATE_DAYS_IN_PAST = 16 as const; diff --git a/libs/common/src/schemas/portal-amendment.ts b/libs/common/src/schemas/portal-amendment.ts index c4a7370900..89275b067a 100644 --- a/libs/common/src/schemas/portal-amendment.ts +++ b/libs/common/src/schemas/portal-amendment.ts @@ -40,7 +40,7 @@ export const PORTAL_FACILITY_AMENDMENT_USER_VALUES = z ), }) .optional(), - effectiveFrom: z.number().nonnegative().optional(), + effectiveDate: z.number().nonnegative().optional(), }) .strict(); From a590b7dbfaa0892527804781f7c0f77c138829b2 Mon Sep 17 00:00:00 2001 From: Mark Roberts Date: Mon, 3 Feb 2025 14:49:01 +0000 Subject: [PATCH 5/5] feat(DTFS2-7781): update e2e tests --- .../e2e/pages/amendments/effective-date.js | 12 ++++++ .../e2e/pages/amendments/effective-from.js | 12 ------ ...-cover-end-date-and-facility-value.spec.js | 2 +- ...ge-cover-end-date-with-BRD-journey.spec.js | 2 +- ...ge-cover-end-date-with-FED-journey.spec.js | 2 +- .../change-facility-value-journey.spec.js | 2 +- .../amendments/pages/effective-date.spec.js | 40 +++++++++---------- 7 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 e2e-tests/gef/cypress/e2e/pages/amendments/effective-date.js delete mode 100644 e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js diff --git a/e2e-tests/gef/cypress/e2e/pages/amendments/effective-date.js b/e2e-tests/gef/cypress/e2e/pages/amendments/effective-date.js new file mode 100644 index 0000000000..f4dd74e3cb --- /dev/null +++ b/e2e-tests/gef/cypress/e2e/pages/amendments/effective-date.js @@ -0,0 +1,12 @@ +const effectiveDate = { + effectiveDateDay: () => cy.get('[data-cy="effective-date-day"]'), + effectiveDateMonth: () => cy.get('[data-cy="effective-date-month"]'), + effectiveDateYear: () => cy.get('[data-cy="effective-date-year"]'), + errorSummary: () => cy.get('[data-cy="error-summary"]'), + effectiveDateInlineError: () => cy.get('[data-cy="effective-date-inline-error"]'), + pageHeading: () => cy.get('[data-cy="page-heading"]'), + backLink: () => cy.get('[data-cy="back-link"]'), + cancelLink: () => cy.get('[data-cy="cancel-link"]'), +}; + +module.exports = effectiveDate; diff --git a/e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js b/e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js deleted file mode 100644 index 65cd0ac053..0000000000 --- a/e2e-tests/gef/cypress/e2e/pages/amendments/effective-from.js +++ /dev/null @@ -1,12 +0,0 @@ -const effectiveFrom = { - effectiveFromDay: () => cy.get('[data-cy="effective-from-day"]'), - effectiveFromMonth: () => cy.get('[data-cy="effective-from-month"]'), - effectiveFromYear: () => cy.get('[data-cy="effective-from-year"]'), - errorSummary: () => cy.get('[data-cy="error-summary"]'), - effectiveFromInlineError: () => cy.get('[data-cy="effective-from-inline-error"]'), - pageHeading: () => cy.get('[data-cy="page-heading"]'), - backLink: () => cy.get('[data-cy="back-link"]'), - cancelLink: () => cy.get('[data-cy="cancel-link"]'), -}; - -module.exports = effectiveFrom; diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js index 25d1fcbcfd..f36dbaf3a7 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-both-cover-end-date-and-facility-value.spec.js @@ -93,7 +93,7 @@ context('Amendments - Change both cover end date and facility value - full journ cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); - cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.completeDateFormFields({ idPrefix: 'effective-date' }); cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js index 24d3e61d1e..972c9711ad 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-BRD-journey.spec.js @@ -88,7 +88,7 @@ context('Amendments - Change cover end date with bank review date - full journey cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); - cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.completeDateFormFields({ idPrefix: 'effective-date' }); cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js index 4fccf559b5..56fbd5e29d 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-cover-end-date-with-FED-journey.spec.js @@ -87,7 +87,7 @@ context('Amendments - Change cover end date with facility end date - full journe cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); - cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.completeDateFormFields({ idPrefix: 'effective-date' }); cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js index 736e2c9823..6551a061a6 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/journeys/change-facility-value-journey.spec.js @@ -72,7 +72,7 @@ context('Amendments - change facility value - full journey', () => { cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/effective-date`)); - cy.completeDateFormFields({ idPrefix: 'effective-from' }); + cy.completeDateFormFields({ idPrefix: 'effective-date' }); cy.clickContinueButton(); cy.url().should('eq', relative(`/gef/application-details/${dealId}/facilities/${facilityId}/amendments/${amendmentId}/check-your-answers`)); diff --git a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js index abbacaf7cc..ba899688f6 100644 --- a/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js +++ b/e2e-tests/ukef/cypress/e2e/journeys/portal/amendments/pages/effective-date.spec.js @@ -6,8 +6,8 @@ import { applicationPreview } from '../../../../../../../gef/cypress/e2e/pages'; import whatDoYouNeedToChange from '../../../../../../../gef/cypress/e2e/pages/amendments/what-do-you-need-to-change'; import facilityValue from '../../../../../../../gef/cypress/e2e/pages/amendments/facility-value'; import eligibility from '../../../../../../../gef/cypress/e2e/pages/amendments/eligibility'; -import effectiveFrom from '../../../../../../../gef/cypress/e2e/pages/amendments/effective-from'; -import { twoDaysAgo, twoMonths, yesterday } from '../../../../../../../e2e-fixtures/dateConstants'; +import effectiveDate from '../../../../../../../gef/cypress/e2e/pages/amendments/effective-date'; +import { twoDaysAgo, twoMonths, today } from '../../../../../../../e2e-fixtures/dateConstants'; const { BANK1_MAKER1 } = MOCK_USERS; @@ -73,31 +73,31 @@ context('Amendments - Date amendment effective from - page tests', () => { }); it('should render key features of the page', () => { - effectiveFrom.pageHeading().contains('Date amendment effective from'); - effectiveFrom.backLink(); - effectiveFrom.cancelLink(); + effectiveDate.pageHeading().contains('Date amendment effective from'); + effectiveDate.backLink(); + effectiveDate.cancelLink(); }); it('should render an error if no date is provided', () => { cy.clickContinueButton(); - effectiveFrom.errorSummary().should('be.visible'); - effectiveFrom.errorSummary().contains('Enter the date amendment effective from'); + effectiveDate.errorSummary().should('be.visible'); + effectiveDate.errorSummary().contains('Enter the date amendment effective from'); - effectiveFrom.effectiveFromInlineError().should('be.visible'); - effectiveFrom.effectiveFromInlineError().contains('Enter the date amendment effective from'); + effectiveDate.effectiveDateInlineError().should('be.visible'); + effectiveDate.effectiveDateInlineError().contains('Enter the date amendment effective from'); }); - const effectiveFromErrorTestCases = [ + const effectiveDateErrorTestCases = [ { description: 'the date amendment effective from consists of invalid characters', dateFieldInput: { day: 'aa', month: '11', year: '2025' }, - expectedErrorMessage: 'date amendment effective from must be a real date', + expectedErrorMessage: 'Date amendment effective from must be a real date', }, { description: 'the date amendment effective from is missing a field', - dateFieldInput: { day: '2', month: '', year: '2025' }, - expectedErrorMessage: 'date amendment effective from must include a month', + dateFieldInput: { day: '2', month: ' ', year: '2025' }, + expectedErrorMessage: 'Date amendment effective from must include a month', }, { description: 'the date amendment effective from is greater than 30 days in the future', @@ -107,19 +107,19 @@ context('Amendments - Date amendment effective from - page tests', () => { { description: 'the date amendment effective from is before the cover start date', dateFieldInput: twoDaysAgo, - expectedErrorMessage: `Date amendment effective from cannot be before the cover start date ${yesterday.d_MMMM_yyyy}`, + expectedErrorMessage: `Date amendment effective from cannot be before the cover start date ${today.d_MMMM_yyyy}`, }, ]; - effectiveFromErrorTestCases.forEach(({ description, dateFieldInput, expectedErrorMessage }) => { + effectiveDateErrorTestCases.forEach(({ description, dateFieldInput, expectedErrorMessage }) => { it(`should render an error on the bank review date page if ${description}`, () => { - cy.completeDateFormFields({ idPrefix: 'effective-from', ...dateFieldInput }); + cy.completeDateFormFields({ idPrefix: 'effective-date', ...dateFieldInput }); cy.clickContinueButton(); - effectiveFrom.errorSummary().should('be.visible'); - effectiveFrom.errorSummary().contains(expectedErrorMessage); - effectiveFrom.effectiveFromInlineError().should('be.visible'); - effectiveFrom.effectiveFromInlineError().contains(expectedErrorMessage); + effectiveDate.errorSummary().should('be.visible'); + effectiveDate.errorSummary().contains(expectedErrorMessage); + effectiveDate.effectiveDateInlineError().should('be.visible'); + effectiveDate.effectiveDateInlineError().contains(expectedErrorMessage); }); });