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

47 lines2,458 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { readCookie } from "./mission.ts";
5import { chosenWorkspace, forgetWorkspace, 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});
39
40test("a deleted workspace you had chosen gives way to another, or to none", () => {
41 // syntaqx deleted: the cookie still names it, and you are in Flagon only.
42 assert.equal(chosenWorkspace([{ slug: "flagon-io" }], "syntaqx")?.slug, "flagon-io");
43 assert.equal(workspaceFor([{ slug: "flagon-io" }], "syntaqx", {})?.slug, "flagon-io");
44 // In no workspace at all: an account still works, with nothing chosen.
45 assert.equal(workspaceFor([], "syntaqx", {}), null);
46 assert.match(forgetWorkspace(true), /^g1t_ws=; Path=\/; Max-Age=0; SameSite=Lax; Secure$/);
47});