Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 allowedMergeMethods,
4 canPerformPullRequestAction,
5 mergeSummary,
6 mergeUnavailableReason,
7 ALL_PR_ACTIONS,
8} from "./pullRequestActions";
9
10type Detail = Parameters<typeof allowedMergeMethods>[0];
11
12function detail(overrides: Partial<Detail> = {}): Detail {
13 return {
14 state: "open",
15 isDraft: false,
16 mergeability: "mergeable",
17 autoMergeEnabled: false,
18 capabilities: {
19 actions: ALL_PR_ACTIONS,
20 mergeMethods: ["merge", "squash", "rebase"],
21 updateMethods: ["merge", "rebase"],
22 },
23 viewerPermissions: { actions: ALL_PR_ACTIONS, updateMethods: ["merge"] },
24 mergeCapabilities: { merge: true, squash: true, rebase: false },
25 ...overrides,
26 };
27}
28
29describe("mobile pull request actions", () => {
30 it("requires both provider support and account permission", () => {
31 expect(
32 canPerformPullRequestAction(detail({ viewerPermissions: { actions: [] } }), "merge"),
33 ).toBe(false);
34 expect(
35 canPerformPullRequestAction(
36 detail({ capabilities: { actions: [], mergeMethods: ["merge"] } }),
37 "merge",
38 ),
39 ).toBe(false);
40 expect(mergeUnavailableReason(detail(), false)).toContain("read-only");
41 });
42
43 it("blocks a conflicting PR's immediate merge and explains why", () => {
44 const pr = detail({ mergeability: "conflicting" });
45 expect(canPerformPullRequestAction(pr, "merge")).toBe(false);
46 expect(mergeUnavailableReason(pr, true)).toContain("conflicts");
47 expect(mergeSummary(pr, true)).toBe("Has conflicts");
48 });
49});