History

feat(pull-requests): link multiple pull requests to threads (#10839)

Julius Marminge committed 2 months ago

Commit afb84891 parent 383cc40172 files · +12057 −908Browse files

Showing the changes to apps/server/src/pullRequest/pullRequestSyncKey.test.ts (1 of 172 files). Show all

Unified · Split

apps/server/src/pullRequest/pullRequestSyncKey.test.ts+46−0
@@ -0,0 +1,46 @@
1+import { ProjectId } from "@t3tools/contracts";
2+import { describe, expect, it } from "vite-plus/test";
3+
4+import { pullRequestSyncKey } from "./pullRequestSyncKey.ts";
5+
6+describe("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+});