mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
Resolve repo aliases in JSON and raw API
This commit is contained in:
@@ -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`);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user