forked from GitHubMirrors/silverbullet-icalendar
chore(test): Add integration test scaffolding for real-world ICS data
This commit is contained in:
70
tests/integration_test.ts
Normal file
70
tests/integration_test.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
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";
|
||||
|
||||
Deno.test("Integration - parse and expand real-world ICS samples", async () => {
|
||||
const testDataDir = "./test_data";
|
||||
let files: string[] = [];
|
||||
try {
|
||||
for await (const dirEntry of Deno.readDir(testDataDir)) {
|
||||
if (dirEntry.isFile && dirEntry.name.endsWith(".ics")) {
|
||||
files.push(`${testDataDir}/${dirEntry.name}`);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
console.warn("⚠️ No test_data directory found or accessible. Skipping real-data integration test.");
|
||||
// We might be running from root
|
||||
}
|
||||
|
||||
if (files.length === 0) {
|
||||
// Try current dir if test_data is empty (fallback for CI or root execution)
|
||||
try {
|
||||
for await (const dirEntry of Deno.readDir(".")) {
|
||||
if (dirEntry.isFile && dirEntry.name.endsWith(".ics") && dirEntry.name !== "PLUG.md") {
|
||||
files.push(dirEntry.name);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (files.length === 0) {
|
||||
console.warn("⚠️ No .ics files found for integration test.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Found ${files.length} files to test.`);
|
||||
|
||||
for (const file of files) {
|
||||
console.log(` Testing file: ${file}`);
|
||||
const text = await Deno.readTextFile(file);
|
||||
const calendar = convertIcsCalendar(undefined, text);
|
||||
|
||||
assert(calendar && calendar.events, `Failed to parse ${file}`);
|
||||
|
||||
for (const icsEvent of calendar.events) {
|
||||
if (icsEvent.status?.toUpperCase() === "CANCELLED") continue;
|
||||
|
||||
const finalDate = await resolveEventStart(icsEvent);
|
||||
if (!finalDate) continue;
|
||||
|
||||
const localIso = localDateString(finalDate);
|
||||
const baseEvent = {
|
||||
...icsEvent,
|
||||
name: icsEvent.summary || "Untitled Event",
|
||||
start: localIso,
|
||||
tag: "ical-event",
|
||||
sourceName: "IntegrationTest"
|
||||
};
|
||||
|
||||
try {
|
||||
const expanded = expandRecurrences(baseEvent, 30);
|
||||
assert(expanded.length >= 1, `Expected at least 1 occurrence for event "${icsEvent.summary}" in ${file}`);
|
||||
} catch (err) {
|
||||
console.error(`❌ Error expanding recurrence for event "${icsEvent.summary}" in ${file}:`, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user