Skip to content

Commit

Permalink
fix(EMS-3466): no pdf - application submission - XLSX - your buyer se…
Browse files Browse the repository at this point in the history
…ction (#2554)

* fix(EMS-3466): no pdf - application submission - xlsx - buyer section

* fix(EMS-3466): improve unit test coverage

* fix(EMS-3466): fix/update documentation

* fix(EMS-3466): fix/update unit tests

* fix(EMS-3466): update todo comments

* fix(EMS-3466): linting issue
  • Loading branch information
ttbarnes authored Jun 11, 2024
1 parent 2a902fb commit 3750ce1
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 105 deletions.
43 changes: 22 additions & 21 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
Expand Up @@ -31,7 +31,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
TITLES: {
...indexes.TITLES,
BUYER: indexes.TITLES.BUYER + 1,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 7,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 5,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { XLSX_ROW_INDEXES } from '.';
import { INDEXES } from './INDEXES';
import { APPLICATION } from '../application';
import { mockApplicationMultiplePolicyTotalContractValueOverThreshold } from '../../test-mocks';

describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.MULTIPLE} - total contract value over threshold`, () => {
it('should return the correct row indexes', () => {
const result = XLSX_ROW_INDEXES(mockApplicationMultiplePolicyTotalContractValueOverThreshold);

const indexes = INDEXES();

const expected = {
...indexes,
BUYER_ADDRESS: indexes.BUYER_ADDRESS + 1,
BUYER_CONTACT_DETAILS: indexes.BUYER_CONTACT_DETAILS + 1,
TITLES: {
...indexes.TITLES,
BUYER: indexes.TITLES.BUYER + 1,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 3,
},
};

expect(result).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...indexes.TITLES,
POLICY: indexes.TITLES.POLICY + 3,
BUYER: indexes.TITLES.BUYER + 4,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 4,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 3,
},
};

Expand All @@ -63,7 +63,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...incremented.TITLES,
POLICY: incremented.TITLES.POLICY + 3,
BUYER: incremented.TITLES.BUYER + 4,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 4,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 3,
},
};

Expand Down Expand Up @@ -94,7 +94,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...incremented.TITLES,
POLICY: incremented.TITLES.POLICY + 3,
BUYER: incremented.TITLES.BUYER + 4,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 4,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 3,
},
};

Expand Down Expand Up @@ -122,7 +122,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...secondIncrement.TITLES,
POLICY: incremented.TITLES.POLICY + 3,
BUYER: incremented.TITLES.BUYER + 4,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 4,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 3,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...indexes.TITLES,
POLICY: indexes.TITLES.POLICY + 3,
BUYER: indexes.TITLES.BUYER + 5,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 11,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 8,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...indexes,
TITLES: {
...indexes.TITLES,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 6,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 4,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { XLSX_ROW_INDEXES } from '.';
import { INDEXES } from './INDEXES';
import { APPLICATION } from '../application';
import { mockApplicationSinglePolicyTotalContractValueOverThreshold } from '../../test-mocks';

describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TYPE.SINGLE} - total contract value over threshold`, () => {
it('should return the correct row indexes', () => {
const result = XLSX_ROW_INDEXES(mockApplicationSinglePolicyTotalContractValueOverThreshold);

const indexes = INDEXES();

const expected = {
...indexes,
TITLES: {
...indexes.TITLES,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 2,
},
};

expect(result).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...indexes.TITLES,
POLICY: indexes.TITLES.POLICY + 3,
BUYER: indexes.TITLES.BUYER + 3,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 3,
DECLARATIONS: indexes.TITLES.DECLARATIONS + 2,
},
};

Expand All @@ -61,7 +61,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...incremented.TITLES,
POLICY: incremented.TITLES.POLICY + 3,
BUYER: incremented.TITLES.BUYER + 3,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 3,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 2,
},
};

Expand Down Expand Up @@ -91,7 +91,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...incremented.TITLES,
POLICY: incremented.TITLES.POLICY + 3,
BUYER: incremented.TITLES.BUYER + 3,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 3,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 2,
},
};

