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/web/app/lib/workspace-choice.test.ts

38 lines1,875 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { readCookie } from "./mission.ts";
5import { chosenWorkspace, rememberWorkspace, workspaceFor } from "./workspace-choice.ts";
6
7const mine = [{ slug: "flagon-io" }, { slug: "syntaqx" }];
8
9test("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
17test("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
26test("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
32test("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});