Skip to content

Commit

Permalink
(PC-33683) feat(NC): remove getExchangeRates
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeneston-pass committed Jan 16, 2025
1 parent 9dc2b8a commit 50d8859
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/cheatcodes/pages/others/CheatcodesScreenNewCaledonia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export const CheatcodesScreenNewCaledonia = () => {
<TypoDS.Body>Devise affichée à l’utilisateur&nbsp;:</TypoDS.Body>
<TypoDS.Title3>{currency}</TypoDS.Title3>
<StyledSeparator />
<TypoDS.Body>Taux de change sur Firestore&nbsp;:</TypoDS.Body>
<TypoDS.Body>Taux de change depuis le backend&nbsp;:</TypoDS.Body>
<TypoDS.Title3>{pacificFrancToEuroRate}</TypoDS.Title3>
<StyledSeparator />
<TypoDS.Body>Taux de change dans le code&nbsp;:</TypoDS.Body>
<TypoDS.Body>Taux de change par défaut côté frontend&nbsp;:</TypoDS.Body>
<TypoDS.Title3>{DEFAULT_PACIFIC_FRANC_TO_EURO_RATE}</TypoDS.Title3>
<StyledSeparator />
<TextInput
Expand Down
2 changes: 2 additions & 0 deletions src/features/auth/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SettingsResponse } from 'api/gen'
import { DEFAULT_PACIFIC_FRANC_TO_EURO_RATE } from 'libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate'

export const CURRENT_DATE = new Date('2020-12-01T00:00:00.000Z')
export const ELIGIBLE_AGE_DATE = new Date('2003-12-01T00:00:00.000Z')
Expand All @@ -19,4 +20,5 @@ export const defaultSettings: SettingsResponse = {
idCheckAddressAutocompletion: true,
isRecaptchaEnabled: true,
objectStorageUrl: 'https://localhost-storage',
rates: { pacificFrancToEuro: DEFAULT_PACIFIC_FRANC_TO_EURO_RATE },
}

This file was deleted.

25 changes: 0 additions & 25 deletions src/libs/firebase/firestore/exchangeRates/getExchangeRates.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
import { onlineManager } from 'react-query'

import { getExchangeRates } from 'libs/firebase/firestore/exchangeRates/getExchangeRates'
import { defaultSettings } from 'features/auth/fixtures/fixtures'
import {
DEFAULT_PACIFIC_FRANC_TO_EURO_RATE,
useGetPacificFrancToEuroRate,
} from 'libs/firebase/firestore/exchangeRates/useGetPacificFrancToEuroRate'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, renderHook } from 'tests/utils'

jest.mock('@react-native-firebase/firestore')
jest.mock('libs/firebase/firestore/exchangeRates/getExchangeRates')
const mockGetExchangeRates = getExchangeRates as jest.Mock
const mockSettings = jest.fn().mockReturnValue({ data: defaultSettings })
jest.mock('features/auth/context/SettingsContext', () => ({
useSettingsContext: jest.fn(() => mockSettings()),
}))

describe('useGetPacificFrancToEuroRate', () => {
beforeEach(() => {
jest.clearAllMocks()
})
beforeEach(() => jest.clearAllMocks())

it('should initialize with the default rate', async () => {
mockGetExchangeRates.mockReturnValueOnce(undefined)
mockSettings.mockReturnValueOnce({ data: undefined })
const { result } = renderUseGetPacificFrancToEuroRate()

await act(async () => {})

expect(result.current).toEqual(DEFAULT_PACIFIC_FRANC_TO_EURO_RATE)
})

it('should return remote exchange rate from firestore', async () => {
mockGetExchangeRates.mockReturnValueOnce(0.05)
it('should return exchange rate from backend', async () => {
mockSettings.mockReturnValueOnce({
data: { ...defaultSettings, rates: { pacificFrancToEuro: 0.05 } },
})
const { result } = renderUseGetPacificFrancToEuroRate()

await act(async () => {})

expect(result.current).toEqual(0.05)
})

it('should return default rate when connection is disabled', () => {
onlineManager.setOnline(false)
mockGetExchangeRates.mockReturnValueOnce(0.05)

const { result } = renderUseGetPacificFrancToEuroRate()

expect(result.current).toEqual(DEFAULT_PACIFIC_FRANC_TO_EURO_RATE)
})
})

const renderUseGetPacificFrancToEuroRate = () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { onlineManager, useQuery } from 'react-query'

import { getExchangeRates } from 'libs/firebase/firestore/exchangeRates/getExchangeRates'
import { QueryKeys } from 'libs/queryKeys'
import { useSettingsContext } from 'features/auth/context/SettingsContext'

export const DEFAULT_PACIFIC_FRANC_TO_EURO_RATE = 0.00838

export const useGetPacificFrancToEuroRate = (): number => {
const { data: pacificFrancToEuroRate } = useQuery(QueryKeys.EXCHANGE_RATES, getExchangeRates, {
staleTime: 1000 * 30,
cacheTime: 1000 * 30,
enabled: onlineManager.isOnline(),
})

return pacificFrancToEuroRate ?? DEFAULT_PACIFIC_FRANC_TO_EURO_RATE
const { data: settings } = useSettingsContext()
return settings?.rates?.pacificFrancToEuro ?? DEFAULT_PACIFIC_FRANC_TO_EURO_RATE
}
1 change: 0 additions & 1 deletion src/libs/firebase/firestore/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export const FIRESTORE_ROOT_COLLECTION = 'root'
export enum RemoteStoreDocuments {
APPLICATION_VERSIONS = 'applicationVersions',
COOKIES_LAST_UPDATE = 'cookiesLastUpdate',
EXCHANGE_RATES = 'exchangeRates',
FEATURE_FLAGS = 'featureFlags',
MAINTENANCE = 'maintenance',
UBBLE = 'ubble',
Expand Down
1 change: 0 additions & 1 deletion src/libs/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export enum QueryKeys {
EMAIL_UPDATE_STATUS = 'emailUpdateStatus',
EMAIL_UPDATE_STATUS_V2 = 'emailUpdateStatusV2',
EMAIL_VALIDATION_REMAINING_ATTEMPTS = 'emailValidationRemainingAttempts',
EXCHANGE_RATES = 'exchangeRates',
ERROR_ASYNC = 'errorAsync',
FAVORITES = 'favorites',
FAVORITES_COUNT = 'favoritesCount',
Expand Down

0 comments on commit 50d8859

Please sign in to comment.