Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions apps/web/src/app/api/pages/reorder/__tests__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,40 @@ describe('PATCH /api/pages/reorder', () => {
expect(pageReorderService.reorderPage).not.toHaveBeenCalled();
});

it('returns 400 for negative position values', async () => {
it('accepts negative position values (for fractional positioning)', async () => {
const response = await PATCH(createRequest({
pageId: mockPageId,
newParentId: null,
newPosition: -1,
}));
const body = await response.json();

expect(response.status).toBe(200);
expect(pageReorderService.reorderPage).toHaveBeenCalledWith(
expect.objectContaining({ newPosition: -1 })
);
});

it('accepts fractional position values (for between-item positioning)', async () => {
const response = await PATCH(createRequest({
pageId: mockPageId,
newParentId: null,
newPosition: 2.5,
}));

expect(response.status).toBe(200);
expect(pageReorderService.reorderPage).toHaveBeenCalledWith(
expect.objectContaining({ newPosition: 2.5 })
);
});

it('returns 400 for non-finite position values', async () => {
const response = await PATCH(createRequest({
pageId: mockPageId,
newParentId: null,
newPosition: Infinity,
}));

expect(response.status).toBe(400);
expect(body.error).toMatch(/position|non-negative/i);
expect(pageReorderService.reorderPage).not.toHaveBeenCalled();
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/pages/reorder/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const AUTH_OPTIONS = { allow: ['jwt', 'mcp'] as const, requireCSRF: true };
const reorderSchema = z.object({
pageId: z.string(),
newParentId: z.string().nullable(),
newPosition: z.number().int().gte(0, 'Position must be a non-negative integer'),
newPosition: z.number().finite(),
});

export async function PATCH(request: Request) {
Expand Down