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

gitHubPullRequests.test.ts

79 lines2.6 KB

1import * as Result from "effect/Result";
2import { expect, it } from "vite-plus/test";
3​
4import { decodeGitHubPullRequestListJson } from "./gitHubPullRequests.ts";
5​
6// gh before 2.47 names the head repository without its owner, and a fork's checkout needs both.
7it("names a fork's head repository from its owner when gh leaves nameWithOwner out", () => {
8 const decoded = decodeGitHubPullRequestListJson(
9 JSON.stringify([
10 {
11 number: 642,
12 title: "fix: use commit as the default git action without origin",
13 url: "https://github.com/pingdotgg/t3code/pull/642",
14 baseRefName: "main",
15 headRefName: "fix/git-action-default-without-origin",
16 isCrossRepository: true,
17 headRepository: { id: "R_1", name: "t3code" },
18 headRepositoryOwner: { login: "binbandit" },
19 },
20 ]),
21 );
22​
23 expect(Result.getOrThrow(decoded)[0]).toMatchObject({
24 headRepositoryNameWithOwner: "binbandit/t3code",
25 headRepositoryOwnerLogin: "binbandit",
26 });
27});
28​
29it("skips rows that do not decode and trims the ones that do", () => {
30 const decoded = decodeGitHubPullRequestListJson(
31 JSON.stringify([
32 {
33 number: 0,
34 title: "invalid",
35 url: "https://github.com/pingdotgg/codething-mvp/pull/0",
36 baseRefName: "main",
37 headRefName: "feature/invalid",
38 },
39 {
40 number: 15,
41 title: " Valid PR title ",
42 url: " https://github.com/pingdotgg/codething-mvp/pull/15 ",
43 baseRefName: " main ",
44 headRefName: "\tfeature/status-valid-pr-entry\t",
45 headRepository: { nameWithOwner: " " },
46 headRepositoryOwner: { login: " " },
47 },
48 ]),
49 );
50​
51 const rows = Result.getOrThrow(decoded);
52 expect(rows).toHaveLength(1);
53 expect(rows[0]).toMatchObject({
54 number: 15,
55 title: "Valid PR title",
56 url: "https://github.com/pingdotgg/codething-mvp/pull/15",
57 baseRefName: "main",
58 headRefName: "feature/status-valid-pr-entry",
59 state: "open",
60 });
61 expect(rows[0]).not.toHaveProperty("headRepositoryNameWithOwner");
62 expect(rows[0]).not.toHaveProperty("headRepositoryOwnerLogin");
63});
64​
65it("reads lowercase closed and merged states", () => {
66 const row = (number: number, state: string) => ({
67 number,
68 title: "PR",
69 url: `https://github.com/pingdotgg/codething-mvp/pull/${number}`,
70 baseRefName: "main",
71 headRefName: "feature/status-lowercase-state",
72 state,
73 });
74 const decoded = decodeGitHubPullRequestListJson(
75 JSON.stringify([row(16, "closed"), row(17, "merged"), row(18, "open")]),
76 );
77​
78 expect(Result.getOrThrow(decoded).map((pr) => pr.state)).toEqual(["closed", "merged", "open"]);
79});