g1t/apps/web/app/lib/workspace-deletion.test.ts

35 lines1,470 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { confirmsSlug, deletionRefusal, whatGoes } from "./workspace-deletion.ts";
5
6const nothing = { repositories: 0, projects: 0, members: 0, billing: null, protected: false };
7
8test("what goes lists only what the workspace holds", () => {
9 assert.deepEqual(whatGoes(nothing, null), []);
10 assert.deepEqual(whatGoes({ ...nothing, repositories: 1, projects: 2, members: 1 }, 3), [
11 "1 repository, with its issues, pull requests and workflow runs",
12 "2 projects",
13 "3 live apps, taken offline",
14 "Access for 1 member; their own accounts stay",
15 ]);
16 assert.deepEqual(whatGoes({ ...nothing, repositories: 4 }, 0), [
17 "4 repositories, with their issues, pull requests and workflow runs",
18 ]);
19});
20
21test("only billing or protection stands in the way", () => {
22 assert.equal(deletionRefusal("acme", null), null);
23 assert.equal(deletionRefusal("acme", { ...nothing, repositories: 9, projects: 2 }), null);
24 assert.equal(deletionRefusal("acme", { ...nothing, billing: "Pay first." }), "Pay first.");
25 assert.equal(
26 deletionRefusal("flagon-io", { ...nothing, billing: "Pay first.", protected: true }),
27 "flagon-io is protected and can never be deleted.",
28 );
29});
30
31test("the slug confirms in any case, and nothing else does", () => {
32 assert.ok(confirmsSlug("acme", " ACME "));
33 assert.ok(!confirmsSlug("acme", ""));
34 assert.ok(!confirmsSlug("acme", "acme-inc"));
35});