mirror of
https://github.com/kennethnym/aris.git
synced 2026-04-15 22:31:19 +01:00
feat: add CalDAV source provider (#111)
Wire CalDavSourceProvider into the backend to support CalDAV calendar sources (e.g. iCloud) with basic auth. Config accepts serverUrl, username, lookAheadDays, and timeZone. Credentials (app-specific password) are stored encrypted via the existing credential storage infrastructure. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
85
apps/aelis-backend/src/caldav/provider.test.ts
Normal file
85
apps/aelis-backend/src/caldav/provider.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
||||
import { CalDavSourceProvider } from "./provider.ts"
|
||||
|
||||
describe("CalDavSourceProvider", () => {
|
||||
const provider = new CalDavSourceProvider()
|
||||
|
||||
test("sourceId is aelis.caldav", () => {
|
||||
expect(provider.sourceId).toBe("aelis.caldav")
|
||||
})
|
||||
|
||||
test("throws when credentials are null", async () => {
|
||||
const config = { serverUrl: "https://caldav.icloud.com", username: "user@icloud.com" }
|
||||
await expect(provider.feedSourceForUser("user-1", config, null)).rejects.toThrow(
|
||||
"No CalDAV credentials configured",
|
||||
)
|
||||
})
|
||||
|
||||
test("throws when credentials are missing password", async () => {
|
||||
const config = { serverUrl: "https://caldav.icloud.com", username: "user@icloud.com" }
|
||||
await expect(provider.feedSourceForUser("user-1", config, {})).rejects.toThrow(
|
||||
"password must be a string",
|
||||
)
|
||||
})
|
||||
|
||||
test("throws when config is missing serverUrl", async () => {
|
||||
const credentials = { password: "app-specific-password" }
|
||||
await expect(
|
||||
provider.feedSourceForUser("user-1", { username: "user@icloud.com" }, credentials),
|
||||
).rejects.toThrow("Invalid CalDAV config")
|
||||
})
|
||||
|
||||
test("throws when config is missing username", async () => {
|
||||
const credentials = { password: "app-specific-password" }
|
||||
await expect(
|
||||
provider.feedSourceForUser("user-1", { serverUrl: "https://caldav.icloud.com" }, credentials),
|
||||
).rejects.toThrow("Invalid CalDAV config")
|
||||
})
|
||||
|
||||
test("throws when config has extra keys", async () => {
|
||||
const config = {
|
||||
serverUrl: "https://caldav.icloud.com",
|
||||
username: "user@icloud.com",
|
||||
extra: true,
|
||||
}
|
||||
const credentials = { password: "app-specific-password" }
|
||||
await expect(provider.feedSourceForUser("user-1", config, credentials)).rejects.toThrow(
|
||||
"Invalid CalDAV config",
|
||||
)
|
||||
})
|
||||
|
||||
test("throws when credentials have extra keys", async () => {
|
||||
const config = { serverUrl: "https://caldav.icloud.com", username: "user@icloud.com" }
|
||||
const credentials = { password: "app-specific-password", extra: true }
|
||||
await expect(provider.feedSourceForUser("user-1", config, credentials)).rejects.toThrow(
|
||||
"extra must be removed",
|
||||
)
|
||||
})
|
||||
|
||||
test("returns CalDavSource with valid config and credentials", async () => {
|
||||
const config = {
|
||||
serverUrl: "https://caldav.icloud.com",
|
||||
username: "user@icloud.com",
|
||||
lookAheadDays: 3,
|
||||
timeZone: "Europe/London",
|
||||
}
|
||||
const credentials = { password: "app-specific-password" }
|
||||
|
||||
const source = await provider.feedSourceForUser("user-1", config, credentials)
|
||||
expect(source).toBeDefined()
|
||||
expect(source.id).toBe("aelis.caldav")
|
||||
})
|
||||
|
||||
test("returns CalDavSource with minimal config", async () => {
|
||||
const config = {
|
||||
serverUrl: "https://caldav.icloud.com",
|
||||
username: "user@icloud.com",
|
||||
}
|
||||
const credentials = { password: "app-specific-password" }
|
||||
|
||||
const source = await provider.feedSourceForUser("user-1", config, credentials)
|
||||
expect(source).toBeDefined()
|
||||
expect(source.id).toBe("aelis.caldav")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user