diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f964d5894b..70a95fdd38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -521,7 +521,6 @@ jobs: 'eligibility/cannot-apply/**/*.spec.js', 'eligibility/cannot-apply-multiple-risks/**/*.spec.js', 'eligibility/cannot-skip-flow/**/*.spec.js', - 'eligibility/contract-too-short/**/*.spec.js', 'eligibility/change-your-answers/**/*.spec.js', 'eligibility/check-your-answers/**/*.spec.js', 'eligibility/companies-house/**/*.spec.js', @@ -535,6 +534,7 @@ jobs: 'eligibility/member-of-a-group/**/*.spec.js', 'eligibility/no-companies-house-number/**/*.spec.js', 'eligibility/party-to-consortium/**/*.spec.js', + 'eligibility/talk-to-an-export-finance-manager/**/*.spec.js', 'eligibility/total-value-insured/**/*.spec.js', 'eligibility/uk-goods-or-services/**/*.spec.js', ] diff --git a/e2e-tests/commands/insurance/complete-about-goods-or-services-form.js b/e2e-tests/commands/insurance/complete-about-goods-or-services-form.js index d6a2faea93..5481398576 100644 --- a/e2e-tests/commands/insurance/complete-about-goods-or-services-form.js +++ b/e2e-tests/commands/insurance/complete-about-goods-or-services-form.js @@ -26,7 +26,7 @@ const completeAboutGoodsOrServicesForm = ({ cy.clickYesRadioInput(); if (includeFinalDestination) { - cy.keyboardInput(autoCompleteField(FINAL_DESTINATION).input(), COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME); + cy.keyboardInput(autoCompleteField(FINAL_DESTINATION).input(), COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME); } } else { cy.clickNoRadioInput(); diff --git a/e2e-tests/commands/shared-commands/eligibility/complete-and-submit-buyer-country-form.js b/e2e-tests/commands/shared-commands/eligibility/complete-and-submit-buyer-country-form.js index 27c8402e4b..13a9b44a9f 100644 --- a/e2e-tests/commands/shared-commands/eligibility/complete-and-submit-buyer-country-form.js +++ b/e2e-tests/commands/shared-commands/eligibility/complete-and-submit-buyer-country-form.js @@ -1,15 +1,16 @@ import { autoCompleteField } from '../../../pages/shared'; import { FIELD_IDS } from '../../../constants'; -import { DZA } from '../../../fixtures/countries'; +import { COUNTRY_QUOTE_SUPPORT } from '../../../fixtures/countries'; const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; +const { ONLINE_SUPPORT_1 } = COUNTRY_QUOTE_SUPPORT; /** * completeAndSubmitBuyerCountryForm * Complete and submit a buyer country form. - * @param {String} countryName to input - defaults to Algeria mock country + * @param {String} countryName to input - defaults to ONLINE_SUPPORT_1 mock country */ -export const completeAndSubmitBuyerCountryForm = ({ countryName = DZA.NAME }) => { +export const completeAndSubmitBuyerCountryForm = ({ countryName = ONLINE_SUPPORT_1.NAME }) => { cy.keyboardInput(autoCompleteField(FIELD_ID).input(), countryName); const results = autoCompleteField(FIELD_ID).results(); results.first().click(); diff --git a/e2e-tests/constants/api.js b/e2e-tests/constants/api.js index 2896a4f4da..4f45b2e43d 100644 --- a/e2e-tests/constants/api.js +++ b/e2e-tests/constants/api.js @@ -2,12 +2,12 @@ export const API = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard Risk', }, - SHORT_TERM_COVER_AVAILABLE: { + SHORT_TERM_COVER: { YES: 'Yes', ILC: 'ILC Only', CILC: 'CILC Only', diff --git a/e2e-tests/constants/external-apis.js b/e2e-tests/constants/external-apis.js index 70797251ec..84d8166d22 100644 --- a/e2e-tests/constants/external-apis.js +++ b/e2e-tests/constants/external-apis.js @@ -2,12 +2,13 @@ export const EXTERNAL_API_DEFINITIONS = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard Risk', + NONE: 'None', }, - SHORT_TERM_COVER_AVAILABLE: { + SHORT_TERM_COVER: { YES: 'Yes', NO: 'No', ILC: 'ILC Only', @@ -20,8 +21,22 @@ export const EXTERNAL_API_DEFINITIONS = { NO: 'N', }, NO_COVER: 'Off cover', - INVALID_COUNTRIES: ['EC Market n/k', 'Non EC Market n/k', 'Non UK', 'Third Country', 'Eastern and Southern African Trade and Development Bank'], + INVALID_COUNTRIES: [ + 'CABEI', + 'Cor Andino Fom', + 'Eastern and Southern African Trade and Development Bank', + 'EC Market n/k', + 'Non EC Market n/k', + 'Non UK', + 'Third Country', + ], INVALID_CURRENCIES: ['Gold'], + COUNTRY_RATINGS: { + A: ['AAA', 'AA+', 'AA', 'AA-', 'A+', 'A', 'A-'], + B: ['BBB+', 'BBB', 'BBB-', 'BB+', 'BB', 'BB-', 'B+', 'B', 'B-'], + C: ['CCC+', 'CCC', 'CCC-', 'CC', 'C'], + D: ['D'], + }, }, COMPANIES_HOUSE: { COMPANY_STATUS: { @@ -32,7 +47,7 @@ export const EXTERNAL_API_DEFINITIONS = { export const EXTERNAL_API_MAPPINGS = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard', diff --git a/e2e-tests/constants/routes/insurance/index.js b/e2e-tests/constants/routes/insurance/index.js index 95a915f5e0..3700cc1aa8 100644 --- a/e2e-tests/constants/routes/insurance/index.js +++ b/e2e-tests/constants/routes/insurance/index.js @@ -48,7 +48,7 @@ export const INSURANCE_ROUTES = { ELIGIBLE_TO_APPLY_ONLINE: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/eligible-to-apply-online`, HAVE_AN_ACCOUNT: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/do-you-have-an-account`, NEED_TO_START_AGAIN: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/need-to-start-again`, - CONTRACT_TOO_SHORT_EXIT: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/contract-too-short`, + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/contract-too-short`, PARTY_TO_CONSORTIUM: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/party-to-any-consortium`, PARTY_TO_CONSORTIUM_CHANGE: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/party-to-any-consortium/change`, MEMBER_OF_A_GROUP: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/member-of-a-group`, diff --git a/e2e-tests/content-strings/pages/insurance/eligibility/index.js b/e2e-tests/content-strings/pages/insurance/eligibility/index.js index d87c80905d..ea58918a0f 100644 --- a/e2e-tests/content-strings/pages/insurance/eligibility/index.js +++ b/e2e-tests/content-strings/pages/insurance/eligibility/index.js @@ -168,7 +168,7 @@ export const HAVE_AN_ACCOUNT = { PAGE_TITLE: 'Do you have an account with us?', }; -export const CONTRACT_TOO_SHORT_EXIT = { +export const TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT = { PAGE_TITLE: 'Talk to an export finance manager', INTRO: "We do not normally offer short term cover for the country you've selected.", CONTACT_EFM: { diff --git a/e2e-tests/fixtures/application.js b/e2e-tests/fixtures/application.js index e630acb1a5..7150f6562b 100644 --- a/e2e-tests/fixtures/application.js +++ b/e2e-tests/fixtures/application.js @@ -101,7 +101,7 @@ export const endDate = new Date(date.setMonth(date.getMonth() + 6)); // Add 6 mo const application = { ELIGIBILITY: { - buyerCountryIsoCode: COUNTRY_APPLICATION_SUPPORT.ONLINE.ISO_CODE, + buyerCountryIsoCode: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.ISO_CODE, [COVER_PERIOD_ID]: COVER_PERIOD_CONSTANTS.LESS_THAN_2_YEARS.DB_ID, [HAS_COMPANIES_HOUSE_NUMBER]: true, [HAS_END_BUYER]: false, @@ -111,7 +111,7 @@ const application = { [IS_PARTY_TO_CONSORTIUM]: false, [IS_MEMBER_OF_A_GROUP]: false, }, - [BUYER_COUNTRY]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME, + [BUYER_COUNTRY]: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME, COMPANY: mockCompanies[COMPANIES_HOUSE_NUMBER], YOUR_COMPANY: { [DIFFERENT_TRADING_NAME]: 'Mock different trading name', @@ -149,14 +149,14 @@ const application = { }, REQUESTED_JOINTLY_INSURED_PARTY: { [COMPANY_NAME]: 'Mock jointly insured company name', - [COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME, + [COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME, [COMPANY_NUMBER]: 'Mock jointly insured company number', }, EXPORT_CONTRACT: { [AWARD_METHOD]: EXPORT_CONTRACT_AWARD_METHOD.OTHER.DB_ID, [OTHER_AWARD_METHOD]: 'Mock other award method description', [DESCRIPTION]: 'Mock description', - [FINAL_DESTINATION]: COUNTRY_APPLICATION_SUPPORT.ONLINE.ISO_CODE, + [FINAL_DESTINATION]: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.ISO_CODE, HOW_WILL_YOU_GET_PAID: { [PAYMENT_TERMS_DESCRIPTION]: mockAddress0, }, @@ -166,7 +166,7 @@ const application = { }, AGENT_DETAILS: { [AGENT_NAME]: "Mock export contract agent name O'Neill", - [AGENT_COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME, + [AGENT_COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME, [AGENT_FULL_ADDRESS]: mockAddress0, }, AGENT_SERVICE: { @@ -178,7 +178,7 @@ const application = { [FIXED_SUM_AMOUNT]: '1500', [FIXED_SUM_CURRENCY_CODE]: GBP_CURRENCY_CODE, [METHOD]: AGENT_SERVICE_CHARGE.METHOD.FIXED_SUM, - [PAYABLE_COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME, + [PAYABLE_COUNTRY_CODE]: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME, }, }, EXPORTER_BUSINESS: { @@ -199,7 +199,7 @@ const application = { BUYER: { [COMPANY_OR_ORGANISATION_NAME]: 'Test name', [ADDRESS]: 'Test address', - [COUNTRY]: COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME, + [COUNTRY]: COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME, [REGISTRATION_NUMBER]: '12345', [WEBSITE]: WEBSITE_EXAMPLES.VALID, [CONNECTION_WITH_BUYER]: FIELD_VALUES.NO, @@ -223,6 +223,6 @@ const application = { }, }; -export const country = COUNTRY_APPLICATION_SUPPORT.ONLINE; +export const country = COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1; export default application; diff --git a/e2e-tests/fixtures/countries.js b/e2e-tests/fixtures/countries.js index 4f471d53c7..83358a500a 100644 --- a/e2e-tests/fixtures/countries.js +++ b/e2e-tests/fixtures/countries.js @@ -1,6 +1,16 @@ -export const XAD = { - NAME: 'Abu Dhabi', - ISO_CODE: 'XAD', +export const AGO = { + NAME: 'Angola', + ISO_CODE: 'AGO', +}; + +export const ARG = { + NAME: 'Argentina', + ISO_CODE: 'AGO', +}; + +export const BRA = { + NAME: 'Brazil', + ISO_CODE: 'BRA', }; export const DZA = { @@ -8,9 +18,9 @@ export const DZA = { ISO_CODE: 'DZA', }; -export const AGO = { - NAME: 'Angola', - ISO_CODE: 'AGO', +export const ERI = { + NAME: 'Eritrea', + ISO_CODE: 'ERI', }; export const FRA = { @@ -18,79 +28,69 @@ export const FRA = { ISO_CODE: 'FRA', }; -export const BRA = { - NAME: 'Brazil', - ISO_CODE: 'BRA', +export const GBR = { + NAME: 'United Kingdom', + ISO_CODE: 'GBR', }; -export const AFG = { - NAME: 'Afghanistan', - ISO_CODE: 'AFG', +export const IOT = { + NAME: 'British Indian Ocean Territory', + ISO_CODE: 'IOT', }; -export const AUS = { - NAME: 'Australia', - ISO_CODE: 'AUS', +export const NCL = { + NAME: 'New Caledonia', + ISO_CODE: 'NCL', }; -export const BLR = { - NAME: 'Belarus', - ISO_CODE: 'BLR', +export const TN = { + NAME: 'Tunisia', + ISO_CODE: 'TN', }; -export const RUS = { - NAME: 'Russia', - ISO_CODE: 'RUS', +export const XAD = { + NAME: 'Abu Dhabi', + ISO_CODE: 'XAD', }; -export const MMR = { - NAME: 'Burma', - ISO_CODE: 'MMR', -}; +const mockCountries = [DZA, FRA, AGO, GBR, XAD, BRA]; -export const GBR = { - NAME: 'United Kingdom', - ISO_CODE: 'GBR', -}; +const ONLINE_SUPPORT_1 = DZA; + +const NO_ONLINE_SUPPORT_1 = FRA; +const NO_ONLINE_SUPPORT_2 = AGO; +const NO_ONLINE_SUPPORT_3 = ARG; +const NO_ONLINE_SUPPORT_4 = TN; -const mockCountries = [XAD, AFG, DZA, AGO, AUS, BLR, BRA, MMR, FRA, RUS, GBR]; +const NOT_SUPPORTED_1 = GBR; +const NOT_SUPPORTED_2 = ERI; +const NOT_SUPPORTED_3 = IOT; +const NOT_SUPPORTED_4 = NCL; /** * COUNTRY_QUOTE_SUPPORT * Different types of country support for a quote. */ -const { 2: QUOTE_ONLINE, 3: QUOTE_BY_EMAIL, 8: QUOTE_UNSUPPORTED } = mockCountries; - export const COUNTRY_QUOTE_SUPPORT = { - ONLINE: QUOTE_ONLINE, - BY_EMAIL: QUOTE_BY_EMAIL, - UNSUPPORTED: QUOTE_UNSUPPORTED, + ONLINE_SUPPORT_1, + NO_ONLINE_SUPPORT_1, + NOT_SUPPORTED_1, }; /** * COUNTRY_APPLICATION_SUPPORT * Different types of country support for an application */ -const { - 2: APPLICATION_ONLINE, - 3: APPLICATION_BY_EMAIL, - 8: APPLICATION_NO_SHORT_TERM_COVER_1, - 4: APPLICATION_NO_SHORT_TERM_COVER_2, - 1: APPLICATION_UNSUPPORTED_1, - 5: APPLICATION_UNSUPPORTED_2, - 7: APPLICATION_UNSUPPORTED_3, - 9: APPLICATION_UNSUPPORTED_4, -} = mockCountries; - export const COUNTRY_APPLICATION_SUPPORT = { - ONLINE: APPLICATION_ONLINE, - BY_EMAIL: APPLICATION_BY_EMAIL, - UNSUPPORTED_1: APPLICATION_UNSUPPORTED_1, - UNSUPPORTED_2: APPLICATION_UNSUPPORTED_2, - UNSUPPORTED_3: APPLICATION_UNSUPPORTED_3, - UNSUPPORTED_4: APPLICATION_UNSUPPORTED_4, - NO_SHORT_TERM_COVER_1: APPLICATION_NO_SHORT_TERM_COVER_1, - NO_SHORT_TERM_COVER_2: APPLICATION_NO_SHORT_TERM_COVER_2, + ONLINE_SUPPORT_1, + NO_ONLINE_SUPPORT_1, + NO_ONLINE_SUPPORT_2, + NO_ONLINE_SUPPORT_3, + NO_ONLINE_SUPPORT_4, + NOT_SUPPORTED_1, + NOT_SUPPORTED_2, + NOT_SUPPORTED_3, + NOT_SUPPORTED_4, }; export default mockCountries; diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-no-online-support.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-no-online-support.spec.js new file mode 100644 index 0000000000..a4c024ed52 --- /dev/null +++ b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-no-online-support.spec.js @@ -0,0 +1,46 @@ +import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; +import { COUNTRY_APPLICATION_SUPPORT } from '../../../../../../fixtures/countries'; + +const { + ELIGIBILITY: { TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT }, +} = INSURANCE_ROUTES; + +const COUNTRY_NAME_1 = COUNTRY_APPLICATION_SUPPORT.NO_ONLINE_SUPPORT_1.NAME; +const COUNTRY_NAME_2 = COUNTRY_APPLICATION_SUPPORT.NO_ONLINE_SUPPORT_2.NAME; +const COUNTRY_NAME_3 = COUNTRY_APPLICATION_SUPPORT.NO_ONLINE_SUPPORT_3.NAME; +const COUNTRY_NAME_4 = COUNTRY_APPLICATION_SUPPORT.NO_ONLINE_SUPPORT_4.NAME; + +context( + 'Insurance - Buyer country page - As an exporter, I want to check if UKEF offer credit insurance policy for where my buyer is based - submit countries that have no online insurance support', + () => { + beforeEach(() => { + cy.saveSession(); + + cy.completeAndSubmitEligibilityForms({ stopSubmittingAfter: 'companyDetails' }); + }); + + describe(COUNTRY_NAME_1, () => { + it(`should redirect to ${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT} exit page`, () => { + cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_1, TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); + }); + }); + + describe(COUNTRY_NAME_2, () => { + it(`should redirect to ${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT} exit page`, () => { + cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_2, TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); + }); + }); + + describe(COUNTRY_NAME_3, () => { + it(`should redirect to ${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT} exit page`, () => { + cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_3, TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); + }); + }); + + describe(COUNTRY_NAME_4, () => { + it(`should redirect to ${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT} exit page`, () => { + cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_4, TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); + }); + }); + }, +); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-no-short-term-cover.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-no-short-term-cover.spec.js deleted file mode 100644 index 1c8c31169e..0000000000 --- a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-no-short-term-cover.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; -import { COUNTRY_APPLICATION_SUPPORT } from '../../../../../../fixtures/countries'; - -const { - ELIGIBILITY: { CONTRACT_TOO_SHORT_EXIT }, -} = INSURANCE_ROUTES; - -const COUNTRY_NAME_1 = COUNTRY_APPLICATION_SUPPORT.NO_SHORT_TERM_COVER_1.NAME; -const COUNTRY_NAME_2 = COUNTRY_APPLICATION_SUPPORT.NO_SHORT_TERM_COVER_2.NAME; - -context( - 'Insurance - Buyer country page - As an exporter, I want to check if UKEF offer credit insurance policy for where my buyer is based - submit no short term country cover', - () => { - beforeEach(() => { - cy.saveSession(); - - cy.completeAndSubmitEligibilityForms({ stopSubmittingAfter: 'companyDetails' }); - }); - - describe(COUNTRY_NAME_1, () => { - it(`redirects to ${CONTRACT_TOO_SHORT_EXIT} exit page`, () => { - cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_1, CONTRACT_TOO_SHORT_EXIT); - }); - }); - - describe(COUNTRY_NAME_2, () => { - it(`redirects to ${CONTRACT_TOO_SHORT_EXIT} exit page`, () => { - cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_2, CONTRACT_TOO_SHORT_EXIT); - }); - }); - }, -); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-unsupported-countries.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-unsupported-countries.spec.js index 9974e85429..964c12f200 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-unsupported-countries.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country-unsupported-countries.spec.js @@ -5,13 +5,13 @@ const { ELIGIBILITY: { CANNOT_APPLY_EXIT }, } = INSURANCE_ROUTES; -const COUNTRY_NAME_1 = COUNTRY_APPLICATION_SUPPORT.UNSUPPORTED_1.NAME; -const COUNTRY_NAME_2 = COUNTRY_APPLICATION_SUPPORT.UNSUPPORTED_2.NAME; -const COUNTRY_NAME_3 = COUNTRY_APPLICATION_SUPPORT.UNSUPPORTED_3.NAME; -const COUNTRY_NAME_4 = COUNTRY_APPLICATION_SUPPORT.UNSUPPORTED_4.NAME; +const COUNTRY_NAME_1 = COUNTRY_APPLICATION_SUPPORT.NOT_SUPPORTED_1.NAME; +const COUNTRY_NAME_2 = COUNTRY_APPLICATION_SUPPORT.NOT_SUPPORTED_2.NAME; +const COUNTRY_NAME_3 = COUNTRY_APPLICATION_SUPPORT.NOT_SUPPORTED_3.NAME; +const COUNTRY_NAME_4 = COUNTRY_APPLICATION_SUPPORT.NOT_SUPPORTED_4.NAME; const contextString = - 'As an exporter I want to enter the country where my buyer is based So that I can ascertain if I can obtain UKEF Credit Insurance for the country where my buyer is based'; + 'As an exporter I want to enter the country where my buyer is based So that I can ascertain if I can obtain UKEF Credit Insurance for the country where my buyer is based - submit countries that cannot apply'; context(`Insurance - Buyer country page - ${contextString} - Unsupported countries`, () => { beforeEach(() => { @@ -21,25 +21,25 @@ context(`Insurance - Buyer country page - ${contextString} - Unsupported countri }); describe(COUNTRY_NAME_1, () => { - it(`redirects to ${CANNOT_APPLY_EXIT} exit page`, () => { + it(`should redirect to ${CANNOT_APPLY_EXIT} exit page`, () => { cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_1, CANNOT_APPLY_EXIT); }); }); describe(COUNTRY_NAME_2, () => { - it(`redirects to ${CANNOT_APPLY_EXIT} exit page`, () => { + it(`should redirect to ${CANNOT_APPLY_EXIT} exit page`, () => { cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_2, CANNOT_APPLY_EXIT); }); }); describe(COUNTRY_NAME_3, () => { - it(`redirects to ${CANNOT_APPLY_EXIT} exit page`, () => { + it(`should redirect to ${CANNOT_APPLY_EXIT} exit page`, () => { cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_3, CANNOT_APPLY_EXIT); }); }); describe(COUNTRY_NAME_4, () => { - it(`redirects to ${CANNOT_APPLY_EXIT} exit page`, () => { + it(`should redirect to ${CANNOT_APPLY_EXIT} exit page`, () => { cy.enterCountryAndAssertExitPageUrlBuyerCountry(COUNTRY_NAME_4, CANNOT_APPLY_EXIT); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country.spec.js index 1d3a134cd9..b5080c72b3 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/buyer-country/buyer-country.spec.js @@ -13,7 +13,7 @@ const { const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; -const COUNTRY_NAME = COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME; +const COUNTRY_NAME = COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME; const baseUrl = Cypress.config('baseUrl'); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply-page.spec.js index ff143ee64f..b4e0e09da4 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply-page.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply-page.spec.js @@ -12,7 +12,7 @@ const { const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; -const COUNTRY_NAME_UNSUPPORTED = COUNTRY_APPLICATION_SUPPORT.UNSUPPORTED_1.NAME; +const COUNTRY_NAME_UNSUPPORTED = COUNTRY_APPLICATION_SUPPORT.NOT_SUPPORTED_1.NAME; const baseUrl = Cypress.config('baseUrl'); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply/cannot-apply-page.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply/cannot-apply-page.spec.js index 7344d8a363..dd3cca87b7 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply/cannot-apply-page.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/cannot-apply/cannot-apply-page.spec.js @@ -13,7 +13,7 @@ const { const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; -const COUNTRY_NAME = COUNTRY_APPLICATION_SUPPORT.UNSUPPORTED_1.NAME; +const COUNTRY_NAME = COUNTRY_APPLICATION_SUPPORT.NOT_SUPPORTED_1.NAME; const baseUrl = Cypress.config('baseUrl'); @@ -35,7 +35,7 @@ context( cy.clickSubmitButton(); }); - it('redirects to `cannot apply` exit page', () => { + it(`redirects to ${CANNOT_APPLY_EXIT} exit page`, () => { const expectedUrl = `${baseUrl}${CANNOT_APPLY_EXIT}`; cy.assertUrl(expectedUrl); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/contract-too-short/contract-too-short.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/talk-to-an-export-finance-manager/talk-to-an-export-finance-manager.spec.js similarity index 75% rename from e2e-tests/insurance/cypress/e2e/journeys/eligibility/contract-too-short/contract-too-short.spec.js rename to e2e-tests/insurance/cypress/e2e/journeys/eligibility/talk-to-an-export-finance-manager/talk-to-an-export-finance-manager.spec.js index 735116f20b..6337e043db 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/eligibility/contract-too-short/contract-too-short.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/eligibility/talk-to-an-export-finance-manager/talk-to-an-export-finance-manager.spec.js @@ -2,18 +2,18 @@ import { actions } from '../../../../../../pages/shared'; import { PAGES } from '../../../../../../content-strings'; import { INSURANCE_ROUTES } from '../../../../../../constants/routes/insurance'; -const CONTENT_STRINGS = PAGES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT; +const CONTENT_STRINGS = PAGES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT; const { CONTACT_EFM } = CONTENT_STRINGS; const { - ELIGIBILITY: { CONTRACT_TOO_SHORT_EXIT }, + ELIGIBILITY: { TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT }, } = INSURANCE_ROUTES; const baseUrl = Cypress.config('baseUrl'); -context('Insurance - Eligibility - Contract too short page', () => { - const url = `${baseUrl}${CONTRACT_TOO_SHORT_EXIT}`; +context('Insurance - Eligibility - Talk to an export finance manager page', () => { + const url = `${baseUrl}${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT}`; before(() => { cy.navigateToUrl(url); @@ -28,8 +28,8 @@ context('Insurance - Eligibility - Contract too short page', () => { it('renders core page elements', () => { cy.corePageChecks({ pageTitle: CONTENT_STRINGS.PAGE_TITLE, - backLink: `${CONTRACT_TOO_SHORT_EXIT}#`, - currentHref: CONTRACT_TOO_SHORT_EXIT, + backLink: `${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT}#`, + currentHref: TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, assertAuthenticatedHeader: false, assertSaveAndBackButtonDoesNotExist: true, hasAForm: false, diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/about-goods-or-services.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/about-goods-or-services.spec.js index ed18eb857a..6a288092a8 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/about-goods-or-services.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/about-goods-or-services.spec.js @@ -135,7 +135,10 @@ context( cy.clickYesRadioInput(); }); - assertCountryAutocompleteInput({ fieldId }); + assertCountryAutocompleteInput({ + fieldId, + assertFilteredCisCountries: false, + }); }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/validation/about-goods-or-services-validation.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/validation/about-goods-or-services-validation.spec.js index ad31782676..1670e91a21 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/validation/about-goods-or-services-validation.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/about-goods-or-services/validation/about-goods-or-services-validation.spec.js @@ -131,7 +131,7 @@ context('Insurance - Export contract - About goods or services page - form valid cy.assertYesRadioOptionIsChecked(); - cy.checkText(autoCompleteField(FINAL_DESTINATION).results(), COUNTRY_APPLICATION_SUPPORT.ONLINE.NAME); + cy.checkText(autoCompleteField(FINAL_DESTINATION).results(), COUNTRY_APPLICATION_SUPPORT.ONLINE_SUPPORT_1.NAME); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges.spec.js index 99bfad98d2..f59d989986 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-charges/agent-charges.spec.js @@ -104,7 +104,10 @@ context( }); describe(`searchable autocomplete input (${PAYABLE_COUNTRY_CODE})`, () => { - assertCountryAutocompleteInput({ fieldId: PAYABLE_COUNTRY_CODE }); + assertCountryAutocompleteInput({ + fieldId: PAYABLE_COUNTRY_CODE, + assertFilteredCisCountries: false, + }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-details/agent-details.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-details/agent-details.spec.js index 5200479c1f..487d01914e 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-details/agent-details.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/export-contract/agent-details/agent-details.spec.js @@ -86,7 +86,10 @@ context( }); describe(`searchable autocomplete input (${COUNTRY_CODE})`, () => { - assertCountryAutocompleteInput({ fieldId: COUNTRY_CODE }); + assertCountryAutocompleteInput({ + fieldId: COUNTRY_CODE, + assertFilteredCisCountries: false, + }); }); }); diff --git a/e2e-tests/insurance/cypress/e2e/journeys/policy/other-company-details/other-company-details.spec.js b/e2e-tests/insurance/cypress/e2e/journeys/policy/other-company-details/other-company-details.spec.js index f378f6207e..85dc33ac78 100644 --- a/e2e-tests/insurance/cypress/e2e/journeys/policy/other-company-details/other-company-details.spec.js +++ b/e2e-tests/insurance/cypress/e2e/journeys/policy/other-company-details/other-company-details.spec.js @@ -77,7 +77,10 @@ context(`Insurance - Policy - Other company details page - ${story}`, () => { }); describe(`searchable autocomplete input (${COUNTRY_CODE})`, () => { - assertCountryAutocompleteInput({ fieldId: COUNTRY_CODE }); + assertCountryAutocompleteInput({ + fieldId: COUNTRY_CODE, + assertFilteredCisCountries: false, + }); }); it(`renders ${COMPANY_NUMBER} label and input`, () => { diff --git a/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-country-only-get-a-quote-by-email.spec.js b/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-country-only-get-a-quote-offline.spec.js similarity index 85% rename from e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-country-only-get-a-quote-by-email.spec.js rename to e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-country-only-get-a-quote-offline.spec.js index 696cb0394d..961d219d97 100644 --- a/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-country-only-get-a-quote-by-email.spec.js +++ b/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-country-only-get-a-quote-offline.spec.js @@ -9,12 +9,12 @@ const { const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; -const NEW_COUNTRY_INPUT = COUNTRY_QUOTE_SUPPORT.BY_EMAIL.NAME; +const COUNTRY_NAME = COUNTRY_QUOTE_SUPPORT.NO_ONLINE_SUPPORT_1.NAME; const baseUrl = Cypress.config('baseUrl'); context( - 'Buyer country page - as an exporter, I want to check if UKEF issue credit insurance cover for where my buyer is based - submit country that can only get a quote offline/via email', + 'Buyer country page - as an exporter, I want to check if UKEF issue credit insurance cover for where my buyer is based - submit country that can only get a quote offline', () => { const url = `${baseUrl}${BUYER_COUNTRY}`; @@ -22,7 +22,7 @@ context( cy.navigateToUrl(url); cy.assertUrl(url); - cy.keyboardInput(autoCompleteField(FIELD_ID).input(), NEW_COUNTRY_INPUT); + cy.keyboardInput(autoCompleteField(FIELD_ID).input(), COUNTRY_NAME); const results = autoCompleteField(FIELD_ID).results(); results.first().click(); @@ -43,7 +43,7 @@ context( it('should prepopulate the field when going back to the page via back link', () => { cy.clickBackLink(); - const expectedValue = NEW_COUNTRY_INPUT; + const expectedValue = COUNTRY_NAME; cy.checkTextAndValue({ textSelector: autoCompleteField(FIELD_ID).results(), diff --git a/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-unsupported-country.spec.js b/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-unsupported-country.spec.js index e355a54aee..461c8b93b1 100644 --- a/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-unsupported-country.spec.js +++ b/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country-unsupported-country.spec.js @@ -11,12 +11,12 @@ const { const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; -const NEW_COUNTRY_INPUT = COUNTRY_QUOTE_SUPPORT.UNSUPPORTED.NAME; +const COUNTRY_NAME = COUNTRY_QUOTE_SUPPORT.NOT_SUPPORTED_1.NAME; const baseUrl = Cypress.config('baseUrl'); context( - 'Buyer country page - as an exporter, I want to check if UKEF issue credit insurance cover for where my buyer is based - submit unsupported country', + 'Buyer country page - as an exporter, I want to check if UKEF issue credit insurance cover for where my buyer is based - submit a country that cannot get a quote', () => { const url = `${baseUrl}${BUYER_COUNTRY}`; @@ -30,7 +30,7 @@ context( cy.navigateToUrl(url); - cy.keyboardInput(autoCompleteField(FIELD_ID).input(), NEW_COUNTRY_INPUT); + cy.keyboardInput(autoCompleteField(FIELD_ID).input(), COUNTRY_NAME); const results = autoCompleteField(FIELD_ID).results(); results.first().click(); @@ -38,26 +38,26 @@ context( cy.clickSubmitButton(); }); - it('redirects to `cannot obtain cover` exit page', () => { + it(`should redirect to ${CANNOT_APPLY_EXIT} exit page`, () => { const expectedUrl = `${baseUrl}${CANNOT_APPLY_EXIT}`; cy.assertUrl(expectedUrl); }); - it('renders a back link with correct url', () => { + it('should render a back link with correct url', () => { cy.checkLink(backLink(), BUYER_COUNTRY, LINKS.BACK); }); - it('renders a specific reason', () => { + it('should render a specific reason', () => { const { REASON } = CONTENT_STRINGS; - const expected = `${REASON.INTRO} ${REASON.UNSUPPORTED_BUYER_COUNTRY_1} ${NEW_COUNTRY_INPUT}, ${REASON.UNSUPPORTED_BUYER_COUNTRY_2}`; + const expected = `${REASON.INTRO} ${REASON.UNSUPPORTED_BUYER_COUNTRY_1} ${COUNTRY_NAME}, ${REASON.UNSUPPORTED_BUYER_COUNTRY_2}`; cy.checkText(cannotApplyPage.reason(), expected); }); it('should prepopulate the field when going back to the page via back link', () => { cy.clickBackLink(); - const expectedValue = NEW_COUNTRY_INPUT; + const expectedValue = COUNTRY_NAME; cy.checkTextAndValue({ textSelector: autoCompleteField(FIELD_ID).results(), diff --git a/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country.spec.js b/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country.spec.js index 231084496d..f9781bca7a 100644 --- a/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country.spec.js +++ b/e2e-tests/quote/cypress/e2e/journeys/quote/buyer-country/buyer-country.spec.js @@ -12,7 +12,7 @@ const { QUOTE: { BUYER_COUNTRY, BUYER_BODY }, } = ROUTES; -const supportedCountryName = COUNTRY_QUOTE_SUPPORT.ONLINE.NAME; +const supportedCountryName = COUNTRY_QUOTE_SUPPORT.ONLINE_SUPPORT_1.NAME; const baseUrl = Cypress.config('baseUrl'); @@ -68,7 +68,7 @@ context('Buyer country page - as an exporter, I want to check if UKEF issue cred }); }); - describe('when submitting with a supported country', () => { + describe('when submitting with a country that can get a quote online', () => { const field = autoCompleteField(FIELD_ID); beforeEach(() => { diff --git a/e2e-tests/quote/cypress/e2e/journeys/quote/get-a-quote-via-email.spec.js b/e2e-tests/quote/cypress/e2e/journeys/quote/get-a-quote-via-email.spec.js index 8170f63a7e..7bc0773c6d 100644 --- a/e2e-tests/quote/cypress/e2e/journeys/quote/get-a-quote-via-email.spec.js +++ b/e2e-tests/quote/cypress/e2e/journeys/quote/get-a-quote-via-email.spec.js @@ -2,12 +2,13 @@ import { autoCompleteField } from '../../../../../pages/shared'; import { getAQuoteByEmailPage } from '../../../../../pages/quote'; import { PAGES } from '../../../../../content-strings'; import { ROUTES, FIELD_IDS } from '../../../../../constants'; +import { COUNTRY_QUOTE_SUPPORT } from '../../../../../fixtures/countries'; const CONTENT_STRINGS = PAGES.QUOTE.GET_A_QUOTE_BY_EMAIL; const FIELD_ID = FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY; -const COUNTRY_NAME_QUOTE_BY_EMAIL_ONLY = 'Egypt'; +const COUNTRY_NAME_QUOTE_BY_EMAIL_ONLY = COUNTRY_QUOTE_SUPPORT.NO_ONLINE_SUPPORT_1.NAME; const baseUrl = Cypress.config('baseUrl'); diff --git a/e2e-tests/shared-test-assertions/country-autocomplete-input/index.js b/e2e-tests/shared-test-assertions/country-autocomplete-input/index.js index ea87c44a2c..d4b3ec9052 100644 --- a/e2e-tests/shared-test-assertions/country-autocomplete-input/index.js +++ b/e2e-tests/shared-test-assertions/country-autocomplete-input/index.js @@ -9,8 +9,9 @@ const { NAME: ALGERIA } = DZA; * assertCountryAutocompleteInput * Assert a country autocomplete field * @param {String} fieldId: Country field ID + * @param {Boolean} assertFilteredCisCountries: Whether to check for filtered CIS countries. */ -export const assertCountryAutocompleteInput = ({ fieldId }) => { +export const assertCountryAutocompleteInput = ({ fieldId, assertFilteredCisCountries }) => { const field = autoCompleteField(fieldId); it('has working client side JS', () => { @@ -25,9 +26,11 @@ export const assertCountryAutocompleteInput = ({ fieldId }) => { assertions.rendersNoResultsMessage(field, 'test'); }); - it('renders `no results` message for invalid/filtered out CIS countries', () => { - assertions.doesNotRenderFilteredCisCountries(field); - }); + if (assertFilteredCisCountries) { + it('renders `no results` message for invalid/filtered out CIS countries', () => { + assertions.doesNotRenderFilteredCisCountries(field); + }); + } it('renders a single country result after searching', () => { assertions.rendersSingleResult(field, 'Alg'); diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 456a719fb0..83a6bbed38 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -826,12 +826,13 @@ var EXPORT_CONTRACT_AWARD_METHOD = { // constants/external-apis.ts var EXTERNAL_API_DEFINITIONS = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard Risk', + NONE: 'None', }, - SHORT_TERM_COVER_AVAILABLE: { + SHORT_TERM_COVER: { YES: 'Yes', NO: 'No', ILC: 'ILC Only', @@ -854,6 +855,13 @@ var EXTERNAL_API_DEFINITIONS = { 'Third Country', ], INVALID_CURRENCIES: ['Gold'], + COUNTRY_RATINGS: { + A: ['AAA', 'AA+', 'AA', 'AA-', 'A+', 'A', 'A-'], + B: ['BBB+', 'BBB', 'BBB-', 'BB+', 'BB', 'BB-', 'B+', 'B', 'B-'], + C: ['CCC+', 'CCC', 'CCC-', 'CC', 'C'], + D: ['D'], + NOT_APPLICABLE: 'N/A', + }, }, COMPANIES_HOUSE: { COMPANY_STATUS: { @@ -863,7 +871,7 @@ var EXTERNAL_API_DEFINITIONS = { }; var EXTERNAL_API_MAPPINGS = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard', @@ -3030,13 +3038,10 @@ var typeDefs = ` name: String shortTermCover: Boolean esraClassification: String - nbiIssueAvailable: Boolean canGetAQuoteOnline: Boolean - canGetAQuoteOffline: Boolean - canGetAQuoteByEmail: Boolean cannotGetAQuote: Boolean - cannotApply: Boolean canApplyForInsuranceOnline: Boolean + noOnlineSupport: Boolean noInsuranceSupport: Boolean } @@ -9152,127 +9157,248 @@ var filterCisEntries = (arr, invalidEntries, entityPropertyName) => { var filter_cis_entries_default = filterCisEntries; // helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.ts -var { CIS } = EXTERNAL_API_DEFINITIONS; +var { + CIS: { ESRA_CLASSIFICATION }, +} = EXTERNAL_API_DEFINITIONS; var mapEsraClassification = (str) => { - if (str === CIS.RISK.STANDARD) { - return EXTERNAL_API_MAPPINGS.CIS.RISK.STANDARD; + if (str === ESRA_CLASSIFICATION.STANDARD) { + return EXTERNAL_API_MAPPINGS.CIS.ESRA_CLASSIFICATION.STANDARD; } - if (str === CIS.RISK.HIGH) { + if (str === ESRA_CLASSIFICATION.HIGH) { return str; } - if (str === CIS.RISK.VERY_HIGH) { + if (str === ESRA_CLASSIFICATION.VERY_HIGH) { return str; } return null; }; var map_esra_classification_default = mapEsraClassification; -// helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.ts -var { CIS: CIS2 } = EXTERNAL_API_DEFINITIONS; -var mapNbiIssueAvailable = (str) => { - if (str === CIS2.NBI_ISSUE_AVAILABLE.YES) { +// helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.ts +var { + CIS: { COUNTRY_RATINGS }, +} = EXTERNAL_API_DEFINITIONS; +var countryRatingIsAorB = (rating) => { + if (COUNTRY_RATINGS.A.includes(rating)) { + return true; + } + if (COUNTRY_RATINGS.B.includes(rating)) { return true; } return false; }; -var map_NBI_issue_available_default = mapNbiIssueAvailable; +var country_rating_is_a_or_b_default = countryRatingIsAorB; -// helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.ts +// helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.ts var { - CIS: { SHORT_TERM_COVER_AVAILABLE }, + CIS: { COUNTRY_RATINGS: COUNTRY_RATINGS2 }, } = EXTERNAL_API_DEFINITIONS; -var mapShortTermCoverAvailable = (str) => { - switch (str) { - case SHORT_TERM_COVER_AVAILABLE.YES: - return true; - case SHORT_TERM_COVER_AVAILABLE.ILC: +var countryRatingIsCorD = (rating) => { + if (COUNTRY_RATINGS2.C.includes(rating)) { + return true; + } + if (COUNTRY_RATINGS2.D.includes(rating)) { + return true; + } + return false; +}; +var country_rating_is_c_or_d_default = countryRatingIsCorD; + +// helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.ts +var { + CIS: { + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + }, +} = EXTERNAL_API_DEFINITIONS; +var esraClassificationIsStandardHighOrVeryHigh = (esraClassification) => { + switch (esraClassification) { + case STANDARD: return true; - case SHORT_TERM_COVER_AVAILABLE.CILC: + case HIGH: return true; - case SHORT_TERM_COVER_AVAILABLE.REFER: + case VERY_HIGH: return true; default: return false; } }; -var map_short_term_cover_available_default = mapShortTermCoverAvailable; +var esra_classification_is_standard_high_or_very_high_default = esraClassificationIsStandardHighOrVeryHigh; -// helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.ts -var canGetAQuoteOnline = ({ shortTermCover, nbiIssueAvailable, esraClassification }) => { - if (esraClassification && shortTermCover && nbiIssueAvailable) { +// helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts +var { + CIS: { + COUNTRY_RATINGS: { NOT_APPLICABLE }, + ESRA_CLASSIFICATION: { NONE }, + SHORT_TERM_COVER: { UNLISTED, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; +var hasNoSupport = ({ countryRating, esraClassification, shortTermCover }) => { + const shortTermCoverIsUnlisted = shortTermCover === UNLISTED; + const esraClassificationIsNone = esraClassification === NONE; + const countryRatingIsNotApplicable = countryRating === NOT_APPLICABLE; + const countryRatingConditions = + country_rating_is_a_or_b_default(countryRating) || country_rating_is_c_or_d_default(countryRating) || countryRatingIsNotApplicable; + if (shortTermCoverIsUnlisted && esraClassificationIsNone && countryRatingConditions) { return true; } - return false; -}; -var can_get_a_quote_online_default = canGetAQuoteOnline; - -// helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.ts -var canGetAQuoteByEmail = ({ shortTermCover, nbiIssueAvailable, esraClassification }) => { - if (shortTermCover && !nbiIssueAvailable && esraClassification) { + const esraClassificationConditions = esra_classification_is_standard_high_or_very_high_default(esraClassification) || esraClassificationIsNone; + if (shortTermCover === CILC && countryRatingIsNotApplicable && esraClassificationConditions) { return true; } return false; }; -var can_get_a_quote_by_email_default = canGetAQuoteByEmail; +var has_no_support_default = hasNoSupport; -// helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.ts -var cannotGetAQuote = ({ shortTermCover, nbiIssueAvailable, esraClassification }) => { - if (!esraClassification || (!shortTermCover && !nbiIssueAvailable)) { - return true; +// helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index.ts +var { + CIS: { + ESRA_CLASSIFICATION: { STANDARD: STANDARD2, HIGH: HIGH2, VERY_HIGH: VERY_HIGH2, NONE: NONE2 }, + SHORT_TERM_COVER: { NO: NO2, ILC, CILC: CILC2 }, + }, +} = EXTERNAL_API_DEFINITIONS; +var aAndBRatingConditions = ({ countryRating, esraClassification, shortTermCover }) => { + if (!country_rating_is_a_or_b_default(countryRating)) { + return false; } - return false; -}; -var cannot_get_a_quote_default = cannotGetAQuote; - -// helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts -var canApplyForInsuranceOnline = (shortTermCover, esraClassification) => { - if (shortTermCover && esraClassification) { + if (esraClassification === STANDARD2 || esraClassification === HIGH2 || esraClassification === VERY_HIGH2) { + if (shortTermCover === ILC) { + return true; + } + if (shortTermCover === CILC2) { + return true; + } + if (shortTermCover === NO2) { + return true; + } + } + if (esraClassification === NONE2 && shortTermCover === NO2) { return true; } return false; }; -var can_apply_for_insurance_online_default = canApplyForInsuranceOnline; +var a_and_b_rating_conditions_default = aAndBRatingConditions; -// helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.ts -var { CIS: CIS3 } = EXTERNAL_API_DEFINITIONS; -var canApplyOffline = (originalShortTermCover) => { - if (originalShortTermCover === CIS3.SHORT_TERM_COVER_AVAILABLE.ILC) { - return true; +// helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index.ts +var { + CIS: { + ESRA_CLASSIFICATION: { STANDARD: STANDARD3, HIGH: HIGH3, VERY_HIGH: VERY_HIGH3, NONE: NONE3 }, + SHORT_TERM_COVER: { YES: YES2, NO: NO3, ILC: ILC2, CILC: CILC3, REFER, UNLISTED: UNLISTED2 }, + }, +} = EXTERNAL_API_DEFINITIONS; +var cAndDRatingConditions = ({ countryRating, esraClassification, shortTermCover }) => { + if (!country_rating_is_c_or_d_default(countryRating)) { + return false; } - if (originalShortTermCover === CIS3.SHORT_TERM_COVER_AVAILABLE.CILC) { - return true; + if (esraClassification === STANDARD3 || esraClassification === HIGH3 || esraClassification === VERY_HIGH3) { + if (shortTermCover === YES2) { + return true; + } + if (shortTermCover === ILC2) { + return true; + } + if (shortTermCover === CILC3) { + return true; + } + if (shortTermCover === REFER) { + return true; + } + if (shortTermCover === UNLISTED2) { + return true; + } + if (shortTermCover === NO3) { + return true; + } } - if (originalShortTermCover === CIS3.SHORT_TERM_COVER_AVAILABLE.REFER) { + if (esraClassification === NONE3 && shortTermCover === NO3) { return true; } return false; }; -var can_apply_offline_default = canApplyOffline; +var c_and_d_rating_conditions_default = cAndDRatingConditions; -// helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.ts -var { NO_COVER } = EXTERNAL_API_DEFINITIONS.CIS; -var noInsuranceSupportAvailable = (marketRiskAppetitePublicDesc) => marketRiskAppetitePublicDesc === NO_COVER; -var no_insurance_support_default = noInsuranceSupportAvailable; +// helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts +var hasNoOnlineSupport = ({ countryRating, esraClassification, shortTermCover }) => { + const aAndBConditions = a_and_b_rating_conditions_default({ + countryRating, + esraClassification, + shortTermCover, + }); + const cAndDConditions = c_and_d_rating_conditions_default({ + countryRating, + esraClassification, + shortTermCover, + }); + const conditions = aAndBConditions || cAndDConditions; + return conditions; +}; +var has_no_online_support_default = hasNoOnlineSupport; + +// helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.ts +var { + CIS: { + SHORT_TERM_COVER: { YES: YES3, REFER: REFER2, UNLISTED: UNLISTED3 }, + }, +} = EXTERNAL_API_DEFINITIONS; +var shortTermCoverIsYesReferOrUnlisted = (shortTermCover) => { + switch (shortTermCover) { + case YES3: + return true; + case REFER2: + return true; + case UNLISTED3: + return true; + default: + return false; + } +}; +var short_term_cover_is_yes_refer_or_unlisted_default = shortTermCoverIsYesReferOrUnlisted; + +// helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.ts +var canGetAQuoteOnline = (cisCountry) => { + const { ESRAClassificationDesc, shortTermCoverAvailabilityDesc, countryRatingDesc } = cisCountry; + const conditions = + esra_classification_is_standard_high_or_very_high_default(ESRAClassificationDesc) && + short_term_cover_is_yes_refer_or_unlisted_default(shortTermCoverAvailabilityDesc) && + country_rating_is_a_or_b_default(countryRatingDesc); + return conditions; +}; +var can_get_a_quote_online_default = canGetAQuoteOnline; + +// helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts +var canApplyForInsuranceOnline = (cisCountry) => { + const { ESRAClassificationDesc, shortTermCoverAvailabilityDesc, countryRatingDesc } = cisCountry; + const conditions = + esra_classification_is_standard_high_or_very_high_default(ESRAClassificationDesc) && + short_term_cover_is_yes_refer_or_unlisted_default(shortTermCoverAvailabilityDesc) && + country_rating_is_a_or_b_default(countryRatingDesc); + return conditions; +}; +var can_apply_for_insurance_online_default = canApplyForInsuranceOnline; // helpers/map-CIS-countries/map-CIS-country/index.ts var mapCisCountry = (cisCountry) => { - const { marketName, isoCode } = cisCountry; + const { countryRatingDesc: countryRating, ESRAClassificationDesc, isoCode, marketName, shortTermCoverAvailabilityDesc: shortTermCover } = cisCountry; const esraClassification = map_esra_classification_default(cisCountry.ESRAClassificationDesc); - const nbiIssueAvailable = map_NBI_issue_available_default(cisCountry.NBIIssue); - const shortTermCover = map_short_term_cover_available_default(cisCountry.shortTermCoverAvailabilityDesc); + const noSupport = has_no_support_default({ + countryRating, + esraClassification: ESRAClassificationDesc, + shortTermCover, + }); const mapped = { - name: marketName, + countryRating, esraClassification, isoCode, - nbiIssueAvailable, - shortTermCover, + name: marketName, + noOnlineSupport: has_no_online_support_default({ + countryRating, + esraClassification: ESRAClassificationDesc, + shortTermCover, + }), + canGetAQuoteOnline: can_get_a_quote_online_default(cisCountry), + cannotGetAQuote: noSupport, + canApplyForInsuranceOnline: can_apply_for_insurance_online_default(cisCountry), + noInsuranceSupport: noSupport, }; - mapped.canGetAQuoteOnline = can_get_a_quote_online_default({ shortTermCover, nbiIssueAvailable, esraClassification }); - mapped.canGetAQuoteOffline = can_apply_offline_default(cisCountry.shortTermCoverAvailabilityDesc); - mapped.canGetAQuoteByEmail = can_get_a_quote_by_email_default({ shortTermCover, nbiIssueAvailable, esraClassification }); - mapped.cannotGetAQuote = cannot_get_a_quote_default({ shortTermCover, nbiIssueAvailable, esraClassification }); - mapped.canApplyForInsuranceOnline = can_apply_for_insurance_online_default(shortTermCover, esraClassification); - mapped.noInsuranceSupport = no_insurance_support_default(cisCountry.marketRiskAppetitePublicDesc); return mapped; }; var map_CIS_country_default = mapCisCountry; @@ -9285,9 +9411,9 @@ var sortArrayAlphabetically = (arr, field) => { var sort_array_alphabetically_default = sortArrayAlphabetically; // helpers/map-CIS-countries/index.ts -var { CIS: CIS4 } = EXTERNAL_API_DEFINITIONS; +var { CIS } = EXTERNAL_API_DEFINITIONS; var mapCisCountries = (countries) => { - const filteredCountries = filter_cis_entries_default(countries, CIS4.INVALID_COUNTRIES, 'marketName'); + const filteredCountries = filter_cis_entries_default(countries, CIS.INVALID_COUNTRIES, 'marketName'); const mapped = filteredCountries.map((country) => map_CIS_country_default(country)); const sorted = sort_array_alphabetically_default(mapped, 'name'); return sorted; @@ -9334,7 +9460,7 @@ var getApimCisCountriesQuery = async () => { var get_APIM_CIS_countries_default2 = getApimCisCountriesQuery; // helpers/map-currencies/index.ts -var { CIS: CIS5 } = EXTERNAL_API_DEFINITIONS; +var { CIS: CIS2 } = EXTERNAL_API_DEFINITIONS; var getSupportedCurrencies = (currencies) => { const supported = currencies.filter((currency) => SUPPORTED_CURRENCIES.find((currencyCode) => currency.isoCode === currencyCode)); return supported; @@ -9344,7 +9470,7 @@ var getAlternativeCurrencies = (currencies) => { return alternate; }; var mapCurrencies = (currencies, alternativeCurrencies) => { - let currenciesArray = filter_cis_entries_default(currencies, CIS5.INVALID_CURRENCIES, 'name'); + let currenciesArray = filter_cis_entries_default(currencies, CIS2.INVALID_CURRENCIES, 'name'); if (!alternativeCurrencies) { currenciesArray = getSupportedCurrencies(currenciesArray); } else { diff --git a/src/api/constants/external-apis.ts b/src/api/constants/external-apis.ts index 7e6ebfbe19..1749ba7059 100644 --- a/src/api/constants/external-apis.ts +++ b/src/api/constants/external-apis.ts @@ -2,12 +2,13 @@ export const EXTERNAL_API_DEFINITIONS = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard Risk', + NONE: 'None', }, - SHORT_TERM_COVER_AVAILABLE: { + SHORT_TERM_COVER: { YES: 'Yes', NO: 'No', ILC: 'ILC Only', @@ -30,6 +31,13 @@ export const EXTERNAL_API_DEFINITIONS = { 'Third Country', ], INVALID_CURRENCIES: ['Gold'], + COUNTRY_RATINGS: { + A: ['AAA', 'AA+', 'AA', 'AA-', 'A+', 'A', 'A-'], + B: ['BBB+', 'BBB', 'BBB-', 'BB+', 'BB', 'BB-', 'B+', 'B', 'B-'], + C: ['CCC+', 'CCC', 'CCC-', 'CC', 'C'], + D: ['D'], + NOT_APPLICABLE: 'N/A', + }, }, COMPANIES_HOUSE: { COMPANY_STATUS: { @@ -40,7 +48,7 @@ export const EXTERNAL_API_DEFINITIONS = { export const EXTERNAL_API_MAPPINGS = { CIS: { - RISK: { + ESRA_CLASSIFICATION: { VERY_HIGH: 'Very High', HIGH: 'High', STANDARD: 'Standard', diff --git a/src/api/custom-schema/type-defs.ts b/src/api/custom-schema/type-defs.ts index 1cdc5027fe..bb8186b268 100644 --- a/src/api/custom-schema/type-defs.ts +++ b/src/api/custom-schema/type-defs.ts @@ -234,13 +234,10 @@ const typeDefs = ` name: String shortTermCover: Boolean esraClassification: String - nbiIssueAvailable: Boolean canGetAQuoteOnline: Boolean - canGetAQuoteOffline: Boolean - canGetAQuoteByEmail: Boolean cannotGetAQuote: Boolean - cannotApply: Boolean canApplyForInsuranceOnline: Boolean + noOnlineSupport: Boolean noInsuranceSupport: Boolean } diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.test.ts index 4a1a6846c4..a2f212d569 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.test.ts @@ -1,52 +1,20 @@ import canApplyForInsuranceOnline from '.'; -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; - -const { - CIS: { - RISK: { VERY_HIGH }, - }, -} = EXTERNAL_API_DEFINITIONS; - -const mockEsraClassification = VERY_HIGH; +import esraClassificationIsStandardHighOrVeryHigh from '../esra-classification-is-standard-high-or-very-high'; +import shortTermCoverIsYesReferOrUnlisted from '../short-term-cover-is-yes-refer-or-unlisted'; +import countryRatingIsAorB from '../country-rating-is-a-or-b'; +import { mockCisCountry } from '../../../../test-mocks'; describe('helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online', () => { - describe('when shortTermCover=true, esraClassification is provided', () => { - it('should return true', () => { - const result = canApplyForInsuranceOnline(true, mockEsraClassification); - - expect(result).toEqual(true); - }); - }); - - describe('when shortTermCover=false, esraClassification is null', () => { - it('should return false', () => { - const result = canApplyForInsuranceOnline(false, null); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=false, esraClassification is an empty string', () => { - it('should return false', () => { - const result = canApplyForInsuranceOnline(false, ''); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=true, esraClassification is null', () => { - it('should return false', () => { - const result = canApplyForInsuranceOnline(true, null); + it('should return the result of 3x conditions', () => { + const result = canApplyForInsuranceOnline(mockCisCountry); - expect(result).toEqual(false); - }); - }); + const { ESRAClassificationDesc, shortTermCoverAvailabilityDesc, marketRiskAppetitePublicDesc } = mockCisCountry; - describe('when shortTermCover=true, esraClassification is an empty string', () => { - it('should return false', () => { - const result = canApplyForInsuranceOnline(true, ''); + const expected = + esraClassificationIsStandardHighOrVeryHigh(ESRAClassificationDesc) && + shortTermCoverIsYesReferOrUnlisted(shortTermCoverAvailabilityDesc) && + countryRatingIsAorB(marketRiskAppetitePublicDesc); - expect(result).toEqual(false); - }); + expect(result).toEqual(expected); }); }); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts index d7197c0af2..6474a2aac3 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/index.ts @@ -1,24 +1,23 @@ +import esraClassificationIsStandardHighOrVeryHigh from '../esra-classification-is-standard-high-or-very-high'; +import shortTermCoverIsYesReferOrUnlisted from '../short-term-cover-is-yes-refer-or-unlisted'; +import countryRatingIsAorB from '../country-rating-is-a-or-b'; +import { CisCountry } from '../../../../types'; + /** * canApplyForInsuranceOnline * Check if a country can apply for insurance online. - * A country can apply if - * 1) The country has a risk category, - * 2) The country has a short term cover definition with one of the following values: - * - Yes - * - ILC - * - CILC - * - Refer - * - Unlisted - * @param {Boolean} shortTermCover: Short term cover flag. - * @param {String} esraClassification: ESRA classification. + * @param {CisCountry} cisCountry: CIS country * @returns {Boolean} */ -const canApplyForInsuranceOnline = (shortTermCover: boolean, esraClassification: string | null) => { - if (shortTermCover && esraClassification) { - return true; - } +const canApplyForInsuranceOnline = (cisCountry: CisCountry): boolean => { + const { ESRAClassificationDesc, shortTermCoverAvailabilityDesc, countryRatingDesc } = cisCountry; + + const conditions = + esraClassificationIsStandardHighOrVeryHigh(ESRAClassificationDesc) && + shortTermCoverIsYesReferOrUnlisted(shortTermCoverAvailabilityDesc) && + countryRatingIsAorB(countryRatingDesc); - return false; + return conditions; }; export default canApplyForInsuranceOnline; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.test.ts deleted file mode 100644 index 86b0c94356..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import canApplyOffline from '.'; -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; -import mockCountries from '../../../../test-mocks/mock-countries'; - -const { CIS } = EXTERNAL_API_DEFINITIONS; - -const { 1: mockCountryBase } = mockCountries; - -describe('helpers/map-cis-countries/map-cis-country/can-apply-offline', () => { - describe(`when shortTermCoverAvailabilityDesc is ${CIS.SHORT_TERM_COVER_AVAILABLE.ILC}`, () => { - it('should return true', () => { - const mockCountry = { - ...mockCountryBase, - shortTermCoverAvailabilityDesc: CIS.SHORT_TERM_COVER_AVAILABLE.ILC, - }; - - const result = canApplyOffline(mockCountry.shortTermCoverAvailabilityDesc); - - expect(result).toEqual(true); - }); - }); - - describe(`when shortTermCoverAvailabilityDesc is ${CIS.SHORT_TERM_COVER_AVAILABLE.CILC}`, () => { - it('should return true', () => { - const mockCountry = { - ...mockCountryBase, - shortTermCoverAvailabilityDesc: CIS.SHORT_TERM_COVER_AVAILABLE.CILC, - }; - - const result = canApplyOffline(mockCountry.shortTermCoverAvailabilityDesc); - - expect(result).toEqual(true); - }); - }); - - describe(`when shortTermCoverAvailabilityDesc is ${CIS.SHORT_TERM_COVER_AVAILABLE.REFER}`, () => { - it('should return true', () => { - const mockCountry = { - ...mockCountryBase, - shortTermCoverAvailabilityDesc: CIS.SHORT_TERM_COVER_AVAILABLE.REFER, - }; - - const result = canApplyOffline(mockCountry.shortTermCoverAvailabilityDesc); - - expect(result).toEqual(true); - }); - }); - - describe('when shortTermCoverAvailabilityDesc does not match anything', () => { - it('should return false', () => { - const mockCountry = { - ...mockCountryBase, - shortTermCoverAvailabilityDesc: 'Something else', - }; - - const result = canApplyOffline(mockCountry.shortTermCoverAvailabilityDesc); - - expect(result).toEqual(false); - }); - }); -}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.ts deleted file mode 100644 index 70ccd04333..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-apply-offline/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; - -const { CIS } = EXTERNAL_API_DEFINITIONS; - -/** - * canApplyOffline - * Check if a country can get a quote offline - * @param {String} Country original short term cover definition from CIS API. - * @returns {Boolean} - */ -export const canApplyOffline = (originalShortTermCover: string) => { - if (originalShortTermCover === CIS.SHORT_TERM_COVER_AVAILABLE.ILC) { - return true; - } - - if (originalShortTermCover === CIS.SHORT_TERM_COVER_AVAILABLE.CILC) { - return true; - } - - if (originalShortTermCover === CIS.SHORT_TERM_COVER_AVAILABLE.REFER) { - return true; - } - - return false; -}; - -export default canApplyOffline; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.test.ts deleted file mode 100644 index 8514fb7e28..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -import canGetAQuoteByEmail from '.'; -import { EXTERNAL_API_MAPPINGS } from '../../../../constants'; - -const { - CIS: { RISK }, -} = EXTERNAL_API_MAPPINGS; - -const mockEsraClassification = RISK.STANDARD; - -describe('helpers/map-cis-countries/map-cis-country/can-get-a-quote-by-email', () => { - describe('when shortTermCover=true, nbiIssueAvailable=false, esraClassification is provided', () => { - it('should return true', () => { - const result = canGetAQuoteByEmail({ shortTermCover: true, nbiIssueAvailable: false, esraClassification: mockEsraClassification }); - - expect(result).toEqual(true); - }); - }); - - describe('when shortTermCover=true, nbiIssueAvailable=false, esraClassification is null', () => { - it('should return false', () => { - const result = canGetAQuoteByEmail({ shortTermCover: true, nbiIssueAvailable: false, esraClassification: null }); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=true, nbiIssueAvailable=false, esraClassification is an empty string', () => { - it('should return false', () => { - const result = canGetAQuoteByEmail({ shortTermCover: true, nbiIssueAvailable: false, esraClassification: '' }); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=false, nbiIssueAvailable=false, esraClassification is provided', () => { - it('should return false', () => { - const result = canGetAQuoteByEmail({ shortTermCover: false, nbiIssueAvailable: false, esraClassification: mockEsraClassification }); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=true, nbiIssueAvailable=true, esraClassification is provided', () => { - it('should return false', () => { - const result = canGetAQuoteByEmail({ shortTermCover: true, nbiIssueAvailable: true, esraClassification: mockEsraClassification }); - - expect(result).toEqual(false); - }); - }); -}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.ts deleted file mode 100644 index 77d3366588..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-by-email/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MapCisCountryParams } from '../../../../types'; - -/** - * canGetAQuoteByEmail - * Check if a country is able to get a quote by email - * @param {MapCisCountryParams} - * @param {Boolean} shortTermCover: Short term cover flag. - * @param {Boolean} nbiIssueAvailable: NBI flag. - * @param {String} esraClassification: ESRA classification. - * @returns {Boolean} - */ -const canGetAQuoteByEmail = ({ shortTermCover, nbiIssueAvailable, esraClassification }: MapCisCountryParams) => { - if (shortTermCover && !nbiIssueAvailable && esraClassification) { - return true; - } - - return false; -}; - -export default canGetAQuoteByEmail; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.test.ts index 7329eea7cd..c909591fd7 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.test.ts @@ -1,50 +1,20 @@ import canGetAQuoteOnline from '.'; -import { EXTERNAL_API_MAPPINGS } from '../../../../constants'; - -const { - CIS: { RISK }, -} = EXTERNAL_API_MAPPINGS; - -const mockEsraClassification = RISK.STANDARD; +import esraClassificationIsStandardHighOrVeryHigh from '../esra-classification-is-standard-high-or-very-high'; +import shortTermCoverIsYesReferOrUnlisted from '../short-term-cover-is-yes-refer-or-unlisted'; +import countryRatingIsAorB from '../country-rating-is-a-or-b'; +import { mockCisCountry } from '../../../../test-mocks'; describe('helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online', () => { - describe('when shortTermCover=true, nbiIssueAvailable=true, esraClassification is provided', () => { - it('should return true', () => { - const result = canGetAQuoteOnline({ shortTermCover: true, nbiIssueAvailable: true, esraClassification: mockEsraClassification }); - - expect(result).toEqual(true); - }); - }); - - describe('when shortTermCover=true, nbiIssueAvailable=true, esraClassification is null', () => { - it('should return false', () => { - const result = canGetAQuoteOnline({ shortTermCover: true, nbiIssueAvailable: true, esraClassification: null }); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=true, nbiIssueAvailable=true, esraClassification is an empty string', () => { - it('should return false', () => { - const result = canGetAQuoteOnline({ shortTermCover: true, nbiIssueAvailable: true, esraClassification: '' }); - - expect(result).toEqual(false); - }); - }); - - describe('when shortTermCover=false, nbiIssueAvailable=true, esraClassification is provided', () => { - it('should return false', () => { - const result = canGetAQuoteOnline({ shortTermCover: false, nbiIssueAvailable: true, esraClassification: mockEsraClassification }); + it('should return the result of 3x conditions', () => { + const result = canGetAQuoteOnline(mockCisCountry); - expect(result).toEqual(false); - }); - }); + const { ESRAClassificationDesc, shortTermCoverAvailabilityDesc, marketRiskAppetitePublicDesc } = mockCisCountry; - describe('when shortTermCover=true, nbiIssueAvailable=false, esraClassification is provided', () => { - it('should return false', () => { - const result = canGetAQuoteOnline({ shortTermCover: true, nbiIssueAvailable: false, esraClassification: mockEsraClassification }); + const expected = + esraClassificationIsStandardHighOrVeryHigh(ESRAClassificationDesc) && + shortTermCoverIsYesReferOrUnlisted(shortTermCoverAvailabilityDesc) && + countryRatingIsAorB(marketRiskAppetitePublicDesc); - expect(result).toEqual(false); - }); + expect(result).toEqual(expected); }); }); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.ts index 1bc5e7d721..e9d23198ec 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/can-get-a-quote-online/index.ts @@ -1,20 +1,23 @@ -import { MapCisCountryParams } from '../../../../types'; +import esraClassificationIsStandardHighOrVeryHigh from '../esra-classification-is-standard-high-or-very-high'; +import shortTermCoverIsYesReferOrUnlisted from '../short-term-cover-is-yes-refer-or-unlisted'; +import countryRatingIsAorB from '../country-rating-is-a-or-b'; +import { CisCountry } from '../../../../types'; /** * canGetAQuoteOnline - * Check if a country is able to get a quote online - * @param {MapCisCountryParams} - * @param {Boolean} shortTermCover: Short term cover flag. - * @param {Boolean} nbiIssueAvailable: NBI flag. - * @param {String} esraClassification: ESRA classification. + * Check if a country can apply for a quote online. + * @param {CisCountry} CIS Country * @returns {Boolean} */ -const canGetAQuoteOnline = ({ shortTermCover, nbiIssueAvailable, esraClassification }: MapCisCountryParams) => { - if (esraClassification && shortTermCover && nbiIssueAvailable) { - return true; - } +const canGetAQuoteOnline = (cisCountry: CisCountry) => { + const { ESRAClassificationDesc, shortTermCoverAvailabilityDesc, countryRatingDesc } = cisCountry; - return false; + const conditions = + esraClassificationIsStandardHighOrVeryHigh(ESRAClassificationDesc) && + shortTermCoverIsYesReferOrUnlisted(shortTermCoverAvailabilityDesc) && + countryRatingIsAorB(countryRatingDesc); + + return conditions; }; export default canGetAQuoteOnline; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.test.ts deleted file mode 100644 index 3e879fb932..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import cannotGetAQuote from '.'; -import { EXTERNAL_API_MAPPINGS } from '../../../../constants'; - -const { - CIS: { RISK }, -} = EXTERNAL_API_MAPPINGS; - -const mockEsraClassification = RISK.STANDARD; - -describe('helpers/map-cis-countries/map-cis-country/cannot-get-a-quote', () => { - describe('when country has shortTermCover=false, nbiIssueAvailable=false and no esraClassification', () => { - it('should return true', () => { - const result = cannotGetAQuote({ shortTermCover: false, nbiIssueAvailable: false, esraClassification: null }); - - expect(result).toEqual(true); - }); - }); - - describe('when country has shortTermCover=false, nbiIssueAvailable=false and has a esraClassification', () => { - it('should return true', () => { - const result = cannotGetAQuote({ shortTermCover: false, nbiIssueAvailable: false, esraClassification: mockEsraClassification }); - - expect(result).toEqual(true); - }); - }); - - describe('when country has shortTermCover=true, nbiIssueAvailable=true and has a esraClassification', () => { - it('should return false', () => { - const result = cannotGetAQuote({ shortTermCover: true, nbiIssueAvailable: true, esraClassification: mockEsraClassification }); - - expect(result).toEqual(false); - }); - }); -}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.ts deleted file mode 100644 index d2b37edd89..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/cannot-get-a-quote/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MapCisCountryParams } from '../../../../types'; - -/** - * cannotGetAQuote - * Check if a country cannot get a quote online or offline - * @param {MapCisCountryParams} - * @param {Boolean} shortTermCover: Short term cover flag. - * @param {Boolean} nbiIssueAvailable: NBI flag. - * @param {String} esraClassification: ESRA classification. - * @returns {Boolean} - */ -const cannotGetAQuote = ({ shortTermCover, nbiIssueAvailable, esraClassification }: MapCisCountryParams) => { - if (!esraClassification || (!shortTermCover && !nbiIssueAvailable)) { - return true; - } - - return false; -}; - -export default cannotGetAQuote; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.test.ts new file mode 100644 index 0000000000..e10f308313 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.test.ts @@ -0,0 +1,40 @@ +import countryRatingIsAorB from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { COUNTRY_RATINGS }, +} = EXTERNAL_API_DEFINITIONS; + +describe('helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b', () => { + describe.each(COUNTRY_RATINGS.A)('COUNTRY_RATINGS.A', (rating) => { + it(`should return true for ${rating}`, () => { + const result = countryRatingIsAorB(rating); + + expect(result).toEqual(true); + }); + }); + + describe.each(COUNTRY_RATINGS.B)('COUNTRY_RATINGS.B', (rating) => { + it(`should return true for ${rating}`, () => { + const result = countryRatingIsAorB(rating); + + expect(result).toEqual(true); + }); + }); + + describe.each(COUNTRY_RATINGS.C)('COUNTRY_RATINGS.C', (rating) => { + it(`should return false for ${rating}`, () => { + const result = countryRatingIsAorB(rating); + + expect(result).toEqual(false); + }); + }); + + describe.each(COUNTRY_RATINGS.D)('COUNTRY_RATINGS.D', (rating) => { + it(`should return false for ${rating}`, () => { + const result = countryRatingIsAorB(rating); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.ts new file mode 100644 index 0000000000..27ab3a51ea --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.ts @@ -0,0 +1,25 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { COUNTRY_RATINGS }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * countryRatingIsAorB + * Check if a country's "country rating" is A or B. + * @param {String} rating: Country rating + * @returns {Boolean} + */ +const countryRatingIsAorB = (rating: string): boolean => { + if (COUNTRY_RATINGS.A.includes(rating)) { + return true; + } + + if (COUNTRY_RATINGS.B.includes(rating)) { + return true; + } + + return false; +}; + +export default countryRatingIsAorB; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.test.ts new file mode 100644 index 0000000000..6c52964795 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.test.ts @@ -0,0 +1,40 @@ +import countryRatingIsCorD from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { COUNTRY_RATINGS }, +} = EXTERNAL_API_DEFINITIONS; + +describe('helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d', () => { + describe.each(COUNTRY_RATINGS.C)('COUNTRY_RATINGS.C', (rating) => { + it(`should return true for ${rating}`, () => { + const result = countryRatingIsCorD(rating); + + expect(result).toEqual(true); + }); + }); + + describe.each(COUNTRY_RATINGS.D)('COUNTRY_RATINGS.D', (rating) => { + it(`should return true for ${rating}`, () => { + const result = countryRatingIsCorD(rating); + + expect(result).toEqual(true); + }); + }); + + describe.each(COUNTRY_RATINGS.A)('COUNTRY_RATINGS.A', (rating) => { + it(`should return false for ${rating}`, () => { + const result = countryRatingIsCorD(rating); + + expect(result).toEqual(false); + }); + }); + + describe.each(COUNTRY_RATINGS.B)('COUNTRY_RATINGS.B', (rating) => { + it(`should return false for ${rating}`, () => { + const result = countryRatingIsCorD(rating); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.ts new file mode 100644 index 0000000000..0cd1944a5e --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.ts @@ -0,0 +1,25 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { COUNTRY_RATINGS }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * countryRatingIsCorD + * Check if a country's "country rating" is C or D. + * @param {String} rating: Country rating + * @returns {Boolean} + */ +const countryRatingIsCorD = (rating: string): boolean => { + if (COUNTRY_RATINGS.C.includes(rating)) { + return true; + } + + if (COUNTRY_RATINGS.D.includes(rating)) { + return true; + } + + return false; +}; + +export default countryRatingIsCorD; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.test.ts new file mode 100644 index 0000000000..79d169f8b7 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.test.ts @@ -0,0 +1,50 @@ +import esraClassificationIsStandardHighOrVeryHigh from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH, NONE }, + }, +} = EXTERNAL_API_DEFINITIONS; + +describe('helpers/map-CIS-countries/map-CIS-country/can-apply-for-insurance-online/has-valid-esra-classification', () => { + describe(`when the classification is ${STANDARD}`, () => { + it('should return true', () => { + const result = esraClassificationIsStandardHighOrVeryHigh(STANDARD); + + expect(result).toEqual(true); + }); + }); + + describe(`when the classification is ${HIGH}`, () => { + it('should return true', () => { + const result = esraClassificationIsStandardHighOrVeryHigh(HIGH); + + expect(result).toEqual(true); + }); + }); + + describe(`when the classification is ${VERY_HIGH}`, () => { + it('should return true', () => { + const result = esraClassificationIsStandardHighOrVeryHigh(VERY_HIGH); + + expect(result).toEqual(true); + }); + }); + + describe(`when the classification is ${NONE}`, () => { + it('should return false', () => { + const result = esraClassificationIsStandardHighOrVeryHigh(NONE); + + expect(result).toEqual(false); + }); + }); + + describe('when the classification is unrecognised', () => { + it('should return false', () => { + const result = esraClassificationIsStandardHighOrVeryHigh('Some other classification'); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.ts new file mode 100644 index 0000000000..957ab4dabe --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.ts @@ -0,0 +1,31 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * esraClassificationIsStandardHighOrVeryHigh + * Check if a country's "ESRA classification" is STANDARD, HIGH or VERY_HIGH + * @param {String} esraClassification: ESRA classification + * @returns {Boolean} + */ +const esraClassificationIsStandardHighOrVeryHigh = (esraClassification: string): boolean => { + switch (esraClassification) { + case STANDARD: + return true; + + case HIGH: + return true; + + case VERY_HIGH: + return true; + + default: + return false; + } +}; + +export default esraClassificationIsStandardHighOrVeryHigh; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-a.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-a.test.ts new file mode 100644 index 0000000000..33feec8e75 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-a.test.ts @@ -0,0 +1,115 @@ +import aAndBRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + SHORT_TERM_COVER: { NO, ILC, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; + +const createMockParams = (esraClassification: string, shortTermCover: string) => + COUNTRY_RATINGS.A.map((rating: string) => ({ + countryRating: rating, + esraClassification, + shortTermCover, + })); + +const params = { + STANDARD: { + [ILC]: createMockParams(STANDARD, ILC), + [CILC]: createMockParams(STANDARD, CILC), + [NO]: createMockParams(STANDARD, NO), + }, + HIGH: { + [ILC]: createMockParams(HIGH, ILC), + [CILC]: createMockParams(HIGH, CILC), + [NO]: createMockParams(HIGH, NO), + }, + VERY_HIGH: { + [ILC]: createMockParams(VERY_HIGH, ILC), + [CILC]: createMockParams(VERY_HIGH, CILC), + [NO]: createMockParams(VERY_HIGH, NO), + }, +}; + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions - rating as A', () => { + describe(`when the ESRA classification is ${STANDARD}`, () => { + describe.each(params.STANDARD[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${HIGH}`, () => { + describe.each(params.HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${VERY_HIGH}`, () => { + describe.each(params.VERY_HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-b.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-b.test.ts new file mode 100644 index 0000000000..bf902d6757 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-b.test.ts @@ -0,0 +1,115 @@ +import aAndBRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + SHORT_TERM_COVER: { NO, ILC, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; + +const createMockParams = (esraClassification: string, shortTermCover: string) => + COUNTRY_RATINGS.B.map((rating: string) => ({ + countryRating: rating, + esraClassification, + shortTermCover, + })); + +const params = { + STANDARD: { + [ILC]: createMockParams(STANDARD, ILC), + [CILC]: createMockParams(STANDARD, CILC), + [NO]: createMockParams(STANDARD, NO), + }, + HIGH: { + [ILC]: createMockParams(HIGH, ILC), + [CILC]: createMockParams(HIGH, CILC), + [NO]: createMockParams(HIGH, NO), + }, + VERY_HIGH: { + [ILC]: createMockParams(VERY_HIGH, ILC), + [CILC]: createMockParams(VERY_HIGH, CILC), + [NO]: createMockParams(VERY_HIGH, NO), + }, +}; + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions - rating as B', () => { + describe(`when the ESRA classification is ${STANDARD}`, () => { + describe.each(params.STANDARD[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${HIGH}`, () => { + describe.each(params.HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${VERY_HIGH}`, () => { + describe.each(params.VERY_HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-c-and-d.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-c-and-d.test.ts new file mode 100644 index 0000000000..b1cbbad41d --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-c-and-d.test.ts @@ -0,0 +1,36 @@ +import aAndBRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { COUNTRY_RATINGS, ESRA_CLASSIFICATION, SHORT_TERM_COVER }, +} = EXTERNAL_API_DEFINITIONS; + +const countryRatingsCParams = COUNTRY_RATINGS.C.map((rating: string) => ({ + countryRating: rating, + esraClassification: ESRA_CLASSIFICATION.STANDARD, + shortTermCover: SHORT_TERM_COVER.YES, +})); + +const countryRatingsDParams = COUNTRY_RATINGS.D.map((rating: string) => ({ + countryRating: rating, + esraClassification: ESRA_CLASSIFICATION.STANDARD, + shortTermCover: SHORT_TERM_COVER.YES, +})); + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions - ratings as C and D', () => { + describe.each(countryRatingsCParams)('when the country rating is `C`', (countryObj) => { + it(`should return false for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(false); + }); + }); + + describe.each(countryRatingsDParams)('when the country rating is `D`', (countryObj) => { + it(`should return false for ${countryObj.countryRating}`, () => { + const result = aAndBRatingConditions(countryObj); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-none.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-none.test.ts new file mode 100644 index 0000000000..9dd2486c78 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-none.test.ts @@ -0,0 +1,36 @@ +import aAndBRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { NONE }, + SHORT_TERM_COVER: { NO }, + }, +} = EXTERNAL_API_DEFINITIONS; + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions - ESRA classification=NONE, short term cover=NO', () => { + describe('when the country rating is `A`', () => { + it('should return true', () => { + const result = aAndBRatingConditions({ + countryRating: COUNTRY_RATINGS.A[0], + esraClassification: NONE, + shortTermCover: NO, + }); + + expect(result).toEqual(true); + }); + }); + + describe('when the country rating is `B`', () => { + it('should return true', () => { + const result = aAndBRatingConditions({ + countryRating: COUNTRY_RATINGS.B[0], + esraClassification: NONE, + shortTermCover: NO, + }); + + expect(result).toEqual(true); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index.ts new file mode 100644 index 0000000000..cc661b67d4 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index.ts @@ -0,0 +1,47 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; +import countryRatingIsAorB from '../../country-rating-is-a-or-b'; +import { NoInsuranceSupportParams } from '../../../../../types'; + +const { + CIS: { + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH, NONE }, + SHORT_TERM_COVER: { NO, ILC, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * aAndBRatingConditions + * Country conditions for "A and B country ratings", + * to determine if a country does NOT have insurance support available. + * @param {String} countryRating: Country rating + * @param {String} esraClassification: ESRA classification + * @param {String} shortTermCover: Short term cover + * @returns {Boolean} + */ +const aAndBRatingConditions = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { + if (!countryRatingIsAorB(countryRating)) { + return false; + } + + if (esraClassification === STANDARD || esraClassification === HIGH || esraClassification === VERY_HIGH) { + if (shortTermCover === ILC) { + return true; + } + + if (shortTermCover === CILC) { + return true; + } + + if (shortTermCover === NO) { + return true; + } + } + + if (esraClassification === NONE && shortTermCover === NO) { + return true; + } + + return false; +}; + +export default aAndBRatingConditions; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-a-and-b.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-a-and-b.test.ts new file mode 100644 index 0000000000..43732b868d --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-a-and-b.test.ts @@ -0,0 +1,36 @@ +import cAndDRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { COUNTRY_RATINGS, ESRA_CLASSIFICATION, SHORT_TERM_COVER }, +} = EXTERNAL_API_DEFINITIONS; + +const countryRatingsAParams = COUNTRY_RATINGS.A.map((rating: string) => ({ + countryRating: rating, + esraClassification: ESRA_CLASSIFICATION.STANDARD, + shortTermCover: SHORT_TERM_COVER.YES, +})); + +const countryRatingsBParams = COUNTRY_RATINGS.B.map((rating: string) => ({ + countryRating: rating, + esraClassification: ESRA_CLASSIFICATION.STANDARD, + shortTermCover: SHORT_TERM_COVER.YES, +})); + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions - rating as A and B', () => { + describe.each(countryRatingsAParams)('when the country rating is `A`', (countryObj) => { + it(`should return false for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(false); + }); + }); + + describe.each(countryRatingsBParams)('when the country rating is `B`', (countryObj) => { + it(`should return false for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-c.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-c.test.ts new file mode 100644 index 0000000000..15298d932a --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-c.test.ts @@ -0,0 +1,196 @@ +import cAndDRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + SHORT_TERM_COVER: { YES, NO, ILC, CILC, REFER, UNLISTED }, + }, +} = EXTERNAL_API_DEFINITIONS; + +const createMockParams = (esraClassification: string, shortTermCover: string) => + COUNTRY_RATINGS.C.map((rating: string) => ({ + countryRating: rating, + esraClassification, + shortTermCover, + })); + +const params = { + STANDARD: { + [YES]: createMockParams(STANDARD, YES), + [ILC]: createMockParams(STANDARD, ILC), + [CILC]: createMockParams(STANDARD, CILC), + [REFER]: createMockParams(STANDARD, REFER), + [UNLISTED]: createMockParams(STANDARD, UNLISTED), + [NO]: createMockParams(STANDARD, NO), + }, + HIGH: { + [YES]: createMockParams(HIGH, YES), + [ILC]: createMockParams(HIGH, ILC), + [CILC]: createMockParams(HIGH, CILC), + [REFER]: createMockParams(HIGH, REFER), + [UNLISTED]: createMockParams(HIGH, UNLISTED), + [NO]: createMockParams(HIGH, NO), + }, + VERY_HIGH: { + [YES]: createMockParams(VERY_HIGH, YES), + [ILC]: createMockParams(VERY_HIGH, ILC), + [CILC]: createMockParams(VERY_HIGH, CILC), + [REFER]: createMockParams(VERY_HIGH, REFER), + [UNLISTED]: createMockParams(VERY_HIGH, UNLISTED), + [NO]: createMockParams(VERY_HIGH, NO), + }, +}; + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions - rating as C', () => { + describe(`when the ESRA classification is ${STANDARD}`, () => { + describe.each(params.STANDARD[YES])(`when the short term cover is ${YES}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[REFER])(`when the short term cover is ${REFER}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[UNLISTED])(`when the short term cover is ${UNLISTED}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${HIGH}`, () => { + describe.each(params.HIGH[YES])(`when the short term cover is ${YES}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[REFER])(`when the short term cover is ${REFER}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[UNLISTED])(`when the short term cover is ${UNLISTED}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${VERY_HIGH}`, () => { + describe.each(params.VERY_HIGH[YES])(`when the short term cover is ${YES}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[REFER])(`when the short term cover is ${REFER}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[UNLISTED])(`when the short term cover is ${UNLISTED}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-d.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-d.test.ts new file mode 100644 index 0000000000..950e5ffd62 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-d.test.ts @@ -0,0 +1,196 @@ +import cAndDRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + SHORT_TERM_COVER: { YES, NO, ILC, CILC, REFER, UNLISTED }, + }, +} = EXTERNAL_API_DEFINITIONS; + +const createMockParams = (esraClassification: string, shortTermCover: string) => + COUNTRY_RATINGS.D.map((rating: string) => ({ + countryRating: rating, + esraClassification, + shortTermCover, + })); + +const params = { + STANDARD: { + [YES]: createMockParams(STANDARD, YES), + [ILC]: createMockParams(STANDARD, ILC), + [CILC]: createMockParams(STANDARD, CILC), + [REFER]: createMockParams(STANDARD, REFER), + [UNLISTED]: createMockParams(STANDARD, UNLISTED), + [NO]: createMockParams(STANDARD, NO), + }, + HIGH: { + [YES]: createMockParams(HIGH, YES), + [ILC]: createMockParams(HIGH, ILC), + [CILC]: createMockParams(HIGH, CILC), + [REFER]: createMockParams(HIGH, REFER), + [UNLISTED]: createMockParams(HIGH, UNLISTED), + [NO]: createMockParams(HIGH, NO), + }, + VERY_HIGH: { + [YES]: createMockParams(VERY_HIGH, YES), + [ILC]: createMockParams(VERY_HIGH, ILC), + [CILC]: createMockParams(VERY_HIGH, CILC), + [REFER]: createMockParams(VERY_HIGH, REFER), + [UNLISTED]: createMockParams(VERY_HIGH, UNLISTED), + [NO]: createMockParams(VERY_HIGH, NO), + }, +}; + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions - rating as D', () => { + describe(`when the ESRA classification is ${STANDARD}`, () => { + describe.each(params.STANDARD[YES])(`when the short term cover is ${YES}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[REFER])(`when the short term cover is ${REFER}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[UNLISTED])(`when the short term cover is ${UNLISTED}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.STANDARD[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${HIGH}`, () => { + describe.each(params.HIGH[YES])(`when the short term cover is ${YES}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[REFER])(`when the short term cover is ${REFER}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[UNLISTED])(`when the short term cover is ${UNLISTED}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); + + describe(`when the ESRA classification is ${VERY_HIGH}`, () => { + describe.each(params.VERY_HIGH[YES])(`when the short term cover is ${YES}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[ILC])(`when the short term cover is ${ILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[CILC])(`when the short term cover is ${CILC}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[REFER])(`when the short term cover is ${REFER}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[UNLISTED])(`when the short term cover is ${UNLISTED}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + + describe.each(params.VERY_HIGH[NO])(`when the short term cover is ${NO}`, (countryObj) => { + it(`should return true for ${countryObj.countryRating}`, () => { + const result = cAndDRatingConditions(countryObj); + + expect(result).toEqual(true); + }); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-none.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-none.test.ts new file mode 100644 index 0000000000..4e9520edd6 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-none.test.ts @@ -0,0 +1,36 @@ +import cAndDRatingConditions from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { NONE }, + SHORT_TERM_COVER: { NO }, + }, +} = EXTERNAL_API_DEFINITIONS; + +describe('helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions - ESRA classification=NONE, short term cover=NO', () => { + describe('when the country rating is `C`', () => { + it('should return true', () => { + const result = cAndDRatingConditions({ + countryRating: COUNTRY_RATINGS.C[0], + esraClassification: NONE, + shortTermCover: NO, + }); + + expect(result).toEqual(true); + }); + }); + + describe('when the country rating is `D`', () => { + it('should return true', () => { + const result = cAndDRatingConditions({ + countryRating: COUNTRY_RATINGS.D[0], + esraClassification: NONE, + shortTermCover: NO, + }); + + expect(result).toEqual(true); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index.ts new file mode 100644 index 0000000000..43d315ef9c --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index.ts @@ -0,0 +1,59 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../../constants'; +import countryRatingIsCorD from '../../country-rating-is-c-or-d'; +import { NoInsuranceSupportParams } from '../../../../../types'; + +const { + CIS: { + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH, NONE }, + SHORT_TERM_COVER: { YES, NO, ILC, CILC, REFER, UNLISTED }, + }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * cAndDRatingConditions + * Country conditions for "C and D country ratings", + * to determine if a country does NOT have insurance support available. + * @param {String} countryRating: Country rating + * @param {String} esraClassification: ESRA classification + * @param {String} shortTermCover: Short term cover + * @returns {Boolean} + */ +const cAndDRatingConditions = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { + if (!countryRatingIsCorD(countryRating)) { + return false; + } + + if (esraClassification === STANDARD || esraClassification === HIGH || esraClassification === VERY_HIGH) { + if (shortTermCover === YES) { + return true; + } + + if (shortTermCover === ILC) { + return true; + } + + if (shortTermCover === CILC) { + return true; + } + + if (shortTermCover === REFER) { + return true; + } + + if (shortTermCover === UNLISTED) { + return true; + } + + if (shortTermCover === NO) { + return true; + } + } + + if (esraClassification === NONE && shortTermCover === NO) { + return true; + } + + return false; +}; + +export default cAndDRatingConditions; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.test.ts new file mode 100644 index 0000000000..0ea8c89afb --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.test.ts @@ -0,0 +1,100 @@ +import hasNoOnlineSupport from '.'; +import aAndBRatingConditions from './a-and-b-rating-conditions'; +import cAndDRatingConditions from './c-and-d-rating-conditions'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; +import { mockCisCountry } from '../../../../test-mocks'; + +const { + CIS: { COUNTRY_RATINGS }, +} = EXTERNAL_API_DEFINITIONS; + +const mockInitCountry = { + esraClassification: mockCisCountry.ESRAClassificationDesc, + shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, +}; + +describe('helpers/map-CIS-countries/map-CIS-country/has-no-online-support', () => { + describe('when a country rating is `A`', () => { + it('should return the result of aAndBRatingConditions', () => { + const [mockRating] = COUNTRY_RATINGS.A; + + const mockCountry = { + ...mockInitCountry, + countryRating: mockRating, + }; + + const result = hasNoOnlineSupport(mockCountry); + + const expected = aAndBRatingConditions({ + countryRating: mockRating, + esraClassification: mockInitCountry.esraClassification, + shortTermCover: mockInitCountry.shortTermCover, + }); + + expect(result).toEqual(expected); + }); + }); + + describe('when a country rating is `B`', () => { + it('should return the result of aAndBRatingConditions', () => { + const [mockRating] = COUNTRY_RATINGS.B; + + const mockCountry = { + ...mockInitCountry, + countryRating: mockRating, + }; + + const result = hasNoOnlineSupport(mockCountry); + + const expected = aAndBRatingConditions({ + countryRating: mockRating, + esraClassification: mockInitCountry.esraClassification, + shortTermCover: mockInitCountry.shortTermCover, + }); + + expect(result).toEqual(expected); + }); + }); + + describe('when a country rating is `C`', () => { + it('should return the result of cAndDRatingConditions', () => { + const [mockRating] = COUNTRY_RATINGS.C; + + const mockCountry = { + ...mockInitCountry, + countryRating: mockRating, + }; + + const result = hasNoOnlineSupport(mockCountry); + + const expected = cAndDRatingConditions({ + countryRating: mockRating, + esraClassification: mockInitCountry.esraClassification, + shortTermCover: mockInitCountry.shortTermCover, + }); + + expect(result).toEqual(expected); + }); + }); + + describe('when a country rating is `D`', () => { + it('should return the result of cAndDRatingConditions', () => { + const [mockRating] = COUNTRY_RATINGS.D; + + const mockCountry = { + ...mockInitCountry, + countryRating: mockRating, + }; + + const result = hasNoOnlineSupport(mockCountry); + + const expected = cAndDRatingConditions({ + countryRating: mockRating, + esraClassification: mockInitCountry.esraClassification, + shortTermCover: mockInitCountry.shortTermCover, + }); + + expect(result).toEqual(expected); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts new file mode 100644 index 0000000000..89f36df849 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts @@ -0,0 +1,31 @@ +import aAndBRatingConditions from './a-and-b-rating-conditions'; +import cAndDRatingConditions from './c-and-d-rating-conditions'; +import { NoInsuranceSupportParams } from '../../../../types'; + +/** + * hasNoOnlineSupport + * Check if a country has no quote or insurance support (online) + * @param {String} countryRating: Country rating + * @param {String} esraClassification: ESRA classification + * @param {String} shortTermCover: Short term cover + * @returns {Boolean} + */ +const hasNoOnlineSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { + const aAndBConditions = aAndBRatingConditions({ + countryRating, + esraClassification, + shortTermCover, + }); + + const cAndDConditions = cAndDRatingConditions({ + countryRating, + esraClassification, + shortTermCover, + }); + + const conditions = aAndBConditions || cAndDConditions; + + return conditions; +}; + +export default hasNoOnlineSupport; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.test.ts new file mode 100644 index 0000000000..d0d05442b2 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.test.ts @@ -0,0 +1,116 @@ +import hasNoSupport from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { VERY_HIGH, HIGH, STANDARD, NONE }, + SHORT_TERM_COVER: { UNLISTED, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; + +const mockInitCountry = { + esraClassification: NONE, + shortTermCover: UNLISTED, +}; + +const createMockParams = (countryRating: string, esraClassification?: string, shortTermCover?: string) => { + const params = { + ...mockInitCountry, + countryRating, + }; + + if (esraClassification) { + params.esraClassification = esraClassification; + } + + if (shortTermCover) { + params.shortTermCover = shortTermCover; + } + + return params; +}; + +const params = { + firstConditions: [ + { + country: createMockParams(COUNTRY_RATINGS.A[0]), + description: 'A', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.B[0]), + description: 'B', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.C[0]), + description: 'C', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.D[0]), + description: 'D', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE), + description: 'NOT_APPLICABLE', + expectation: true, + }, + { + country: createMockParams('not recognised'), + description: 'not recognised', + expectation: false, + }, + ], + secondConditions: [ + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, STANDARD, CILC), + description: 'STANDARD', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, HIGH, CILC), + description: 'HIGH', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, VERY_HIGH, CILC), + description: 'VERY_HIGH', + expectation: true, + }, + + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, NONE, CILC), + description: 'NONE', + expectation: true, + }, + ], +}; + +describe('helpers/map-CIS-countries/map-CIS-country/has-no-support', () => { + describe(`when shortTermCover is ${UNLISTED} and esraClassification is ${NONE}`, () => { + describe.each(params.firstConditions)('', ({ country, description, expectation }) => { + describe(`when the countryRating is ${description}`, () => { + it(`should return ${expectation}`, () => { + const result = hasNoSupport(country); + + expect(result).toEqual(expectation); + }); + }); + }); + }); + + describe(`when shortTermCover is ${CILC} and countryRating is ${COUNTRY_RATINGS.NOT_APPLICABLE}`, () => { + describe.each(params.secondConditions)('', ({ country, description, expectation }) => { + describe(`when the esraClassification is ${description}`, () => { + it(`should return ${expectation}`, () => { + const result = hasNoSupport(country); + + expect(result).toEqual(expectation); + }); + }); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts new file mode 100644 index 0000000000..0e8b266cc9 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts @@ -0,0 +1,43 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; +import countryRatingIsAorB from '../country-rating-is-a-or-b'; +import countryRatingIsCorD from '../country-rating-is-c-or-d'; +import esraClassificationIsStandardHighOrVeryHigh from '../esra-classification-is-standard-high-or-very-high'; +import { NoInsuranceSupportParams } from '../../../../types'; + +const { + CIS: { + COUNTRY_RATINGS: { NOT_APPLICABLE }, + ESRA_CLASSIFICATION: { NONE }, + SHORT_TERM_COVER: { UNLISTED, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * hasNoSupport + * Check if a country has no quote or insurance support (online or offline) + * @param {String} countryRating: Country rating + * @param {String} esraClassification: ESRA classification + * @param {String} shortTermCover: Short term cover + * @returns {Boolean} + */ +const hasNoSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { + const shortTermCoverIsUnlisted = shortTermCover === UNLISTED; + const esraClassificationIsNone = esraClassification === NONE; + const countryRatingIsNotApplicable = countryRating === NOT_APPLICABLE; + + const countryRatingConditions = countryRatingIsAorB(countryRating) || countryRatingIsCorD(countryRating) || countryRatingIsNotApplicable; + + if (shortTermCoverIsUnlisted && esraClassificationIsNone && countryRatingConditions) { + return true; + } + + const esraClassificationConditions = esraClassificationIsStandardHighOrVeryHigh(esraClassification) || esraClassificationIsNone; + + if (shortTermCover === CILC && countryRatingIsNotApplicable && esraClassificationConditions) { + return true; + } + + return false; +}; + +export default hasNoSupport; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/index.test.ts index c891e56b48..1a590e87f3 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/index.test.ts @@ -1,28 +1,22 @@ import mapCisCountry from '.'; import mapEsraClassification from './map-esra-classification'; -import mapShortTermCoverAvailable from './map-short-term-cover-available'; -import mapNbiIssueAvailable from './map-NBI-issue-available'; +import hasNoOnlineSupport from './has-no-online-support'; import canGetAQuoteOnline from './can-get-a-quote-online'; -import canGetAQuoteByEmail from './can-get-a-quote-by-email'; -import cannotGetAQuote from './cannot-get-a-quote'; import canApplyForInsuranceOnline from './can-apply-for-insurance-online'; -import canApplyOffline from './can-apply-offline'; -import noInsuranceSupportAvailable from './no-insurance-support'; +import hasNoSupport from './has-no-support'; import { EXTERNAL_API_DEFINITIONS, EXTERNAL_API_MAPPINGS } from '../../../constants'; import { MappedCisCountry } from '../../../types'; -import { mockCisCountries } from '../../../test-mocks'; +import { mockCisCountry } from '../../../test-mocks'; const { CIS } = EXTERNAL_API_DEFINITIONS; describe('helpers/map-CIS-countries/map-CIS-country', () => { - const { 1: initialMockCountry } = mockCisCountries; - const mockCountryBase = { - ...initialMockCountry, - marketName: initialMockCountry.marketName, - esraClassification: EXTERNAL_API_MAPPINGS.CIS.RISK.STANDARD, - isoCode: initialMockCountry.isoCode, - shortTermCoverAvailabilityDesc: CIS.SHORT_TERM_COVER_AVAILABLE.ILC, + ...mockCisCountry, + marketName: mockCisCountry.marketName, + esraClassification: EXTERNAL_API_MAPPINGS.CIS.ESRA_CLASSIFICATION.STANDARD, + isoCode: mockCisCountry.isoCode, + shortTermCoverAvailabilityDesc: CIS.SHORT_TERM_COVER.ILC, marketRiskAppetitePublicDesc: CIS.NO_COVER, }; @@ -30,30 +24,37 @@ describe('helpers/map-CIS-countries/map-CIS-country', () => { const result = mapCisCountry(mockCountryBase); const esraClassification = mapEsraClassification(mockCountryBase.ESRAClassificationDesc); - const shortTermCover = mapShortTermCoverAvailable(mockCountryBase.shortTermCoverAvailabilityDesc); - const nbiIssueAvailable = mapNbiIssueAvailable(mockCountryBase.NBIIssue); - const mapped = { - name: mockCountryBase.marketName, - isoCode: mockCountryBase.isoCode, + const countryRating = mockCisCountry.countryRatingDesc; + + const mapped: MappedCisCountry = { + countryRating, esraClassification, - shortTermCover, - nbiIssueAvailable, - canGetAQuoteOnline: false, - canGetAQuoteOffline: false, - canGetAQuoteByEmail: false, - cannotGetAQuote: false, - noInsuranceSupport: false, - } as MappedCisCountry; - - mapped.canGetAQuoteOnline = canGetAQuoteOnline({ shortTermCover, nbiIssueAvailable, esraClassification }); - mapped.canGetAQuoteOffline = canApplyOffline(mockCountryBase.shortTermCoverAvailabilityDesc); - mapped.canGetAQuoteByEmail = canGetAQuoteByEmail({ shortTermCover, nbiIssueAvailable, esraClassification }); - mapped.cannotGetAQuote = cannotGetAQuote({ shortTermCover, nbiIssueAvailable, esraClassification }); - - mapped.canApplyForInsuranceOnline = canApplyForInsuranceOnline(mapped.shortTermCover, esraClassification); - - mapped.noInsuranceSupport = noInsuranceSupportAvailable(mockCountryBase.marketRiskAppetitePublicDesc); + isoCode: mockCountryBase.isoCode, + name: mockCountryBase.marketName, + + noOnlineSupport: hasNoOnlineSupport({ + countryRating, + esraClassification: mockCisCountry.ESRAClassificationDesc, + shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, + }), + + canGetAQuoteOnline: canGetAQuoteOnline(mockCisCountry), + + cannotGetAQuote: hasNoSupport({ + countryRating, + esraClassification: mockCisCountry.ESRAClassificationDesc, + shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, + }), + + canApplyForInsuranceOnline: canApplyForInsuranceOnline(mockCisCountry), + + noInsuranceSupport: hasNoSupport({ + countryRating, + esraClassification: mockCisCountry.ESRAClassificationDesc, + shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, + }), + }; expect(result).toEqual(mapped); }); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/index.ts index 8203caaf1b..ef24aaca12 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/index.ts @@ -1,12 +1,8 @@ import mapEsraClassification from './map-esra-classification'; -import mapNbiIssueAvailable from './map-NBI-issue-available'; -import mapShortTermCoverAvailable from './map-short-term-cover-available'; +import hasNoSupport from './has-no-support'; +import hasNoOnlineSupport from './has-no-online-support'; import canGetAQuoteOnline from './can-get-a-quote-online'; -import canGetAQuoteByEmail from './can-get-a-quote-by-email'; -import cannotGetAQuote from './cannot-get-a-quote'; import canApplyForInsuranceOnline from './can-apply-for-insurance-online'; -import canApplyOffline from './can-apply-offline'; -import noInsuranceSupportAvailable from './no-insurance-support'; import { CisCountry, MappedCisCountry } from '../../../types'; /** @@ -16,31 +12,41 @@ import { CisCountry, MappedCisCountry } from '../../../types'; * @returns {MappedCisCountry} Mapped country */ export const mapCisCountry = (cisCountry: CisCountry): MappedCisCountry => { - const { marketName, isoCode } = cisCountry; + const { countryRatingDesc: countryRating, ESRAClassificationDesc, isoCode, marketName, shortTermCoverAvailabilityDesc: shortTermCover } = cisCountry; const esraClassification = mapEsraClassification(cisCountry.ESRAClassificationDesc); - const nbiIssueAvailable = mapNbiIssueAvailable(cisCountry.NBIIssue); - const shortTermCover = mapShortTermCoverAvailable(cisCountry.shortTermCoverAvailabilityDesc); - const mapped = { - name: marketName, - esraClassification, - isoCode, - nbiIssueAvailable, + /** + * Current business logic for "no support" (online or offline) + * Is exactly the same for "get a quote" and "insurance application". + * Therefore we can use hasNoSupport for both. + */ + const noSupport = hasNoSupport({ + countryRating, + esraClassification: ESRAClassificationDesc, shortTermCover, - } as MappedCisCountry; + }); - mapped.canGetAQuoteOnline = canGetAQuoteOnline({ shortTermCover, nbiIssueAvailable, esraClassification }); + const mapped: MappedCisCountry = { + countryRating, + esraClassification, + isoCode, + name: marketName, - mapped.canGetAQuoteOffline = canApplyOffline(cisCountry.shortTermCoverAvailabilityDesc); + noOnlineSupport: hasNoOnlineSupport({ + countryRating, + esraClassification: ESRAClassificationDesc, + shortTermCover, + }), - mapped.canGetAQuoteByEmail = canGetAQuoteByEmail({ shortTermCover, nbiIssueAvailable, esraClassification }); + canGetAQuoteOnline: canGetAQuoteOnline(cisCountry), - mapped.cannotGetAQuote = cannotGetAQuote({ shortTermCover, nbiIssueAvailable, esraClassification }); + cannotGetAQuote: noSupport, - mapped.canApplyForInsuranceOnline = canApplyForInsuranceOnline(shortTermCover, esraClassification); + canApplyForInsuranceOnline: canApplyForInsuranceOnline(cisCountry), - mapped.noInsuranceSupport = noInsuranceSupportAvailable(cisCountry.marketRiskAppetitePublicDesc); + noInsuranceSupport: noSupport, + }; return mapped; }; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.test.ts deleted file mode 100644 index acf131e5af..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import mapNbiIssueAvailable from '.'; -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; - -const { CIS } = EXTERNAL_API_DEFINITIONS; - -describe('helpers/map-cis-countries/map-cis-country/map-NBI-issue-available', () => { - describe(`when the NBI issue field is ${CIS.NBI_ISSUE_AVAILABLE.YES}`, () => { - it('should return true', () => { - const result = mapNbiIssueAvailable(CIS.NBI_ISSUE_AVAILABLE.YES); - - expect(result).toEqual(true); - }); - }); - - it('should return false', () => { - const result = mapNbiIssueAvailable(CIS.NBI_ISSUE_AVAILABLE.NO); - - expect(result).toEqual(false); - }); -}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.ts deleted file mode 100644 index 244908cbd5..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; - -const { CIS } = EXTERNAL_API_DEFINITIONS; - -/** - * mapNbiIssueAvailable - * Transform a countries 'NBI issue available' string to a boolean - * @param {String} NBI flag - * @returns {Boolean} - */ -const mapNbiIssueAvailable = (str: string): boolean => { - if (str === CIS.NBI_ISSUE_AVAILABLE.YES) { - return true; - } - - return false; -}; - -export default mapNbiIssueAvailable; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.test.ts index f8c666ca2c..fcab33ed61 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.test.ts @@ -4,21 +4,21 @@ import { EXTERNAL_API_DEFINITIONS, EXTERNAL_API_MAPPINGS } from '../../../../con const { CIS } = EXTERNAL_API_DEFINITIONS; describe('helpers/map-cis-countries/map-cis-country/map-esra-classification', () => { - describe(`when the risk is '${CIS.RISK.STANDARD}'`, () => { + describe(`when the risk is '${CIS.ESRA_CLASSIFICATION.STANDARD}'`, () => { it('should return simplified string', () => { - const str = CIS.RISK.STANDARD; + const str = CIS.ESRA_CLASSIFICATION.STANDARD; const result = mapEsraClassification(str); - const expected = EXTERNAL_API_MAPPINGS.CIS.RISK.STANDARD; + const expected = EXTERNAL_API_MAPPINGS.CIS.ESRA_CLASSIFICATION.STANDARD; expect(result).toEqual(expected); }); }); - describe(`when the risk is '${CIS.RISK.HIGH}'`, () => { + describe(`when the risk is '${CIS.ESRA_CLASSIFICATION.HIGH}'`, () => { it('should return the string', () => { - const str = CIS.RISK.HIGH; + const str = CIS.ESRA_CLASSIFICATION.HIGH; const result = mapEsraClassification(str); @@ -26,9 +26,9 @@ describe('helpers/map-cis-countries/map-cis-country/map-esra-classification', () }); }); - describe(`when the risk is '${CIS.RISK.VERY_HIGH}'`, () => { + describe(`when the risk is '${CIS.ESRA_CLASSIFICATION.VERY_HIGH}'`, () => { it('should return the string', () => { - const str = CIS.RISK.VERY_HIGH; + const str = CIS.ESRA_CLASSIFICATION.VERY_HIGH; const result = mapEsraClassification(str); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.ts index 322610f701..339782fdcc 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/map-esra-classification/index.ts @@ -1,6 +1,9 @@ import { EXTERNAL_API_DEFINITIONS, EXTERNAL_API_MAPPINGS } from '../../../../constants'; -const { CIS } = EXTERNAL_API_DEFINITIONS; +const { + CIS: { ESRA_CLASSIFICATION }, +} = EXTERNAL_API_DEFINITIONS; + /** * mapEsraClassification * Transform a country's ESRAClassificationDesc field into a consistent string @@ -8,15 +11,15 @@ const { CIS } = EXTERNAL_API_DEFINITIONS; * @returns {String} Consistent ESRA classification */ const mapEsraClassification = (str: string): string | null => { - if (str === CIS.RISK.STANDARD) { - return EXTERNAL_API_MAPPINGS.CIS.RISK.STANDARD; + if (str === ESRA_CLASSIFICATION.STANDARD) { + return EXTERNAL_API_MAPPINGS.CIS.ESRA_CLASSIFICATION.STANDARD; } - if (str === CIS.RISK.HIGH) { + if (str === ESRA_CLASSIFICATION.HIGH) { return str; } - if (str === CIS.RISK.VERY_HIGH) { + if (str === ESRA_CLASSIFICATION.VERY_HIGH) { return str; } diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.test.ts deleted file mode 100644 index e33ec29302..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import mapShortTermCoverAvailable from '.'; -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; - -const { - CIS: { SHORT_TERM_COVER_AVAILABLE }, -} = EXTERNAL_API_DEFINITIONS; - -describe('helpers/map-cis-countries/map-cis-country/map-short-term-cover-available', () => { - describe(`when the short term cover is ${SHORT_TERM_COVER_AVAILABLE.YES}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER_AVAILABLE.YES); - - expect(result).toEqual(true); - }); - }); - - describe(`when the short term cover is ${SHORT_TERM_COVER_AVAILABLE.ILC}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER_AVAILABLE.ILC); - - expect(result).toEqual(true); - }); - }); - - describe(`when the short term cover is ${SHORT_TERM_COVER_AVAILABLE.CILC}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER_AVAILABLE.CILC); - - expect(result).toEqual(true); - }); - }); - - describe(`when the short term cover is ${SHORT_TERM_COVER_AVAILABLE.REFER}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER_AVAILABLE.REFER); - - expect(result).toEqual(true); - }); - }); - - describe('when the short term cover is not recognised', () => { - it('should return false', () => { - const result = mapShortTermCoverAvailable('Not recognised'); - - expect(result).toEqual(false); - }); - }); -}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.ts deleted file mode 100644 index c4aa5dd5d7..0000000000 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; - -const { - CIS: { SHORT_TERM_COVER_AVAILABLE }, -} = EXTERNAL_API_DEFINITIONS; - -/** - * mapShortTermCoverAvailable - * Transform a countries 'short term cover available' string to a boolean - * @param {String} Risk category - * @returns {Boolean} - */ -const mapShortTermCoverAvailable = (str: string): boolean => { - switch (str) { - case SHORT_TERM_COVER_AVAILABLE.YES: - return true; - - case SHORT_TERM_COVER_AVAILABLE.ILC: - return true; - - case SHORT_TERM_COVER_AVAILABLE.CILC: - return true; - - case SHORT_TERM_COVER_AVAILABLE.REFER: - return true; - - default: - return false; - } -}; - -export default mapShortTermCoverAvailable; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.test.ts index 77d869090f..84985ad459 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.test.ts @@ -1,24 +1,116 @@ -import noInsuranceSupportAvailable from '.'; +import noInsuranceSupport from '.'; import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; const { - CIS: { NO_COVER }, + CIS: { + COUNTRY_RATINGS, + ESRA_CLASSIFICATION: { VERY_HIGH, HIGH, STANDARD, NONE }, + SHORT_TERM_COVER: { UNLISTED, CILC }, + }, } = EXTERNAL_API_DEFINITIONS; +const mockInitCountry = { + esraClassification: NONE, + shortTermCover: UNLISTED, +}; + +const createMockParams = (countryRating: string, esraClassification?: string, shortTermCover?: string) => { + const params = { + ...mockInitCountry, + countryRating, + }; + + if (esraClassification) { + params.esraClassification = esraClassification; + } + + if (shortTermCover) { + params.shortTermCover = shortTermCover; + } + + return params; +}; + +const params = { + firstConditions: [ + { + country: createMockParams(COUNTRY_RATINGS.A[0]), + description: 'A', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.B[0]), + description: 'B', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.C[0]), + description: 'C', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.D[0]), + description: 'D', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE), + description: 'NOT_APPLICABLE', + expectation: true, + }, + { + country: createMockParams('not recognised'), + description: 'not recognised', + expectation: false, + }, + ], + secondConditions: [ + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, STANDARD, CILC), + description: 'STANDARD', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, HIGH, CILC), + description: 'HIGH', + expectation: true, + }, + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, VERY_HIGH, CILC), + description: 'VERY_HIGH', + expectation: true, + }, + + { + country: createMockParams(COUNTRY_RATINGS.NOT_APPLICABLE, NONE, CILC), + description: 'NONE', + expectation: true, + }, + ], +}; + describe('helpers/map-CIS-countries/map-CIS-country/no-insurance-support', () => { - describe(`when marketRiskAppetitePublicDesc is ${NO_COVER}`, () => { - it('should return true', () => { - const result = noInsuranceSupportAvailable(NO_COVER); + describe(`when shortTermCover is ${UNLISTED} and esraClassification is ${NONE}`, () => { + describe.each(params.firstConditions)('', ({ country, description, expectation }) => { + describe(`when the countryRating is ${description}`, () => { + it(`should return ${expectation}`, () => { + const result = noInsuranceSupport(country); - expect(result).toEqual(true); + expect(result).toEqual(expectation); + }); + }); }); }); - describe(`when originalShortTermCover is NOT '${NO_COVER}'`, () => { - it('should return false', () => { - const result = noInsuranceSupportAvailable(''); + describe(`when shortTermCover is ${CILC} and countryRating is ${COUNTRY_RATINGS.NOT_APPLICABLE}`, () => { + describe.each(params.secondConditions)('', ({ country, description, expectation }) => { + describe(`when the esraClassification is ${description}`, () => { + it(`should return ${expectation}`, () => { + const result = noInsuranceSupport(country); - expect(result).toEqual(false); + expect(result).toEqual(expectation); + }); + }); }); }); }); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.ts index 2cfe3134ea..9b7cb2290d 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/no-insurance-support/index.ts @@ -1,13 +1,43 @@ import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; +import countryRatingIsAorB from '../country-rating-is-a-or-b'; +import countryRatingIsCorD from '../country-rating-is-c-or-d'; +import esraClassificationIsStandardHighOrVeryHigh from '../esra-classification-is-standard-high-or-very-high'; +import { NoInsuranceSupportParams } from '../../../../types'; -const { NO_COVER } = EXTERNAL_API_DEFINITIONS.CIS; +const { + CIS: { + COUNTRY_RATINGS: { NOT_APPLICABLE }, + ESRA_CLASSIFICATION: { NONE }, + SHORT_TERM_COVER: { UNLISTED, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; /** - * noInsuranceSupportAvailable - * Check if a country cannot apply for insurance - * @param {String} marketRiskAppetitePublicDesc market risk appetite definition from CIS API. + * noInsuranceSupport + * Check if a country has no insurance support (online or offline) + * @param {String} countryRating: Country rating + * @param {String} esraClassification: ESRA classification + * @param {String} shortTermCover: Short term cover * @returns {Boolean} */ -const noInsuranceSupportAvailable = (marketRiskAppetitePublicDesc: string) => marketRiskAppetitePublicDesc === NO_COVER; +const noInsuranceSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { + const shortTermCoverIsUnlisted = shortTermCover === UNLISTED; + const esraClassificationIsNone = esraClassification === NONE; + const countryRatingIsNotApplicable = countryRating === NOT_APPLICABLE; -export default noInsuranceSupportAvailable; + const countryRatingConditions = countryRatingIsAorB(countryRating) || countryRatingIsCorD(countryRating) || countryRatingIsNotApplicable; + + if (shortTermCoverIsUnlisted && esraClassificationIsNone && countryRatingConditions) { + return true; + } + + const esraClassificationConditions = esraClassificationIsStandardHighOrVeryHigh(esraClassification) || esraClassificationIsNone; + + if (shortTermCover === CILC && countryRatingIsNotApplicable && esraClassificationConditions) { + return true; + } + + return false; +}; + +export default noInsuranceSupport; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.test.ts new file mode 100644 index 0000000000..bbef254a76 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.test.ts @@ -0,0 +1,30 @@ +import shortTermCoverIsYesReferOrUnlisted from '.'; +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { + SHORT_TERM_COVER: { YES, REFER, UNLISTED, NO, ILC, CILC }, + }, +} = EXTERNAL_API_DEFINITIONS; + +describe('helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted', () => { + const validShortTermCovers = [YES, REFER, UNLISTED]; + + const invalidShortTermCovers = [NO, ILC, CILC, 'Some other shortTermCover value']; + + describe.each(validShortTermCovers)('valid short term covers', (shortTermCover) => { + it(`should return true for ${shortTermCover}`, () => { + const result = shortTermCoverIsYesReferOrUnlisted(shortTermCover); + + expect(result).toEqual(true); + }); + }); + + describe.each(invalidShortTermCovers)('invalid short term covers', (shortTermCover) => { + it(`should return false for ${shortTermCover}`, () => { + const result = shortTermCoverIsYesReferOrUnlisted(shortTermCover); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.ts new file mode 100644 index 0000000000..f1634ba038 --- /dev/null +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/short-term-cover-is-yes-refer-or-unlisted/index.ts @@ -0,0 +1,31 @@ +import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; + +const { + CIS: { + SHORT_TERM_COVER: { YES, REFER, UNLISTED }, + }, +} = EXTERNAL_API_DEFINITIONS; + +/** + * shortTermCoverIsYesReferOrUnlisted + * Check if a country's "short term cover" flag can apply for insurance online. + * @param {String} shortTermCover: Short term cover + * @returns {Boolean} + */ +const shortTermCoverIsYesReferOrUnlisted = (shortTermCover: string): boolean => { + switch (shortTermCover) { + case YES: + return true; + + case REFER: + return true; + + case UNLISTED: + return true; + + default: + return false; + } +}; + +export default shortTermCoverIsYesReferOrUnlisted; diff --git a/src/api/schema.graphql b/src/api/schema.graphql index 2a7dec1d2d..08eaf8bb76 100644 --- a/src/api/schema.graphql +++ b/src/api/schema.graphql @@ -3746,13 +3746,10 @@ type MappedCisCountry { name: String shortTermCover: Boolean esraClassification: String - nbiIssueAvailable: Boolean canGetAQuoteOnline: Boolean - canGetAQuoteOffline: Boolean - canGetAQuoteByEmail: Boolean cannotGetAQuote: Boolean - cannotApply: Boolean canApplyForInsuranceOnline: Boolean + noOnlineSupport: Boolean noInsuranceSupport: Boolean } diff --git a/src/api/test-mocks/index.ts b/src/api/test-mocks/index.ts index 00c48baf24..22ecf650dd 100644 --- a/src/api/test-mocks/index.ts +++ b/src/api/test-mocks/index.ts @@ -115,6 +115,10 @@ export const mockApplicationMultiplePolicyTotalContractValueOverThreshold = { export const mockCisCountries = cisCountries; +const [firstCisCountry] = mockCisCountries; + +export const mockCisCountry = firstCisCountry; + export const mockMappedCisCountries = mapCisCountries(mockCisCountries); export const mockCompany = company; diff --git a/src/api/test-mocks/mock-CIS-countries.ts b/src/api/test-mocks/mock-CIS-countries.ts index eb392aa123..ebaa45f172 100644 --- a/src/api/test-mocks/mock-CIS-countries.ts +++ b/src/api/test-mocks/mock-CIS-countries.ts @@ -4,25 +4,28 @@ const mockDescription = 'Mock description'; const mockCisCountries = [ { - marketName: 'Abu Dhabi', - isoCode: 'XAD', - shortTermCoverAvailabilityDesc: mockDescription, + countryRatingDesc: 'A', ESRAClassificationDesc: mockDescription, + isoCode: 'XAD', + marketName: 'Abu Dhabi', NBIIssue: '', + shortTermCoverAvailabilityDesc: mockDescription, }, { - marketName: 'Algeria', - isoCode: 'DZA', - shortTermCoverAvailabilityDesc: mockDescription, + countryRatingDesc: 'B+', ESRAClassificationDesc: mockDescription, + isoCode: 'DZA', + marketName: 'Algeria', NBIIssue: '', + shortTermCoverAvailabilityDesc: mockDescription, }, { - marketName: 'Greenland', - isoCode: 'GRL', - shortTermCoverAvailabilityDesc: mockDescription, + countryRatingDesc: 'CCC-', ESRAClassificationDesc: mockDescription, + isoCode: 'GRL', + marketName: 'Greenland', NBIIssue: '', + shortTermCoverAvailabilityDesc: mockDescription, }, ] as Array; diff --git a/src/api/test-mocks/mock-mapped-CIS-countries.ts b/src/api/test-mocks/mock-mapped-CIS-countries.ts index bae522e31d..4d7019e89e 100644 --- a/src/api/test-mocks/mock-mapped-CIS-countries.ts +++ b/src/api/test-mocks/mock-mapped-CIS-countries.ts @@ -3,11 +3,8 @@ import { MappedCisCountry } from '../types'; // mock base country that can get a quote and apply online. const baseCountry = { canGetAQuoteOnline: true, - canGetAQuoteOffline: true, - canGetAQuoteByEmail: true, cannotGetAQuote: false, canApplyForInsuranceOnline: true, - noInsuranceSupport: false, }; const mockCountries = [ diff --git a/src/api/types/country/index.ts b/src/api/types/country/index.ts index 69ee3e51d6..0f4f421aa0 100644 --- a/src/api/types/country/index.ts +++ b/src/api/types/country/index.ts @@ -2,36 +2,32 @@ import { SuccessResponse } from '../generic'; import { Relationship } from '../relationship'; export interface CisCountry { - marketName: string; - isoCode: string; - shortTermCoverAvailabilityDesc: string; + countryRatingDesc: string; ESRAClassificationDesc: string; - NBIIssue: string; + isoCode: string; + marketName: string; marketRiskAppetitePublicDesc: string; + NBIIssue: string; + esraClassification?: string; + shortTermCoverAvailabilityDesc: string; } export interface Country extends Relationship { name: string; isoCode: string; - shortTermCover?: boolean; - nbiIssueAvailable?: boolean; + esraClassification?: string; canGetAQuoteOnline?: boolean; - canGetAQuoteOffline?: boolean; - canGetAQuoteByEmail?: boolean; cannotGetAQuote?: boolean; canApplyForInsuranceOnline?: boolean; - noInsuranceSupport?: boolean; } export interface MappedCisCountry { - name: string; + countryRating: string; + esraClassification?: string | null; isoCode: string; - shortTermCover: boolean; - esraClassification?: string; - nbiIssueAvailable: boolean; + name: string; + noOnlineSupport: boolean; canGetAQuoteOnline: boolean; - canGetAQuoteOffline: boolean; - canGetAQuoteByEmail: boolean; cannotGetAQuote: boolean; canApplyForInsuranceOnline: boolean; noInsuranceSupport: boolean; diff --git a/src/api/types/helpers/index.ts b/src/api/types/helpers/index.ts index 8f8adcb331..8062f28eb4 100644 --- a/src/api/types/helpers/index.ts +++ b/src/api/types/helpers/index.ts @@ -5,6 +5,11 @@ export interface MapYesNoFieldParams { export interface MapCisCountryParams { shortTermCover: boolean; - nbiIssueAvailable: boolean; esraClassification?: string | null; } + +export interface NoInsuranceSupportParams { + countryRating: string; + esraClassification: string; + shortTermCover: string; +} diff --git a/src/ui/server/constants/routes/insurance/index.ts b/src/ui/server/constants/routes/insurance/index.ts index 1b91d3fa12..f6629fa80a 100644 --- a/src/ui/server/constants/routes/insurance/index.ts +++ b/src/ui/server/constants/routes/insurance/index.ts @@ -48,7 +48,7 @@ export const INSURANCE_ROUTES = { ELIGIBLE_TO_APPLY_ONLINE: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/eligible-to-apply-online`, HAVE_AN_ACCOUNT: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/do-you-have-an-account`, NEED_TO_START_AGAIN: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/need-to-start-again`, - CONTRACT_TOO_SHORT_EXIT: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/contract-too-short`, + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/contract-too-short`, PARTY_TO_CONSORTIUM: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/party-to-any-consortium`, PARTY_TO_CONSORTIUM_CHANGE: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/party-to-any-consortium/change`, MEMBER_OF_A_GROUP: `${INSURANCE_ROOT}${ELIGIBILITY_ROOT}/member-of-a-group`, diff --git a/src/ui/server/constants/templates/insurance/eligibility/index.ts b/src/ui/server/constants/templates/insurance/eligibility/index.ts index e20a7c99f1..5f6ac216d7 100644 --- a/src/ui/server/constants/templates/insurance/eligibility/index.ts +++ b/src/ui/server/constants/templates/insurance/eligibility/index.ts @@ -13,5 +13,5 @@ export const ELIGIBILITY_TEMPLATES = { CANNOT_APPLY_MULTIPLE_RISKS_EXIT: 'insurance/eligibility/cannot-apply-multiple-risks.njk', CHECK_YOUR_ANSWERS: 'insurance/eligibility/check-your-answers.njk', ELIGIBLE_TO_APPLY_ONLINE: 'insurance/eligibility/eligible-to-apply-online.njk', - CONTRACT_TOO_SHORT_EXIT: 'insurance/eligibility/contract-too-short.njk', + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT: 'insurance/eligibility/talk-to-an-export-finance-manager.njk', }; diff --git a/src/ui/server/content-strings/pages/insurance/eligibility/index.ts b/src/ui/server/content-strings/pages/insurance/eligibility/index.ts index 8e8bff2d0c..7669a02464 100644 --- a/src/ui/server/content-strings/pages/insurance/eligibility/index.ts +++ b/src/ui/server/content-strings/pages/insurance/eligibility/index.ts @@ -168,7 +168,7 @@ const HAVE_AN_ACCOUNT = { PAGE_TITLE: 'Do you have an account with us?', }; -const CONTRACT_TOO_SHORT_EXIT = { +const TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT = { PAGE_TITLE: 'Talk to an export finance manager', INTRO: "We do not normally offer short term cover for the country you've selected.", CONTACT_EFM: { @@ -206,7 +206,7 @@ export default { CHECK_YOUR_ANSWERS, ELIGIBLE_TO_APPLY_ONLINE, HAVE_AN_ACCOUNT, - CONTRACT_TOO_SHORT_EXIT, + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, PARTY_TO_CONSORTIUM, MEMBER_OF_A_GROUP, MEMBER_OF_A_GROUP_EXIT, diff --git a/src/ui/server/controllers/insurance/eligibility/buyer-country/country-redirects.test.ts b/src/ui/server/controllers/insurance/eligibility/buyer-country/country-redirects.test.ts index 132098e347..2021d57338 100644 --- a/src/ui/server/controllers/insurance/eligibility/buyer-country/country-redirects.test.ts +++ b/src/ui/server/controllers/insurance/eligibility/buyer-country/country-redirects.test.ts @@ -7,19 +7,25 @@ import getCountryByIsoCode from '../../../../helpers/get-country-by-iso-code'; import mapSubmittedEligibilityCountry from '../../../../helpers/mappings/map-submitted-eligibility-country'; import { updateSubmittedData } from '../../../../helpers/update-submitted-data/insurance'; import { Request, Response } from '../../../../../types'; -import { mockReq, mockRes, mockCountries } from '../../../../test-mocks'; +import { + mockReq, + mockRes, + mockCountries, + mockCountryCanApplyForInsuranceOnline, + mockCountryNoInsuranceSupport, + mockCountryNoOnlineSupport, +} from '../../../../test-mocks'; const { - ELIGIBILITY: { CANNOT_APPLY_EXIT: CANNOT_APPLY_ROUTE, TOTAL_VALUE_INSURED, BUYER_COUNTRY_CHANGE, CHECK_YOUR_ANSWERS, CONTRACT_TOO_SHORT_EXIT }, + ELIGIBILITY: { CANNOT_APPLY_EXIT: CANNOT_APPLY_ROUTE, TOTAL_VALUE_INSURED, BUYER_COUNTRY_CHANGE, CHECK_YOUR_ANSWERS, TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT }, } = INSURANCE_ROUTES; +let mockCountriesResponse = mockCountries; + describe('controllers/insurance/eligibility/buyer-country - redirects', () => { let req: Request; let res: Response; - let mockCountriesResponse = mockCountries; - - const { 1: countryApplyOnline, 4: countryCannotApply, 5: countryNoShortTermCover } = mockCountriesResponse; const mockFlash = jest.fn(); beforeEach(() => { @@ -40,7 +46,7 @@ describe('controllers/insurance/eligibility/buyer-country - redirects', () => { api.keystone.APIM.getCisCountries = getCisCountriesSpy; }); - describe('when the submitted country is not found', () => { + describe('when the country is not found', () => { beforeEach(() => { req.body[FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY] = 'Country not in the mock response'; }); @@ -52,27 +58,23 @@ describe('controllers/insurance/eligibility/buyer-country - redirects', () => { }); }); - describe('when the country can apply for an application online', () => { - const selectedCountryIsoCode = countryApplyOnline.isoCode; - - const validBody = { - [FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY]: selectedCountryIsoCode, - }; + describe('when the API returns a noOnlineSupport flag for the submitted country', () => { + const selectedCountryName = mockCountryNoOnlineSupport.isoCode; beforeEach(() => { - req.body = validBody; - - mockCountriesResponse = [countryApplyOnline]; + mockCountriesResponse = [mockCountryNoOnlineSupport]; getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); api.keystone.APIM.getCisCountries = getCisCountriesSpy; + + req.body[FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY] = selectedCountryName; }); - it('should update the session with populated with country object', async () => { + it('should update the session with populated country object', async () => { await post(req, res); - const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); + const selectedCountry = getCountryByIsoCode(mockCountriesResponse, mockCountryNoOnlineSupport.isoCode); const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); @@ -84,41 +86,34 @@ describe('controllers/insurance/eligibility/buyer-country - redirects', () => { expect(req.session.submittedData).toEqual(expected); }); - it(`should redirect to ${TOTAL_VALUE_INSURED}`, async () => { + it(`should redirect to ${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT}`, async () => { await post(req, res); - expect(res.redirect).toHaveBeenCalledWith(TOTAL_VALUE_INSURED); - }); - - describe("when the url's last substring is `change`", () => { - it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { - req.originalUrl = BUYER_COUNTRY_CHANGE; - - await post(req, res); - - const expected = CHECK_YOUR_ANSWERS; - expect(res.redirect).toHaveBeenCalledWith(expected); - }); + expect(res.redirect).toHaveBeenCalledWith(TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); }); }); - describe('when the submitted country does not have short term cover', () => { - const selectedCountryName = countryNoShortTermCover.isoCode; + describe('when the API returns a canApplyForInsuranceOnline flag for the submitted country', () => { + const selectedCountryIsoCode = mockCountryCanApplyForInsuranceOnline.isoCode; - beforeEach(() => { - req.body[FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY] = selectedCountryName; + const validBody = { + [FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY]: selectedCountryIsoCode, + }; - mockCountriesResponse = [countryNoShortTermCover]; + beforeEach(() => { + mockCountriesResponse = [mockCountryCanApplyForInsuranceOnline]; getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); api.keystone.APIM.getCisCountries = getCisCountriesSpy; + + req.body = validBody; }); - it('should update the session with populated country object', async () => { + it('should update the session with populated with country object', async () => { await post(req, res); - const selectedCountry = getCountryByIsoCode(mockCountriesResponse, countryNoShortTermCover.isoCode); + const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); @@ -130,25 +125,36 @@ describe('controllers/insurance/eligibility/buyer-country - redirects', () => { expect(req.session.submittedData).toEqual(expected); }); - it(`should redirect to ${CONTRACT_TOO_SHORT_EXIT}`, async () => { + it(`should redirect to ${TOTAL_VALUE_INSURED}`, async () => { await post(req, res); - expect(res.redirect).toHaveBeenCalledWith(CONTRACT_TOO_SHORT_EXIT); + expect(res.redirect).toHaveBeenCalledWith(TOTAL_VALUE_INSURED); + }); + + describe("when the url's last substring is `change`", () => { + it(`should redirect to ${CHECK_YOUR_ANSWERS}`, async () => { + req.originalUrl = BUYER_COUNTRY_CHANGE; + + await post(req, res); + + const expected = CHECK_YOUR_ANSWERS; + expect(res.redirect).toHaveBeenCalledWith(expected); + }); }); }); - describe('when the submitted country cannot apply for an application', () => { - const selectedCountryName = countryCannotApply.name; - const selectedCountryIsoCode = countryCannotApply.isoCode; + describe('when the API returns a noInsuranceSupport flag for the submitted country', () => { + const selectedCountryName = mockCountryNoInsuranceSupport.name; + const selectedCountryIsoCode = mockCountryNoInsuranceSupport.isoCode; beforeEach(() => { - req.body[FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY] = selectedCountryIsoCode; - - mockCountriesResponse = [countryCannotApply]; + mockCountriesResponse = [mockCountryNoInsuranceSupport]; getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); api.keystone.APIM.getCisCountries = getCisCountriesSpy; + + req.body[FIELD_IDS.ELIGIBILITY.BUYER_COUNTRY] = selectedCountryIsoCode; }); it('should update the session with populated with country object', async () => { diff --git a/src/ui/server/controllers/insurance/eligibility/buyer-country/index.ts b/src/ui/server/controllers/insurance/eligibility/buyer-country/index.ts index 6f7751d311..dab547192e 100644 --- a/src/ui/server/controllers/insurance/eligibility/buyer-country/index.ts +++ b/src/ui/server/controllers/insurance/eligibility/buyer-country/index.ts @@ -25,7 +25,7 @@ export const TEMPLATE = TEMPLATES.SHARED_PAGES.BUYER_COUNTRY; const { PROBLEM_WITH_SERVICE, - ELIGIBILITY: { CANNOT_APPLY_EXIT: CANNOT_APPLY_ROUTE, TOTAL_VALUE_INSURED, CHECK_YOUR_ANSWERS, CONTRACT_TOO_SHORT_EXIT }, + ELIGIBILITY: { CANNOT_APPLY_EXIT: CANNOT_APPLY_ROUTE, TOTAL_VALUE_INSURED, CHECK_YOUR_ANSWERS, TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT }, } = INSURANCE_ROUTES; export const get = async (req: Request, res: Response) => { @@ -91,12 +91,12 @@ export const post = async (req: Request, res: Response) => { } /** - * If a country has no insurance support and no short term cover, - * redirect to CONTRACT_TOO_SHORT_EXIT. + * If a country does not have online insurance support, + * redirect to a specific exit page. */ - const noShortTermCover = !country.noInsuranceSupport && !country.shortTermCover; + if (country.noOnlineSupport) { + console.info('Country support - %s - no online insurance support available', country.name); - if (noShortTermCover) { const populatedData = mapSubmittedEligibilityCountry(country); req.session.submittedData = { @@ -104,10 +104,16 @@ export const post = async (req: Request, res: Response) => { insuranceEligibility: updateSubmittedData(populatedData, req.session.submittedData.insuranceEligibility), }; - return res.redirect(CONTRACT_TOO_SHORT_EXIT); + return res.redirect(TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); } + /** + * If a country can apply for insurance online, + * redirect to the next page. + */ if (country.canApplyForInsuranceOnline) { + console.info('Country support - %s - can apply for insurance online', country.name); + const populatedData = mapSubmittedEligibilityCountry(country); req.session.submittedData = { @@ -122,7 +128,13 @@ export const post = async (req: Request, res: Response) => { return res.redirect(TOTAL_VALUE_INSURED); } + /** + * If a country has no online support + * redirect to a specific exit page. + */ if (country.noInsuranceSupport) { + console.info('Country support - %s - no insurance support', country.name); + const populatedData = mapSubmittedEligibilityCountry(country); req.session.submittedData = { @@ -139,6 +151,10 @@ export const post = async (req: Request, res: Response) => { return res.redirect(CANNOT_APPLY_ROUTE); } + + console.info('Country support - %s - unable to determine country support', country.name); + + return res.redirect(PROBLEM_WITH_SERVICE); } catch (error) { console.error('Error posting insurance - eligibility - buyer-country %o', error); diff --git a/src/ui/server/controllers/insurance/eligibility/contract-too-short/index.test.ts b/src/ui/server/controllers/insurance/eligibility/talk-to-an-export-finance-manager/index.test.ts similarity index 77% rename from src/ui/server/controllers/insurance/eligibility/contract-too-short/index.test.ts rename to src/ui/server/controllers/insurance/eligibility/talk-to-an-export-finance-manager/index.test.ts index 1fd6403b19..c73433ec0e 100644 --- a/src/ui/server/controllers/insurance/eligibility/contract-too-short/index.test.ts +++ b/src/ui/server/controllers/insurance/eligibility/talk-to-an-export-finance-manager/index.test.ts @@ -6,7 +6,7 @@ import getUserNameFromSession from '../../../../helpers/get-user-name-from-sessi import { mockReq, mockRes } from '../../../../test-mocks'; import { Request, Response } from '../../../../../types'; -describe('controllers/insurance/eligibility/contract-too-short', () => { +describe('controllers/insurance/eligibility/talk-to-an-export-finance-manager', () => { let req: Request; let res: Response; @@ -17,7 +17,7 @@ describe('controllers/insurance/eligibility/contract-too-short', () => { describe('TEMPLATE', () => { it('should have the correct template defined', () => { - expect(TEMPLATE).toEqual(TEMPLATES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT); + expect(TEMPLATE).toEqual(TEMPLATES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT); }); }); @@ -27,7 +27,7 @@ describe('controllers/insurance/eligibility/contract-too-short', () => { const expectedVariables = { ...corePageVariables({ - PAGE_CONTENT_STRINGS: PAGES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT, + PAGE_CONTENT_STRINGS: PAGES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, BACK_LINK: req.headers.referer, }), userName: getUserNameFromSession(req.session.user), diff --git a/src/ui/server/controllers/insurance/eligibility/contract-too-short/index.ts b/src/ui/server/controllers/insurance/eligibility/talk-to-an-export-finance-manager/index.ts similarity index 65% rename from src/ui/server/controllers/insurance/eligibility/contract-too-short/index.ts rename to src/ui/server/controllers/insurance/eligibility/talk-to-an-export-finance-manager/index.ts index d60848344b..510a07c1db 100644 --- a/src/ui/server/controllers/insurance/eligibility/contract-too-short/index.ts +++ b/src/ui/server/controllers/insurance/eligibility/talk-to-an-export-finance-manager/index.ts @@ -4,19 +4,19 @@ import { Request, Response } from '../../../../../types'; import corePageVariables from '../../../../helpers/page-variables/core/insurance'; import getUserNameFromSession from '../../../../helpers/get-user-name-from-session'; -export const TEMPLATE = TEMPLATES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT; +export const TEMPLATE = TEMPLATES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT; /** * get - * Render the "Talk to EFM - contract too short" exit page + * Render the "Talk to an export finance manager" exit page * @param {Express.Request} Express request * @param {Express.Response} Express response - * @returns {Express.Response.render} "Talk to EFM - contract too short" exit page + * @returns {Express.Response.render} "Talk to an export finance manager" exit page */ export const get = (req: Request, res: Response) => res.render(TEMPLATE, { ...corePageVariables({ - PAGE_CONTENT_STRINGS: PAGES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT, + PAGE_CONTENT_STRINGS: PAGES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, BACK_LINK: req.headers.referer, }), userName: getUserNameFromSession(req.session.user), diff --git a/src/ui/server/controllers/quote/buyer-country/country-redirects.test.ts b/src/ui/server/controllers/quote/buyer-country/country-redirects.test.ts new file mode 100644 index 0000000000..714d76c982 --- /dev/null +++ b/src/ui/server/controllers/quote/buyer-country/country-redirects.test.ts @@ -0,0 +1,198 @@ +import { FIELD_ID, post } from '.'; +import { PAGES } from '../../../content-strings'; +import { ROUTES } from '../../../constants'; +import getCountryByIsoCode from '../../../helpers/get-country-by-iso-code'; +import mapSubmittedEligibilityCountry from '../../../helpers/mappings/map-submitted-eligibility-country'; +import api from '../../../api'; +import { updateSubmittedData } from '../../../helpers/update-submitted-data/quote'; +import { + mockReq, + mockRes, + mockCountries, + mockCountryCannotGetAQuote, + mockCountryCanGetAQuoteOnline, + mockCountryCanGetAQuoteByEmail, +} from '../../../test-mocks'; +import { Request, Response } from '../../../../types'; + +let mockCountriesResponse = mockCountries; + +describe('controllers/quote/buyer-country - redirects', () => { + let req: Request; + let res: Response; + + const mockFlash = jest.fn(); + + beforeEach(() => { + req = mockReq(); + req.flash = mockFlash; + + res = mockRes(); + }); + + afterAll(() => { + jest.resetAllMocks(); + }); + + describe('post', () => { + let getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); + + beforeEach(() => { + api.keystone.APIM.getCisCountries = getCisCountriesSpy; + }); + + describe('when the submitted country is not found', () => { + beforeEach(() => { + req.body[FIELD_ID] = 'Country not in the mock response'; + }); + + it(`should redirect to ${ROUTES.QUOTE.CANNOT_APPLY_EXIT}`, async () => { + await post(req, res); + + expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.CANNOT_APPLY_EXIT); + }); + }); + + describe('when the API returns a canGetAQuoteOnline flag for the submitted country', () => { + const selectedCountryIsoCode = mockCountryCanGetAQuoteOnline.isoCode; + + beforeEach(() => { + jest.resetAllMocks(); + + mockCountriesResponse = [mockCountryCanGetAQuoteOnline]; + + getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); + + api.keystone.APIM.getCisCountries = getCisCountriesSpy; + + req.body[FIELD_ID] = selectedCountryIsoCode; + }); + + it('should update the session with submitted data, populated with country object', async () => { + await post(req, res); + + const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); + + const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); + + const expected = updateSubmittedData(expectedPopulatedData, req.session.submittedData.quoteEligibility); + + expect(req.session.submittedData.quoteEligibility).toEqual(expected); + }); + + it(`should redirect to ${ROUTES.QUOTE.BUYER_BODY}`, async () => { + await post(req, res); + + expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.BUYER_BODY); + }); + + describe("when the url's last substring is `change`", () => { + it(`should redirect to ${ROUTES.QUOTE.CHECK_YOUR_ANSWERS}`, async () => { + req.originalUrl = 'mock/change'; + + await post(req, res); + + expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.CHECK_YOUR_ANSWERS); + }); + }); + }); + + describe('when the API returns a noOnlineSupport flag for the submitted country', () => { + const selectedCountryIsoCode = mockCountryCanGetAQuoteByEmail.isoCode; + + beforeEach(() => { + jest.resetAllMocks(); + + mockCountriesResponse = [mockCountryCanGetAQuoteByEmail]; + + getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); + + api.keystone.APIM.getCisCountries = getCisCountriesSpy; + + req.body[FIELD_ID] = mockCountryCanGetAQuoteByEmail.isoCode; + }); + + it('should update the session with submitted data, populated with country object', async () => { + await post(req, res); + + const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); + + const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); + + const expected = updateSubmittedData(expectedPopulatedData, req.session.submittedData.quoteEligibility); + + expect(req.session.submittedData.quoteEligibility).toEqual(expected); + }); + + it('should add previousRoute, exitReason and exitDescription to req.flash', async () => { + await post(req, res); + + expect(mockFlash).toHaveBeenCalledTimes(3); + + expect(mockFlash.mock.calls[0]).toEqual(['previousRoute', ROUTES.QUOTE.BUYER_COUNTRY]); + + const { GET_A_QUOTE_BY_EMAIL } = PAGES.QUOTE; + const { REASON } = GET_A_QUOTE_BY_EMAIL; + + expect(mockFlash.mock.calls[1]).toEqual(['exitReason', REASON.BUYER_COUNTRY]); + expect(mockFlash.mock.calls[2]).toEqual(['exitDescription', REASON.BUYER_COUNTRY_DESCRIPTION]); + }); + + it(`should redirect to ${ROUTES.QUOTE.GET_A_QUOTE_BY_EMAIL}`, async () => { + await post(req, res); + + expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.GET_A_QUOTE_BY_EMAIL); + }); + }); + + describe('when the API returns a cannotGetAQuote flag for the submitted country', () => { + const selectedCountryName = mockCountryCannotGetAQuote.name; + const selectedCountryIsoCode = mockCountryCannotGetAQuote.isoCode; + + beforeEach(() => { + jest.resetAllMocks(); + + mockCountriesResponse = [mockCountryCannotGetAQuote]; + + getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); + + api.keystone.APIM.getCisCountries = getCisCountriesSpy; + + req.body[FIELD_ID] = selectedCountryIsoCode; + }); + + it('should update the session with submitted data, populated with country object', async () => { + await post(req, res); + + const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); + + const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); + + const expected = updateSubmittedData(expectedPopulatedData, req.session.submittedData.quoteEligibility); + + expect(req.session.submittedData.quoteEligibility).toEqual(expected); + }); + + it('should add previousRoute and exitReason to req.flash', async () => { + await post(req, res); + + expect(req.flash).toHaveBeenCalledWith('previousRoute', ROUTES.QUOTE.BUYER_COUNTRY); + + const countryName = selectedCountryName; + + const { CANNOT_APPLY_EXIT } = PAGES; + const { REASON } = CANNOT_APPLY_EXIT; + + const expectedReason = `${REASON.UNSUPPORTED_BUYER_COUNTRY_1} ${countryName}, ${REASON.UNSUPPORTED_BUYER_COUNTRY_2}`; + + expect(req.flash).toHaveBeenCalledWith('exitReason', expectedReason); + }); + + it(`should redirect to ${ROUTES.QUOTE.CANNOT_APPLY_EXIT}`, async () => { + await post(req, res); + + expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.CANNOT_APPLY_EXIT); + }); + }); + }); +}); diff --git a/src/ui/server/controllers/quote/buyer-country/index.test.ts b/src/ui/server/controllers/quote/buyer-country/index.test.ts index 04f7a7f02b..b2eaca2808 100644 --- a/src/ui/server/controllers/quote/buyer-country/index.test.ts +++ b/src/ui/server/controllers/quote/buyer-country/index.test.ts @@ -6,11 +6,8 @@ import getUserNameFromSession from '../../../helpers/get-user-name-from-session' import constructPayload from '../../../helpers/construct-payload'; import { validation as generateValidationErrors } from '../../../shared-validation/buyer-country'; import isChangeRoute from '../../../helpers/is-change-route'; -import getCountryByIsoCode from '../../../helpers/get-country-by-iso-code'; -import mapSubmittedEligibilityCountry from '../../../helpers/mappings/map-submitted-eligibility-country'; import api from '../../../api'; import mapCountries from '../../../helpers/mappings/map-countries'; -import { updateSubmittedData } from '../../../helpers/update-submitted-data/quote'; import { mockReq, mockRes, mockCountries, mockSpyPromiseRejection } from '../../../test-mocks'; import { Request, Response } from '../../../../types'; @@ -18,10 +15,6 @@ describe('controllers/quote/buyer-country', () => { let req: Request; let res: Response; - let mockCountriesResponse = mockCountries; - - const { 0: countryUnsupported, 1: countryQuoteOnline, 2: countryQuoteByEmail } = mockCountriesResponse; - const mockFlash = jest.fn(); beforeEach(() => { @@ -106,7 +99,7 @@ describe('controllers/quote/buyer-country', () => { }); describe('get', () => { - let getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); + let getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountries)); beforeEach(() => { api.keystone.APIM.getCisCountries = getCisCountriesSpy; @@ -124,7 +117,7 @@ describe('controllers/quote/buyer-country', () => { const expectedVariables = { ...singleInputPageVariables({ ...PAGE_VARIABLES, BACK_LINK: getBackLink(req.headers.referer), ORIGINAL_URL: req.originalUrl }), userName: getUserNameFromSession(req.session.user), - countries: mapCountries(mockCountriesResponse, req.session.submittedData.quoteEligibility[FIELD_ID]?.isoCode), + countries: mapCountries(mockCountries, req.session.submittedData.quoteEligibility[FIELD_ID]?.isoCode), submittedValues: req.session.submittedData.quoteEligibility, isChangeRoute: isChangeRoute(req.originalUrl), }; @@ -197,7 +190,7 @@ describe('controllers/quote/buyer-country', () => { }); describe('post', () => { - let getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); + let getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountries)); beforeEach(() => { api.keystone.APIM.getCisCountries = getCisCountriesSpy; @@ -212,167 +205,18 @@ describe('controllers/quote/buyer-country', () => { expect(res.render).toHaveBeenCalledWith(TEMPLATES.SHARED_PAGES.BUYER_COUNTRY, { ...singleInputPageVariables({ ...PAGE_VARIABLES, BACK_LINK: getBackLink(req.headers.referer), ORIGINAL_URL: req.originalUrl }), userName: getUserNameFromSession(req.session.user), - countries: mapCountries(mockCountriesResponse), + countries: mapCountries(mockCountries), validationErrors: generateValidationErrors(payload), isChangeRoute: isChangeRoute(req.originalUrl), }); }); }); - describe('when the submitted country can only get a quote via email', () => { - const selectedCountryisoCode = countryQuoteByEmail.isoCode; - - mockCountriesResponse = [countryQuoteByEmail]; - - getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); - - beforeEach(() => { - req.body[FIELD_ID] = countryQuoteByEmail.isoCode; - }); - - it('should update the session with submitted data, populated with country object', async () => { - await post(req, res); - - const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryisoCode); - - const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); - - const expected = updateSubmittedData(expectedPopulatedData, req.session.submittedData.quoteEligibility); - - expect(req.session.submittedData.quoteEligibility).toEqual(expected); - }); - - it('should add previousRoute, exitReason and exitDescription to req.flash', async () => { - await post(req, res); - - expect(mockFlash).toHaveBeenCalledTimes(3); - - expect(mockFlash.mock.calls[0]).toEqual(['previousRoute', ROUTES.QUOTE.BUYER_COUNTRY]); - - const { GET_A_QUOTE_BY_EMAIL } = PAGES.QUOTE; - const { REASON } = GET_A_QUOTE_BY_EMAIL; - - expect(mockFlash.mock.calls[1]).toEqual(['exitReason', REASON.BUYER_COUNTRY]); - expect(mockFlash.mock.calls[2]).toEqual(['exitDescription', REASON.BUYER_COUNTRY_DESCRIPTION]); - }); - - it(`should redirect to ${ROUTES.QUOTE.GET_A_QUOTE_BY_EMAIL}`, async () => { - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.GET_A_QUOTE_BY_EMAIL); - }); - }); - - describe('when the submitted country is not found', () => { - beforeEach(() => { - req.body[FIELD_ID] = 'Country not in the mock response'; - }); - - it(`should redirect to ${ROUTES.QUOTE.CANNOT_APPLY_EXIT}`, async () => { - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.CANNOT_APPLY_EXIT); - }); - }); - - describe('when the submitted country is not supported', () => { - const selectedCountryName = countryUnsupported.name; - const selectedCountryIsoCode = countryUnsupported.isoCode; - - beforeEach(() => { - req.body[FIELD_ID] = selectedCountryIsoCode; - - mockCountriesResponse = [countryUnsupported]; - - getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); - - api.keystone.APIM.getCisCountries = getCisCountriesSpy; - }); - - it('should update the session with submitted data, populated with country object', async () => { - await post(req, res); - - const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); - - const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); - - const expected = updateSubmittedData(expectedPopulatedData, req.session.submittedData.quoteEligibility); - - expect(req.session.submittedData.quoteEligibility).toEqual(expected); - }); - - it('should add previousRoute and exitReason to req.flash', async () => { - await post(req, res); - - expect(req.flash).toHaveBeenCalledWith('previousRoute', ROUTES.QUOTE.BUYER_COUNTRY); - - const countryName = selectedCountryName; - - const { CANNOT_APPLY_EXIT } = PAGES; - const { REASON } = CANNOT_APPLY_EXIT; - - const expectedReason = `${REASON.UNSUPPORTED_BUYER_COUNTRY_1} ${countryName}, ${REASON.UNSUPPORTED_BUYER_COUNTRY_2}`; - - expect(req.flash).toHaveBeenCalledWith('exitReason', expectedReason); - }); - - it(`should redirect to ${ROUTES.QUOTE.CANNOT_APPLY_EXIT}`, async () => { - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.CANNOT_APPLY_EXIT); - }); - }); - - describe('when the country is supported for an online quote and there are no validation errors', () => { - const selectedCountryIsoCode = countryQuoteOnline.isoCode; - - const validBody = { - [FIELD_ID]: selectedCountryIsoCode, - }; - - beforeEach(() => { - req.body = validBody; - - mockCountriesResponse = [countryQuoteOnline]; - - getCisCountriesSpy = jest.fn(() => Promise.resolve(mockCountriesResponse)); - - api.keystone.APIM.getCisCountries = getCisCountriesSpy; - }); - - it('should update the session with submitted data, populated with country object', async () => { - await post(req, res); - - const selectedCountry = getCountryByIsoCode(mockCountriesResponse, selectedCountryIsoCode); - - const expectedPopulatedData = mapSubmittedEligibilityCountry(selectedCountry); - - const expected = updateSubmittedData(expectedPopulatedData, req.session.submittedData.quoteEligibility); - - expect(req.session.submittedData.quoteEligibility).toEqual(expected); - }); - - it(`should redirect to ${ROUTES.QUOTE.BUYER_BODY}`, async () => { - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.BUYER_BODY); - }); - - describe("when the url's last substring is `change`", () => { - it(`should redirect to ${ROUTES.QUOTE.CHECK_YOUR_ANSWERS}`, async () => { - req.originalUrl = 'mock/change'; - - await post(req, res); - - expect(res.redirect).toHaveBeenCalledWith(ROUTES.QUOTE.CHECK_YOUR_ANSWERS); - }); - }); - }); - describe('api error handling', () => { describe('when the get CIS countries API call fails', () => { beforeEach(() => { getCisCountriesSpy = mockSpyPromiseRejection; + api.keystone.APIM.getCisCountries = getCisCountriesSpy; }); @@ -386,6 +230,7 @@ describe('controllers/quote/buyer-country', () => { describe('when the get CIS countries API call does not return a populated array', () => { beforeEach(() => { getCisCountriesSpy = jest.fn(() => Promise.resolve([])); + api.keystone.APIM.getCisCountries = getCisCountriesSpy; }); diff --git a/src/ui/server/controllers/quote/buyer-country/index.ts b/src/ui/server/controllers/quote/buyer-country/index.ts index dedee1355a..5b19832c9b 100644 --- a/src/ui/server/controllers/quote/buyer-country/index.ts +++ b/src/ui/server/controllers/quote/buyer-country/index.ts @@ -121,7 +121,13 @@ export const post = async (req: Request, res: Response) => { return res.redirect(ROUTES.QUOTE.CANNOT_APPLY_EXIT); } + /** + * If a country cannot get a quote online, + * redirect to a specific exit page. + */ if (country.canGetAQuoteOnline) { + console.info('Country support - %s - can get a quote online', country.name); + const populatedData = mapSubmittedEligibilityCountry(country); req.session.submittedData.quoteEligibility = updateSubmittedData(populatedData, req.session.submittedData.quoteEligibility); @@ -133,7 +139,13 @@ export const post = async (req: Request, res: Response) => { return res.redirect(ROUTES.QUOTE.BUYER_BODY); } - if (country.canGetAQuoteByEmail) { + /** + * If a country has no online support, + * redirect to a specific exit page. + */ + if (country.noOnlineSupport) { + console.info('Country support - %s - can get a quote by email', country.name); + const populatedData = mapSubmittedEligibilityCountry(country); req.session.submittedData.quoteEligibility = updateSubmittedData(populatedData, req.session.submittedData.quoteEligibility); @@ -149,7 +161,13 @@ export const post = async (req: Request, res: Response) => { return res.redirect(ROUTES.QUOTE.GET_A_QUOTE_BY_EMAIL); } + /** + * If a country cannot get a quote, + * redirect to a specific exit page. + */ if (country.cannotGetAQuote) { + console.info('Country support - %s - cannot a quote', country.name); + const populatedData = mapSubmittedEligibilityCountry(country); req.session.submittedData.quoteEligibility = updateSubmittedData(populatedData, req.session.submittedData.quoteEligibility); @@ -165,6 +183,10 @@ export const post = async (req: Request, res: Response) => { return res.redirect(ROUTES.QUOTE.CANNOT_APPLY_EXIT); } + + console.info('Country support - %s - unable to determine country support', country.name); + + return res.redirect(ROUTES.PROBLEM_WITH_SERVICE); } catch (error) { console.error('Error getting CIS countries %o', error); diff --git a/src/ui/server/generate-quote/get-premium-rate/index.test.ts b/src/ui/server/generate-quote/get-premium-rate/index.test.ts index 319367545b..a35952dff9 100644 --- a/src/ui/server/generate-quote/get-premium-rate/index.test.ts +++ b/src/ui/server/generate-quote/get-premium-rate/index.test.ts @@ -3,9 +3,9 @@ import { EXTERNAL_API_MAPPINGS, FIELD_VALUES } from '../../constants'; import PRICING_GRID from '../pricing-grid.json'; import { PricingGridMonth, PricingGridRate } from '../../../types'; -const expectedPremiumRate = (policyType: string, riskCategory: string, totalMonths: number, insuredFor: number) => { +const expectedPremiumRate = (policyType: string, esraClassification: string, totalMonths: number, insuredFor: number) => { const mappedPolicyType = PRICING_GRID_MAP.POLICY_TYPE[policyType]; - const mappedRiskCategory = PRICING_GRID_MAP.RISK_CATEGORY[riskCategory]; + const mappedRiskCategory = PRICING_GRID_MAP.RISK_CATEGORY[esraClassification]; const risk = PRICING_GRID[mappedPolicyType][mappedRiskCategory]; @@ -18,10 +18,10 @@ const expectedPremiumRate = (policyType: string, riskCategory: string, totalMont return expected; }; -const getResultAndExpected = (policyType: string, riskCategory: string, totalMonths: number, insuredFor: number) => { - const result = getPremiumRate(policyType, riskCategory, totalMonths, insuredFor); +const getResultAndExpected = (policyType: string, esraClassification: string, totalMonths: number, insuredFor: number) => { + const result = getPremiumRate(policyType, esraClassification, totalMonths, insuredFor); - const expected = expectedPremiumRate(policyType, riskCategory, totalMonths, insuredFor); + const expected = expectedPremiumRate(policyType, esraClassification, totalMonths, insuredFor); return { result, @@ -40,7 +40,7 @@ describe('server/generate-quote/get-premium-rate', () => { totalMonths: 2, }; - it('returns a number', () => { + it('should return a number', () => { const result = getPremiumRate(mock.policyType, mock.esraClassification, mock.totalMonths, mock.insuredFor); expect(typeof result).toEqual('number'); diff --git a/src/ui/server/graphql/queries/APIM/CIS-countries.ts b/src/ui/server/graphql/queries/APIM/CIS-countries.ts index f155b38aac..414956fc8d 100644 --- a/src/ui/server/graphql/queries/APIM/CIS-countries.ts +++ b/src/ui/server/graphql/queries/APIM/CIS-countries.ts @@ -7,13 +7,10 @@ const getApimCisCountries = gql` name esraClassification canGetAQuoteOnline - canGetAQuoteOffline - canGetAQuoteByEmail cannotGetAQuote - cannotApply canApplyForInsuranceOnline + noOnlineSupport noInsuranceSupport - shortTermCover } } `; diff --git a/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.test.ts b/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.test.ts index ec191007b1..40348c82ac 100644 --- a/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.test.ts +++ b/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.test.ts @@ -36,7 +36,7 @@ const { COMPANY_DETAILS_CHANGE, CANNOT_APPLY_MULTIPLE_RISKS_EXIT, ELIGIBLE_TO_APPLY_ONLINE, - CONTRACT_TOO_SHORT_EXIT, + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, PARTY_TO_CONSORTIUM, PARTY_TO_CONSORTIUM_CHANGE, MEMBER_OF_A_GROUP, @@ -156,9 +156,9 @@ describe('middleware/required-data-provided/insurance/eligibility', () => { }); }); - describe(`when req.originalUrl is ${CONTRACT_TOO_SHORT_EXIT}`, () => { + describe(`when req.originalUrl is ${TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT}`, () => { it('should call req.next', () => { - req.originalUrl = CONTRACT_TOO_SHORT_EXIT; + req.originalUrl = TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT; requiredInsuranceEligibilityDataProvided(req, res, nextSpy); expect(nextSpy).toHaveBeenCalled(); diff --git a/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.ts b/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.ts index d6ad878b34..74c267689f 100644 --- a/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.ts +++ b/src/ui/server/middleware/required-data-provided/insurance/eligibility/index.ts @@ -35,7 +35,7 @@ const { COMPANY_DETAILS_CHANGE, CANNOT_APPLY_MULTIPLE_RISKS_EXIT, ELIGIBLE_TO_APPLY_ONLINE, - CONTRACT_TOO_SHORT_EXIT, + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, PARTY_TO_CONSORTIUM, PARTY_TO_CONSORTIUM_CHANGE, MEMBER_OF_A_GROUP, @@ -137,7 +137,7 @@ export const requiredInsuranceEligibilityDataProvided = (req: Request, res: Resp HAVE_AN_ACCOUNT, ACCOUNT.CREATE.YOUR_DETAILS, ACCOUNT.SIGN_IN.ROOT, - CONTRACT_TOO_SHORT_EXIT, + TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, MEMBER_OF_A_GROUP_EXIT, PARTY_TO_CONSORTIUM_EXIT, ]; diff --git a/src/ui/server/routes/insurance/eligibility/index.test.ts b/src/ui/server/routes/insurance/eligibility/index.test.ts index 6b7bab8284..ab4f93c4fd 100644 --- a/src/ui/server/routes/insurance/eligibility/index.test.ts +++ b/src/ui/server/routes/insurance/eligibility/index.test.ts @@ -22,7 +22,7 @@ import { get as eligibleToApplyOnlineGet, post as eligibleToApplyOnlinePost } fr import { get as haveAnAccountGet, post as haveAnAccountPost } from '../../../controllers/insurance/eligibility/do-you-have-an-account'; import { get as cannotApplyGet } from '../../../controllers/insurance/eligibility/cannot-apply'; import { get as needToStartAgainGet, post as needToStartAgainPost } from '../../../controllers/insurance/eligibility/need-to-start-again'; -import { get as contractTooShortGet } from '../../../controllers/insurance/eligibility/contract-too-short'; +import { get as contractTooShortGet } from '../../../controllers/insurance/eligibility/talk-to-an-export-finance-manager'; import { get as partyToConsortiumExitGet } from '../../../controllers/insurance/eligibility/party-to-consortium-exit'; import { get as memberOfAGroupExitGet } from '../../../controllers/insurance/eligibility/member-of-a-group-exit'; @@ -102,7 +102,7 @@ describe('routes/insurance/eligibility', () => { expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.ELIGIBILITY.NEED_TO_START_AGAIN, needToStartAgainGet); expect(post).toHaveBeenCalledWith(ROUTES.INSURANCE.ELIGIBILITY.NEED_TO_START_AGAIN, needToStartAgainPost); - expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT, contractTooShortGet); + expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, contractTooShortGet); expect(get).toHaveBeenCalledWith(ROUTES.INSURANCE.ELIGIBILITY.PARTY_TO_CONSORTIUM_EXIT, partyToConsortiumExitGet); diff --git a/src/ui/server/routes/insurance/eligibility/index.ts b/src/ui/server/routes/insurance/eligibility/index.ts index 91c53d5447..7865b47103 100644 --- a/src/ui/server/routes/insurance/eligibility/index.ts +++ b/src/ui/server/routes/insurance/eligibility/index.ts @@ -22,7 +22,7 @@ import { get as eligibleToApplyOnlineGet, post as eligibleToApplyOnlinePost } fr import { get as haveAnAccountGet, post as haveAnAccountPost } from '../../../controllers/insurance/eligibility/do-you-have-an-account'; import { get as cannotApplyGet } from '../../../controllers/insurance/eligibility/cannot-apply'; import { get as needToStartAgainGet, post as needToStartAgainPost } from '../../../controllers/insurance/eligibility/need-to-start-again'; -import { get as talkToEfmTooShortGet } from '../../../controllers/insurance/eligibility/contract-too-short'; +import { get as talkToEfmTooShortGet } from '../../../controllers/insurance/eligibility/talk-to-an-export-finance-manager'; import { get as partyToConsortiumExitGet } from '../../../controllers/insurance/eligibility/party-to-consortium-exit'; import { get as memberOfAGroupExitGet } from '../../../controllers/insurance/eligibility/member-of-a-group-exit'; @@ -111,7 +111,7 @@ insuranceEligibilityRouter.get(ROUTES.INSURANCE.ELIGIBILITY.CANNOT_APPLY_EXIT, c insuranceEligibilityRouter.get(ROUTES.INSURANCE.ELIGIBILITY.NEED_TO_START_AGAIN, needToStartAgainGet); insuranceEligibilityRouter.post(ROUTES.INSURANCE.ELIGIBILITY.NEED_TO_START_AGAIN, needToStartAgainPost); -insuranceEligibilityRouter.get(ROUTES.INSURANCE.ELIGIBILITY.CONTRACT_TOO_SHORT_EXIT, talkToEfmTooShortGet); +insuranceEligibilityRouter.get(ROUTES.INSURANCE.ELIGIBILITY.TALK_TO_AN_EXPORT_FINANCE_MANAGER_EXIT, talkToEfmTooShortGet); insuranceEligibilityRouter.get(ROUTES.INSURANCE.ELIGIBILITY.PARTY_TO_CONSORTIUM_EXIT, partyToConsortiumExitGet); diff --git a/src/ui/server/test-mocks/index.ts b/src/ui/server/test-mocks/index.ts index 65e7b14551..475df7ff4b 100644 --- a/src/ui/server/test-mocks/index.ts +++ b/src/ui/server/test-mocks/index.ts @@ -5,7 +5,7 @@ import mockAccount from './mock-account'; import mockAnswers from './mock-answers'; import mockSession from './mock-session'; import mockQuote from './mock-quote'; -import mockCountries from './mock-countries'; +export * from './mock-countries'; import mockCountriesAndCurrencies from './mock-countries-and-currencies'; import mockCurrencies, { EUR, HKD, JPY, GBP, USD, mockCurrenciesResponse, mockCurrenciesEmptyResponse } from './mock-currencies'; import mockCompaniesHouseResponse from './mock-companies-house-response'; @@ -156,7 +156,6 @@ export { mockBuyerOutstandingOrOverduePayments, mockBuyerRelationship, mockBuyerTradingHistory, - mockCountries, mockCountriesAndCurrencies, mockCompaniesHouseResponse, mockCompany, diff --git a/src/ui/server/test-mocks/mock-countries.ts b/src/ui/server/test-mocks/mock-countries.ts index 300b0b402a..cbed3e6a78 100644 --- a/src/ui/server/test-mocks/mock-countries.ts +++ b/src/ui/server/test-mocks/mock-countries.ts @@ -5,97 +5,58 @@ const { CIS: { RISK }, } = EXTERNAL_API_MAPPINGS; -// mock base country that can get a quote and apply online. const baseCountry = { - canGetAQuoteOnline: true, - canGetAQuoteOffline: false, - canGetAQuoteByEmail: false, + noOnlineSupport: false, + canGetAQuoteOnline: false, cannotGetAQuote: false, - canApplyForInsuranceOnline: true, + canApplyForInsuranceOnline: false, noInsuranceSupport: false, - shortTermCover: true, + shortTermCover: false, + esraClassification: RISK.STANDARD, +}; + +export const mockCountryCannotGetAQuote: Country = { + ...baseCountry, + name: 'Abu Dhabi', + isoCode: 'XAD', + cannotGetAQuote: true, +}; + +export const mockCountryCanGetAQuoteOnline: Country = { + ...baseCountry, + name: 'Algeria', + isoCode: 'DZA', + canGetAQuoteOnline: true, +}; + +export const mockCountryCanApplyForInsuranceOnline: Country = { + ...baseCountry, + name: 'Algeria', + isoCode: 'DZA', + canApplyForInsuranceOnline: true, +}; + +export const mockCountryNoInsuranceSupport: Country = { + ...baseCountry, + name: 'Algeria', + isoCode: 'DZA', + noInsuranceSupport: true, +}; + +export const mockCountryNoOnlineSupport: Country = { + ...baseCountry, + name: 'Algeria', + isoCode: 'DZA', + noOnlineSupport: true, +}; + +export const mockCountryCanGetAQuoteByEmail: Country = { + ...baseCountry, + name: 'Egypt', + isoCode: 'EGY', + noOnlineSupport: true, }; -const mockCountries = [ - /** - * mock country that: - * - cannot get a quote online - * - cannot apply for insurance - */ - { - name: 'Abu Dhabi', - ...baseCountry, - isoCode: 'XAD', - esraClassification: RISK.STANDARD, - shortTermCover: false, - canGetAQuoteOnline: false, - canApplyForInsuranceOnline: false, - cannotGetAQuote: true, - }, - { - name: 'Algeria', - isoCode: 'DZA', - esraClassification: RISK.STANDARD, - ...baseCountry, - }, - /** - * mock country that: - * - cannot get a quote online - * - can get a quote by email - */ - { - name: 'Egypt', - isoCode: 'EGY', - esraClassification: RISK.VERY_HIGH, - ...baseCountry, - canGetAQuoteOnline: false, - canGetAQuoteByEmail: true, - }, - /** - * mock country that: - * - can only apply for insurance offline - */ - { - name: 'Gabon', - isoCode: 'GAB', - esraClassification: RISK.VERY_HIGH, - ...baseCountry, - canGetAQuoteOnline: false, - canApplyForInsuranceOnline: false, - }, - /** - * mock country that: - * - cannot get a quote, online or offline - * - cannot apply for insurance, online or offline - */ - { - name: 'Gibraltar', - isoCode: 'GIB', - ...baseCountry, - esraClassification: RISK.STANDARD, - canGetAQuoteOnline: false, - canGetAQuoteOffline: false, - canApplyForInsuranceOnline: false, - noInsuranceSupport: true, - }, - /** - * mock country that: - * - can get a quote, online or offline - * - can apply for insurance, online - * - cannot get short term cover - */ - { - name: 'France', - isoCode: 'FRA', - ...baseCountry, - esraClassification: RISK.STANDARD, - canGetAQuoteOnline: true, - canGetAQuoteOffline: true, - canApplyForInsuranceOnline: true, - canApplyForInsuranceOffline: false, - noInsuranceSupport: false, - shortTermCover: false, - }, -] as Array; +export const mockCountries = [mockCountryCannotGetAQuote, mockCountryCanGetAQuoteOnline, mockCountryCanGetAQuoteByEmail] as Array; export default mockCountries; diff --git a/src/ui/templates/insurance/eligibility/contract-too-short.njk b/src/ui/templates/insurance/eligibility/talk-to-an-export-finance-manager.njk similarity index 100% rename from src/ui/templates/insurance/eligibility/contract-too-short.njk rename to src/ui/templates/insurance/eligibility/talk-to-an-export-finance-manager.njk diff --git a/src/ui/types/country.d.ts b/src/ui/types/country.d.ts index 09be7ddc94..f54c0c5658 100644 --- a/src/ui/types/country.d.ts +++ b/src/ui/types/country.d.ts @@ -2,16 +2,14 @@ interface Country { id?: string; name: string; isoCode: string; - esraClassification?: string; + esraClassification: string; selected?: boolean; - value: string; + value?: string; canGetAQuoteOnline: boolean; - canGetAQuoteOffline: boolean; - canGetAQuoteByEmail: boolean; cannotGetAQuote: boolean; canApplyForInsuranceOnline: boolean; + noOnlineSupport: boolean; noInsuranceSupport: boolean; - shortTermCover: boolean; } export { Country };