Skip to content

Commit

Permalink
fix(EMS-3234): no PDF - Export contract - Fixed sum amount - decimal …
Browse files Browse the repository at this point in the history
…number data saving (#2653)

* feat(EMS-3234): fixed decimal issue by changing sql field type and transforming number

* feat(EMS-3234): fixed check your answers and tests

* feat(EMS-3234): lint fix

* fix(EMS-3234): code and test improvements

---------

Co-authored-by: Zain Kassam <zkassam@ukexportfinance.gov.uk>
  • Loading branch information
Zainzzkk and Zain Kassam authored Jul 2, 2024
1 parent 1753a3a commit 8ae5ba9
Show file tree
Hide file tree
Showing 31 changed files with 508 additions and 55 deletions.
2 changes: 1 addition & 1 deletion database/exip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ DROP TABLE IF EXISTS `ExportContractAgentServiceCharge`;
CREATE TABLE `ExportContractAgentServiceCharge` (
`id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`percentageCharge` int DEFAULT NULL,
`fixedSumAmount` int DEFAULT NULL,
`fixedSumAmount` decimal(18,2) DEFAULT NULL,
`fixedSumCurrencyCode` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'GBP',
`method` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`payableCountryCode` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ const {
AGENT_DETAILS: { NAME, FULL_ADDRESS, COUNTRY_CODE },
AGENT_SERVICE: { IS_CHARGING, SERVICE_DESCRIPTION },
AGENT_CHARGES: {
FIXED_SUM_AMOUNT,
FIXED_SUM_CURRENCY_CODE,
PERCENTAGE_CHARGE,
PAYABLE_COUNTRY_CODE,
FIXED_SUM_AMOUNT, FIXED_SUM_CURRENCY_CODE, PERCENTAGE_CHARGE, PAYABLE_COUNTRY_CODE,
},
} = FIELD_IDS;

Expand Down Expand Up @@ -212,15 +209,19 @@ const checkExportContractSummaryList = {
cy.assertSummaryListRowDoesNotExist(summaryList, fieldId);
}
},
[FIXED_SUM_AMOUNT]: ({ shouldRender = false }) => {
[FIXED_SUM_AMOUNT]: ({ shouldRender = false, agentChargeFixedSumAmount }) => {
const fieldId = FIXED_SUM_AMOUNT;

if (shouldRender) {
const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.AGENT_CHARGES);

const currencyCode = application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_CURRENCY_CODE];

const expectedValue = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[fieldId], currencyCode);
let expectedValue = formatCurrency(application.EXPORT_CONTRACT.AGENT_CHARGES[fieldId], currencyCode);

if (agentChargeFixedSumAmount) {
expectedValue = formatCurrency(agentChargeFixedSumAmount, currencyCode, 2);
}

const { expectedKey, expectedChangeLinkText } = getSummaryListField(fieldId, FIELDS.AGENT_CHARGES);

cy.assertSummaryListRow(summaryList, fieldId, expectedKey, expectedValue, expectedChangeLinkText);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import application from '../../fixtures/application';
import FIELD_IDS from '../../constants/field-ids/insurance/export-contract';

const {
AGENT_CHARGES: { FIXED_SUM_AMOUNT },
} = FIELD_IDS;

/**
* completeAndSubmitAgentChargesForm
* Complete and submit the "Agent charges" form
Expand All @@ -10,7 +17,7 @@
const completeAndSubmitAgentChargesForm = ({
fixedSumMethod,
percentageMethod,
fixedSumAmount,
fixedSumAmount = application.EXPORT_CONTRACT.AGENT_CHARGES[FIXED_SUM_AMOUNT],
percentageCharge,
payableCountry,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Complete the "Export contract" section
* @param {Boolean} agentIsCharging: Agent is charging
* @param {Boolean} agentChargeMethodFixedSum: Agent charge method is "fixed sum"
* @param {String} agentChargeFixedSumAmount: Agent charge fixed sum amount
* @param {Boolean} agentChargeMethodPercentage: Agent charge method is "percentage"
* @param {Boolean} attemptedPrivateMarketCover: Has attempted to insure through the private market
* @param {Boolean} finalDestinationKnown: "Final destination known"
Expand All @@ -14,6 +15,7 @@
const completeExportContractSection = ({
agentIsCharging = false,
agentChargeMethodFixedSum = false,
agentChargeFixedSumAmount,
agentChargeMethodPercentage = false,
attemptedPrivateMarketCover = false,
finalDestinationKnown,
Expand Down Expand Up @@ -45,6 +47,7 @@ const completeExportContractSection = ({
if (agentIsCharging) {
cy.completeAndSubmitAgentChargesForm({
fixedSumMethod: agentChargeMethodFixedSum,
fixedSumAmount: agentChargeFixedSumAmount,
percentageMethod: agentChargeMethodPercentage,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { POLICY_TYPE } = APPLICATION;
* Runs through the full "prepare your application" section/journey for multiple contract policy
* All params default to false, except for submitCheckYourAnswers.
* @param {Boolean} agentChargeMethodFixedSum: Agent charge method is "fixed sum".
* @param {String} agentChargeFixedSumAmount: Agent charge fixed sum amount
* @param {Boolean} agentChargeMethodPercentage: Agent charge method is "percentage".
* @param {Boolean} agentIsCharging: Should submit "yes" to "agent is charging" in the "agent details" form.
* @param {Boolean} alternativeBuyerCurrency: Should submit an "alternative currency" in the buyer section.
Expand Down Expand Up @@ -37,6 +38,7 @@ const { POLICY_TYPE } = APPLICATION;
*/
const completePrepareApplicationMultiplePolicyType = ({
agentChargeMethodFixedSum = false,
agentChargeFixedSumAmount,
agentChargeMethodPercentage = false,
agentIsCharging = false,
alternativeBuyerCurrency = false,
Expand Down Expand Up @@ -102,6 +104,7 @@ const completePrepareApplicationMultiplePolicyType = ({
cy.completeExportContractSection({
agentIsCharging,
agentChargeMethodFixedSum,
agentChargeFixedSumAmount,
agentChargeMethodPercentage,
attemptedPrivateMarketCover,
finalDestinationKnown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { POLICY_TYPE } = FIELD_VALUES;
* Runs through the full "prepare your application" section/journey for a single contract policy
* All params default to false, except for submitCheckYourAnswers.
* @param {Boolean} agentChargeMethodFixedSum: Agent charge method is "fixed sum".
* @param {String} agentChargeFixedSumAmount: Agent charge fixed sum amount
* @param {Boolean} agentChargeMethodPercentage: Agent charge method is "percentage".
* @param {Boolean} agentIsCharging: Should submit "yes" to "agent is charging" in the "agent details" form.
* @param {Boolean} alternativeBuyerCurrency: Should submit an "alternative currency" in the buyer section.
Expand Down Expand Up @@ -60,6 +61,7 @@ const completePrepareApplicationSinglePolicyType = ({
isUsingAgent = false,
agentIsCharging = false,
agentChargeMethodFixedSum = false,
agentChargeFixedSumAmount,
agentChargeMethodPercentage = false,
submitCheckYourAnswers = true,
alternativeCurrencyTurnover = false,
Expand Down Expand Up @@ -102,6 +104,7 @@ const completePrepareApplicationSinglePolicyType = ({
cy.completeExportContractSection({
agentIsCharging,
agentChargeMethodFixedSum,
agentChargeFixedSumAmount,
agentChargeMethodPercentage,
attemptedPrivateMarketCover,
finalDestinationKnown,
Expand Down
12 changes: 7 additions & 5 deletions e2e-tests/helpers/format-currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { GBP_CURRENCY_CODE } from '../fixtures/currencies';
* Transform a number into a currency string
* @param {String} str: Amount
* @param {String} Currency code - defaults to GBP
* @param {Number} decimalPlaces - defaults to 0
* @returns {String} formatted currency
*/
const formatCurrency = (str, currency = GBP_CURRENCY_CODE) => Number(str).toLocaleString('en', {
style: 'currency',
currency,
minimumFractionDigits: 0,
});
const formatCurrency = (str, currency = GBP_CURRENCY_CODE, decimalPlaces = 0) =>
Number(str).toLocaleString('en', {
style: 'currency',
currency,
minimumFractionDigits: decimalPlaces,
});

export default formatCurrency;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import partials from '../../../../../../../partials';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import { assertFullyPopulatedExportContractSummaryListRows } from '../../../../../../../shared-test-assertions';

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

const { taskList } = partials.insurancePartials;

const task = taskList.submitApplication.tasks.checkAnswers;

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

context(
'Insurance - Change your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is charging - fixed sum method with decimal places - multiple policy',
() => {
let referenceNumber;
let url;

const fixedSumAmount = '1000.50';

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

cy.completePrepareApplicationMultiplePolicyType({
referenceNumber,
totalContractValueOverThreshold: true,
attemptedPrivateMarketCover: true,
isUsingAgent: true,
agentIsCharging: true,
agentChargeMethodFixedSum: true,
finalDestinationKnown: true,
agentChargeFixedSumAmount: fixedSumAmount,
});

task.link().click();

// To get past previous "Check your answers" pages
cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 });

url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${EXPORT_CONTRACT}`;
});
});

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

