From a67f80a1076c0cfb1042008a1eed7a436910f1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Latzarus?= Date: Fri, 14 Apr 2023 16:10:26 +0200 Subject: [PATCH] feat: hide banner for DOM-TOM countries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rébecca Kaci --- services/should-show-out-of-france-banner.js | 27 +++++++++++++++++-- .../should-show-out-of-france-banner.test.js | 16 +++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/services/should-show-out-of-france-banner.js b/services/should-show-out-of-france-banner.js index 081a47b4b..02f0ddf32 100644 --- a/services/should-show-out-of-france-banner.js +++ b/services/should-show-out-of-france-banner.js @@ -6,8 +6,7 @@ export async function shouldShowOutOfFranceBanner(baseUrl) { const country = await _getCountry(baseUrl) if (!country) return false - const FR_COUNTRY_CODE = 'FR' - return country !== FR_COUNTRY_CODE + return _shouldShowBannerForCountry(country) } async function _getCountry(baseUrl) { @@ -18,3 +17,27 @@ async function _getCountry(baseUrl) { return response.country } + +function _shouldShowBannerForCountry(country) { + const FR_COUNTRY_CODE = 'FR' + const DOM_TOM_COUNTRY_CODES = [ + 'GA', + 'GF', + 'MQ', + 'RE', + 'YT', + 'NC', + 'PF', + 'BL', + 'MF', + 'PM', + 'TF', + 'WF', + ] + const COUNTRIES_WHERE_BANNER_SHOULD_NOT_BE_SHOWN = [ + FR_COUNTRY_CODE, + ...DOM_TOM_COUNTRY_CODES, + ] + + return !COUNTRIES_WHERE_BANNER_SHOULD_NOT_BE_SHOWN.includes(country) +} diff --git a/tests/services/should-show-out-of-france-banner.test.js b/tests/services/should-show-out-of-france-banner.test.js index c811a57c5..c99ed211e 100644 --- a/tests/services/should-show-out-of-france-banner.test.js +++ b/tests/services/should-show-out-of-france-banner.test.js @@ -78,6 +78,22 @@ describe('shouldShowOutOfFranceBanner', () => { }) }) + describe("When user's location is in a DOM-TOM", () => { + it('returns false', async () => { + // given + global.fetch = jest + .fn() + .mockResolvedValue(fetchResponse({ country: 'GA' })) + + // when + const result = await shouldShowOutOfFranceBanner(baseUrl) + + // then + expect(global.fetch).toHaveBeenCalled() + expect(result).toBe(false) + }) + }) + describe("When user's location is not provided", () => { it('returns false', async () => { // given