Files
t3code/apps/web/src/pullRequestReference.test.ts
T

38 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parsePullRequestReference } from "./pullRequestReference";
describe("parsePullRequestReference", () => {
it("accepts GitHub pull request URLs", () => {
expect(parsePullRequestReference("https://github.com/pingdotgg/t3code/pull/42")).toBe(
"https://github.com/pingdotgg/t3code/pull/42",
);
});
it("accepts raw numbers", () => {
expect(parsePullRequestReference("42")).toBe("42");
});
it("accepts #number references", () => {
expect(parsePullRequestReference("#42")).toBe("42");
});
it("accepts gh pr checkout commands with raw numbers", () => {
expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
});
it("accepts gh pr checkout commands with #number references", () => {
expect(parsePullRequestReference("gh pr checkout #42")).toBe("42");
});
it("accepts gh pr checkout commands with GitHub pull request URLs", () => {
expect(
parsePullRequestReference("gh pr checkout https://github.com/pingdotgg/t3code/pull/42"),
).toBe("https://github.com/pingdotgg/t3code/pull/42");
});
it("rejects non-pull-request input", () => {
expect(parsePullRequestReference("feature/my-branch")).toBeNull();
});
});