Skip to content

Commit

Permalink
fix(EMS-3787): export contract - agent name with an apostrophe (#2989)
Browse files Browse the repository at this point in the history
* fix(EMS-3787): export contract - agent name with an apostrophe

* fix(EMS-3787): update agent name test mocks
  • Loading branch information
ttbarnes authored Aug 22, 2024
1 parent 869054b commit 7f64dcf
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 6 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/fixtures/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const application = {
[DECLINED_DESCRIPTION]: mockAddress0,
},
AGENT_DETAILS: {
[AGENT_NAME]: 'Mock export contract agent name',
[AGENT_NAME]: "Mock export contract agent name O'Neill",
[AGENT_COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME,
[AGENT_FULL_ADDRESS]: mockAddress0,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { INSURANCE_ROUTES } from '../../../../../constants/routes/insurance';
import { EXPORT_CONTRACT as FIELD_IDS } from '../../../../../constants/field-ids/insurance/export-contract';
import { field } from '../../../../../pages/shared';

const {
ROOT: INSURANCE_ROOT,
EXPORT_CONTRACT: { AGENT_DETAILS },
} = INSURANCE_ROUTES;

const {
AGENT_DETAILS: { NAME },
} = FIELD_IDS;

const nameValue = "O'Neill";

const baseUrl = Cypress.config('baseUrl');

context('Insurance - Name fields - Export contract - Name field should render an apostrophe without character codes after submission', () => {
let referenceNumber;
let agentDetailsUrl;

before(() => {
cy.completeSignInAndGoToApplication({}).then(({ referenceNumber: refNumber }) => {
referenceNumber = refNumber;

// go to the page we want to test.
cy.completeAndSubmitExportContractForms({
isUsingAgent: true,
formToStopAt: 'agent',
});

agentDetailsUrl = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${AGENT_DETAILS}`;

cy.assertUrl(agentDetailsUrl);
});
});

beforeEach(() => {
cy.saveSession();
});

after(() => {
cy.deleteApplication(referenceNumber);
});

describe(NAME, () => {
describe('when submitting the name field with an apostrophe and going back to the page', () => {
beforeEach(() => {
cy.saveSession();

cy.navigateToUrl(agentDetailsUrl);

cy.completeAndSubmitAgentDetailsForm({ name: nameValue });

cy.clickBackLink();

cy.assertUrl(agentDetailsUrl);
});

it('should render name exactly as they were submitted', () => {
cy.checkValue(field(NAME), nameValue);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const {
},
} = INSURANCE_FIELD_IDS;

const baseUrl = Cypress.config('baseUrl');

const { POLICY } = application;

const nameValue = `${POLICY[NAME]}-'`;

const baseUrl = Cypress.config('baseUrl');

context('Insurance - Name fields - Loss payee details - Name field should render special characters without character codes after submission', () => {
let referenceNumber;
let url;
Expand Down
2 changes: 1 addition & 1 deletion src/api/test-mocks/mock-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const mockExportContractAgent = {
export const mockExportContractAgentFullyPopulated = {
finalDestinationCountryCode: mockCountries[0].isoCode,
fullAddress: 'Mock export contract agent address',
name: 'Mock export contract agent name',
name: "Mock export contract agent name O'Neill",
privateMarket: mockPrivateMarket,
service: mockExportContractAgentService,
agent: mockExportContractAgent,
Expand Down
20 changes: 20 additions & 0 deletions src/ui/server/helpers/mappings/map-name-fields/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { mockApplication } from '../../../test-mocks';
const {
ACCOUNT: { FIRST_NAME, LAST_NAME },
COMPANIES_HOUSE: { COMPANY_NAME },
EXPORT_CONTRACT: {
AGENT_DETAILS: { NAME: AGENT_NAME },
},
YOUR_BUYER: {
COMPANY_OR_ORGANISATION: { NAME: BUYER_NAME },
},
Expand All @@ -28,6 +31,13 @@ const mockApplicationWithCharacterCodes = {
...mockApplication.company,
[COMPANY_NAME]: mockStringWithCharacterCodes,
},
exportContract: {
...mockApplication.exportContract,
agent: {
...mockApplication.exportContract.agent,
[AGENT_NAME]: mockStringWithCharacterCodes,
},
},
policyContact: {
...mockApplication.policyContact,
[FIRST_NAME]: mockStringWithCharacterCodes,
Expand Down Expand Up @@ -60,6 +70,16 @@ describe('server/helpers/mappings/map-name-fields', () => {
expect(result.company[COMPANY_NAME]).toEqual(expected);
});

it(`should replace character codes in exportContract.agent.${AGENT_NAME}`, () => {
const result = mapNameFields(mockApplicationWithCharacterCodes);

const fieldValue = mockApplicationWithCharacterCodes.exportContract.agent[AGENT_NAME];

const expected = replaceCharacterCodesWithCharacters(fieldValue);

expect(result.exportContract.agent[AGENT_NAME]).toEqual(expected);
});

it(`should replace character codes in nominatedLossPayee.${LOSS_PAYEE_NAME}`, () => {
const result = mapNameFields(mockApplicationWithCharacterCodes);

Expand Down
11 changes: 10 additions & 1 deletion src/ui/server/helpers/mappings/map-name-fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Application } from '../../../../types';
const {
ACCOUNT: { FIRST_NAME, LAST_NAME },
COMPANIES_HOUSE: { COMPANY_NAME },
EXPORT_CONTRACT: {
AGENT_DETAILS: { NAME: AGENT_NAME },
},
POLICY: {
LOSS_PAYEE_DETAILS: { NAME: LOSS_PAYEE_NAME },
},
Expand All @@ -20,7 +23,7 @@ const {
* @returns {Object} Application with mapped name field characters
*/
const mapNameFields = (application: Application): Application => {
const { buyer, company, nominatedLossPayee, policyContact } = application;
const { buyer, company, exportContract, nominatedLossPayee, policyContact } = application;

if (buyer?.[BUYER_NAME]) {
const fieldValue = buyer[BUYER_NAME];
Expand All @@ -34,6 +37,12 @@ const mapNameFields = (application: Application): Application => {
company[COMPANY_NAME] = replaceCharacterCodesWithCharacters(fieldValue);
}

if (exportContract?.agent?.[AGENT_NAME]) {
const fieldValue = exportContract.agent[AGENT_NAME];

exportContract.agent[AGENT_NAME] = replaceCharacterCodesWithCharacters(fieldValue);
}

if (nominatedLossPayee?.[LOSS_PAYEE_NAME]) {
const fieldValue = nominatedLossPayee[LOSS_PAYEE_NAME];

Expand Down
2 changes: 1 addition & 1 deletion src/ui/server/test-mocks/mock-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const mockExportContractAgent = {
countryCode: mockCountries[0].isoCode,
fullAddress: 'Mock export contract agent address',
isUsingAgent: false,
name: 'Mock export contract agent name',
name: "Mock export contract agent name O'Neill",
service: mockExportContractAgentService,
};

Expand Down

0 comments on commit 7f64dcf

Please sign in to comment.