import { describe, expect, test } from "vitest"; import { calculatePrice, EARLY_BIRD_START, pricePhaseAt, REGULAR_START } from "@/lib/pricing"; import { formatEuro } from "@/lib/money"; describe("Gesamtpreise laut Preistabelle", () => { test.each([ ["EARLY_BIRD", false, 220_000], ["EARLY_BIRD", true, 198_000], ["REGULAR", false, 275_000], ["REGULAR", true, 247_500], ] as const)("%s mit Stammmodel-Code=%s kostet %i Cent", (phase, code, expected) => { expect(calculatePrice(phase, code).totalCents).toBe(expected); }); test("kombinierter Nachlass im Early Bird betraegt 28 %, nicht 30 %", () => { const price = calculatePrice("EARLY_BIRD", true); const discount = price.basePriceCents - price.totalCents; expect(discount / price.basePriceCents).toBe(0.28); expect(price.phaseDiscountCents).toBe(55_000); expect(price.voucherDiscountCents).toBe(22_000); }); test("Formatierung in Euro", () => { expect(formatEuro(220_000)).toBe("2.200,00 €"); expect(formatEuro(123_750)).toBe("1.237,50 €"); }); }); describe("Zeitgrenzen in Europe/Berlin", () => { test("Early Bird beginnt am 01.11.2026 um 00:00 Berliner Zeit (= 31.10. 23:00 UTC, Winterzeit)", () => { expect(EARLY_BIRD_START.toISOString()).toBe("2026-10-31T23:00:00.000Z"); expect(pricePhaseAt(new Date("2026-10-31T22:59:59.999Z"))).toBe("PREVIEW"); expect(pricePhaseAt(new Date("2026-10-31T23:00:00.000Z"))).toBe("EARLY_BIRD"); }); test("Sommerzeit-Ende am 25.10.2026 verschiebt die Grenze nicht", () => { // 31.10.2026 20:00 Berlin (Winterzeit) ist noch Vorschau. expect(pricePhaseAt(new Date("2026-10-31T19:00:00Z"))).toBe("PREVIEW"); }); test("Early Bird gilt bis einschliesslich 31.12.2026, regulaer ab 01.01.2027 00:00 Berlin", () => { expect(REGULAR_START.toISOString()).toBe("2026-12-31T23:00:00.000Z"); expect(pricePhaseAt(new Date("2026-12-31T22:59:59.999Z"))).toBe("EARLY_BIRD"); expect(pricePhaseAt(new Date("2026-12-31T23:00:00.000Z"))).toBe("REGULAR"); expect(pricePhaseAt(new Date("2027-06-01T12:00:00Z"))).toBe("REGULAR"); }); });