Skip to content
Source
Sign inSign up
Open History to see the last commit

threadPullRequestCompatibility.test.ts

60 lines2.0 KB

1import type { ExecutionEnvironmentCapabilities } from "@t3tools/contracts";
2import { ThreadId } from "@t3tools/contracts";
3import { describe, expect, it } from "@effect/vitest";
4import {
5 planThreadPullRequestMutation,
6 threadPullRequestLinkMode,
7} from "./threadPullRequestCompatibility.ts";
8​
9const reference = {
10 host: "github.example",
11 repository: "team/repo",
12 number: 7,
13 url: "https://github.example/team/repo/pull/7",
14};
15const input = {
16 threadId: ThreadId.make("thread"),
17 reference,
18 linked: true,
19};
20const capabilities = { repositoryIdentity: true } satisfies ExecutionEnvironmentCapabilities;
21​
22describe("thread pull request capability negotiation", () => {
23 it.each([true, false])(
24 "preserves Forgejo ports in a multi-link mutation: linked=%s",
25 (linked) => {
26 const mutation = planThreadPullRequestMutation({
27 ...input,
28 linked,
29 capabilities,
30 reference: {
31 host: "forge.example",
32 repository: "team/repo",
33 number: 7,
34 url: "http://forge.example:3000/team/repo/pulls/7",
35 },
36 });
37 expect(mutation).toMatchObject({ input: { host: "forge.example:3000", number: 7 } });
38 },
39 );
40​
41 it("does not dispatch before the server config loads", () => {
42 expect(threadPullRequestLinkMode(undefined)).toBe("unsupported");
43 expect(planThreadPullRequestMutation({ ...input, capabilities: undefined })).toBeNull();
44 });
45 it("plans link and unlink commands", () => {
46 expect(planThreadPullRequestMutation({ ...input, capabilities })).toEqual({
47 type: "thread.pull-request.link",
48 input: { threadId: input.threadId, ...reference, source: "manual" },
49 });
50 expect(planThreadPullRequestMutation({ ...input, capabilities, linked: false })).toEqual({
51 type: "thread.pull-request.unlink",
52 input: {
53 threadId: input.threadId,
54 host: reference.host,
55 repository: reference.repository,
56 number: reference.number,
57 },
58 });
59 });
60});