@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 95 lines 3.3 KB
Raw
1 import {
2 SourceControlProviderKind,
3 type PullRequestDetail,
4 type PullRequestReaction,
5 type PullRequestReactionContent,
6 } from "@t3tools/contracts";
7 import { describe, expect, it } from "vite-plus/test";
8
9 import {
10 applyPendingPullRequestReactions,
11 canReactPullRequestComment,
12 } from "./pullRequestReactions.ts";
13
14 function reaction(overrides: Partial<PullRequestReaction> = {}): PullRequestReaction {
15 return {
16 content: "heart",
17 count: 1,
18 actors: ["octocat"],
19 viewerHasReacted: false,
20 ...overrides,
21 };
22 }
23
24 describe("comment reaction permissions", () => {
25 it("excludes only GitCafe review summaries from comment reactions", () => {
26 const detail = {
27 provider: SourceControlProviderKind.make("gitcafe"),
28 capabilities: {
29 diff: true,
30 comment: true,
31 actions: [],
32 mergeMethods: [],
33 search: true,
34 reactions: true,
35 review: { inlineComment: true, reply: true, resolve: true, verdicts: [] },
36 reviewers: { request: true, listCandidates: true },
37 },
38 } satisfies Pick<PullRequestDetail, "provider" | "capabilities">;
39
40 expect(canReactPullRequestComment(detail, { kind: "issue-comment" })).toBe(true);
41 expect(canReactPullRequestComment(detail, { kind: "review-comment" })).toBe(true);
42 expect(
43 canReactPullRequestComment(
44 { ...detail, provider: SourceControlProviderKind.make("github") },
45 { kind: "review" },
46 ),
47 ).toBe(true);
48 expect(canReactPullRequestComment(detail, { kind: "review" })).toBe(false);
49 });
50 });
51
52 describe("pending reactions", () => {
53 const pending = (entries: ReadonlyArray<readonly [PullRequestReactionContent, boolean]>) =>
54 new Map(entries.map(([content, reacted]) => [content, { reacted }] as const));
55
56 it("adds a reaction nobody had yet, in picker order", () => {
57 const applied = applyPendingPullRequestReactions(
58 [reaction({ content: "rocket", count: 2, actors: ["a", "b"] })],
59 pending([["thumbs-up", true]]),
60 );
61 expect(applied).toEqual([
62 { content: "thumbs-up", count: 1, actors: [], viewerHasReacted: true },
63 { content: "rocket", count: 2, actors: ["a", "b"], viewerHasReacted: false },
64 ]);
65 });
66
67 it("joins and leaves an existing reaction, and drops the pill nobody is left on", () => {
68 expect(
69 applyPendingPullRequestReactions(
70 [reaction({ count: 2, actors: ["a", "b"] })],
71 pending([["heart", true]]),
72 ),
73 ).toEqual([{ content: "heart", count: 3, actors: ["a", "b"], viewerHasReacted: true }]);
74 expect(
75 applyPendingPullRequestReactions(
76 [reaction({ count: 2, actors: ["a", "b"], viewerHasReacted: true })],
77 pending([["heart", false]]),
78 ),
79 ).toEqual([{ content: "heart", count: 1, actors: ["a", "b"], viewerHasReacted: false }]);
80 expect(
81 applyPendingPullRequestReactions(
82 [reaction({ count: 1, viewerHasReacted: true })],
83 pending([["heart", false]]),
84 ),
85 ).toEqual([]);
86 });
87
88 it("ignores a pending state the host has already caught up with", () => {
89 const reactions = [reaction({ count: 3, viewerHasReacted: true })];
90 expect(applyPendingPullRequestReactions(reactions, pending([["heart", true]]))).toEqual(
91 reactions,
92 );
93 expect(applyPendingPullRequestReactions([], pending([["heart", false]]))).toEqual([]);
94 });
95 });