cy.navigateToUrl(url);
});

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

assertFullyPopulatedExportContractSummaryListRows({
agentChargeMethodFixedSum: true,
agentChargeFixedSumAmount: fixedSumAmount,
});
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import partials from '../../../../../../../partials';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import { assertFullyPopulatedExportContractSummaryListRows } from '../../../../../../../shared-test-assertions';

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

const { taskList } = partials.insurancePartials;

const task = taskList.submitApplication.tasks.checkAnswers;

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

context(
'Insurance - Change your answers - Export contract - Summary list - total contract value threshold, private insurance attempt, using an agent, agent is chraging - fixed sum method with decimal places',
() => {
let referenceNumber;
let url;

const fixedSumAmount = '1000.50';

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

cy.completePrepareApplicationSinglePolicyType({
referenceNumber,
totalContractValueOverThreshold: true,
attemptedPrivateMarketCover: true,
isUsingAgent: true,
agentIsCharging: true,
agentChargeMethodFixedSum: true,
finalDestinationKnown: true,
agentChargeFixedSumAmount: fixedSumAmount,
});

task.link().click();

// To get past previous "Check your answers" pages
cy.completeAndSubmitMultipleCheckYourAnswers({ count: 3 });

url = `${baseUrl}${INSURANCE_ROOT}/${referenceNumber}${EXPORT_CONTRACT}`;
});
});

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

cy.navigateToUrl(url);
});

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

assertFullyPopulatedExportContractSummaryListRows({
agentChargeMethodFixedSum: true,
agentChargeFixedSumAmount: fixedSumAmount,
});
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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 as decimal', () => {
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} as a decimal number`, () => {
const fixedSumAmount = '100.54';

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 values', () => {
cy.assertAgentChargesFieldValues({ fixedSumMethod: true, expectedFixedSumAmount: fixedSumAmount });
});
});
});
});
});
Loading

0 comments on commit 8ae5ba9

Please sign in to comment.