g1t/apps/web/app/lib/workspace-choice.test.ts
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 { readCookie } from "./mission.ts"; | |
| 5 | import { chosenWorkspace, rememberWorkspace, workspaceFor } from "./workspace-choice.ts"; | |
| 6 | ||
| 7 | const mine = [{ slug: "flagon-io" }, { slug: "syntaqx" }]; | |
| 8 | ||
| 9 | test("the chosen workspace holds while you are a member, else the first", () => { | |
| 10 | assert.equal(chosenWorkspace(mine, "syntaqx")?.slug, "syntaqx"); | |
| 11 | assert.equal(chosenWorkspace(mine, "SYNTAQX")?.slug, "syntaqx"); | |
| 12 | assert.equal(chosenWorkspace(mine, "someone-else")?.slug, "flagon-io"); | |
| 13 | assert.equal(chosenWorkspace(mine, null)?.slug, "flagon-io"); | |
| 14 | assert.equal(chosenWorkspace([], "syntaqx"), null); | |
| 15 | }); | |
| 16 | ||
| 17 | test("a project in another workspace does not change which one you are in", () => { | |
| 18 | // In Flagon, looking at syntaqx/g1t: still Flagon. | |
| 19 | assert.equal(workspaceFor(mine, "flagon-io", { owner: "syntaqx", repo: "g1t" })?.slug, "flagon-io"); | |
| 20 | // A public project somewhere else entirely: still Flagon. | |
| 21 | assert.equal(workspaceFor(mine, "flagon-io", { owner: "acme", repo: "web" })?.slug, "flagon-io"); | |
| 22 | // Mission control: still Flagon. | |
| 23 | assert.equal(workspaceFor(mine, "flagon-io", {})?.slug, "flagon-io"); | |
| 24 | }); | |
| 25 | ||
| 26 | test("a workspace's own pages are about that workspace", () => { | |
| 27 | assert.equal(workspaceFor(mine, "flagon-io", { owner: "syntaqx" })?.slug, "syntaqx"); | |
| 28 | // Not yours: the chosen one. | |
| 29 | assert.equal(workspaceFor(mine, "flagon-io", { owner: "acme" })?.slug, "flagon-io"); | |
| 30 | }); | |
| 31 | ||
| 32 | test("the cookie reads back what was remembered", () => { | |
| 33 | const set = rememberWorkspace("Flagon-IO", true); | |
| 34 | assert.match(set, /^g1t_ws=flagon-io; Path=\/; Max-Age=31536000; SameSite=Lax; Secure$/); | |
| 35 | assert.equal(readCookie("a=1; g1t_ws=flagon-io; b=2", "g1t_ws"), "flagon-io"); | |
| 36 | assert.equal(readCookie(null, "g1t_ws"), null); | |
| 37 | assert.equal(readCookie("g1t_ws=%E0%A4%A", "g1t_ws"), null); | |
| 38 | }); |