1import { ProjectId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { pullRequestSyncKey } from "./pullRequestSyncKey.ts";
5
6describe("pullRequestSyncKey", () => {
7 const reference = { projectId: ProjectId.make("project"), repository: "web", number: 7 };
8 it.each([
9 "dev.azure.com/org/project/_git/web",
10 "ssh.dev.azure.com/v3/org/project/web",
11 "vs-ssh.visualstudio.com/v3/org/project/web",
12 "org.visualstudio.com/defaultcollection/project/_git/web",
13 ])("resolves hostless and checkout-host Azure references for %s", (canonicalKey) => {
14 const identity = {
15 canonicalKey,
16 provider: "azure-devops",
17 name: "web",
18 displayName: canonicalKey.split("/").slice(1).join("/"),
19 locator: {
20 source: "git-remote" as const,
21 remoteName: "origin",
22 remoteUrl: `https://${canonicalKey}`,
23 },
24 };
25 const expected = { host: "dev.azure.com", repository: "org/project/_git/web", number: 7 };
26 expect(pullRequestSyncKey(reference, identity)).toEqual(expected);
27 expect(
28 pullRequestSyncKey({ ...reference, host: canonicalKey.split("/")[0]! }, identity),
29 ).toEqual(expected);
30 expect(pullRequestSyncKey({ ...reference, repository: "other" }, identity)).toBeNull();
31 expect(pullRequestSyncKey({ ...reference, host: "unrelated.test" }, identity)).toBeNull();
32 });
33 it("normalizes complete hosted aliases without requiring a checkout", () => {
34 expect(
35 pullRequestSyncKey({
36 ...reference,
37 host: "org.visualstudio.com",
38 repository: "project/_git/web",
39 }),
40 ).toEqual({ host: "dev.azure.com", repository: "org/project/_git/web", number: 7 });
41 expect(
42 pullRequestSyncKey({ ...reference, host: "github.com", repository: "acme/web" }),
43 ).toEqual({ host: "github.com", repository: "acme/web", number: 7 });
44 expect(pullRequestSyncKey(reference)).toBeNull();
45 });
46});