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

gitHubPullRequests.test.ts

43 lines1.5 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("reads lowercase closed and merged states", () => {
30 const row = (number: number, state: string) => ({
31 number,
32 title: "PR",
33 url: `https://github.com/pingdotgg/codething-mvp/pull/${number}`,
34 baseRefName: "main",
35 headRefName: "feature/status-lowercase-state",
36 state,
37 });
38 const decoded = decodeGitHubPullRequestListJson(
39 JSON.stringify([row(16, "closed"), row(17, "merged"), row(18, "open")]),
40 );
41​
42 expect(Result.getOrThrow(decoded).map((pr) => pr.state)).toEqual(["closed", "merged", "open"]);
43});