Resolve repo aliases in JSON and raw API

This commit is contained in:
Rūdolfs Ošiņš
2026-07-29 14:05:06 +02:00
parent 8d8339165c
commit 256b060770
26 changed files with 341 additions and 129 deletions
+27 -1
View File
@@ -1,5 +1,9 @@
import { describe, expect, test } from "vitest";
import { testExports } from "@app/views/repos/router";
import {
repoRouteToPath,
resolveRepoRoute,
testExports,
} from "@app/views/repos/router";
// Defining the window.origin value, since vitest doesn't provide one.
window.origin = "http://localhost:3000";
@@ -12,3 +16,25 @@ describe("isOid", () => {
expect(testExports.isOid(oid)).toEqual(expected);
});
});
describe("repo alias in routes", () => {
const node = { hostname: "localhost", port: 8080, scheme: "http" };
const rid = "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5";
test.each([
{ segment: "heartwood", description: "an alias" },
{ segment: rid, description: "a RID" },
])(
"preserves $description as the repo segment through the router",
({ segment }) => {
// The segment (alias or RID) is parsed in as `route.repo` verbatim …
const route = resolveRepoRoute(node, segment, ["issues"], "");
expect(route).not.toBeNull();
expect(route?.repo).toEqual(segment);
// … and rendered back into the path unchanged, so in-repo links keep
// whichever form the user navigated in with.
expect(repoRouteToPath(route!)).toContain(`/${segment}/issues`);
},
);
});
+15
View File
@@ -286,3 +286,18 @@ describe("isLocal", () => {
});
});
});
describe("repoSegment", () => {
const rid = "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5";
test("prefers the alias when the node advertises one", () => {
expect(utils.repoSegment({ rid, alias: "heartwood" })).toEqual("heartwood");
});
test.each([
{ repo: { rid }, description: "no alias field" },
{ repo: { rid, alias: undefined }, description: "undefined alias" },
])("falls back to the RID with $description", ({ repo }) => {
expect(utils.repoSegment(repo)).toEqual(rid);
});
});