Summary
The currency exchange rate module in `apps/web/lib/currency/exchange-rates.ts` contains utility functions for multi-currency conversion that have no unit tests. The synchronous `convertToBase` function and the caching logic are particularly well-suited for testing.
Functions to test
- `convertToBase(amount, fromCurrency, baseCurrency, rates)` — synchronous currency conversion using a pre-fetched rates map
- `convertCurrency(amount, fromCurrency, toCurrency)` — async conversion that fetches rates (mock the fetch)
- `getExchangeRates()` — rate fetching with caching and fallback logic
Files
- Source: `apps/web/lib/currency/exchange-rates.ts`
- Test file to create: `apps/web/tests/lib/currency/exchange-rates.test.ts`
Acceptance criteria
Getting started
You'll need to mock `fetch` for the async functions. Look at how Vitest's `vi.fn()` and `vi.spyOn(globalThis, 'fetch')` work. The `convertToBase` function is synchronous and needs no mocking — start there.
Summary
The currency exchange rate module in `apps/web/lib/currency/exchange-rates.ts` contains utility functions for multi-currency conversion that have no unit tests. The synchronous `convertToBase` function and the caching logic are particularly well-suited for testing.
Functions to test
Files
Acceptance criteria
Getting started
You'll need to mock `fetch` for the async functions. Look at how Vitest's `vi.fn()` and `vi.spyOn(globalThis, 'fetch')` work. The `convertToBase` function is synchronous and needs no mocking — start there.