Skip to content

Commit

Permalink
fix(EMS-3520): no pdf - dashboard - policy currency code (#2641)
Browse files Browse the repository at this point in the history
* fix(EMS-3520): no pdf - dashboard - policy currency code

* fix(EMS-3520): no pdf - dashboard - policy currency code

* fix(EMS-3520): improve test description

* fix(EMS-3520): linting issues

* fix(EMS-3520): fix linting issues
  • Loading branch information
ttbarnes authored Jun 26, 2024
1 parent 3c22794 commit 44a1f60
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import mockCompanies from '../../fixtures/companies';

const {
COMPANIES_HOUSE: {
COMPANY_ADDRESS, COMPANY_NUMBER, COMPANY_NAME, COMPANY_INCORPORATED, COMPANY_SIC, INDUSTRY_SECTOR_NAMES,
COMPANY_ADDRESS,
COMPANY_NUMBER,
COMPANY_NAME,
COMPANY_INCORPORATED,
COMPANY_SIC,
INDUSTRY_SECTOR_NAMES,
},
} = INSURANCE_FIELD_IDS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* Complete and submit the "multiple contract policy" form
* @param {String} isoCode: Policy currency ISO code
* @param {Boolean} alternativeCurrency: Select the "alternative currency" option
* @param {Boolean} chooseCurrency: Whether to choose a currency or not
*/
const completeAndSubmitMultipleContractPolicyForm = ({ isoCode, alternativeCurrency }) => {
const completeAndSubmitMultipleContractPolicyForm = ({ isoCode, alternativeCurrency, chooseCurrency }) => {
cy.completeMultipleContractPolicyForm({
isoCode,
alternativeCurrency,
chooseCurrency,
});

cy.clickSubmitButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* Complete and submit the "single contract policy" form.
* @param {String} isoCode: Policy currency ISO code
* @param {Boolean} alternativeCurrency: Select the "alternative currency" option
* @param {Boolean} chooseCurrency: Whether to choose a currency or not
*/
const completeAndSubmitSingleContractPolicyForm = ({ isoCode, alternativeCurrency }) => {
const completeAndSubmitSingleContractPolicyForm = ({ isoCode, alternativeCurrency, chooseCurrency }) => {
cy.completeSingleContractPolicyForm({
isoCode,
alternativeCurrency,
chooseCurrency,
});

cy.clickSubmitButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const { TABLE_HEADERS } = CONTENT_STRINGS;

const {
YOUR_BUYER: {
COMPANY_OR_ORGANISATION: {
COUNTRY,
NAME,
},
COMPANY_OR_ORGANISATION: { COUNTRY, NAME },
},
POLICY: {
CONTRACT_POLICY: {
Expand All @@ -31,7 +28,7 @@ const {
},
} = INSURANCE_FIELD_IDS;

context('Insurance - Dashboard - populated application', () => {
context('Insurance - Dashboard - populated application - GBP currency', () => {
const baseUrl = Cypress.config('baseUrl');
let referenceNumber;
let url;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import dashboardPage from '../../../../../pages/insurance/dashboard';
import partials from '../../../../../partials';
import { PAGES } from '../../../../../content-strings';
import { ROUTES, FIELD_VALUES } from '../../../../../constants';
import { POLICY as FIELD_IDS } from '../../../../../constants/field-ids/insurance/policy';
import application from '../../../../../fixtures/application';
import { NON_STANDARD_CURRENCY_CODE } from '../../../../../fixtures/currencies';
import formatCurrency from '../../../../../helpers/format-currency';

const { table } = dashboardPage;

const { DASHBOARD } = ROUTES.INSURANCE;

const CONTENT_STRINGS = PAGES.INSURANCE.DASHBOARD;

const { TABLE_HEADERS } = CONTENT_STRINGS;

const {
CONTRACT_POLICY: {
SINGLE: { TOTAL_CONTRACT_VALUE },
},
EXPORT_VALUE: {
MULTIPLE: { MAXIMUM_BUYER_WILL_OWE },
},
} = FIELD_IDS;

context('Insurance - Dashboard - populated application - alternative (non GBP) currency', () => {
const baseUrl = Cypress.config('baseUrl');
let referenceNumber;
let url;

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

url = `${baseUrl}${DASHBOARD}`;

partials.header.navigation.applications().click();

cy.assertUrl(url);
});
});

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

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

describe('when completing the `policy - tell us about your policy` form - single policy type', () => {
beforeEach(() => {
const policyType = FIELD_VALUES.POLICY_TYPE.SINGLE;

cy.navigateToUrl(url);

// go to application
table.body.row(referenceNumber).submittedLink().click();

// go to the 'policy' section via task list
cy.startInsurancePolicySection({});

// complete the first form - single contract policy
cy.completeAndSubmitPolicyTypeForm({ policyType });

// complete and submit the next 2 forms
cy.completeAndSubmitSingleContractPolicyForm({ alternativeCurrency: true, chooseCurrency: true });
cy.completeAndSubmitTotalContractValueForm({});
});

it(`should render a formatted value of ${TOTAL_CONTRACT_VALUE} in the ${TABLE_HEADERS.VALUE} cell`, () => {
partials.header.navigation.applications().click();

const cell = table.body.row(referenceNumber).value();

const expected = formatCurrency(application.POLICY[TOTAL_CONTRACT_VALUE], NON_STANDARD_CURRENCY_CODE);

cy.checkText(cell, expected);
});
});

describe('when completing the `policy - tell us about your policy` form - multiple policy type', () => {
beforeEach(() => {
cy.navigateToUrl(url);

const policyType = FIELD_VALUES.POLICY_TYPE.MULTIPLE;

// go to application
table.body.row(referenceNumber).submittedLink().click();

// go to the 'policy' section via task list
cy.startInsurancePolicySection({});

// complete the first form - single contract policy
cy.completeAndSubmitPolicyTypeForm({ policyType });

// complete and submit the next 2 forms
cy.completeAndSubmitMultipleContractPolicyForm({ alternativeCurrency: true, chooseCurrency: true });
cy.completeAndSubmitExportValueForm({ policyType });
});

it(`should render a formatted value of ${MAXIMUM_BUYER_WILL_OWE} in the ${TABLE_HEADERS.VALUE} cell`, () => {
partials.header.navigation.applications().click();

const cell = table.body.row(referenceNumber).value();

const expected = formatCurrency(application.POLICY[MAXIMUM_BUYER_WILL_OWE], NON_STANDARD_CURRENCY_CODE);

cy.checkText(cell, expected);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { companyDetails } from '../../../../../../pages/your-business';
import partials from '../../../../../../partials';
import {
body, field, yesRadioInput, noRadioInput,
body,
field,
yesRadioInput,
noRadioInput,
} from '../../../../../../pages/shared';
import { PAGES } from '../../../../../../content-strings';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';
Expand All @@ -18,7 +21,11 @@ const CONTENT_STRINGS = PAGES.INSURANCE.EXPORTER_BUSINESS.COMPANY_DETAILS;
const {
EXPORTER_BUSINESS: {
YOUR_COMPANY: {
TRADING_ADDRESS, HAS_DIFFERENT_TRADING_NAME, WEBSITE, PHONE_NUMBER, DIFFERENT_TRADING_NAME,
TRADING_ADDRESS,
HAS_DIFFERENT_TRADING_NAME,
WEBSITE,
PHONE_NUMBER,
DIFFERENT_TRADING_NAME,
},
},
} = INSURANCE_FIELD_IDS;
Expand Down
1 change: 1 addition & 0 deletions src/ui/server/graphql/queries/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const applicationsQuery = gql`
companyOrOrganisationName
}
policy {
policyCurrencyCode
policyType
totalValueOfContract
maximumBuyerWillOwe
Expand Down
60 changes: 54 additions & 6 deletions src/ui/server/helpers/mappings/map-applications/map-value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import INSURANCE_FIELD_IDS from '../../../constants/field-ids/insurance';
import { DEFAULT } from '../../../content-strings';
import formatCurrency from '../../format-currency';
import mockApplication, { mockSinglePolicy, mockMultiplePolicy } from '../../../test-mocks/mock-application';
import { EUR } from '../../../test-mocks/mock-currencies';

const { policy: initPolicy } = mockApplication;

const {
POLICY: {
CONTRACT_POLICY: {
POLICY_CURRENCY_CODE,
SINGLE: { TOTAL_CONTRACT_VALUE },
},
EXPORT_VALUE: {
Expand All @@ -19,11 +21,34 @@ const {
} = INSURANCE_FIELD_IDS;

describe('server/helpers/mappings/map-applications/map-value', () => {
describe('when the policy type is single policy type', () => {
it(`should return formatted ${TOTAL_CONTRACT_VALUE}`, () => {
describe(`when the policy type is single policy type and ${POLICY_CURRENCY_CODE} is available`, () => {
it(`should return formatted ${TOTAL_CONTRACT_VALUE} with default ${GBP_CURRENCY_CODE}`, () => {
const singlePolicyApplication = {
...mockApplication,
policy: mockSinglePolicy,
policy: {
...mockSinglePolicy,
[POLICY_CURRENCY_CODE]: EUR.isoCode,
},
};

const result = mapInsuredFor(singlePolicyApplication);

const { policy } = singlePolicyApplication;

const expected = formatCurrency(policy[TOTAL_CONTRACT_VALUE], policy[POLICY_CURRENCY_CODE]);

expect(result).toEqual(expected);
});
});

describe(`when the policy type is single policy type and ${POLICY_CURRENCY_CODE} is NOT available`, () => {
it(`should return formatted ${TOTAL_CONTRACT_VALUE} with default ${GBP_CURRENCY_CODE}`, () => {
const singlePolicyApplication = {
...mockApplication,
policy: {
...mockSinglePolicy,
[POLICY_CURRENCY_CODE]: null,
},
};

const result = mapInsuredFor(singlePolicyApplication);
Expand All @@ -36,11 +61,34 @@ describe('server/helpers/mappings/map-applications/map-value', () => {
});
});

describe('when the policy type is multiple policy type', () => {
it(`should return formatted ${MAXIMUM_BUYER_WILL_OWE}`, () => {
describe(`when the policy type is multiple policy type and ${POLICY_CURRENCY_CODE} is available`, () => {
it(`should return formatted ${MAXIMUM_BUYER_WILL_OWE} with default ${GBP_CURRENCY_CODE}`, () => {
const multiplePolicyApplication = {
...mockApplication,
policy: mockMultiplePolicy,
policy: {
...mockMultiplePolicy,
[POLICY_CURRENCY_CODE]: EUR.isoCode,
},
};

const result = mapInsuredFor(multiplePolicyApplication);

const { policy } = multiplePolicyApplication;

const expected = formatCurrency(policy[MAXIMUM_BUYER_WILL_OWE], policy[POLICY_CURRENCY_CODE]);

expect(result).toEqual(expected);
});
});

describe(`when the policy type is multiple policy type and ${POLICY_CURRENCY_CODE} is NOT available`, () => {
it(`should return formatted ${MAXIMUM_BUYER_WILL_OWE} with default ${GBP_CURRENCY_CODE}`, () => {
const multiplePolicyApplication = {
...mockApplication,
policy: {
...mockMultiplePolicy,
[POLICY_CURRENCY_CODE]: null,
},
};

const result = mapInsuredFor(multiplePolicyApplication);
Expand Down
7 changes: 5 additions & 2 deletions src/ui/server/helpers/mappings/map-applications/map-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
POLICY: {
POLICY_TYPE,
CONTRACT_POLICY: {
POLICY_CURRENCY_CODE,
SINGLE: { TOTAL_CONTRACT_VALUE },
},
EXPORT_VALUE: {
Expand All @@ -30,12 +31,14 @@ const mapValue = (application: Application) => {

const policyType = policy[POLICY_TYPE];

const currencyCode = application.policy[POLICY_CURRENCY_CODE] || GBP_CURRENCY_CODE;

if (isSinglePolicyType(policyType) && objectHasProperty(policy, TOTAL_CONTRACT_VALUE)) {
return formatCurrency(policy[TOTAL_CONTRACT_VALUE], GBP_CURRENCY_CODE);
return formatCurrency(policy[TOTAL_CONTRACT_VALUE], currencyCode);
}

if (isMultiplePolicyType(policyType) && objectHasProperty(policy, MAXIMUM_BUYER_WILL_OWE)) {
return formatCurrency(policy[MAXIMUM_BUYER_WILL_OWE], GBP_CURRENCY_CODE);
return formatCurrency(policy[MAXIMUM_BUYER_WILL_OWE], currencyCode);
}
}

Expand Down

0 comments on commit 44a1f60

Please sign in to comment.