1- import { dbChainMockFns } from '@sim/testing'
1+ import { dbChainMockFns , resetDbChainMock } from '@sim/testing'
22import { billingStorageMock } from '@sim/testing/mocks/billing-storage.mock'
3+ import { projectMembershipMock } from '@sim/testing/mocks/project-membership.mock'
34import { realtimeNotifyMock } from '@sim/testing/mocks/realtime-notify.mock'
45import { storageServiceMock , storageServiceMockFns } from '@sim/testing/mocks/storage-service.mock'
56import { uploadsMock } from '@sim/testing/mocks/uploads.mock'
@@ -9,16 +10,7 @@ import {
910} from '@sim/testing/mocks/workspace-file-folders.mock'
1011import { beforeEach , expect , it , vi } from 'vitest'
1112
12- const mocks = vi . hoisted ( ( ) => {
13- const values = vi . fn ( )
14- const insert = vi . fn ( ( ) => ( {
15- values : ( metadata : Record < string , unknown > ) => {
16- values ( metadata )
17- return { onConflictDoNothing : ( ) => ( { returning : async ( ) => [ metadata ] } ) }
18- } ,
19- } ) )
20- return { values, insert }
21- } )
13+ vi . mock ( '@/lib/projects/membership' , ( ) => projectMembershipMock )
2214vi . mock ( '@/lib/billing/storage' , ( ) => billingStorageMock )
2315vi . mock ( '@/lib/folders/locks' , ( ) => ( { acquireFolderMutationLock : vi . fn ( ) } ) )
2416vi . mock ( '@/lib/realtime/notify' , ( ) => realtimeNotifyMock )
@@ -41,11 +33,12 @@ workspaceFileFoldersMockFns.mockNormalizeWorkspaceFileItemName.mockImplementatio
4133const mockUpload = storageServiceMockFns . mockUploadFile
4234
4335beforeEach ( ( ) => {
44- dbChainMockFns . transaction . mockImplementation (
45- async ( run : ( tx : { insert : typeof mocks . insert } ) => Promise < unknown > ) =>
46- run ( { insert : mocks . insert } )
47- )
48- mockUpload . mockImplementation ( async ( { fileName } : { fileName : string } ) => ( { key : fileName } ) )
36+ resetDbChainMock ( )
37+ dbChainMockFns . returning . mockImplementation ( async ( ) => {
38+ const metadata = dbChainMockFns . values . mock . calls . at ( - 1 ) ?. [ 0 ]
39+ return metadata ? [ metadata ] : [ ]
40+ } )
41+ mockUpload . mockImplementation ( async ( { customKey } ) => ( { key : customKey } ) )
4942} )
5043
5144it ( 'registers agent-authored Page source as a native Page and preserves editable source' , async ( ) => {
@@ -68,7 +61,7 @@ it('registers agent-authored Page source as a native Page and preserves editable
6861 type : SIM_PAGE_CONTENT_TYPE ,
6962 size : bytes . length ,
7063 } )
71- expect ( mocks . values ) . toHaveBeenCalledWith (
64+ expect ( dbChainMockFns . values ) . toHaveBeenCalledWith (
7265 expect . objectContaining ( { originalName : 'Team handbook' , contentType : SIM_PAGE_CONTENT_TYPE } )
7366 )
7467 expect ( mockUpload ) . toHaveBeenCalledWith (
@@ -83,7 +76,7 @@ it('keeps a complete HTML document as HTML rather than mislabeling it a native P
8376 exactName : true ,
8477 } )
8578 expect ( file ) . toMatchObject ( { name : 'report.html' , type : 'text/html' } )
86- expect ( mocks . values ) . toHaveBeenCalledWith (
79+ expect ( dbChainMockFns . values ) . toHaveBeenCalledWith (
8780 expect . objectContaining ( { originalName : 'report.html' , contentType : 'text/html' } )
8881 )
8982} )
0 commit comments