Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Team plan, an open-source pool, monthly trials and honest metering; the sidebar for everyone; a workspace that stays put | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { type MissingKind, missingKind, notFoundCopy } from "./not-found.ts"; | |
| 5 | ||
| 6 | test("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("Issue not found.", "/acme/web/issues/3"), "issue"); | |
| 12 | }); | |
| 13 | ||
| 14 | test("without one, the shape of the address decides", () => { | |
| 15 | const cases: [string, MissingKind][] = [ | |
| 16 | ["/acme", "workspace"], | |
| 17 | ["/acme/web", "project"], | |
| 18 | ["/acme/web/issues/12", "issue"], | |
| 19 | ["/acme/web/pull/12", "pull"], | |
| 20 | ["/acme/web/issues", "page"], | |
| 21 | ["/acme/web/settings", "page"], | |
| 22 | ["/acme/-/billing", "page"], | |
| 23 | ["/u/ada", "person"], | |
| 24 | ["/explore/nothing", "page"], | |
| 25 | ["/", "page"], | |
| 26 | ]; | |
| 27 | for (const [path, kind] of cases) assert.equal(missingKind(null, path), kind, path); | |
| 28 | }); | |
| 29 | ||
| 30 | const KINDS: [MissingKind, string][] = [ | |
| 31 | ["project", "project"], | |
| 32 | ["issue", "issue"], | |
| 33 | ["pull", "pull request"], | |
| 34 | ["workspace", "workspace"], | |
| 35 | ["page", "page"], | |
| 36 | ]; | |
| 37 | ||
| 38 | test("signed out: sign in to see it, which may be private or missing", () => { | |
| 39 | for (const [kind, noun] of KINDS) { | |
| 40 | const copy = notFoundCopy(kind, null); | |
| 41 | assert.equal(copy.title, `Sign in to see this ${noun}`); | |
| 42 | assert.equal(copy.body, "It may be private, or it may not exist."); | |
| 43 | assert.equal(copy.signIn, true); | |
| 44 | assert.equal(copy.signedInAs, null); | |
| 45 | assert.equal(copy.askOwner, false); | |
| 46 | } | |
| 47 | }); | |
| 48 | ||
| 49 | test("signed in: it does not exist or you cannot see it, and who you are", () => { | |
| 50 | for (const [kind, noun] of KINDS) { | |
| 51 | const copy = notFoundCopy(kind, "ada"); | |
| 52 | assert.equal(copy.title, `This ${noun} doesn't exist, or you don't have access to it`); | |
| 53 | assert.equal(copy.signIn, false); | |
| 54 | assert.equal(copy.signedInAs, "ada"); | |
| 55 | assert.equal(copy.askOwner, true); | |
| 56 | } | |
| 57 | }); | |
| 58 | ||
| 59 | test("a missing person is simply no one, signed in or not", () => { | |
| 60 | for (const viewer of [null, "ada"]) { | |
| 61 | const copy = notFoundCopy("person", viewer); | |
| 62 | assert.equal(copy.title, "No one goes by that name"); | |
| 63 | assert.equal(copy.signIn, false); | |
| 64 | assert.equal(copy.askOwner, false); | |
| 65 | } | |
| 66 | }); | |
| 67 | ||
| 68 | test("the page depends only on the kind and the viewer", () => { | |
| 69 | // The same inputs for a private project and a missing one: the loader | |
| 70 | // throws the same kind, at the same address, so the copy is identical. | |
| 71 | const privateOne = notFoundCopy(missingKind({ kind: "project" }, "/acme/secret"), null); | |
| 72 | const missingOne = notFoundCopy(missingKind({ kind: "project" }, "/acme/secret"), null); | |
| 73 | assert.deepEqual(privateOne, missingOne); | |
| 74 | }); |