Files
TREK/server/tests/unit/nest/llm-parse/currency-code.test.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

54 lines
2.1 KiB
TypeScript

import { toIsoCurrency } from '../../../../src/nest/llm-parse/currency-code';
import { describe, it, expect } from 'vitest';
describe('toIsoCurrency', () => {
it('keeps an ISO 4217 code in any case and spacing', () => {
expect(toIsoCurrency('EUR')).toBe('EUR');
expect(toIsoCurrency('eur')).toBe('EUR');
expect(toIsoCurrency(' chf ')).toBe('CHF');
expect(toIsoCurrency('ALL')).toBe('ALL');
});
it('reads a value that starts with a real code as that code (#2477)', () => {
expect(toIsoCurrency('EURials')).toBe('EUR');
expect(toIsoCurrency('Euros')).toBe('EUR');
expect(toIsoCurrency('EUR 89,35')).toBe('EUR');
});
it('maps a currency symbol that stands alone', () => {
expect(toIsoCurrency('€')).toBe('EUR');
expect(toIsoCurrency('£')).toBe('GBP');
expect(toIsoCurrency('¥')).toBe('JPY');
expect(toIsoCurrency(' $ ')).toBe('USD');
});
it('answers undefined for anything that is not a currency it can name', () => {
// The lek is ALL; LEK is no code, and its prefix is none either.
expect(toIsoCurrency('LEK')).toBeUndefined();
expect(toIsoCurrency('XYZ')).toBeUndefined();
// A dollar with a country in front is not guessed as USD.
expect(toIsoCurrency('CA$')).toBeUndefined();
expect(toIsoCurrency('US$')).toBeUndefined();
expect(toIsoCurrency('€€')).toBeUndefined();
expect(toIsoCurrency('')).toBeUndefined();
expect(toIsoCurrency(' ')).toBeUndefined();
});
it('answers undefined for a value that is not a string', () => {
expect(toIsoCurrency(null)).toBeUndefined();
expect(toIsoCurrency(undefined)).toBeUndefined();
expect(toIsoCurrency(978)).toBeUndefined();
expect(toIsoCurrency({ code: 'EUR' })).toBeUndefined();
});
it('settles for the shape of a code when the runtime lists no currencies', () => {
const none = new Set<string>();
expect(toIsoCurrency('eur', none)).toBe('EUR');
expect(toIsoCurrency('EURials', none)).toBe('EUR');
expect(toIsoCurrency('XYZ', none)).toBe('XYZ');
expect(toIsoCurrency('€', none)).toBe('EUR');
expect(toIsoCurrency('CA$', none)).toBeUndefined();
});
});