fix(documents): port-scope folder test cleanup + tighten parent-validation message
Code-review followups on 4b31f01:
- beforeEach now scopes the documentFolders cleanup to the test port
via .where(eq(documentFolders.portId, portId)) so parallel suites
don't wipe each other's fixtures.
- Cross-port parent guard message changed from "Parent folder not
found in this port" (read like a 404) to "Invalid parent folder"
to match the ValidationError type that already maps to 400.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -88,7 +88,7 @@ export async function createFolder(
|
||||
const parent = await db.query.documentFolders.findFirst({
|
||||
where: and(eq(documentFolders.id, data.parentId), eq(documentFolders.portId, portId)),
|
||||
});
|
||||
if (!parent) throw new ValidationError('Parent folder not found in this port');
|
||||
if (!parent) throw new ValidationError('Invalid parent folder');
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
||||
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
import { db } from '@/lib/db';
|
||||
import { documentFolders } from '@/lib/db/schema/documents';
|
||||
import { user } from '@/lib/db/schema/users';
|
||||
@@ -29,7 +31,7 @@ describe('document-folders service · listTree', () => {
|
||||
beforeEach(async () => {
|
||||
const port = await makePort();
|
||||
portId = port.id;
|
||||
await db.delete(documentFolders).execute();
|
||||
await db.delete(documentFolders).where(eq(documentFolders.portId, portId));
|
||||
});
|
||||
|
||||
it('returns an empty array when no folders exist', async () => {
|
||||
@@ -64,7 +66,7 @@ describe('document-folders service · createFolder unique-sibling guard', () =>
|
||||
beforeEach(async () => {
|
||||
const port = await makePort();
|
||||
portId = port.id;
|
||||
await db.delete(documentFolders).execute();
|
||||
await db.delete(documentFolders).where(eq(documentFolders.portId, portId));
|
||||
});
|
||||
|
||||
it('rejects a duplicate sibling name (case-insensitive)', async () => {
|
||||
@@ -91,6 +93,6 @@ describe('document-folders service · createFolder unique-sibling guard', () =>
|
||||
});
|
||||
await expect(
|
||||
createFolder(portId, TEST_USER_ID, { name: 'Should fail', parentId: otherFolder.id }),
|
||||
).rejects.toThrow(/not found in this port/i);
|
||||
).rejects.toThrow(/invalid parent/i);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user