From 4684dbc6af81d9a6b0c54252fdf9f7062803f0d5 Mon Sep 17 00:00:00 2001 From: Tony Barnes Date: Mon, 23 Dec 2024 10:48:41 +0000 Subject: [PATCH] chore(EMS-4079): country risk logic - simplify/improve mapping function (#3436) --- src/api/.keystone/config.js | 215 +++++++----------- src/api/custom-schema/type-defs.ts | 1 - .../index-rating-a.test.ts | 0 .../index-rating-b.test.ts | 0 .../index-rating-c-and-d.test.ts | 0 .../index-rating-none.test.ts | 0 .../a-and-b-rating-conditions/index.ts | 0 .../index-rating-a-and-b.test.ts | 0 .../index-rating-c.test.ts | 0 .../index-rating-d.test.ts | 0 .../index-rating-none.test.ts | 0 .../c-and-d-rating-conditions/index.ts | 0 .../index.test.ts | 12 +- .../index.ts | 6 +- .../index.test.ts | 8 +- .../{no-support => has-no-support}/index.ts | 6 +- .../map-CIS-country/index.test.ts | 16 +- .../map-CIS-country/index.ts | 39 ++-- .../map-NBI-issue-available/index.test.ts | 20 -- .../map-NBI-issue-available/index.ts | 19 -- .../index.test.ts | 48 ---- .../map-short-term-cover-available/index.ts | 32 --- src/api/schema.graphql | 1 - src/api/types/country/index.ts | 4 - src/api/types/helpers/index.ts | 1 - .../graphql/queries/APIM/CIS-countries.ts | 1 - src/ui/types/country.d.ts | 1 - 27 files changed, 126 insertions(+), 304 deletions(-) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/a-and-b-rating-conditions/index-rating-a.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/a-and-b-rating-conditions/index-rating-b.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/a-and-b-rating-conditions/index-rating-c-and-d.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/a-and-b-rating-conditions/index-rating-none.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/a-and-b-rating-conditions/index.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/c-and-d-rating-conditions/index-rating-a-and-b.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/c-and-d-rating-conditions/index-rating-c.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/c-and-d-rating-conditions/index-rating-d.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/c-and-d-rating-conditions/index-rating-none.test.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/c-and-d-rating-conditions/index.ts (100%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/index.test.ts (88%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-online-support => has-no-online-support}/index.ts (81%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-support => has-no-support}/index.test.ts (93%) rename src/api/helpers/map-CIS-countries/map-CIS-country/{no-support => has-no-support}/index.ts (90%) delete mode 100644 src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.test.ts delete mode 100644 src/api/helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.ts delete mode 100644 src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.test.ts delete mode 100644 src/api/helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.ts diff --git a/src/api/.keystone/config.js b/src/api/.keystone/config.js index 00658d9c2d..a9cb2e1d16 100644 --- a/src/api/.keystone/config.js +++ b/src/api/.keystone/config.js @@ -2822,7 +2822,6 @@ var typeDefs = ` name: String shortTermCover: Boolean esraClassification: String - nbiIssueAvailable: Boolean canGetAQuoteOnline: Boolean cannotGetAQuote: Boolean cannotApply: Boolean @@ -8987,135 +8986,150 @@ var mapEsraClassification = (str) => { }; var map_esra_classification_default = mapEsraClassification; -// helpers/map-CIS-countries/map-CIS-country/map-short-term-cover-available/index.ts +// helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.ts var { - CIS: { SHORT_TERM_COVER }, + CIS: { COUNTRY_RATINGS }, } = EXTERNAL_API_DEFINITIONS; -var mapShortTermCoverAvailable = (str) => { - switch (str) { - case SHORT_TERM_COVER.YES: - return true; - case SHORT_TERM_COVER.ILC: - return true; - case SHORT_TERM_COVER.CILC: - return true; - case SHORT_TERM_COVER.REFER: - return true; - default: - return false; +var countryRatingIsAorB = (rating) => { + if (COUNTRY_RATINGS.A.includes(rating)) { + return true; + } + if (COUNTRY_RATINGS.B.includes(rating)) { + return true; } + return false; }; -var map_short_term_cover_available_default = mapShortTermCoverAvailable; +var country_rating_is_a_or_b_default = countryRatingIsAorB; -// helpers/map-CIS-countries/map-CIS-country/map-NBI-issue-available/index.ts -var { CIS } = EXTERNAL_API_DEFINITIONS; -var mapNbiIssueAvailable = (str) => { - if (str === CIS.NBI_ISSUE_AVAILABLE.YES) { +// helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.ts +var { + CIS: { COUNTRY_RATINGS: COUNTRY_RATINGS2 }, +} = EXTERNAL_API_DEFINITIONS; +var countryRatingIsCorD = (rating) => { + if (COUNTRY_RATINGS2.C.includes(rating)) { + return true; + } + if (COUNTRY_RATINGS2.D.includes(rating)) { return true; } return false; }; -var map_NBI_issue_available_default = mapNbiIssueAvailable; +var country_rating_is_c_or_d_default = countryRatingIsCorD; -// helpers/map-CIS-countries/map-CIS-country/country-rating-is-a-or-b/index.ts +// helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.ts var { - CIS: { COUNTRY_RATINGS }, + CIS: { + ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH }, + }, } = EXTERNAL_API_DEFINITIONS; -var countryRatingIsAorB = (rating) => { - if (COUNTRY_RATINGS.A.includes(rating)) { +var esraClassificationIsStandardHighOrVeryHigh = (esraClassification) => { + switch (esraClassification) { + case STANDARD: + return true; + case HIGH: + return true; + case VERY_HIGH: + return true; + default: + return false; + } +}; +var esra_classification_is_standard_high_or_very_high_default = esraClassificationIsStandardHighOrVeryHigh; + +// 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; } - if (COUNTRY_RATINGS.B.includes(rating)) { + const esraClassificationConditions = esra_classification_is_standard_high_or_very_high_default(esraClassification) || esraClassificationIsNone; + if (shortTermCover === CILC && countryRatingIsNotApplicable && esraClassificationConditions) { return true; } return false; }; -var country_rating_is_a_or_b_default = countryRatingIsAorB; +var has_no_support_default = hasNoSupport; -// helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions/index.ts +// helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index.ts var { CIS: { - ESRA_CLASSIFICATION: { STANDARD, HIGH, VERY_HIGH, NONE }, - SHORT_TERM_COVER: { NO: NO2, ILC, CILC }, + 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; } - if (esraClassification === STANDARD || esraClassification === HIGH || esraClassification === VERY_HIGH) { + if (esraClassification === STANDARD2 || esraClassification === HIGH2 || esraClassification === VERY_HIGH2) { if (shortTermCover === ILC) { return true; } - if (shortTermCover === CILC) { + if (shortTermCover === CILC2) { return true; } if (shortTermCover === NO2) { return true; } } - if (esraClassification === NONE && shortTermCover === NO2) { + if (esraClassification === NONE2 && shortTermCover === NO2) { return true; } return false; }; var a_and_b_rating_conditions_default = aAndBRatingConditions; -// helpers/map-CIS-countries/map-CIS-country/country-rating-is-c-or-d/index.ts -var { - CIS: { COUNTRY_RATINGS: COUNTRY_RATINGS2 }, -} = EXTERNAL_API_DEFINITIONS; -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/no-online-support/c-and-d-rating-conditions/index.ts +// helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index.ts var { CIS: { - ESRA_CLASSIFICATION: { STANDARD: STANDARD2, HIGH: HIGH2, VERY_HIGH: VERY_HIGH2, NONE: NONE2 }, - SHORT_TERM_COVER: { YES: YES2, NO: NO3, ILC: ILC2, CILC: CILC2, REFER, UNLISTED }, + 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 (esraClassification === STANDARD2 || esraClassification === HIGH2 || esraClassification === VERY_HIGH2) { + if (esraClassification === STANDARD3 || esraClassification === HIGH3 || esraClassification === VERY_HIGH3) { if (shortTermCover === YES2) { return true; } if (shortTermCover === ILC2) { return true; } - if (shortTermCover === CILC2) { + if (shortTermCover === CILC3) { return true; } if (shortTermCover === REFER) { return true; } - if (shortTermCover === UNLISTED) { + if (shortTermCover === UNLISTED2) { return true; } if (shortTermCover === NO3) { return true; } } - if (esraClassification === NONE2 && shortTermCover === NO3) { + if (esraClassification === NONE3 && shortTermCover === NO3) { return true; } return false; }; var c_and_d_rating_conditions_default = cAndDRatingConditions; -// helpers/map-CIS-countries/map-CIS-country/no-online-support/index.ts -var noOnlineSupport = ({ countryRating, esraClassification, shortTermCover }) => { +// 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, @@ -9129,32 +9143,12 @@ var noOnlineSupport = ({ countryRating, esraClassification, shortTermCover }) => const conditions = aAndBConditions || cAndDConditions; return conditions; }; -var no_online_support_default = noOnlineSupport; - -// helpers/map-CIS-countries/map-CIS-country/esra-classification-is-standard-high-or-very-high/index.ts -var { - CIS: { - ESRA_CLASSIFICATION: { STANDARD: STANDARD3, HIGH: HIGH3, VERY_HIGH: VERY_HIGH3 }, - }, -} = EXTERNAL_API_DEFINITIONS; -var esraClassificationIsStandardHighOrVeryHigh = (esraClassification) => { - switch (esraClassification) { - case STANDARD3: - return true; - case HIGH3: - return true; - case VERY_HIGH3: - return true; - default: - return false; - } -}; -var esra_classification_is_standard_high_or_very_high_default = esraClassificationIsStandardHighOrVeryHigh; +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: UNLISTED2 }, + SHORT_TERM_COVER: { YES: YES3, REFER: REFER2, UNLISTED: UNLISTED3 }, }, } = EXTERNAL_API_DEFINITIONS; var shortTermCoverIsYesReferOrUnlisted = (shortTermCover) => { @@ -9163,7 +9157,7 @@ var shortTermCoverIsYesReferOrUnlisted = (shortTermCover) => { return true; case REFER2: return true; - case UNLISTED2: + case UNLISTED3: return true; default: return false; @@ -9193,62 +9187,29 @@ var canApplyForInsuranceOnline = (cisCountry) => { }; var can_apply_for_insurance_online_default = canApplyForInsuranceOnline; -// helpers/map-CIS-countries/map-CIS-country/no-support/index.ts -var { - CIS: { - COUNTRY_RATINGS: { NOT_APPLICABLE }, - ESRA_CLASSIFICATION: { NONE: NONE3 }, - SHORT_TERM_COVER: { UNLISTED: UNLISTED3, CILC: CILC3 }, - }, -} = EXTERNAL_API_DEFINITIONS; -var noSupport = ({ countryRating, esraClassification, shortTermCover }) => { - const shortTermCoverIsUnlisted = shortTermCover === UNLISTED3; - const esraClassificationIsNone = esraClassification === NONE3; - 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; - } - const esraClassificationConditions = esra_classification_is_standard_high_or_very_high_default(esraClassification) || esraClassificationIsNone; - if (shortTermCover === CILC3 && countryRatingIsNotApplicable && esraClassificationConditions) { - return true; - } - return false; -}; -var no_support_default = noSupport; - // helpers/map-CIS-countries/map-CIS-country/index.ts var mapCisCountry = (cisCountry) => { - const { countryRatingDesc, ESRAClassificationDesc, isoCode, marketName, shortTermCoverAvailabilityDesc } = 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 countryRating = countryRatingDesc; + const noSupport = has_no_support_default({ + countryRating, + esraClassification: ESRAClassificationDesc, + shortTermCover, + }); const mapped = { countryRating, esraClassification, isoCode, name: marketName, - nbiIssueAvailable, - shortTermCover, - noOnlineSupport: no_online_support_default({ + noOnlineSupport: has_no_online_support_default({ countryRating, esraClassification: ESRAClassificationDesc, - shortTermCover: shortTermCoverAvailabilityDesc, + shortTermCover, }), canGetAQuoteOnline: can_get_a_quote_online_default(cisCountry), - cannotGetAQuote: no_support_default({ - countryRating, - esraClassification: ESRAClassificationDesc, - shortTermCover: shortTermCoverAvailabilityDesc, - }), + cannotGetAQuote: noSupport, canApplyForInsuranceOnline: can_apply_for_insurance_online_default(cisCountry), - noInsuranceSupport: no_support_default({ - countryRating, - esraClassification: ESRAClassificationDesc, - shortTermCover: shortTermCoverAvailabilityDesc, - }), + noInsuranceSupport: noSupport, }; return mapped; }; @@ -9262,9 +9223,9 @@ var sortArrayAlphabetically = (arr, field) => { var sort_array_alphabetically_default = sortArrayAlphabetically; // helpers/map-CIS-countries/index.ts -var { CIS: CIS2 } = EXTERNAL_API_DEFINITIONS; +var { CIS } = EXTERNAL_API_DEFINITIONS; var mapCisCountries = (countries) => { - const filteredCountries = filter_cis_entries_default(countries, CIS2.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; @@ -9289,7 +9250,7 @@ var getApimCisCountries = async () => { var get_APIM_CIS_countries_default = getApimCisCountries; // helpers/map-currencies/index.ts -var { CIS: CIS3 } = 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; @@ -9299,7 +9260,7 @@ var getAlternativeCurrencies = (currencies) => { return alternate; }; var mapCurrencies = (currencies, alternativeCurrencies) => { - let currenciesArray = filter_cis_entries_default(currencies, CIS3.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/custom-schema/type-defs.ts b/src/api/custom-schema/type-defs.ts index 059ce6611c..08f0ee4caf 100644 --- a/src/api/custom-schema/type-defs.ts +++ b/src/api/custom-schema/type-defs.ts @@ -229,7 +229,6 @@ const typeDefs = ` name: String shortTermCover: Boolean esraClassification: String - nbiIssueAvailable: Boolean canGetAQuoteOnline: Boolean cannotGetAQuote: Boolean cannotApply: Boolean diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions/index-rating-a.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-a.test.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions/index-rating-b.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-b.test.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions/index-rating-c-and-d.test.ts rename to 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 diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions/index-rating-none.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index-rating-none.test.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/a-and-b-rating-conditions/index.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/a-and-b-rating-conditions/index.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions/index-rating-a-and-b.test.ts rename to 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 diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions/index-rating-c.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-c.test.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions/index-rating-d.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-d.test.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions/index-rating-none.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index-rating-none.test.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/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 similarity index 100% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/c-and-d-rating-conditions/index.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/c-and-d-rating-conditions/index.ts diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.test.ts similarity index 88% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/index.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.test.ts index f27b485c7a..0ea8c89afb 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.test.ts @@ -1,4 +1,4 @@ -import noOnlineSupport from '.'; +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'; @@ -13,7 +13,7 @@ const mockInitCountry = { shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, }; -describe('helpers/map-CIS-countries/map-CIS-country/no-online-support', () => { +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; @@ -23,7 +23,7 @@ describe('helpers/map-CIS-countries/map-CIS-country/no-online-support', () => { countryRating: mockRating, }; - const result = noOnlineSupport(mockCountry); + const result = hasNoOnlineSupport(mockCountry); const expected = aAndBRatingConditions({ countryRating: mockRating, @@ -44,7 +44,7 @@ describe('helpers/map-CIS-countries/map-CIS-country/no-online-support', () => { countryRating: mockRating, }; - const result = noOnlineSupport(mockCountry); + const result = hasNoOnlineSupport(mockCountry); const expected = aAndBRatingConditions({ countryRating: mockRating, @@ -65,7 +65,7 @@ describe('helpers/map-CIS-countries/map-CIS-country/no-online-support', () => { countryRating: mockRating, }; - const result = noOnlineSupport(mockCountry); + const result = hasNoOnlineSupport(mockCountry); const expected = cAndDRatingConditions({ countryRating: mockRating, @@ -86,7 +86,7 @@ describe('helpers/map-CIS-countries/map-CIS-country/no-online-support', () => { countryRating: mockRating, }; - const result = noOnlineSupport(mockCountry); + const result = hasNoOnlineSupport(mockCountry); const expected = cAndDRatingConditions({ countryRating: mockRating, diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts similarity index 81% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/index.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts index d73fc143df..89f36df849 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/no-online-support/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-online-support/index.ts @@ -3,14 +3,14 @@ import cAndDRatingConditions from './c-and-d-rating-conditions'; import { NoInsuranceSupportParams } from '../../../../types'; /** - * noOnlineSupport + * 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 noOnlineSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { +const hasNoOnlineSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { const aAndBConditions = aAndBRatingConditions({ countryRating, esraClassification, @@ -28,4 +28,4 @@ const noOnlineSupport = ({ countryRating, esraClassification, shortTermCover }: return conditions; }; -export default noOnlineSupport; +export default hasNoOnlineSupport; diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/no-support/index.test.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.test.ts similarity index 93% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-support/index.test.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.test.ts index 4ccd4a8a2b..d0d05442b2 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/no-support/index.test.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.test.ts @@ -1,4 +1,4 @@ -import noSupport from '.'; +import hasNoSupport from '.'; import { EXTERNAL_API_DEFINITIONS } from '../../../../constants'; const { @@ -89,12 +89,12 @@ const params = { ], }; -describe('helpers/map-CIS-countries/map-CIS-country/no-support', () => { +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 = noSupport(country); + const result = hasNoSupport(country); expect(result).toEqual(expectation); }); @@ -106,7 +106,7 @@ describe('helpers/map-CIS-countries/map-CIS-country/no-support', () => { describe.each(params.secondConditions)('', ({ country, description, expectation }) => { describe(`when the esraClassification is ${description}`, () => { it(`should return ${expectation}`, () => { - const result = noSupport(country); + const result = hasNoSupport(country); expect(result).toEqual(expectation); }); diff --git a/src/api/helpers/map-CIS-countries/map-CIS-country/no-support/index.ts b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts similarity index 90% rename from src/api/helpers/map-CIS-countries/map-CIS-country/no-support/index.ts rename to src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts index 64e15c900e..0e8b266cc9 100644 --- a/src/api/helpers/map-CIS-countries/map-CIS-country/no-support/index.ts +++ b/src/api/helpers/map-CIS-countries/map-CIS-country/has-no-support/index.ts @@ -13,14 +13,14 @@ const { } = EXTERNAL_API_DEFINITIONS; /** - * noSupport + * 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 noSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { +const hasNoSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsuranceSupportParams): boolean => { const shortTermCoverIsUnlisted = shortTermCover === UNLISTED; const esraClassificationIsNone = esraClassification === NONE; const countryRatingIsNotApplicable = countryRating === NOT_APPLICABLE; @@ -40,4 +40,4 @@ const noSupport = ({ countryRating, esraClassification, shortTermCover }: NoInsu return false; }; -export default noSupport; +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 191830c438..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,11 +1,9 @@ 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 noOnlineSupport from './no-online-support'; +import hasNoOnlineSupport from './has-no-online-support'; import canGetAQuoteOnline from './can-get-a-quote-online'; import canApplyForInsuranceOnline from './can-apply-for-insurance-online'; -import noSupport from './no-support'; +import hasNoSupport from './has-no-support'; import { EXTERNAL_API_DEFINITIONS, EXTERNAL_API_MAPPINGS } from '../../../constants'; import { MappedCisCountry } from '../../../types'; import { mockCisCountry } from '../../../test-mocks'; @@ -26,8 +24,6 @@ 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 countryRating = mockCisCountry.countryRatingDesc; @@ -36,10 +32,8 @@ describe('helpers/map-CIS-countries/map-CIS-country', () => { esraClassification, isoCode: mockCountryBase.isoCode, name: mockCountryBase.marketName, - nbiIssueAvailable, - shortTermCover, - noOnlineSupport: noOnlineSupport({ + noOnlineSupport: hasNoOnlineSupport({ countryRating, esraClassification: mockCisCountry.ESRAClassificationDesc, shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, @@ -47,7 +41,7 @@ describe('helpers/map-CIS-countries/map-CIS-country', () => { canGetAQuoteOnline: canGetAQuoteOnline(mockCisCountry), - cannotGetAQuote: noSupport({ + cannotGetAQuote: hasNoSupport({ countryRating, esraClassification: mockCisCountry.ESRAClassificationDesc, shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, @@ -55,7 +49,7 @@ describe('helpers/map-CIS-countries/map-CIS-country', () => { canApplyForInsuranceOnline: canApplyForInsuranceOnline(mockCisCountry), - noInsuranceSupport: noSupport({ + noInsuranceSupport: hasNoSupport({ countryRating, esraClassification: mockCisCountry.ESRAClassificationDesc, shortTermCover: mockCisCountry.shortTermCoverAvailabilityDesc, 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 6efb281114..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,10 +1,8 @@ import mapEsraClassification from './map-esra-classification'; -import mapShortTermCoverAvailable from './map-short-term-cover-available'; -import mapNbiIssueAvailable from './map-NBI-issue-available'; -import noOnlineSupport from './no-online-support'; +import hasNoSupport from './has-no-support'; +import hasNoOnlineSupport from './has-no-online-support'; import canGetAQuoteOnline from './can-get-a-quote-online'; import canApplyForInsuranceOnline from './can-apply-for-insurance-online'; -import noSupport from './no-support'; import { CisCountry, MappedCisCountry } from '../../../types'; /** @@ -14,43 +12,40 @@ import { CisCountry, MappedCisCountry } from '../../../types'; * @returns {MappedCisCountry} Mapped country */ export const mapCisCountry = (cisCountry: CisCountry): MappedCisCountry => { - const { countryRatingDesc, ESRAClassificationDesc, isoCode, marketName, shortTermCoverAvailabilityDesc } = 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 countryRating = countryRatingDesc; + /** + * 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, + }); const mapped: MappedCisCountry = { countryRating, esraClassification, isoCode, name: marketName, - nbiIssueAvailable, - shortTermCover, - noOnlineSupport: noOnlineSupport({ + noOnlineSupport: hasNoOnlineSupport({ countryRating, esraClassification: ESRAClassificationDesc, - shortTermCover: shortTermCoverAvailabilityDesc, + shortTermCover, }), canGetAQuoteOnline: canGetAQuoteOnline(cisCountry), - cannotGetAQuote: noSupport({ - countryRating, - esraClassification: ESRAClassificationDesc, - shortTermCover: shortTermCoverAvailabilityDesc, - }), + cannotGetAQuote: noSupport, canApplyForInsuranceOnline: canApplyForInsuranceOnline(cisCountry), - noInsuranceSupport: noSupport({ - countryRating, - esraClassification: ESRAClassificationDesc, - shortTermCover: shortTermCoverAvailabilityDesc, - }), + 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 f8be363855..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} - */ -export 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-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 353eeacb2d..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 }, -} = 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.YES}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER.YES); - - expect(result).toEqual(true); - }); - }); - - describe(`when the short term cover is ${SHORT_TERM_COVER.ILC}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER.ILC); - - expect(result).toEqual(true); - }); - }); - - describe(`when the short term cover is ${SHORT_TERM_COVER.CILC}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER.CILC); - - expect(result).toEqual(true); - }); - }); - - describe(`when the short term cover is ${SHORT_TERM_COVER.REFER}`, () => { - it('should return true', () => { - const result = mapShortTermCoverAvailable(SHORT_TERM_COVER.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 44c2c9e2a0..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 }, -} = 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.YES: - return true; - - case SHORT_TERM_COVER.ILC: - return true; - - case SHORT_TERM_COVER.CILC: - return true; - - case SHORT_TERM_COVER.REFER: - return true; - - default: - return false; - } -}; - -export default mapShortTermCoverAvailable; diff --git a/src/api/schema.graphql b/src/api/schema.graphql index 966beaa723..0d2431a695 100644 --- a/src/api/schema.graphql +++ b/src/api/schema.graphql @@ -3743,7 +3743,6 @@ type MappedCisCountry { name: String shortTermCover: Boolean esraClassification: String - nbiIssueAvailable: Boolean canGetAQuoteOnline: Boolean cannotGetAQuote: Boolean cannotApply: Boolean diff --git a/src/api/types/country/index.ts b/src/api/types/country/index.ts index 825a6b284b..2670446d6a 100644 --- a/src/api/types/country/index.ts +++ b/src/api/types/country/index.ts @@ -16,8 +16,6 @@ export interface Country extends Relationship { name: string; isoCode: string; esraClassification?: string; - shortTermCover?: boolean; - nbiIssueAvailable?: boolean; canGetAQuoteOnline?: boolean; cannotGetAQuote?: boolean; canApplyForInsuranceOnline?: boolean; @@ -37,9 +35,7 @@ export interface MappedCisCountry { countryRating: string; esraClassification?: string | null; isoCode: string; - nbiIssueAvailable: boolean; name: string; - shortTermCover: boolean; noOnlineSupport: boolean; canGetAQuoteOnline: boolean; cannotGetAQuote: boolean; diff --git a/src/api/types/helpers/index.ts b/src/api/types/helpers/index.ts index ead4c81e5c..8062f28eb4 100644 --- a/src/api/types/helpers/index.ts +++ b/src/api/types/helpers/index.ts @@ -5,7 +5,6 @@ export interface MapYesNoFieldParams { export interface MapCisCountryParams { shortTermCover: boolean; - nbiIssueAvailable: boolean; esraClassification?: string | null; } diff --git a/src/ui/server/graphql/queries/APIM/CIS-countries.ts b/src/ui/server/graphql/queries/APIM/CIS-countries.ts index a6ecbcc115..dac20373cb 100644 --- a/src/ui/server/graphql/queries/APIM/CIS-countries.ts +++ b/src/ui/server/graphql/queries/APIM/CIS-countries.ts @@ -12,7 +12,6 @@ const getApimCisCountries = gql` canApplyForInsuranceOnline noOnlineSupport noInsuranceSupport - shortTermCover } } `; diff --git a/src/ui/types/country.d.ts b/src/ui/types/country.d.ts index 53024a8b3a..f54c0c5658 100644 --- a/src/ui/types/country.d.ts +++ b/src/ui/types/country.d.ts @@ -10,7 +10,6 @@ interface Country { canApplyForInsuranceOnline: boolean; noOnlineSupport: boolean; noInsuranceSupport: boolean; - shortTermCover: boolean; } export { Country };