import { describe, expect, test } from "vitest"; import { evaluateSales, type CampGateFields } from "@/lib/sales-gate"; const unreleased: CampGateFields = { salesEnabled: false, capacityConfirmed: false, stammmodelQuotaConfirmed: false, campStartDate: null, dateConfirmed: false, locationName: null, locationConfirmed: false, accommodationText: null, accommodationConfirmed: false, servicesConfirmed: false, organizerName: null, organizerAddress: null, organizerEmail: null, organizerConfirmed: false, taxNote: null, taxConfirmed: false, termsVersion: null, termsApproved: false, withdrawalText: null, withdrawalApproved: false, travelLawChecked: false, installmentsApproved: false, installmentRuleApproved: false, testPhaseOverride: null, }; const released: CampGateFields = { ...unreleased, salesEnabled: true, capacityConfirmed: true, stammmodelQuotaConfirmed: true, campStartDate: "2027-06-05", dateConfirmed: true, locationName: "Villa", locationConfirmed: true, accommodationText: "Beschreibung", accommodationConfirmed: true, servicesConfirmed: true, organizerName: "Veranstalter", organizerAddress: "Adresse", organizerEmail: "kontakt@example.org", organizerConfirmed: true, taxNote: "Hinweis", taxConfirmed: true, termsVersion: "1", termsApproved: true, withdrawalText: "Belehrung", withdrawalApproved: true, travelLawChecked: true, }; const earlyBird = new Date("2026-11-10T12:00:00Z"); describe("Verkaufsfreigabe", () => { test("Livemodus ohne Freigaben: Checkout gesperrt, alle Blocker benannt", () => { const state = evaluateSales(earlyBird, unreleased, "live"); expect(state.checkoutOpen).toBe(false); expect(state.closedReason).toBe("NOT_RELEASED"); expect(state.releaseBlockers).toHaveLength(12); }); test("Livemodus: eine einzige fehlende Freigabe sperrt den Verkauf", () => { const state = evaluateSales(earlyBird, { ...released, travelLawChecked: false }, "live"); expect(state.checkoutOpen).toBe(false); expect(state.releaseBlockers).toEqual(["TRAVEL_LAW"]); }); test("Livemodus mit allen Freigaben in der Early-Bird-Phase: offen", () => { expect(evaluateSales(earlyBird, released, "live").checkoutOpen).toBe(true); }); test("Livemodus vor dem 01.11.2026: Vorschau ohne Kaufmoeglichkeit, Override wirkungslos", () => { const state = evaluateSales(new Date("2026-10-01T12:00:00Z"), { ...released, testPhaseOverride: "EARLY_BIRD" }, "live"); expect(state.checkoutOpen).toBe(false); expect(state.closedReason).toBe("PREVIEW"); }); test("Testmodus ohne Freigaben: Checkout offen, Preisphase simulierbar", () => { const state = evaluateSales(new Date("2026-10-01T12:00:00Z"), { ...unreleased, testPhaseOverride: "REGULAR" }, "test"); expect(state.checkoutOpen).toBe(true); expect(state.effectivePhase).toBe("REGULAR"); expect(state.phaseSimulated).toBe(true); }); test("Testmodus ohne Override vor Verkaufsstart bleibt Vorschau", () => { expect(evaluateSales(new Date("2026-10-01T12:00:00Z"), unreleased, "test").checkoutOpen).toBe(false); }); test("Ratenzahlung live erst nach ausdruecklicher Freigabe", () => { expect(evaluateSales(earlyBird, released, "live").installmentsAllowed).toBe(false); expect( evaluateSales(earlyBird, { ...released, installmentsApproved: true, installmentRuleApproved: true }, "live") .installmentsAllowed, ).toBe(true); }); test("ab Anreisetag ist der Verkauf geschlossen", () => { const state = evaluateSales(new Date("2027-06-05T08:00:00Z"), released, "live"); expect(state.closedReason).toBe("CAMP_STARTED"); }); });