Skip to content

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

68 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { type MissingKind, missingKind, notFoundCopy } from "./not-found.ts";
5
6test("the kind a loader names wins over the address", () => {
7 assert.equal(missingKind({ kind: "project" }, "/acme/web/blob/main/x"), "project");
8 assert.equal(missingKind({ kind: "pull" }, "/acme/web/pull/7"), "pull");
9 // Anything else a loader put there is ignored.
10 assert.equal(missingKind({ kind: "secret" }, "/acme/web"), "project");
11 assert.equal(missingKind("Work item not found.", "/acme/-/work/3"), "item");
12});
13
14test("without one, the shape of the address decides", () => {
15 const cases: [string, MissingKind][] = [
16 ["/acme", "workspace"],
17 ["/acme/web", "project"],
18 ["/acme/-/work/12", "item"],
19 ["/acme/web/issues/12", "item"],
20 ["/acme/-/work", "page"],
21 ["/acme/web/pull/12", "pull"],
22 ["/acme/web/issues", "page"],
23 ["/acme/web/settings", "page"],
24 ["/acme/-/billing", "page"],
25 ["/u/ada", "person"],
26 ["/explore/nothing", "page"],
27 ["/", "page"],
28 ];
29 for (const [path, kind] of cases) assert.equal(missingKind(null, path), kind, path);
30});
31
32const KINDS: MissingKind[] = ["project", "item", "pull", "workspace", "page"];
33
34test("signed out: nothing here, which may be private, and sign in if it is yours", () => {
35 for (const kind of KINDS) {
36 const copy = notFoundCopy(kind, null);
37 assert.equal(copy.title, "Nothing here");
38 assert.equal(copy.body, "This page doesn't exist, or it's private. Sign in if it's yours.");
39 assert.equal(copy.signIn, true);
40 assert.equal(copy.signedInAs, null);
41 }
42});
43
44test("signed in: it does not exist or you cannot see it, and who you are", () => {
45 for (const kind of KINDS) {
46 const copy = notFoundCopy(kind, "ada");
47 assert.equal(copy.title, "Nothing here");
48 assert.equal(copy.body, "This page doesn't exist, or you don't have access to it.");
49 assert.equal(copy.signIn, false);
50 assert.equal(copy.signedInAs, "ada");
51 }
52});
53
54test("a missing person is simply no one, signed in or not", () => {
55 for (const viewer of [null, "ada"]) {
56 const copy = notFoundCopy("person", viewer);
57 assert.equal(copy.body, "No one on g1t goes by that name.");
58 assert.equal(copy.signIn, false);
59 }
60});
61
62test("the page depends only on the kind and the viewer", () => {
63 // The same inputs for a private project and a missing one: the loader
64 // throws the same kind, at the same address, so the copy is identical.
65 const privateOne = notFoundCopy(missingKind({ kind: "project" }, "/acme/secret"), null);
66 const missingOne = notFoundCopy(missingKind({ kind: "project" }, "/acme/secret"), null);
67 assert.deepEqual(privateOne, missingOne);
68});