feat: execute route and release recovery contracts
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ROUTE_RUNTIME_CONTRACT } from "../../src/contracts/route-runtime-contract.js";
|
||||
import { ROUTE_REGISTRY } from "../../src/contracts/routes.js";
|
||||
import {
|
||||
buildRouteUrl,
|
||||
parseRouteInput,
|
||||
} from "../../src/presentation/routes/route-codecs.js";
|
||||
import { ROUTE_RUNTIME } from "../../src/presentation/routes/route-runtime.js";
|
||||
|
||||
describe("typed route contract and runtime", () => {
|
||||
it("keeps contract, runtime contribution, and executable module complete", () => {
|
||||
expect(Object.keys(ROUTE_RUNTIME_CONTRACT).sort()).toEqual(
|
||||
Object.keys(ROUTE_REGISTRY).sort(),
|
||||
);
|
||||
expect(Object.keys(ROUTE_RUNTIME).sort()).toEqual(
|
||||
Object.keys(ROUTE_REGISTRY).sort(),
|
||||
);
|
||||
});
|
||||
|
||||
it("round-trips canonical search through the registered codec", () => {
|
||||
const url = buildRouteUrl("SAMPLE_RESOURCE_LIST", {
|
||||
search: {
|
||||
tags: ["open", "new"],
|
||||
cursor: "a/b",
|
||||
limit: 5,
|
||||
},
|
||||
});
|
||||
expect(url).toBe(
|
||||
"/sample/resources?cursor=a%2Fb&limit=5&tags=open&tags=new",
|
||||
);
|
||||
const parsedUrl = new URL(url, "https://app.test");
|
||||
expect(
|
||||
parseRouteInput(
|
||||
"SAMPLE_RESOURCE_LIST",
|
||||
{},
|
||||
parsedUrl.searchParams,
|
||||
),
|
||||
).toEqual({
|
||||
success: true,
|
||||
data: {
|
||||
routeId: "SAMPLE_RESOURCE_LIST",
|
||||
params: {},
|
||||
search: {
|
||||
cursor: "a/b",
|
||||
limit: 5,
|
||||
tags: ["open", "new"],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unknown search and accepts the not-found splat owner", () => {
|
||||
expect(
|
||||
parseRouteInput(
|
||||
"SAMPLE_RESOURCE_LIST",
|
||||
{},
|
||||
new URLSearchParams("unknown=value"),
|
||||
),
|
||||
).toEqual({ success: false, code: "ROUTE_SEARCH_INVALID" });
|
||||
expect(
|
||||
parseRouteInput(
|
||||
"NOT_FOUND",
|
||||
{ "*": "missing/path" },
|
||||
new URLSearchParams(),
|
||||
),
|
||||
).toMatchObject({ success: true });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user