Skip to content

Commit 14b0a48

Browse files
fix(files): classify missing archive targets
1 parent 89a27ca commit 14b0a48

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

apps/sim/app/api/workspaces/[id]/files/folders/[folderId]/route.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ vi.mock('@/lib/workspace-files/application/workspace-file-folders', () => ({
2929
},
3030
}))
3131

32+
import { WorkspaceFileItemsNotFoundError } from '@/lib/uploads/contexts/workspace/workspace-file-folder-manager'
3233
import { POST as RESTORE } from '@/app/api/workspaces/[id]/files/folders/[folderId]/restore/route'
3334
import { DELETE, PATCH } from '@/app/api/workspaces/[id]/files/folders/[folderId]/route'
3435

@@ -116,6 +117,19 @@ describe('/api/workspaces/[id]/files/folders/[folderId]', () => {
116117
})
117118
})
118119

120+
it('returns not found when deleting an already archived folder', async () => {
121+
mocks.deleteFolder.mockRejectedValueOnce(new WorkspaceFileItemsNotFoundError([], [FOLDER_ID]))
122+
123+
const response = await DELETE(request('DELETE'), context)
124+
125+
expect(response.status).toBe(404)
126+
expect(await response.json()).toEqual({
127+
success: false,
128+
error: `Workspace file items not found (folders: ${FOLDER_ID})`,
129+
})
130+
expect(mocks.captureServerEvent).not.toHaveBeenCalled()
131+
})
132+
119133
it('restores a folder through the shared use case', async () => {
120134
const response = await RESTORE(request('POST'), context)
121135

apps/sim/lib/uploads/contexts/workspace/workspace-file-folder-manager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ export class WorkspaceFileMoveConflictError extends Error {
4848
}
4949
}
5050

51-
export class WorkspaceFileItemsNotFoundError extends Error {
52-
readonly code = 'WORKSPACE_FILE_ITEMS_NOT_FOUND' as const
53-
51+
export class WorkspaceFileItemsNotFoundError extends OrchestrationError {
5452
constructor(fileIds: string[], folderIds: string[]) {
5553
const parts = [
5654
fileIds.length > 0 ? `files: ${fileIds.join(', ')}` : null,
5755
folderIds.length > 0 ? `folders: ${folderIds.join(', ')}` : null,
5856
].filter(Boolean)
59-
super(`Workspace file items not found (${parts.join('; ')})`)
57+
super('not_found', `Workspace file items not found (${parts.join('; ')})`)
58+
this.name = 'WorkspaceFileItemsNotFoundError'
6059
}
6160
}
6261

0 commit comments

Comments
 (0)