Skip to content

Commit

Permalink
feat(EMS-3773-3792): policy - single contract - credit limit field (#…
Browse files Browse the repository at this point in the history
…3026)

* feat(EMS-3792): single contract policy - credit limit field

* chore(EMS-3792): policy e2e improvements

* feat(EMS-3792): fix/update e2e tests

* feat(EMS-3792): fix/update unit test

* feat(EMS-3792): fix/update e2e tests

* feat(EMS-3792): rename creditLimit to requestedCreditLimit

* feat(EMS-3792): fix/update e2e test

* chore(tests): fix typos

* chore(tests): add missing e2e coverage

* feat(EMS-3792): update e2e test

* chore(tests): fix/update e2e test

* chore(docs): fix typos

* chore(deps): revert package-lock change
  • Loading branch information
ttbarnes authored Sep 13, 2024
1 parent c905028 commit ef3edaf
Show file tree
Hide file tree
Showing 96 changed files with 582 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ jobs:
'your-buyer/connection-with-the-buyer/**/*.spec.js',
'your-buyer/credit-insurance-cover/**/*.spec.js',
'your-buyer/currency-of-late-payments/**/*.spec.js',
'your-buyer/failed-to-pay/**/*.spec.js',
'your-buyer/failed-to-pay-on-time/**/*.spec.js',
'your-buyer/outstanding-or-overdue-payments/**/*.spec.js',
'your-buyer/root/**/*.spec.js',
'your-buyer/traded-with-buyer/**/*.spec.js',
Expand Down
1 change: 1 addition & 0 deletions database/exip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ CREATE TABLE IF NOT EXISTS `Policy` (
`totalSalesToBuyer` int DEFAULT NULL,
`maximumBuyerWillOwe` int DEFAULT NULL,
`needPreCreditPeriodCover` tinyint(1) DEFAULT NULL,
`requestedCreditLimit` int DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `Policy_application_idx` (`application`),
CONSTRAINT `Policy_application_fkey` FOREIGN KEY (`application`) REFERENCES `Application` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/**
* completeAndSubmitTotalContractValueForm
* Complete and submit the "Total contract value" form
* @param {Object} Object with flags completing and submitting the form
* - policyValueOverMvpMaximum: should submit an application with the value over the MVP maximum amount
* @param {Boolean} policyValueOverMvpMaximum: Should submit an application with a value over the MVP maximum amount
* @param {String} totalContractValue: Total contract value
* @param {String} requestedCreditLimit: Requested credit limit
*/
const completeAndSubmitTotalContractValueForm = ({ policyValueOverMvpMaximum = false }) => {
cy.completeTotalContractValueForm({ policyValueOverMvpMaximum });
const completeAndSubmitTotalContractValueForm = ({ policyValueOverMvpMaximum, totalContractValue, requestedCreditLimit }) => {
cy.completeTotalContractValueForm({
policyValueOverMvpMaximum,
totalContractValue,
requestedCreditLimit,
});

cy.clickSubmitButton();
};
Expand Down
22 changes: 16 additions & 6 deletions e2e-tests/commands/insurance/complete-total-contract-value-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@ import application from '../../fixtures/application';
const {
POLICY: {
CONTRACT_POLICY: {
SINGLE: { TOTAL_CONTRACT_VALUE },
SINGLE: { REQUESTED_CREDIT_LIMIT, TOTAL_CONTRACT_VALUE },
},
},
} = INSURANCE_FIELD_IDS;

/**
* completeTotalContractValueForm
* Complete the "Total contract value" form
* @param {Object} Object with flags completing and submitting the form
* - policyValueOverMvpMaximum: should submit an application with a value over the MVP maximum amount
* @param {Boolean} policyValueOverMvpMaximum: Should submit an application with a value over the MVP maximum amount
* @param {String} totalContractValue: Total contract value
* @param {String} requestedCreditLimit: Requested credit limit
*/
const completeTotalContractValueForm = ({ policyValueOverMvpMaximum = false }) => {
const completeTotalContractValueForm = ({
policyValueOverMvpMaximum = false,
totalContractValue = application.POLICY[TOTAL_CONTRACT_VALUE],
requestedCreditLimit = application.POLICY[REQUESTED_CREDIT_LIMIT],
}) => {
if (policyValueOverMvpMaximum) {
const mvpMaximumPlusOne = 50000 + 1;

cy.keyboardInput(field(TOTAL_CONTRACT_VALUE).input(), mvpMaximumPlusOne);
} else {
cy.keyboardInput(field(TOTAL_CONTRACT_VALUE).input(), application.POLICY[TOTAL_CONTRACT_VALUE]);
} else if (totalContractValue) {
cy.keyboardInput(field(TOTAL_CONTRACT_VALUE).input(), totalContractValue);
}

if (requestedCreditLimit) {
cy.keyboardInput(field(REQUESTED_CREDIT_LIMIT).input(), requestedCreditLimit);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { yesRadio } from '../../../pages/shared';
/**
* clickYesRadioInput
* Click a "yes" radio input.
* * @param {Integer} index: Optional radio index
* @param {Integer} index: Optional radio index
*/
const clickYesRadioInput = (index = 0) => {
yesRadio().label().eq(index).click();
Expand Down
3 changes: 0 additions & 3 deletions e2e-tests/constants/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export const APPLICATION = {
},
},
POLICY: {
TOTAL_VALUE_OF_CONTRACT: {
MINIMUM: 1,
},
TOTAL_MONTHS_OF_COVER: 12,
},
STATUS: {
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/constants/field-ids/insurance/policy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const POLICY = {
CONTRACT_COMPLETION_DATE_MONTH: `${CONTRACT_COMPLETION_DATE}-month`,
CONTRACT_COMPLETION_DATE_YEAR: `${CONTRACT_COMPLETION_DATE}-year`,
TOTAL_CONTRACT_VALUE: 'totalValueOfContract',
REQUESTED_CREDIT_LIMIT: 'requestedCreditLimit',
},
MULTIPLE: {
TOTAL_MONTHS_OF_COVER: 'totalMonthsOfCover',
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/constants/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const MINIMUM_CHARACTERS = {
ACCOUNT_NUMBER: 6,
BIC_SWIFT_CODE: 8,
IBAN: 16,
POLICY: {
REQUESTED_CREDIT_LIMIT: 1,
TOTAL_CONTRACT_VALUE: 1,
},
};

export const MAXIMUM_CHARACTERS = {
Expand Down
7 changes: 6 additions & 1 deletion e2e-tests/content-strings/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ export const ERROR_MESSAGES = {
[FIELD_IDS.INSURANCE.POLICY.CONTRACT_POLICY.SINGLE.TOTAL_CONTRACT_VALUE]: {
IS_EMPTY: 'Enter the total value of the contract you want to insure as a whole number - do not enter decimals',
INCORRECT_FORMAT: 'Enter the total value of the contract you want to insure as a whole number - do not enter decimals',
BELOW_MINIMUM: 'The total value of the contract you want to insure must be 1 or more',
BELOW_MINIMUM: `The total value of the contract you want to insure must be ${MINIMUM_CHARACTERS.POLICY.TOTAL_CONTRACT_VALUE} or more`,
},
[FIELD_IDS.INSURANCE.POLICY.CONTRACT_POLICY.SINGLE.REQUESTED_CREDIT_LIMIT]: {
IS_EMPTY: 'Enter the credit limit you require as a whole number - do not enter decimals',
INCORRECT_FORMAT: 'Enter the credit limit you require as a whole number - do not enter decimals',
BELOW_MINIMUM: `The credit limit you want to insure must be ${MINIMUM_CHARACTERS.POLICY.REQUESTED_CREDIT_LIMIT} or more`,
},
},
MULTIPLE: {
Expand Down
9 changes: 9 additions & 0 deletions e2e-tests/content-strings/fields/insurance/policy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,21 @@ export const POLICY_FIELDS = {
},
},
[CONTRACT_POLICY.SINGLE.TOTAL_CONTRACT_VALUE]: {
LABEL: "What's the total value of the contract you want to insure?",
HINT: 'Enter a whole number. Do not enter decimals.',
SUMMARY: {
TITLE: 'Contract value',
FORM_TITLE: POLICY_FORM_TITLES.CONTRACT_POLICY,
},
},
[CONTRACT_POLICY.SINGLE.REQUESTED_CREDIT_LIMIT]: {
LABEL: 'What credit limit do you require?',
HINT: 'For example, your total contract maybe £250,000 but the amount you want to insure is £100,000.',
SUMMARY: {
TITLE: 'Credit limit',
FORM_TITLE: POLICY_FORM_TITLES.CONTRACT_POLICY,
},
},
},
MULTIPLE: {
[CONTRACT_POLICY.MULTIPLE.TOTAL_MONTHS_OF_COVER]: {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/content-strings/pages/insurance/policy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const MULTIPLE_CONTRACT_POLICY = {

const SINGLE_CONTRACT_POLICY_TOTAL_CONTRACT_VALUE = {
...SHARED,
PAGE_TITLE: "What's the total value of the contract you want to insure in",
PAGE_TITLE: 'Tell us about the value of the contract and the value of the policy in',
};

const MULTIPLE_CONTRACT_POLICY_EXPORT_VALUE = {
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/fixtures/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const {
CONTRACT_POLICY: {
REQUESTED_START_DATE,
POLICY_CURRENCY_CODE,
SINGLE: { CONTRACT_COMPLETION_DATE, TOTAL_CONTRACT_VALUE },
SINGLE: { CONTRACT_COMPLETION_DATE, REQUESTED_CREDIT_LIMIT, TOTAL_CONTRACT_VALUE },
MULTIPLE: { TOTAL_MONTHS_OF_COVER },
},
EXPORT_VALUE: {
Expand Down Expand Up @@ -128,6 +128,7 @@ const application = {
year: endDate.getFullYear(),
},
[TOTAL_CONTRACT_VALUE]: '10000',
[REQUESTED_CREDIT_LIMIT]: '8000',
[POLICY_CURRENCY_CODE]: GBP_CURRENCY_CODE,
[TOTAL_MONTHS_OF_COVER]: '2',
[TOTAL_SALES_TO_BUYER]: '1000',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { field as fieldSelector } from '../../../../../../../pages/shared';
import { ERROR_MESSAGES } from '../../../../../../../content-strings';
import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
import { APPLICATION } from '../../../../../../../constants';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import dateField from '../../../../../../../commands/insurance/date-field';
Expand All @@ -11,10 +11,8 @@ const {
} = INSURANCE_ROUTES;

const {
POLICY: {
CONTRACT_POLICY: { REQUESTED_START_DATE },
},
} = INSURANCE_FIELD_IDS;
CONTRACT_POLICY: { REQUESTED_START_DATE },
} = POLICY_FIELD_IDS;

const {
INSURANCE: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { field as fieldSelector } from '../../../../../../../pages/shared';
import { ERROR_MESSAGES } from '../../../../../../../content-strings';
import { APPLICATION } from '../../../../../../../constants';
import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';

const {
Expand All @@ -10,12 +10,10 @@ const {
} = APPLICATION;

const {
POLICY: {
CONTRACT_POLICY: {
MULTIPLE: { TOTAL_MONTHS_OF_COVER },
},
CONTRACT_POLICY: {
MULTIPLE: { TOTAL_MONTHS_OF_COVER },
},
} = INSURANCE_FIELD_IDS;
} = POLICY_FIELD_IDS;

const {
ROOT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { field as fieldSelector } from '../../../../../../pages/shared';
import { INSURANCE_FIELD_IDS } from '../../../../../../constants/field-ids/insurance';
import { POLICY as POLICY_FIELD_IDS } from '../../../../../../constants/field-ids/insurance/policy';
import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance';

const {
Expand All @@ -8,10 +8,8 @@ const {
} = INSURANCE_ROUTES;

const {
POLICY: {
CONTRACT_POLICY: { REQUESTED_START_DATE },
},
} = INSURANCE_FIELD_IDS;
CONTRACT_POLICY: { REQUESTED_START_DATE },
} = POLICY_FIELD_IDS;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { field as fieldSelector } from '../../../../../../../pages/shared';
import { INSURANCE_ROUTES } from '../../../../../../../constants/routes/insurance';
import { INSURANCE_FIELD_IDS } from '../../../../../../../constants/field-ids/insurance';
import { POLICY as FIELD_IDS } from '../../../../../../../constants/field-ids/insurance/policy';
import application from '../../../../../../../fixtures/application';

const {
Expand All @@ -9,12 +9,10 @@ const {
} = INSURANCE_ROUTES;

const {
POLICY: {
CONTRACT_POLICY: {
SINGLE: { TOTAL_CONTRACT_VALUE },
},
CONTRACT_POLICY: {
SINGLE: { TOTAL_CONTRACT_VALUE, REQUESTED_CREDIT_LIMIT },
},
} = INSURANCE_FIELD_IDS;
} = FIELD_IDS;

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

Expand Down Expand Up @@ -52,20 +50,13 @@ context('Insurance - Policy - Single contract policy - Total contract value page
it('should redirect to `all sections`', () => {
cy.assertAllSectionsUrl(referenceNumber);
});

it('should retain the `type of policy` task status as `in progress`', () => {
cy.checkTaskPolicyStatusIsInProgress();
});
});

describe('when entering an invalid total contract value and submitting the form via `save and go back` button', () => {
const field = fieldSelector(TOTAL_CONTRACT_VALUE);
const invalidValue = 'Not a number';

describe(`when only ${TOTAL_CONTRACT_VALUE} is provided`, () => {
beforeEach(() => {
cy.navigateToUrl(url);

cy.keyboardInput(field.input(), invalidValue);
cy.completeTotalContractValueForm({ requestedCreditLimit: '' });

cy.clickSaveAndBackButton();
});
Expand All @@ -78,33 +69,43 @@ context('Insurance - Policy - Single contract policy - Total contract value page
cy.checkTaskPolicyStatusIsInProgress();
});

describe('when going back to the page', () => {
beforeEach(() => {
cy.navigateToUrl(url);
it('should have the submitted values when going back to the page', () => {
cy.navigateToUrl(url);

fieldSelector(TOTAL_CONTRACT_VALUE).input().should('have.value', application.POLICY[TOTAL_CONTRACT_VALUE]);
fieldSelector(REQUESTED_CREDIT_LIMIT).input().should('have.value', '');
});
});

describe(`when only ${REQUESTED_CREDIT_LIMIT} is provided`, () => {
beforeEach(() => {
cy.navigateToUrl(url);

cy.completeTotalContractValueForm({ totalContractValue: '' });

cy.keyboardInput(field.input(), invalidValue);
cy.clickSaveAndBackButton();
});

cy.clickSaveAndBackButton();
it('should redirect to `all sections`', () => {
cy.assertAllSectionsUrl(referenceNumber);
});

cy.startInsurancePolicySection({});
it('should retain the `type of policy` task status as `in progress`', () => {
cy.checkTaskPolicyStatusIsInProgress();
});

// go through the first 2 single contract policy forms.
cy.clickSubmitButtonMultipleTimes({ count: 2 });
});
it('should have the submitted values when going back to the page', () => {
cy.navigateToUrl(url);

it('should NOT have saved the submitted value', () => {
field.input().should('have.value', '');
});
fieldSelector(REQUESTED_CREDIT_LIMIT).input().should('have.value', application.POLICY[REQUESTED_CREDIT_LIMIT]);
});
});

describe('when entering a valid total contract value and submitting the form via `save and go back` button', () => {
const field = fieldSelector(TOTAL_CONTRACT_VALUE);

describe('when all fields are provided', () => {
beforeEach(() => {
cy.navigateToUrl(url);

cy.keyboardInput(field.input(), application.POLICY[TOTAL_CONTRACT_VALUE]);
cy.completeTotalContractValueForm({});

cy.clickSaveAndBackButton();
});
Expand All @@ -117,14 +118,11 @@ context('Insurance - Policy - Single contract policy - Total contract value page
cy.checkTaskPolicyStatusIsInProgress();
});

describe('when going back to the page', () => {
beforeEach(() => {
cy.navigateToUrl(url);
});
it('should have the submitted values when going back to the page', () => {
cy.navigateToUrl(url);

it('should have the submitted value', () => {
fieldSelector(TOTAL_CONTRACT_VALUE).input().should('have.value', application.POLICY[TOTAL_CONTRACT_VALUE]);
});
fieldSelector(TOTAL_CONTRACT_VALUE).input().should('have.value', application.POLICY[TOTAL_CONTRACT_VALUE]);
fieldSelector(REQUESTED_CREDIT_LIMIT).input().should('have.value', application.POLICY[REQUESTED_CREDIT_LIMIT]);
});
});
});
Loading

0 comments on commit ef3edaf

Please sign in to comment.