Skip to content

Commit

Permalink
fix(EMS-3546): no PDF - Export contract - Agent charges - fixed sum c…
Browse files Browse the repository at this point in the history
…ommas (#2678)

Co-authored-by: Zain Kassam <zkassam@ukexportfinance.gov.uk>
  • Loading branch information
Zainzzkk and Zain Kassam authored Jul 4, 2024
1 parent adaea21 commit 26c1b6e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 });
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 26c1b6e

Please sign in to comment.