server-params.test.ts
This file
Path
apps/web/test/server-params.test.ts
54 lines · 1.6 KiB · TypeScript
Last changed by
Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
History of this fileTake it
Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248
lines 1–2why, one step back1// Start runs every matched route's `params.parse` before a server handler, so the handler reads the full name2// once: parsing it again would name `oscabriel/oscabriel/datekit`.Merge build/1431-fix-handler-params into mainoscabrielbefore adoption3878778
lines 3–54why, one step back3import { describe, expect, it } from "@effect/vitest";45import { getRouter } from "../src/router.tsx";6import { addressRewrite } from "../src/server/addresses.ts";78const handedAt = (pathname: string) => {9 const router = getRouter();1011 const url = addressRewrite.input?.({12 url: new URL(pathname, "https://web.test"),13 });1415 const [matched, raw] = router.getMatchedRoutes(16 url instanceof URL ? url.pathname : pathname17 );1819 const params = { ...raw };2021 for (const route of matched) {22 const parse = route.options.params?.parse;2324 if (parse !== undefined) {25 Object.assign(params, parse(params));26 }27 }2829 return params;30};3132describe("a project route's server handler", () => {33 it("is handed the project's full name as project, for an owner's project", () => {34 expect(handedAt("/oscabriel/datekit/llms.txt")).toMatchObject({35 owner: "oscabriel",36 project: "oscabriel/datekit",37 });38 expect(handedAt("/oscabriel/datekit/asks/format-ordinal.md")).toMatchObject(39 {40 project: "oscabriel/datekit",41 }42 );43 });4445 it("is handed the project's full name as project, at its source namespace", () => {46 expect(handedAt("/github.com/pallets/click")).toMatchObject({47 owner: "github.com/pallets",48 project: "github.com/pallets/click",49 });50 expect(handedAt("/github.com/pallets/click/llms.txt")).toMatchObject({51 project: "github.com/pallets/click",52 });53 });54});