Expand All @@ -118,7 +118,7 @@ describe(`api/constants/XLSX-CONFIG - XLSX_ROW_INDEXES - ${APPLICATION.POLICY_TY
...secondIncrement.TITLES,
POLICY: incremented.TITLES.POLICY + 3,
BUYER: incremented.TITLES.BUYER + 3,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 3,
DECLARATIONS: incremented.TITLES.DECLARATIONS + 2,
},
};

Expand Down
16 changes: 8 additions & 8 deletions src/api/constants/XLSX-CONFIG/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TOTAL_CONTRACT_VALUE } from '../total-contract-value';
import { INDEXES, incrementIndexes } from './INDEXES';
import { POLICY as POLICY_FIELD_IDS } from '../field-ids/insurance/policy';
import { isMultiplePolicyType } from '../../helpers/policy-type';
Expand Down Expand Up @@ -28,12 +29,12 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
broker,
buyer: {
buyerTradingHistory: { exporterHasTradedWithBuyer, outstandingPayments: buyerHasOutstandingPayments },
relationship: { exporterIsConnectedWithBuyer, exporterHasPreviousCreditInsuranceWithBuyer },
},
company: {
differentTradingAddress: { fullAddress: hasDifferentTradingAddress },
hasDifferentTradingName,
},
eligibility: { totalContractValue },
nominatedLossPayee: { isAppointed: nominatedLossPayeeAppointed },
} = application;

Expand All @@ -52,7 +53,7 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
if (broker[USING_BROKER]) {
indexes.TITLES.POLICY += 3;
indexes.TITLES.BUYER += 3;
indexes.TITLES.DECLARATIONS += 3;
indexes.TITLES.DECLARATIONS += 2;

indexes.BROKER_ADDRESS = 48;
indexes.BUYER_ADDRESS += 3;
Expand All @@ -72,10 +73,6 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
indexes.ALTERNATIVE_TRADING_ADDRESS = 38;
}

if (exporterIsConnectedWithBuyer) {
indexes.TITLES.DECLARATIONS += 1;
}

if (exporterHasTradedWithBuyer) {
indexes.TITLES.DECLARATIONS += 2;

Expand All @@ -84,8 +81,11 @@ export const XLSX_ROW_INDEXES = (application: Application): XLSXRowIndexes => {
}
}

if (exporterHasPreviousCreditInsuranceWithBuyer) {
indexes.TITLES.DECLARATIONS += 1;
// TODO: EMS-3467: move to getPopulatedApplication.
const totalContractValueOverThreshold = totalContractValue.value === TOTAL_CONTRACT_VALUE.MORE_THAN_250K.VALUE;

if (totalContractValueOverThreshold) {
indexes.TITLES.DECLARATIONS += 2;
}

if (nominatedLossPayeeAppointed) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mapBuyer from '.';
import { FIELD_VALUES } from '../../../constants';
import FIELD_IDS from '../../../constants/field-ids/insurance/your-buyer';
import { XLSX } from '../../../content-strings';
import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/your-buyer';
Expand All @@ -20,7 +19,6 @@ const {
COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE },
CONNECTION_WITH_BUYER,
HAS_BUYER_FINANCIAL_ACCOUNTS,
HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER,
TRADED_WITH_BUYER,
} = FIELD_IDS;

Expand All @@ -30,7 +28,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-buyer', () => {
it('should return an array of mapped buyer fields', () => {
const result = mapBuyer(mockApplication);

const { buyer } = mockApplication;
const { eligibility, buyer } = mockApplication;
const { buyerTradingHistory, relationship } = buyer;

const expected = [
Expand All @@ -47,15 +45,7 @@ describe('api/generate-xlsx/map-application-to-xlsx/map-buyer', () => {

...mapBuyerTradingHistory(buyerTradingHistory),

xlsxRow(
String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]),
mapYesNoField({
answer: relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER],
defaultValue: FIELD_VALUES.NO,
}),
),

mapPreviousCoverWithBuyer(relationship),
...mapPreviousCoverWithBuyer(eligibility, relationship),

xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField({ answer: relationship[HAS_BUYER_FINANCIAL_ACCOUNTS] })),
];
Expand Down
14 changes: 2 additions & 12 deletions src/api/generate-xlsx/map-application-to-XLSX/map-buyer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FIELD_VALUES } from '../../../constants';
import FIELD_IDS from '../../../constants/field-ids/insurance/your-buyer';
import { XLSX } from '../../../content-strings';
import { YOUR_BUYER_FIELDS } from '../../../content-strings/fields/insurance/your-buyer';
Expand All @@ -19,7 +18,6 @@ const {
COMPANY_OR_ORGANISATION: { NAME, ADDRESS, COUNTRY, REGISTRATION_NUMBER, WEBSITE },
CONNECTION_WITH_BUYER,
HAS_BUYER_FINANCIAL_ACCOUNTS,
HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER,
TRADED_WITH_BUYER,
} = FIELD_IDS;

Expand All @@ -32,7 +30,7 @@ const { SECTION_TITLES, FIELDS } = XLSX;
* @returns {Array<object>} Array of objects for XLSX generation
*/
const mapBuyer = (application: Application) => {
const { buyer } = application;
const { buyer, eligibility } = application;
const { buyerTradingHistory, relationship } = buyer;

const mapped = [
Expand All @@ -49,15 +47,7 @@ const mapBuyer = (application: Application) => {

...mapBuyerTradingHistory(buyerTradingHistory),

xlsxRow(
String(FIELDS[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER]),
mapYesNoField({
answer: relationship[HAS_PREVIOUS_CREDIT_INSURANCE_COVER_WITH_BUYER],
defaultValue: FIELD_VALUES.NO,
}),
),

mapPreviousCoverWithBuyer(relationship),
...mapPreviousCoverWithBuyer(eligibility, relationship),

xlsxRow(String(FIELDS[HAS_BUYER_FINANCIAL_ACCOUNTS]), mapYesNoField({ answer: relationship[HAS_BUYER_FINANCIAL_ACCOUNTS] })),
];
Expand Down
Loading

0 comments on commit 3750ce1

Please sign in to comment.