forked from GitHubMirrors/silverbullet-icalendar
switch to ical.js and cleanup obsolete files - v0.4.6 [skip-ci]
All checks were successful
Build SilverBullet Plug / build (push) Successful in 11s
All checks were successful
Build SilverBullet Plug / build (push) Successful in 11s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { assertEquals, assert } from "jsr:@std/assert";
|
||||
import { convertIcsCalendar } from "https://esm.sh/ts-ics@2.4.0";
|
||||
import { expandRecurrences, resolveEventStart, localDateString } from "../icalendar.ts";
|
||||
import ICAL from "ical.js";
|
||||
import { expandRecurrences, resolveEventStart, dateToTimezoneString } from "../icalendar.ts";
|
||||
|
||||
Deno.test("Integration - parse and expand real-world ICS samples", async () => {
|
||||
const testDataDir = "./test_data";
|
||||
@@ -39,30 +39,39 @@ Deno.test("Integration - parse and expand real-world ICS samples", async () => {
|
||||
for (const file of files) {
|
||||
console.log(` Testing file: ${file}`);
|
||||
const text = await Deno.readTextFile(file);
|
||||
const calendar = convertIcsCalendar(undefined, text);
|
||||
const jcalData = ICAL.parse(text);
|
||||
const vcalendar = new ICAL.Component(jcalData);
|
||||
const vevents = vcalendar.getAllSubcomponents("vevent");
|
||||
|
||||
assert(calendar && calendar.events, `Failed to parse ${file}`);
|
||||
assert(vevents.length > 0, `Failed to parse ${file} or no events found`);
|
||||
|
||||
for (const icsEvent of calendar.events) {
|
||||
if (icsEvent.status?.toUpperCase() === "CANCELLED") continue;
|
||||
for (const vevent of vevents) {
|
||||
const icsEvent = new ICAL.Event(vevent);
|
||||
const status = vevent.getFirstPropertyValue("status") as string | null;
|
||||
if (status?.toUpperCase() === "CANCELLED") continue;
|
||||
|
||||
const finalDate = await resolveEventStart(icsEvent);
|
||||
if (!finalDate) continue;
|
||||
const startDateUTC = icsEvent.startDate.toJSDate();
|
||||
const summary = icsEvent.summary;
|
||||
const rrule = vevent.getFirstPropertyValue("rrule");
|
||||
const exdates = vevent.getAllProperties("exdate").map((p: any) => p.getFirstValue().toJSDate().toISOString());
|
||||
|
||||
const localIso = localDateString(finalDate);
|
||||
const localIso = dateToTimezoneString(startDateUTC, "UTC");
|
||||
const baseEvent = {
|
||||
...icsEvent,
|
||||
name: icsEvent.summary || "Untitled Event",
|
||||
start: localIso,
|
||||
summary,
|
||||
name: summary || "Untitled Event",
|
||||
start: startDateUTC.toISOString(),
|
||||
startLocal: localIso,
|
||||
tag: "ical-event",
|
||||
sourceName: "IntegrationTest"
|
||||
sourceName: "IntegrationTest",
|
||||
rrule: rrule ? rrule.toString() : undefined,
|
||||
exdate: exdates.length > 0 ? exdates : undefined
|
||||
};
|
||||
|
||||
try {
|
||||
const expanded = expandRecurrences(baseEvent, 30);
|
||||
assert(expanded.length >= 1, `Expected at least 1 occurrence for event "${icsEvent.summary}" in ${file}`);
|
||||
assert(expanded.length >= 1, `Expected at least 1 occurrence for event "${summary}" in ${file}`);
|
||||
} catch (err) {
|
||||
console.error(`❌ Error expanding recurrence for event "${icsEvent.summary}" in ${file}:`, err);
|
||||
console.error(`❌ Error expanding recurrence for event "${summary}" in ${file}:`, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user