Files
ihasmail/web/src/store/__tests__/participants.test.ts
T
jcoffey-dev cc073693f4 Say it in the words Stalwart 0.16 answers to
Guests added to an event vanished on save and no invitation was ever
sent. Not a guard in the editor, and nothing the server complained
about: ihasmail addresses a participant the way RFC 8984 does, with
sendTo and email, and Stalwart 0.16 keeps that address under
calendarAddress. Handed the RFC's spelling it stores the event, drops
the entire participant map, and reports success. Six shapes were tried
against a live 0.16.19, down to sendTo and roles alone; all six were
dropped, and patching a participant onto an existing event fails
outright with "Patch operation failed".

The same disagreement runs through two more properties. The organizer is
organizerCalendarAddress, not replyTo. A recurrence is a single
recurrenceRule, not a recurrenceRules array — and that one Stalwart
refuses honestly, with invalidProperties, so no recurring event could be
created at all and existing ones showed no repeat.

So writes now use Stalwart's names and reads accept either, since a
mailbox may hold events written by other clients. The mock now refuses
what the real server refuses and drops what it drops: advertising the
RFC spelling is exactly how this reached a live server unnoticed, the
same way the capability-placement bug did.

Verified against 0.16.19: participants, organizer and rule all survive a
create, an update and a re-read, with the roles kept as sent.

Fixes #26
Fixes #30
2026-08-25 08:26:34 -07:00

59 lines
3.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { participantAddresses, participantEmail, isAttendee, eventRule, makeParticipant } from "@/store/calendar";
import type { CalendarEvent, JSCalendarParticipant } from "@/jmap/types";
/**
* Stalwart 0.16.19 and RFC 8984 disagree about where a participant's address
* lives. Sent the RFC's way, Stalwart keeps the event and drops the participant
* map without a word — guests vanished and no invitation was ever sent (#26).
* Shapes below are what a live 0.16.19 returned.
*/
const p = (o: Partial<JSCalendarParticipant>): JSCalendarParticipant => ({ roles: {}, ...o });
const ev = (o: Partial<CalendarEvent>): CalendarEvent => ({ id: "e1", "@type": "Event", uid: "u1", calendarIds: { c1: true }, start: "2030-01-01T10:00:00", ...o } as CalendarEvent);
describe("participant addresses", () => {
it("reads Stalwart's calendarAddress", () => {
expect(participantEmail(p({ calendarAddress: "mailto:[email protected]" }))).toBe("[email protected]");
});
it("still reads the RFC 8984 spellings, for events written by other clients", () => {
expect(participantEmail(p({ sendTo: { imip: "mailto:[email protected]" } }))).toBe("[email protected]");
expect(participantEmail(p({ email: "[email protected]" }))).toBe("[email protected]");
expect(participantAddresses(p({ calendarAddress: "mailto:[email protected]", email: "[email protected]" }))).toEqual(["mailto:[email protected]", "mailto:[email protected]"]);
});
it("has no address to offer when the participant carries none", () => {
expect(participantEmail(p({ name: "Nameless" }))).toBe("");
});
it("counts a participant as attending under either role name", () => {
expect(isAttendee(p({ roles: { attendee: true } }))).toBe(true);
expect(isAttendee(p({ roles: { required: true } }))).toBe(true); // what Stalwart writes for REQ-PARTICIPANT
expect(isAttendee(p({ roles: { optional: true } }))).toBe(true);
expect(isAttendee(p({ roles: { owner: true } }))).toBe(false);
});
});
describe("makeParticipant", () => {
it("addresses a guest the way Stalwart stores them", () => {
const guest = makeParticipant("[email protected]", "Guest", "attendee");
expect(guest.calendarAddress).toBe("mailto:[email protected]");
expect(guest.sendTo).toBeUndefined();
expect(guest.roles).toEqual({ attendee: true, required: true });
expect(guest.participationStatus).toBe("needs-action");
expect(guest.expectReply).toBe(true);
});
it("marks the organizer as owner and keeps a status already given", () => {
const me = makeParticipant("[email protected]", "John Coffey", "owner");
expect(me.roles).toEqual({ owner: true, attendee: true });
expect(me.participationStatus).toBe("accepted");
expect(me.expectReply).toBe(false);
expect(makeParticipant("[email protected]", null, "attendee", "declined").participationStatus).toBe("declined");
});
});
describe("eventRule", () => {
it("reads Stalwart's singular rule and the RFC's array", () => {
expect(eventRule(ev({ recurrenceRule: { "@type": "RecurrenceRule", frequency: "weekly" } }))?.frequency).toBe("weekly");
expect(eventRule(ev({ recurrenceRules: [{ "@type": "RecurrenceRule", frequency: "daily" }] }))?.frequency).toBe("daily");
expect(eventRule(ev({}))).toBeUndefined();
});
});