@@ -6,7 +6,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
66
77const mocks = vi . hoisted ( ( ) => ( {
88 getSession : vi . fn ( ) ,
9- extract : vi . fn ( ) ,
109 rename : vi . fn ( ) ,
1110 deleteItems : vi . fn ( ) ,
1211 getUserEntityPermissions : vi . fn ( ) ,
@@ -15,13 +14,6 @@ const mocks = vi.hoisted(() => ({
1514
1615vi . mock ( '@/lib/auth' , ( ) => ( { getSession : mocks . getSession } ) )
1716
18- vi . mock ( '@/lib/workspace-files/application/extract-workspace-file' , ( ) => ( {
19- extractWorkspaceFile : {
20- operation : { id : 'files.extract_archive' , minimumRole : 'write' , workspaceApiKey : 'deny' } ,
21- execute : mocks . extract ,
22- } ,
23- } ) )
24-
2517vi . mock ( '@/lib/workspace-files/application/rename-workspace-file' , ( ) => ( {
2618 renameWorkspaceFile : {
2719 operation : { id : 'files.rename' , minimumRole : 'write' , workspaceApiKey : 'allow' } ,
@@ -46,8 +38,7 @@ import {
4638 WorkspaceApiKeyScopeAuthorizationError ,
4739} from '@/lib/core/application'
4840import { OrchestrationError } from '@/lib/core/orchestration/types'
49- import { ArchiveError } from '@/lib/uploads/archive'
50- import { PATCH , POST } from '@/app/api/workspaces/[id]/files/[fileId]/route'
41+ import { PATCH } from '@/app/api/workspaces/[id]/files/[fileId]/route'
5142
5243const WORKSPACE_ID = 'workspace-1'
5344const FILE_ID = 'wf_1'
@@ -64,15 +55,6 @@ function callRename(body: unknown) {
6455 )
6556}
6657
67- function callExtract ( ) {
68- return POST (
69- new NextRequest ( `http://localhost:3000/api/workspaces/${ WORKSPACE_ID } /files/${ FILE_ID } ` , {
70- method : 'POST' ,
71- } ) ,
72- context
73- )
74- }
75-
7658function fileRecord ( ) {
7759 return {
7860 id : FILE_ID ,
@@ -97,7 +79,6 @@ describe('PATCH /api/workspaces/[id]/files/[fileId]', () => {
9779 session : { id : 'session-1' } ,
9880 } )
9981 mocks . rename . mockResolvedValue ( { file : fileRecord ( ) } )
100- mocks . extract . mockResolvedValue ( { folderName : 'bundle' , extractedCount : 2 , skippedCount : 0 } )
10182 } )
10283
10384 it ( 'authenticates before parsing the request' , async ( ) => {
@@ -189,49 +170,3 @@ describe('PATCH /api/workspaces/[id]/files/[fileId]', () => {
189170 } )
190171 } )
191172} )
192-
193- describe ( 'POST /api/workspaces/[id]/files/[fileId]' , ( ) => {
194- beforeEach ( ( ) => {
195- vi . clearAllMocks ( )
196- mocks . getSession . mockResolvedValue ( {
197- user : { id : 'user-1' } ,
198- session : { id : 'session-1' } ,
199- } )
200- mocks . extract . mockResolvedValue ( { folderName : 'bundle' , extractedCount : 2 , skippedCount : 0 } )
201- } )
202-
203- it ( 'passes a session principal and canonical assertion to the extraction use case' , async ( ) => {
204- const response = await callExtract ( )
205-
206- expect ( response . status ) . toBe ( 200 )
207- expect ( await response . json ( ) ) . toEqual ( {
208- success : true ,
209- folderName : 'bundle' ,
210- extractedCount : 2 ,
211- skippedCount : 0 ,
212- } )
213- expect ( mocks . extract ) . toHaveBeenCalledWith ( {
214- principal : { kind : 'session' , userId : 'user-1' , sessionId : 'session-1' } ,
215- input : { fileId : FILE_ID , assertedWorkspaceId : WORKSPACE_ID } ,
216- request : expect . anything ( ) ,
217- } )
218- } )
219-
220- it ( 'authenticates before invoking extraction' , async ( ) => {
221- mocks . getSession . mockResolvedValue ( null )
222-
223- const response = await callExtract ( )
224-
225- expect ( response . status ) . toBe ( 401 )
226- expect ( mocks . extract ) . not . toHaveBeenCalled ( )
227- } )
228-
229- it ( 'returns a caller-safe error for an invalid zip' , async ( ) => {
230- mocks . extract . mockRejectedValue ( new ArchiveError ( 'invalid' , 'Not a valid .zip archive.' ) )
231-
232- const response = await callExtract ( )
233-
234- expect ( response . status ) . toBe ( 400 )
235- expect ( await response . json ( ) ) . toEqual ( { error : 'Not a valid .zip archive.' } )
236- } )
237- } )
0 commit comments