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.

56 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { accountDeletionRefusal, confirmsUsername, whatAccountDeletionTakes } from "./account-deletion.ts";
5
6const nothing = {
7 username: "ada",
8 workspaces: 0,
9 tokens: 0,
10 ssh_keys: 0,
11 applications: 0,
12 repositories: 0,
13 sole_owner_of: [],
14 protected: false,
15};
16
17const sole = (slug: string) => ({ slug, name: slug, members: 3, billing: null, protected: false });
18
19test("the dialog lists only what the account has", () => {
20 assert.deepEqual(whatAccountDeletionTakes(nothing), []);
21 assert.deepEqual(whatAccountDeletionTakes({ ...nothing, workspaces: 2, repositories: 1, tokens: 3, ssh_keys: 1, applications: 2 }), [
22 "Your membership of 2 workspaces",
23 "Your role on 1 repository you were added to",
24 "3 access tokens",
25 "1 SSH key",
26 "2 connected applications",
27 ]);
28 assert.deepEqual(whatAccountDeletionTakes({ ...nothing, workspaces: 1, tokens: 1 }), ["Your membership of 1 workspace", "1 access token"]);
29});
30
31test("owning a workspace alone stands in the way, and names it", () => {
32 assert.equal(accountDeletionRefusal(null), null);
33 assert.equal(accountDeletionRefusal({ ...nothing, workspaces: 4 }), null);
34 assert.equal(
35 accountDeletionRefusal({ ...nothing, sole_owner_of: [sole("acme")] }),
36 "You are the only owner of acme. Make someone else an owner of it, or delete it, first.",
37 );
38 assert.equal(
39 accountDeletionRefusal({ ...nothing, sole_owner_of: [sole("acme"), sole("globex"), sole("initech")] }),
40 "You are the only owner of acme, globex and initech. Make someone else an owner of each, or delete them, first.",
41 );
42});
43
44test("a protected account says so first", () => {
45 assert.equal(
46 accountDeletionRefusal({ ...nothing, username: "g1t", protected: true, sole_owner_of: [sole("acme")] }),
47 "g1t is protected and can never be deleted.",
48 );
49});
50
51test("only the username itself confirms", () => {
52 assert.ok(confirmsUsername("ada", " Ada "));
53 assert.ok(!confirmsUsername("ada", ""));
54 assert.ok(!confirmsUsername("ada", " "));
55 assert.ok(!confirmsUsername("ada", "ada-l"));
56});