Files
Artista-Filmcamp/tests/sales-gate.test.ts
T
Nick Szaunig 59bb5a38a3
Docker-Images bauen und veroeffentlichen / build-and-push (push) Failing after 1m32s
first commit
2026-09-27 06:06:56 +02:00

102 lines
3.5 KiB
TypeScript

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,
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: "[email protected]",
organizerConfirmed: true,
taxNote: "Hinweis",
taxConfirmed: true,
termsVersion: "1",
termsApproved: 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(11);
});
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");
});
});