mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 20:41:16 +00:00
54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
NOTIFICATION_TYPES,
|
|
NOTIFICATION_TYPE_KEYS,
|
|
isNotificationType,
|
|
resolveNotificationSettings,
|
|
} from "@/src/modules/notifications/lib/notification-types";
|
|
|
|
describe("isNotificationType", () => {
|
|
it("erkennt gültige Registry-Keys", () => {
|
|
expect(isNotificationType("booking.created")).toBe(true);
|
|
expect(isNotificationType("course.cancelled")).toBe(true);
|
|
});
|
|
|
|
it("lehnt unbekannte Keys ab", () => {
|
|
expect(isNotificationType("booking.unknown")).toBe(false);
|
|
expect(isNotificationType("")).toBe(false);
|
|
expect(isNotificationType("__proto__")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("resolveNotificationSettings", () => {
|
|
it("liefert bei null alle Registry-Defaults", () => {
|
|
const resolved = resolveNotificationSettings(null);
|
|
expect(Object.keys(resolved).sort()).toEqual([...NOTIFICATION_TYPE_KEYS].sort());
|
|
for (const key of NOTIFICATION_TYPE_KEYS) {
|
|
expect(resolved[key]).toBe(NOTIFICATION_TYPES[key].defaultOn);
|
|
}
|
|
});
|
|
|
|
it("übersteuert einzelne Keys aus dem gespeicherten Wert", () => {
|
|
const resolved = resolveNotificationSettings({ "booking.created": false });
|
|
expect(resolved["booking.created"]).toBe(false);
|
|
// nicht gesetzte Keys fallen weiterhin auf den Default zurück
|
|
expect(resolved["course.cancelled"]).toBe(NOTIFICATION_TYPES["course.cancelled"].defaultOn);
|
|
});
|
|
|
|
it("ignoriert unbekannte Keys und Nicht-Boolean-Werte", () => {
|
|
const resolved = resolveNotificationSettings({
|
|
"booking.created": "yes",
|
|
"bogus.key": true,
|
|
"course.full": 1,
|
|
});
|
|
expect(resolved["booking.created"]).toBe(NOTIFICATION_TYPES["booking.created"].defaultOn);
|
|
expect(resolved["course.full"]).toBe(NOTIFICATION_TYPES["course.full"].defaultOn);
|
|
expect("bogus.key" in resolved).toBe(false);
|
|
});
|
|
|
|
it("behandelt Arrays / primitive Werte als leer", () => {
|
|
expect(resolveNotificationSettings([1, 2, 3])).toEqual(resolveNotificationSettings(null));
|
|
expect(resolveNotificationSettings("string")).toEqual(resolveNotificationSettings(null));
|
|
expect(resolveNotificationSettings(42)).toEqual(resolveNotificationSettings(null));
|
|
});
|
|
});
|