Skip to content

Commit

Permalink
fix(EMS-3515): no PDF - XLSX - Policy - Pre credit period (#2636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zainzzkk authored Jun 26, 2024
1 parent 44a1f60 commit 1bd056e
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 44 deletions.
77 changes: 51 additions & 26 deletions src/api/.keystone/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { XLSX_ROW_INDEXES } from '.';
import { INDEXES } from './INDEXES';
import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy';
import { APPLICATION } from '../application';
import { mockApplicationMinimalBrokerBuyerAndCompany } from '../../test-mocks';

const {
TYPE_OF_POLICY: { POLICY_TYPE },
NEED_PRE_CREDIT_PERIOD,
CREDIT_PERIOD_WITH_BUYER,
} = POLICY_FIELD_IDS;

const application = {
...mockApplicationMinimalBrokerBuyerAndCompany,
policy: {
...mockApplicationMinimalBrokerBuyerAndCompany.policy,
[POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE,
[NEED_PRE_CREDIT_PERIOD]: true,
[CREDIT_PERIOD_WITH_BUYER]: 'mock value',
},
};

describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - ${NEED_PRE_CREDIT_PERIOD} true`, () => {
it('should return default multiple contract policy row indexes', () => {
const result = XLSX_ROW_INDEXES(application);

const indexes = INDEXES();

const expected = {
...indexes,
BROKER_ADDRESS: indexes.BROKER_ADDRESS + 2,
BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1,
LOSS_PAYEE_ADDRESS: indexes.LOSS_PAYEE_ADDRESS + 1,
TITLES: {
...indexes.TITLES,
BUYER: indexes.TITLES.BUYER + 1,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 1,
EXPORT_CONTRACT: indexes.TITLES.EXPORT_CONTRACT + 1,
},
};

expect(result).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { XLSX_ROW_INDEXES } from '.';
import { INDEXES } from './INDEXES';
import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy';
import { APPLICATION } from '../application';
import { mockApplicationMinimalBrokerBuyerAndCompany } from '../../test-mocks';

const {
TYPE_OF_POLICY: { POLICY_TYPE },
NEED_PRE_CREDIT_PERIOD,
CREDIT_PERIOD_WITH_BUYER,
} = POLICY_FIELD_IDS;

const application = {
...mockApplicationMinimalBrokerBuyerAndCompany,
policy: {
...mockApplicationMinimalBrokerBuyerAndCompany.policy,
[POLICY_TYPE]: APPLICATION.POLICY_TYPE.SINGLE,
[NEED_PRE_CREDIT_PERIOD]: true,
[CREDIT_PERIOD_WITH_BUYER]: 'mock value',
},
};

describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - ${NEED_PRE_CREDIT_PERIOD} true`, () => {
it('should return default single contract policy row indexes', () => {
const result = XLSX_ROW_INDEXES(application);

const indexes = INDEXES();

const expected = {
...indexes,
BROKER_ADDRESS: indexes.BROKER_ADDRESS + 2,
BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1,
LOSS_PAYEE_ADDRESS: indexes.LOSS_PAYEE_ADDRESS + 1,
TITLES: {
...indexes.TITLES,
BUYER: indexes.TITLES.BUYER + 1,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 1,
EXPORT_CONTRACT: indexes.TITLES.EXPORT_CONTRACT + 1,
},
};

expect(result).toEqual(expected);
});
});
15 changes: 15 additions & 0 deletions src/api/constants/XLSX-CONFIG/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
nominatedLossPayee: { isAppointed: nominatedLossPayeeAppointed },
policy: {
jointlyInsuredParty: { requested: requestedJointlyInsuredParty },
needPreCreditPeriodCover,
},
policyContact: { isSameAsOwner: policyContactIsSameAsOwner },
} = application;
Expand Down Expand Up @@ -124,6 +125,16 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
indexes.TITLES.EXPORT_CONTRACT += 3;
}

if (needPreCreditPeriodCover) {
indexes.BROKER_ADDRESS += 2;
indexes.BUYER_ADDRESS += 1;
indexes.LOSS_PAYEE_ADDRESS += 1;

indexes.TITLES.BUYER += 1;
indexes.TITLES.DECLARATIONS += 1;
indexes.TITLES.EXPORT_CONTRACT += 1;
}

if (nominatedLossPayeeAppointed) {
indexes.TITLES.BUYER += 5;
indexes.TITLES.DECLARATIONS += 5;
Expand Down Expand Up @@ -163,6 +174,10 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
indexes.TITLES.DECLARATIONS += 5;
indexes.AGENT_ADDRESS = 75;

if (needPreCreditPeriodCover) {
indexes.AGENT_ADDRESS += 1;
}

if (isMultiplePolicy) {
indexes.AGENT_ADDRESS += 1;

Expand Down
4 changes: 3 additions & 1 deletion src/api/content-strings/XLSX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const {
LOSS_PAYEE_FINANCIAL_UK: { SORT_CODE, ACCOUNT_NUMBER },
NAME_ON_POLICY,
NEED_PRE_CREDIT_PERIOD,
CREDIT_PERIOD_WITH_BUYER,
REQUESTED_JOINTLY_INSURED_PARTY,
TYPE_OF_POLICY: { POLICY_TYPE },
USING_BROKER,
Expand Down Expand Up @@ -125,7 +126,7 @@ export const XLSX = {
},
EXPORT_CONTRACT: {
[DESCRIPTION]: "About the exporter's goods or services",
[FINAL_DESTINATION_KNOWN]: 'Does the exporter know the final destination of the goods?',
[FINAL_DESTINATION_KNOWN]: 'Does the exporter know the final destination of the goods or services?',
[PAYMENT_TERMS_DESCRIPTION]: 'How the exporter will be paid for their export',
[ATTEMPTED_PRIVATE_MARKET]: 'Did the exporter try to insure through the private market?',
[DECLINED_DESCRIPTION]: 'Why could they not get insurance through the private market? ',
Expand Down Expand Up @@ -159,6 +160,7 @@ export const XLSX = {
[NAME_ON_POLICY.POSITION]: 'Position at the company',
},
[NEED_PRE_CREDIT_PERIOD]: 'Is there a pre-credit period?',
[CREDIT_PERIOD_WITH_BUYER]: 'The period of pre-credit cover required',
NO_FINANCIAL_YEAR_END_DATE: 'No data from Companies House',
[OUTSTANDING_PAYMENTS]: 'Does the exporter currently have any outstanding or overdue payments from the buyer?',
[PHONE_NUMBER]: 'Exporter UK telephone number (optional)',
Expand Down
Loading

0 comments on commit 1bd056e

Please sign in to comment.