Skip to content

Commit 619bb56

Browse files
authored
fix(api): export handleSchemaCollectionReorder from the handlers barrel (#2814)
The collection reorder route imports its handler from "#api/index.js", but the schema block in the handlers barrel re-exports by explicit name and this one was never added. The binding resolved to undefined, so POST /_emdash/api/schema/collections/reorder threw before it could do any work and reordering content types in the admin sidebar failed instead of saving the new order. Field reordering was unaffected because handleSchemaFieldReorder is in the list. Typecheck could not have caught this: packages/core/tsconfig.json excludes src/astro/**, so the route file is outside the program. The regression test drives the route's POST against a real in-memory SQLite database and asserts the persisted sort order, which is the layer where the gap is actually observable. Closes #2813
1 parent c3c49dd commit 619bb56

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"emdash": patch
3+
---
4+
5+
Fixes reordering content types in the admin sidebar, which failed with a server error instead of saving the new order. Reordering fields within a content type was unaffected.

packages/core/src/api/handlers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export {
110110
handleSchemaFieldCreate,
111111
handleSchemaFieldUpdate,
112112
handleSchemaFieldDelete,
113+
handleSchemaCollectionReorder,
113114
handleSchemaFieldReorder,
114115
handleOrphanedTableList,
115116
handleOrphanedTableRegister,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Role } from "@emdash-cms/auth";
2+
import type { Kysely } from "kysely";
3+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
4+
5+
import { POST } from "../../../src/astro/routes/api/schema/collections/reorder.js";
6+
import type { Database } from "../../../src/database/types.js";
7+
import { SchemaRegistry } from "../../../src/schema/registry.js";
8+
import { setupTestDatabase, teardownTestDatabase } from "../../utils/test-db.js";
9+
10+
type RouteContext = Parameters<typeof POST>[0];
11+
12+
describe("schema collections reorder route", () => {
13+
let db: Kysely<Database>;
14+
let registry: SchemaRegistry;
15+
16+
beforeEach(async () => {
17+
db = await setupTestDatabase();
18+
registry = new SchemaRegistry(db);
19+
await registry.createCollection({ slug: "posts", label: "Posts" });
20+
await registry.createCollection({ slug: "pages", label: "Pages" });
21+
await registry.createCollection({ slug: "authors", label: "Authors" });
22+
});
23+
24+
afterEach(async () => {
25+
await teardownTestDatabase(db);
26+
});
27+
28+
it("persists the requested sidebar order", async () => {
29+
const response = await POST(reorderContext(["posts", "authors", "pages"]));
30+
31+
expect(response.status).toBe(200);
32+
33+
const collections = await registry.listCollections();
34+
expect(collections.map((collection) => collection.slug)).toEqual(["posts", "authors", "pages"]);
35+
expect(collections.map((collection) => collection.sortOrder)).toEqual([0, 1, 2]);
36+
});
37+
38+
function reorderContext(slugs: string[]): RouteContext {
39+
return {
40+
request: new Request("http://localhost/_emdash/api/schema/collections/reorder", {
41+
method: "POST",
42+
headers: { "Content-Type": "application/json", "X-EmDash-Request": "1" },
43+
body: JSON.stringify({ slugs }),
44+
}),
45+
locals: {
46+
emdash: { db },
47+
user: { id: "admin-1", role: Role.ADMIN },
48+
},
49+
} as RouteContext;
50+
}
51+
});

0 commit comments

Comments
 (0)