g1t/apps/web/app/lib/opened-by.test.ts

30 lines1,412 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { workOwner } from "../../../../packages/contracts/src/work.ts";
5import { madeByG1t, openedBy } from "./opened-by.ts";
6
7const syntaqx = { id: "usr_1", username: "syntaqx" };
8const g1t = { id: "usr_g1t_agent", username: "g1t", kind: "agent" as const };
9
10test("a pull request g1t made shows g1t, requested by whoever asked", () => {
11 const pull = { agent: "g1t", branch: null, author: g1t, requestedBy: syntaqx };
12 assert.equal(madeByG1t(pull), true);
13 assert.deepEqual(openedBy(pull), { name: "g1t", requestedBy: "syntaqx" });
14 // It is theirs to manage, as their own would be.
15 assert.equal(workOwner(pull).id, "usr_1");
16});
17
18test("anything else shows its author", () => {
19 // Someone's own agent.
20 assert.deepEqual(openedBy({ author: syntaqx, requestedBy: null }), { name: "syntaqx", requestedBy: null });
21 // A branch pushed to the repository, even with g1t named on it.
22 assert.equal(madeByG1t({ agent: "g1t", branch: "fix-login" }), false);
23 assert.equal(workOwner({ author: syntaqx, requestedBy: null }).id, "usr_1");
24});
25
26test("work g1t started itself names nobody as asking", () => {
27 const pull = { author: { id: "g1t", username: "g1t", kind: "system" as const }, requestedBy: null };
28 assert.deepEqual(openedBy(pull), { name: "g1t", requestedBy: null });
29 assert.equal(workOwner(pull).username, "g1t");
30});