35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { centsToFrancs, formatMoney, francsToCents } from '../../src/sim/money';
|
|
|
|
describe('money', () => {
|
|
it('converts francs to euro cents at the fixed rate', () => {
|
|
expect(francsToCents(249)).toBe(3796);
|
|
expect(francsToCents(199)).toBe(3034);
|
|
expect(francsToCents(0)).toBe(0);
|
|
});
|
|
|
|
it('converts cents back to francs', () => {
|
|
expect(centsToFrancs(3796)).toBeCloseTo(249, 1);
|
|
});
|
|
|
|
it('formats in francs before 2002', () => {
|
|
expect(formatMoney(3796, { year: 1990, month: 9, day: 28 })).toBe('249,00 F');
|
|
});
|
|
|
|
it('displays whole franc amounts without conversion drift', () => {
|
|
const d = { year: 1990, month: 9, day: 28 };
|
|
expect(formatMoney(francsToCents(300), d)).toBe('300,00 F');
|
|
expect(formatMoney(francsToCents(149), d)).toBe('149,00 F');
|
|
expect(formatMoney(francsToCents(6000), d)).toBe('6000,00 F');
|
|
expect(formatMoney(francsToCents(249.9), d)).toBe('249,90 F');
|
|
});
|
|
|
|
it('formats in euros from 2002', () => {
|
|
expect(formatMoney(3796, { year: 2002, month: 1, day: 1 })).toBe('37,96 €');
|
|
});
|
|
|
|
it('formats negative amounts', () => {
|
|
expect(formatMoney(-3796, { year: 2002, month: 1, day: 1 })).toBe('-37,96 €');
|
|
});
|
|
});
|