Skip to content
30 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { inviteTarget, looksLikeEmail, peopleQuery } from "./people-search.ts";
5import { declinedLine, invitationLine } from "./invitations.ts";
6
7test("people are searched by username or name, and an email address is never looked up", () => {
8 assert.equal(peopleQuery(" @daw "), "daw");
9 assert.equal(peopleQuery("Dawn W"), "Dawn W");
10 assert.equal(peopleQuery("dawn@example.com"), null);
11 assert.equal(peopleQuery(" "), null);
12 assert.equal(peopleQuery("@"), null);
13 assert.equal(looksLikeEmail("@ada"), false);
14});
15
16test("the invite form names an address or a username", () => {
17 assert.deepEqual(inviteTarget("Ada@Example.com "), { email: "Ada@Example.com" });
18 assert.deepEqual(inviteTarget("@DaWeazl"), { username: "daweazl" });
19 assert.equal(inviteTarget(" "), null);
20});
21
22test("an invitation says the role it joins with and how long it works", () => {
23 const now = Date.parse("2026-10-08T12:00:00Z");
24 assert.equal(
25 invitationLine({ role: "member", expiresAt: "2026-11-07T12:00:00Z" }, now),
26 "invited you to join as a member. It works for 30 more days.",
27 );
28 assert.equal(invitationLine({ role: "owner", expiresAt: "2026-10-09T00:00:00Z" }, now), "invited you to join as an owner. It expires within a day.");
29 assert.match(declinedLine("Flagon, Inc."), /declined the invitation to Flagon, Inc\..*told/);
30});