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.

103 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import {
5 accountWentSummary,
6 confirmsUsername,
7 deletedWithAccount,
8 soleOwnerNote,
9 soleWorkspacesRefusal,
10 staffDeleteProblem,
11 staffDeletionRefusal,
12} from "./deleted-accounts.ts";
13
14const deletion = {
15 username: "ada",
16 workspaces: 2,
17 tokens: 1,
18 ssh_keys: 0,
19 applications: 0,
20 repositories: 0,
21 sole_owner_of: [],
22 protected: false,
23};
24
25const sole = (slug: string) => ({ slug, name: slug, members: 1, billing: null, protected: false });
26
27const went = { workspaces: 2, teams: 1, repositories: 3, tokens: 1, sshKeys: 2, staff: null, reason: null, deletedWorkspaces: [] };
28
29test("what went reads as one line", () => {
30 assert.equal(accountWentSummary(went), "2 workspaces, 1 team, 3 repositories, 1 token, 2 SSH keys");
31});
32
33test("only a protected account is refused outright", () => {
34 assert.equal(staffDeletionRefusal(deletion), null);
35 const owner = { ...deletion, sole_owner_of: [sole("acme")] };
36 assert.equal(staffDeletionRefusal(owner), null);
37 assert.equal(staffDeletionRefusal({ ...owner, username: "g1t", protected: true }), "g1t is protected and can never be deleted.");
38});
39
40test("workspaces it owns alone go with it, said up front", () => {
41 assert.equal(soleOwnerNote(deletion), null);
42 assert.match(soleOwnerNote({ ...deletion, sole_owner_of: [sole("ada")] })!, /^ada is the only owner of 1 workspace\. Deleting the account deletes it first/);
43 assert.match(soleOwnerNote({ ...deletion, sole_owner_of: [sole("a"), sole("b")] })!, /of 2 workspaces\. Deleting the account deletes them first/);
44 assert.equal(soleWorkspacesRefusal({ ...deletion, sole_owner_of: [sole("ada")] }), null);
45});
46
47test("a protected workspace or billing that cannot settle stops it, naming which", () => {
48 const owner = {
49 ...deletion,
50 sole_owner_of: [
51 sole("ada"),
52 { ...sole("flagon-io"), protected: true },
53 { ...sole("ada-labs"), billing: "ada-labs has an unpaid invoice. Pay it from the workspace's Billing page first." },
54 ],
55 };
56 assert.equal(
57 soleWorkspacesRefusal(owner),
58 "ada cannot be deleted with its workspaces yet. flagon-io is protected and can never be deleted. ada-labs has an unpaid invoice. Pay it from the workspace's Billing page first.",
59 );
60});
61
62test("staff confirm with the username", () => {
63 assert.ok(confirmsUsername("ada", " ADA "));
64 assert.ok(!confirmsUsername("ada", ""));
65 assert.ok(!confirmsUsername("ada", "grace"));
66});
67
68test("the form needs a reason, the username, and the box ticked when workspaces go too", () => {
69 const form = { username: "ada", reason: "Retired test account", confirm: "ada", withWorkspaces: false, acknowledged: false };
70 assert.equal(staffDeleteProblem(form), null);
71 assert.equal(staffDeleteProblem({ ...form, reason: "" }), "Say why the account is being deleted.");
72 assert.equal(staffDeleteProblem({ ...form, confirm: "grace" }), "Type ada to confirm.");
73 assert.equal(staffDeleteProblem({ ...form, withWorkspaces: true }), "Tick the box to say the workspaces it alone owns are deleted too.");
74 assert.equal(staffDeleteProblem({ ...form, withWorkspaces: true, acknowledged: true }), null);
75});
76
77test("workspaces deleted with the account are matched to their deletions", () => {
78 const waiting = {
79 workspaceId: "wsp_1",
80 slug: "ada",
81 name: "Ada",
82 deletedAt: "2026-10-08T00:00:00.000Z",
83 deletedBy: "staff@g1t.sh",
84 purgeAfter: "2026-11-07T00:00:00.000Z",
85 went: { repositories: 1, projects: 0, members: 1, billing: null, protected: false },
86 restorable: true,
87 };
88 const gone = deletedWithAccount(
89 {
90 ...went,
91 deletedWorkspaces: [
92 { workspaceId: "wsp_1", slug: "ada" },
93 { workspaceId: "wsp_2", slug: "ada-labs" },
94 ],
95 },
96 [waiting],
97 );
98 assert.deepEqual(gone, [
99 { workspaceId: "wsp_1", slug: "ada", deleted: waiting },
100 { workspaceId: "wsp_2", slug: "ada-labs", deleted: null },
101 ]);
102 assert.deepEqual(deletedWithAccount(went, [waiting]), []);
103});