diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js new file mode 100644 index 0000000000..5ebb781303 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges-fixed-sum-amount-with-comma.spec.js @@ -0,0 +1,77 @@ +import FIELD_IDS from '../../../../../../constants/field-ids/insurance/export-contract'; +import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; + +const { + ROOT, + EXPORT_CONTRACT: { AGENT_CHARGES, CHECK_YOUR_ANSWERS }, +} = INSURANCE_ROUTES; + +const { + AGENT_CHARGES: { METHOD, FIXED_SUM }, +} = FIELD_IDS; + +const baseUrl = Cypress.config('baseUrl'); + +context('Insurance - Export contract - Agent charges page - Fixed sum amount with a comma', () => { + let referenceNumber; + let url; + let checkYourAnswersUrl; + + before(() => { + cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => { + referenceNumber = refNumber; + + // go to the page we want to test. + cy.startInsuranceExportContractSection({}); + cy.completeAndSubmitAboutGoodsOrServicesForm({}); + cy.completeAndSubmitHowYouWillGetPaidForm({}); + cy.completeAndSubmitAgentForm({ isUsingAgent: true }); + cy.completeAndSubmitAgentDetailsForm({}); + cy.completeAndSubmitAgentServiceForm({ agentIsCharging: true }); + + url = `${baseUrl}${ROOT}/${referenceNumber}${AGENT_CHARGES}`; + checkYourAnswersUrl = `${baseUrl}${ROOT}/${referenceNumber}${CHECK_YOUR_ANSWERS}`; + }); + }); + + beforeEach(() => { + cy.saveSession(); + }); + + after(() => { + cy.deleteApplication(referenceNumber); + }); + + describe('form submission', () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + describe(`when submitting with ${METHOD} as ${FIXED_SUM} with a comma`, () => { + const fixedSumAmount = '1,000'; + const amount = '1000'; + + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, () => { + cy.completeAndSubmitAgentChargesForm({ fixedSumMethod: true, fixedSumAmount }); + + cy.assertUrl(checkYourAnswersUrl); + }); + + it('should update the `export contract` task status to `completed`', () => { + cy.navigateToAllSectionsUrl(referenceNumber); + + cy.checkTaskExportContractStatusIsComplete(); + }); + + describe('when going back to the page', () => { + beforeEach(() => { + cy.navigateToUrl(url); + }); + + it('should have the submitted value without the comma', () => { + cy.assertAgentChargesFieldValues({ fixedSumMethod: true, expectedFixedSumAmount: amount }); + }); + }); + }); + }); +}); diff --git a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.test.ts b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.test.ts index 455e7eb7b6..f6f82ad7f2 100644 --- a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.test.ts +++ b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.test.ts @@ -1,6 +1,7 @@ import mapSubmittedData from '.'; import { APPLICATION } from '../../../../../constants'; import FIELD_IDS from '../../../../../constants/field-ids/insurance'; +import { stripCommas } from '../../../../../helpers/string'; import { EUR, HKD } from '../../../../../test-mocks'; const { @@ -40,6 +41,28 @@ describe('controllers/insurance/export-contract/map-submitted-data/agent-service expect(result).toEqual(expected); }); + describe(`when ${METHOD} is ${FIXED_SUM} and contains a comma`, () => { + it('should return the form body with mapped data with the comma stripped', () => { + const mockFormBody = { + [METHOD]: FIXED_SUM, + [FIXED_SUM_AMOUNT]: '1,500', + [ALTERNATIVE_CURRENCY_CODE]: EUR.isoCode, + [CURRENCY_CODE]: EUR.isoCode, + }; + + const result = mapSubmittedData(mockFormBody); + + const expected = { + ...mockFormBody, + [FIXED_SUM_AMOUNT]: stripCommas(String(mockFormBody[FIXED_SUM_AMOUNT])), + [PERCENTAGE_CHARGE]: null, + [FIXED_SUM_CURRENCY_CODE]: EUR.isoCode, + }; + + expect(result).toEqual(expected); + }); + }); + it(`should set ${ALTERNATIVE_CURRENCY_CODE} to null when ${CURRENCY_CODE} is NOT ${ALTERNATIVE_CURRENCY_CODE}`, () => { const mockFormBody = { [METHOD]: FIXED_SUM, diff --git a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.ts b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.ts index dbafb82287..ba41b65533 100644 --- a/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.ts +++ b/src/ui/server/controllers/insurance/export-contract/map-submitted-data/agent-service-charge/index.ts @@ -1,7 +1,7 @@ import { APPLICATION } from '../../../../../constants'; import FIELD_IDS from '../../../../../constants/field-ids/insurance'; import { objectHasProperty } from '../../../../../helpers/object'; -import { isEmptyString } from '../../../../../helpers/string'; +import { isEmptyString, stripCommas } from '../../../../../helpers/string'; import { RequestBody } from '../../../../../../types'; const { @@ -31,7 +31,7 @@ const mapSubmittedData = (formBody: RequestBody): object => { const populatedData = formBody; if (formBody[METHOD] === FIXED_SUM) { - populatedData[FIXED_SUM_AMOUNT] = String(populatedData[FIXED_SUM_AMOUNT]); + populatedData[FIXED_SUM_AMOUNT] = stripCommas(String(populatedData[FIXED_SUM_AMOUNT])); populatedData[PERCENTAGE_CHARGE] = null; }