Skip to content

Commit

Permalink
feat: hide banner for DOM-TOM countries
Browse files Browse the repository at this point in the history
Co-authored-by: Rébecca Kaci <[email protected]>
  • Loading branch information
clemlatz and reibecca committed Apr 14, 2023
1 parent d41f1d1 commit a67f80a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
27 changes: 25 additions & 2 deletions services/should-show-out-of-france-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
16 changes: 16 additions & 0 deletions tests/services/should-show-out-of-france-banner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a67f80a

Please sign in to comment.