Skip to content

Commit cdbacdf

Browse files
committed
test: cover untested emailDraftSchema and eventDraftSchema branches
emailDraftSchema's multi-line subject rejection and its cc/bcc/attachmentIds length limits had no coverage, and eventDraftSchema's requirement that timed events carry an explicit UTC offset was only exercised incidentally. Add direct tests for these branches plus the schemas' defaults.
1 parent 82ff35b commit cdbacdf

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

‎tests/domain.test.ts‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
import {
4+
emailDraftSchema,
5+
eventDraftSchema,
6+
proposalSchema,
7+
} from "../packages/domain/src/index.ts";
8+
9+
const email = {
10+
to: ["reader@example.com"],
11+
subject: "Your visit",
12+
body: "See you soon.",
13+
};
14+
const event = {
15+
title: "Museum visit",
16+
start: "2026-10-10T10:00:00-07:00",
17+
end: "2026-10-10T14:00:00-07:00",
18+
};
19+
20+
test("email drafts default cc, bcc, and attachmentIds to empty arrays", () => {
21+
const parsed = emailDraftSchema.parse(email);
22+
assert.deepEqual(parsed.cc, []);
23+
assert.deepEqual(parsed.bcc, []);
24+
assert.deepEqual(parsed.attachmentIds, []);
25+
});
26+
27+
test("email drafts reject a subject containing a line break", () => {
28+
assert.equal(emailDraftSchema.safeParse({ ...email, subject: "Visit\nplan" }).success, false);
29+
assert.equal(emailDraftSchema.safeParse({ ...email, subject: "Visit\rplan" }).success, false);
30+
});
31+
32+
test("email drafts enforce recipient, cc/bcc, and attachment limits", () => {
33+
assert.equal(emailDraftSchema.safeParse({ ...email, to: [] }).success, false);
34+
assert.equal(
35+
emailDraftSchema.safeParse({
36+
...email,
37+
cc: Array.from({ length: 51 }, (_, i) => `person${i}@example.com`),
38+
}).success,
39+
false,
40+
);
41+
assert.equal(
42+
emailDraftSchema.safeParse({
43+
...email,
44+
attachmentIds: Array.from({ length: 11 }, (_, i) => `file-${i}`),
45+
}).success,
46+
false,
47+
);
48+
});
49+
50+
test("email drafts reject malformed addresses", () => {
51+
assert.equal(emailDraftSchema.safeParse({ ...email, to: ["not-an-email"] }).success, false);
52+
});
53+
54+
test("timed events require an explicit UTC offset", () => {
55+
assert.equal(eventDraftSchema.parse(event).timeZone, "America/Los_Angeles");
56+
assert.equal(
57+
eventDraftSchema.safeParse({ ...event, start: "2026-10-10T10:00:00" }).success,
58+
false,
59+
);
60+
assert.equal(
61+
eventDraftSchema.safeParse({ ...event, start: "2026-10-10T10:00:00Z" }).success,
62+
true,
63+
);
64+
});
65+
66+
test("all-day events reject a full timestamp in place of a date", () => {
67+
const allDay = { ...event, allDay: true, start: "2026-10-10", end: "2026-10-11" };
68+
assert.equal(eventDraftSchema.parse(allDay).allDay, true);
69+
assert.equal(
70+
eventDraftSchema.safeParse({ ...allDay, start: "2026-10-10T00:00:00Z" }).success,
71+
false,
72+
);
73+
});
74+
75+
test("events reject an end at or before the start", () => {
76+
assert.equal(
77+
eventDraftSchema.safeParse({ ...event, end: "2026-10-09T10:00:00-07:00" }).success,
78+
false,
79+
);
80+
assert.equal(eventDraftSchema.safeParse({ ...event, end: event.start }).success, false);
81+
});
82+
83+
test("events default calendarId, location, and description", () => {
84+
const parsed = eventDraftSchema.parse(event);
85+
assert.equal(parsed.calendarId, "primary");
86+
assert.equal(parsed.location, "");
87+
assert.equal(parsed.description, "");
88+
});
89+
90+
test("proposal schema discriminates on kind and validates nested data", () => {
91+
assert.equal(proposalSchema.safeParse({ kind: "email.send", data: email }).success, true);
92+
assert.equal(
93+
proposalSchema.safeParse({ kind: "email.send", data: { ...email, subject: "" } }).success,
94+
false,
95+
);
96+
assert.equal(proposalSchema.safeParse({ kind: "unknown.kind", data: {} }).success, false);
97+
});

0 commit comments

Comments
 (0)