Skip to content
38 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { INVITES_DONE, MAX_GRANT, doneMessage, invitesHref, invitesTab, joinedThrough, parseGrant } from "./invites.ts";
5
6test("the page has one address, with its search and tab", () => {
7 assert.equal(invitesHref(), "/invites");
8 assert.equal(invitesHref({ q: "g1t-k7m2", empty: "" }), "/invites?q=g1t-k7m2");
9 assert.equal(invitesHref({ tab: "g1t" }), "/invites?tab=g1t");
10 assert.equal(invitesTab("g1t"), "g1t");
11 assert.equal(invitesTab("waitlist"), "all");
12 assert.equal(invitesTab(null), "all");
13});
14
15test("revoking and granting say so, and nothing else is flashed", () => {
16 assert.equal(doneMessage("revoked"), INVITES_DONE.revoked);
17 assert.equal(doneMessage("granted"), INVITES_DONE.granted);
18 assert.equal(doneMessage("approved"), null);
19 assert.equal(doneMessage(null), null);
20});
21
22test("an account made with a shared link says where it came from", () => {
23 assert.equal(joinedThrough("Cloudflare judges"), "Joined through Cloudflare judges");
24});
25
26test("a grant names a person, a whole number of invites and why", () => {
27 const form = (fields: Record<string, string>) => new Map(Object.entries(fields));
28 assert.deepEqual(parseGrant(form({ username: "@Ada", amount: "10", note: "Bringing her team" })), {
29 ok: true,
30 value: { username: "ada", amount: 10, note: "Bringing her team" },
31 });
32 assert.equal(parseGrant(form({ username: "ada", amount: "-5", note: "Too many" })).ok, true);
33 assert.equal(parseGrant(form({ username: "not a name", amount: "10", note: "why" })).ok, false);
34 assert.equal(parseGrant(form({ username: "ada", amount: "0", note: "why" })).ok, false);
35 assert.equal(parseGrant(form({ username: "ada", amount: String(MAX_GRANT + 1), note: "why" })).ok, false);
36 assert.equal(parseGrant(form({ username: "ada", amount: "2.5", note: "why" })).ok, false);
37 assert.equal(parseGrant(form({ username: "ada", amount: "10", note: "" })).ok, false);
38});