Files
emdash-cms--emdash/packages/core/tests/unit/api/byline-fields-route-registration.test.ts
wehub-resource-sync b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:23:53 +08:00

69 lines
2.8 KiB
TypeScript

/**
* Byline-fields route registration test (Phase 4 of Discussion #1174).
*
* Regression guard mirroring `email-settings-route.test.ts` (#151).
* Route files under `src/astro/routes/` are only reachable in real
* integrated apps if `injectCoreRoutes` calls `injectRoute` for them —
* the directory layout alone does nothing. This test asserts that
* every byline-fields endpoint is wired up.
*
* Order matters too: the static `/byline-fields/reorder` route must be
* registered before the dynamic `/byline-fields/[slug]` route so
* Astro's resolver dispatches POST /byline-fields/reorder to the
* reorder handler instead of treating "reorder" as a slug. The
* `reorder` slug is also reserved at the data layer
* (RESERVED_BYLINE_FIELD_SLUGS) for defence in depth, but route
* ordering is the primary mechanism.
*/
import { describe, expect, it, vi } from "vitest";
import { injectCoreRoutes } from "../../../src/astro/integration/routes.js";
interface InjectRouteCall {
pattern: string;
entrypoint: string;
}
describe("byline-fields route registration (Phase 4)", () => {
function collectPatterns(): { patterns: string[]; ordered: InjectRouteCall[] } {
const injectRoute = vi.fn();
injectCoreRoutes(injectRoute);
const calls = injectRoute.mock.calls.map((call) => call[0] as InjectRouteCall);
return { patterns: calls.map((c) => c.pattern), ordered: calls };
}
it("registers list / create at /_emdash/api/admin/byline-fields", () => {
const { patterns } = collectPatterns();
expect(patterns).toContain("/_emdash/api/admin/byline-fields");
});
it("registers single-field CRUD at /_emdash/api/admin/byline-fields/[slug]", () => {
const { patterns } = collectPatterns();
expect(patterns).toContain("/_emdash/api/admin/byline-fields/[slug]");
});
it("registers reorder at /_emdash/api/admin/byline-fields/reorder", () => {
const { patterns } = collectPatterns();
expect(patterns).toContain("/_emdash/api/admin/byline-fields/reorder");
});
it("registers usage at /_emdash/api/admin/byline-fields/[slug]/usage", () => {
const { patterns } = collectPatterns();
expect(patterns).toContain("/_emdash/api/admin/byline-fields/[slug]/usage");
});
it("registers the static `reorder` route before the dynamic `[slug]` route", () => {
// Astro's route resolver picks static over dynamic, but the
// `routes.ts` ordering still matters for build determinism and
// matches the convention used by every other reorder/[slug]
// pairing in the file (see schema/collections/[slug]/fields/).
const { patterns } = collectPatterns();
const reorderIdx = patterns.indexOf("/_emdash/api/admin/byline-fields/reorder");
const slugIdx = patterns.indexOf("/_emdash/api/admin/byline-fields/[slug]");
expect(reorderIdx).toBeGreaterThanOrEqual(0);
expect(slugIdx).toBeGreaterThanOrEqual(0);
expect(reorderIdx).toBeLessThan(slugIdx);
});
});