Files
Kitchen2/tests/unit/currency.test.ts
T

28 lines
1.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { formatCurrency, calculateBasePrice, calculateStockValueCents } from '@/lib/formatting/currency';
describe('Currency & Stock Value Formatting', () => {
it('formats integer cents into German Euro currency string', () => {
expect(formatCurrency(249)).toContain('2,49');
expect(formatCurrency(0)).toContain('0,00');
expect(formatCurrency(1299)).toContain('12,99');
});
it('calculates full package stock value correctly', () => {
// 2 packages @ 1,99 € (199 Cent) = 398 Cent
expect(calculateStockValueCents(2, 1, 199)).toBe(398);
});
it('calculates partial package stock value correctly (750g of 1000g @ 1,29 € = 0,97 €)', () => {
// 750g / 1000g * 129 Cent = 96.75 Cent -> rounded to 97 Cent
expect(calculateStockValueCents(750, 1000, 129)).toBe(97);
});
it('calculates base price (Grundpreis) per 1kg for grams', () => {
// 500g Barilla Spaghetti @ 1,89 € (189 Cent) -> 3.78 € / kg (378 Cent)
const base = calculateBasePrice(189, 500, 'g');
expect(base.basePriceCents).toBe(378);
expect(base.basePriceUnit).toBe('1 kg');
});
});