Public: anyone can read this; the crew can change it.

A test pins making a board: a title that makes no slug is refused, and a repeat title gets a fresh slug #7121

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/7114-a-test-pins-making-a-board-a-title-that → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/7114-a-test-pins-making-a-board-a-title-that was merged into main as fabb226.

Review

Sign in to review this change.
1 file changed +69 −0
test/board-make-slug.test.ts added +69
@@ -0,0 +1,69 @@
1 /**
2 * makeBoard turns a title into a slug: `Ops` is `ops`, a title with nothing
3 * to slug is `no_slug` and stores nothing, a repeat title gets a fresh slug
4 * and leaves the first board alone, and a non-admin is told `not_found`.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { listAllBoards, makeBoard, showBoard } from "../src/actions/boards.ts";
11 import { createApp } from "../src/app.ts";
12 import { createUser, type User } from "../src/core/users.ts";
13
14 let dir: string;
15 let app: ReturnType<typeof createApp>;
16 let alice: User;
17 let bob: User;
18
19 beforeAll(async () => {
20 dir = await mkdtemp(join(tmpdir(), "forge-board-make-slug-"));
21 app = createApp({ dataDir: dir, port: 0 });
22 const mk = async (username: string, adminIfFirst?: boolean) => {
23 const r = await createUser(app.db, {
24 origin: "seed", trusted: true, username, email: `${username}@forge.local`,
25 password: "a-good-passphrase", ...(adminIfFirst ? { adminIfFirst } : {}),
26 });
27 if (!r.ok) throw new Error(r.error);
28 return r.value;
29 };
30 alice = await mk("alice", true);
31 bob = await mk("bob");
32 });
33
34 afterAll(async () => {
35 await rm(dir, { recursive: true, force: true });
36 });
37
38 const slugs = async () => {
39 const all = await listAllBoards(app, alice);
40 if (!all.ok) throw new Error(all.error);
41 return all.value.map((s) => s.slug).sort();
42 };
43
44 test("a non-admin is refused and nothing is stored", async () => {
45 expect(await makeBoard(app, bob, "Ops")).toEqual({ ok: false, error: "not_found" });
46 expect(await makeBoard(app, undefined, "Ops")).toEqual({ ok: false, error: "not_found" });
47 expect(await slugs()).toEqual([]);
48 });
49

The non-admin case duplicates test/boards-store.test.ts:152; keep it here for the empty-store check, but the 20-slug exhaustion and long-title suffix cases are the ones that add coverage.

50 test("a title of only punctuation or emoji is no_slug and no board is stored", async () => {
51 for (const title of ["!!!", " --- ", "🔥🔥", ""]) {
52 expect(await makeBoard(app, alice, title)).toEqual({ ok: false, error: "no_slug" });
53 }
54 expect(await slugs()).toEqual([]);
55 });
56
57 test("an admin makes Ops as ops, and a second Ops gets a fresh slug", async () => {
58 const first = await makeBoard(app, alice, "Ops");
59 expect(first).toEqual({ ok: true, value: "ops" });
60 const before = await showBoard(app, alice, "ops");
61
62 const second = await makeBoard(app, alice, "Ops");
63 expect(second.ok).toBe(true);
64 if (!second.ok) return;
65 expect(second.value).not.toBe("ops");
66 expect(await slugs()).toEqual(["ops", second.value].sort());
67 expect(await showBoard(app, alice, "ops")).toEqual(before);
68 expect(await showBoard(app, alice, second.value)).toMatchObject({ ok: true, value: { title: "Ops" } });
69 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs