flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/sudo/app/lib/invites.test.ts

43 lines2,309 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { INVITES_DONE, invitesHref, parseGrant, parseMintEmail, parseTab, parseWaitlistStatus } from "./invites.ts";
5
6const form = (fields: Record<string, string>) => ({ get: (name: string) => fields[name] ?? null });
7
8test("the page opens on the waitlist, and each tab has an address", () => {
9 assert.equal(parseTab(null), "waitlist");
10 assert.equal(parseTab("tree"), "tree");
11 assert.equal(parseTab("nope"), "waitlist");
12 assert.equal(invitesHref("invites", { q: "g1t-k7m2", empty: "" }), "/invites?tab=invites&q=g1t-k7m2");
13 assert.equal(parseWaitlistStatus(null), "waiting");
14 assert.equal(parseWaitlistStatus("all"), "all");
15 assert.equal(parseWaitlistStatus("dismissed"), "dismissed");
16});
17
18test("a grant names who, how many and why", () => {
19 assert.deepEqual(parseGrant(form({ target: "user", name: "@Ada", amount: "10", note: "Launch partner" })), {
20 ok: true,
21 value: { target: "user", name: "ada", amount: 10, note: "Launch partner" },
22 });
23 assert.deepEqual(parseGrant(form({ target: "workspace", name: "acme", amount: "-5", note: "Abuse" })), {
24 ok: true,
25 value: { target: "workspace", name: "acme", amount: -5, note: "Abuse" },
26 });
27 assert.equal(parseGrant(form({ target: "team", name: "acme", amount: "5", note: "why" })).ok, false);
28 assert.equal(parseGrant(form({ target: "user", name: "not a name", amount: "5", note: "why" })).ok, false);
29 assert.equal(parseGrant(form({ target: "user", name: "ada", amount: "0", note: "why" })).ok, false);
30 assert.equal(parseGrant(form({ target: "user", name: "ada", amount: "1.5", note: "why" })).ok, false);
31 assert.equal(parseGrant(form({ target: "user", name: "ada", amount: "5000", note: "why" })).ok, false);
32 assert.equal(parseGrant(form({ target: "user", name: "ada", amount: "5", note: "" })).ok, false);
33});
34
35test("a minted invite is for one address, or for anyone", () => {
36 assert.deepEqual(parseMintEmail(""), { ok: true, value: null });
37 assert.deepEqual(parseMintEmail(" Ada@Example.com "), { ok: true, value: "ada@example.com" });
38 assert.equal(parseMintEmail("ada@").ok, false);
39});
40
41test("every outcome has words", () => {
42 for (const key of ["approved", "dismissed", "revoked", "granted"]) assert.ok(INVITES_DONE[key]);
43});