33 lines
1.9 KiB
TypeScript
33 lines
1.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { dueRulesToday, idempotencyKey, parseReminderDays } from "../lib/reminders";
|
|
describe("dueRulesToday", () => {
|
|
it("30/6/1 trifft am richtigen Tag", () => {
|
|
const ablauf = new Date("2026-12-01T00:00:00");
|
|
const rules = [{ id: 1, tageVorher: 30 }, { id: 2, tageVorher: 6 }, { id: 3, tageVorher: 1 }];
|
|
expect(dueRulesToday({ ablaufdatum: ablauf, status: "aktiv" }, rules, new Date("2026-11-01T12:00:00"))).toEqual([1]);
|
|
expect(dueRulesToday({ ablaufdatum: ablauf, status: "aktiv" }, rules, new Date("2026-11-30T08:00:00"))).toEqual([3]);
|
|
});
|
|
it("kein Ablaufdatum und eingelöst nie fällig", () => {
|
|
expect(dueRulesToday({ ablaufdatum: null, status: "aktiv" }, [{ id: 1, tageVorher: 7 }], new Date())).toEqual([]);
|
|
expect(dueRulesToday({ ablaufdatum: new Date(), status: "eingeloest" }, [{ id: 1, tageVorher: 0 }], new Date())).toEqual([]);
|
|
});
|
|
it("key ist stabil", () => {
|
|
expect(idempotencyKey(1, "mail", "a@b.de", "2026-12-01")).toBe("1|mail|a@b.de|2026-12-01");
|
|
});
|
|
it("parseReminderDays: feste Auswahl 30/14/7/6/3/1", () => {
|
|
expect(parseReminderDays("30,6,1")).toEqual([30, 6, 1]);
|
|
expect(parseReminderDays(undefined)).toEqual([30, 6, 1]);
|
|
expect(parseReminderDays("")).toEqual([30, 6, 1]);
|
|
expect(parseReminderDays("30,14,7,6,3,1")).toEqual([30, 14, 7, 6, 3, 1]);
|
|
expect(parseReminderDays("30,99,abc")).toEqual([30]);
|
|
expect(parseReminderDays([30, 6, 1])).toEqual([30, 6, 1]);
|
|
expect(parseReminderDays([1])).toEqual([1]);
|
|
// bewusst keine Erinnerung: leeres Array
|
|
expect(parseReminderDays([])).toEqual([]);
|
|
// "bald"/"abc" parst zu [] → API antwortet 400 mit errors ["reminderDays"]
|
|
expect(parseReminderDays("bald")).toEqual([]);
|
|
expect(parseReminderDays("abc,!!")).toEqual([]);
|
|
expect(parseReminderDays("30,bald,1")).toEqual([30, 1]);
|
|
});
|
|
});
|