test(icalendar): Add validation and object rrule reproduction tests

This commit is contained in:
2026-02-20 11:31:18 -08:00
parent 028ae7d9f9
commit a2239d28d5

View File

@@ -154,3 +154,55 @@ Deno.test("expandRecurrences - non-string rrule (Reproduction)", () => {
assert(warningLogged, "Should have logged a warning for non-string rrule");
});
Deno.test("expandRecurrences - validation of visibility logic", () => {
const now = new Date();
const start = new Date(now.getTime() - 100 * 86400000); // Started 100 days ago
const startStr = localDateString(start);
const icsEvent = {
summary: "Validation Weekly Meeting",
start: startStr,
rrule: "FREQ=WEEKLY;BYDAY=" + ["SU","MO","TU","WE","TH","FR","SA"][start.getDay()]
};
const results = expandRecurrences(icsEvent, 30);
// Should produce occurrences for the last 7 days + next 30 days.
// Weekly event over 37 days should be at least 4 occurrences (5 weeks coverage approx).
assert(results.length >= 4, `Expected at least 4 occurrences, got ${results.length}`);
assertEquals(results[0].recurrent, true);
});
Deno.test("expandRecurrences - object rrule (Reproduction of missing events)", () => {
const now = new Date();
const start = new Date(now.getTime() - 100 * 86400000);
const startStr = localDateString(start);
const icsEvent = {
summary: "Object RRULE Event",
start: startStr,
rrule: { freq: "WEEKLY", byday: "MO" } // Simulating object rrule
};
// Spy on console.warn
let warningLogged = false;
const originalConsoleWarn = console.warn;
console.warn = (...args) => {
if (args[0].includes("Invalid rrule type (object)")) {
warningLogged = true;
}
};
try {
const results = expandRecurrences(icsEvent, 30);
// Currently, it returns [icsEvent] (length 1) and logs a warning.
// This confirms that it is NOT expanding it.
assertEquals(results.length, 1);
} finally {
console.warn = originalConsoleWarn;
}
assert(warningLogged, "Should have logged a warning for object rrule");
});