Skip to content

Commit

Permalink
(PC-32821) feat(NC): update conditions in useGetCurrencyToDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeneston-pass committed Nov 29, 2024
1 parent 2da4ca2 commit e1f5b67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
18 changes: 7 additions & 11 deletions src/shared/currency/useGetCurrencyToDisplay.native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mockUseAuthContext = jest.mocked(useAuthContext)
describe('useGetCurrencyToDisplay', () => {
beforeEach(() => {
activateFeatureFlags()
mockUseGeolocation.mockReturnValue({ userLocation: null } as ILocationContext)
mockUseAuthContext.mockReturnValue({
isLoggedIn: true,
user: undefined,
Expand All @@ -33,13 +34,12 @@ describe('useGetCurrencyToDisplay', () => {
})

it('should return Euro by default when location and user are not provided', () => {
mockUseGeolocation.mockReturnValueOnce({ userLocation: null } as ILocationContext)
const { result } = renderHook(() => useGetCurrencyToDisplay())

expect(result.current).toBe('€')
})

describe('when location is outside New Caledonia', () => {
describe('when user is not connected and location is outside New Caledonia', () => {
beforeEach(() => {
mockUseGeolocation.mockReturnValue({
userLocation: PARIS_DEFAULT_POSITION,
Expand All @@ -66,7 +66,7 @@ describe('useGetCurrencyToDisplay', () => {
})
})

describe('when location is in New Caledonia', () => {
describe('when user is not connected and location is in New Caledonia', () => {
beforeEach(() => {
mockUseGeolocation.mockReturnValue({
userLocation: NOUMEA_DEFAULT_POSITION,
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('useGetCurrencyToDisplay', () => {
})
})

describe('when user is in Euro region', () => {
describe('when user is registered in Euro region', () => {
beforeEach(() => {
mockUseAuthContext.mockReturnValue({
isLoggedIn: true,
Expand Down Expand Up @@ -147,9 +147,7 @@ describe('useGetCurrencyToDisplay', () => {
})

describe('and the feature flag is disabled', () => {
beforeEach(() => {
activateFeatureFlags()
})
beforeEach(() => activateFeatureFlags())

it('should return Euro when displayFormat is "short"', () => {
const { result } = renderHook(() => useGetCurrencyToDisplay('short'))
Expand All @@ -165,7 +163,7 @@ describe('useGetCurrencyToDisplay', () => {
})
})

describe('when user is in Pacific Franc region', () => {
describe('when user is registered in Pacific Franc region', () => {
beforeEach(() => {
mockUseAuthContext.mockReturnValue({
isLoggedIn: true,
Expand Down Expand Up @@ -195,9 +193,7 @@ describe('useGetCurrencyToDisplay', () => {
})

describe('and the feature flag is disabled', () => {
beforeEach(() => {
activateFeatureFlags()
})
beforeEach(() => activateFeatureFlags())

it('should return Euro when displayFormat is "short"', () => {
const { result } = renderHook(() => useGetCurrencyToDisplay('short'))
Expand Down
24 changes: 13 additions & 11 deletions src/shared/currency/useGetCurrencyToDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ export const useGetCurrencyToDisplay = (

const { selectedPlace } = useLocation()
const isNewCaledonianLocationSelected = selectedPlace?.info === 'Nouvelle-Calédonie'
const isNotNewCaledonianLocationSelected = !isNewCaledonianLocationSelected
const isNotNewCaledonianLocationSelected = selectedPlace?.info !== 'Nouvelle-Calédonie'

const pacificFrancCurrency =
displayFormat === 'full' ? Currency.PACIFIC_FRANC_FULL : Currency.PACIFIC_FRANC_SHORT

switch (true) {
case disablePacificFrancCurrency:
case isUserRegisteredInEuroRegion:
case isNotNewCaledonianLocationSelected:
return Currency.EURO
case enablePacificFrancCurrency &&
(isUserRegisteredInPacificFrancRegion || isNewCaledonianLocationSelected):
return pacificFrancCurrency
default:
return Currency.EURO
if (disablePacificFrancCurrency) return Currency.EURO

if (selectedPlace) {
if (isNotNewCaledonianLocationSelected) return Currency.EURO
if (isNewCaledonianLocationSelected) return pacificFrancCurrency
}

if (user) {
if (isUserRegisteredInEuroRegion) return Currency.EURO
if (isUserRegisteredInPacificFrancRegion) return pacificFrancCurrency
}

return Currency.EURO
}

0 comments on commit e1f5b67

Please sign in to comment.