@@ -6,6 +6,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
66const mocks = vi . hoisted ( ( ) => ( {
77 loadContext : vi . fn ( ) ,
88 getWorkspaceFile : vi . fn ( ) ,
9+ getShareForResource : vi . fn ( ) ,
910 resolvePermission : vi . fn ( ) ,
1011} ) )
1112
@@ -19,6 +20,10 @@ vi.mock('@/lib/uploads/contexts/workspace/workspace-file-manager', () => ({
1920 loadActiveWorkspaceFileContext : mocks . loadContext ,
2021} ) )
2122
23+ vi . mock ( '@/lib/public-shares/share-manager' , ( ) => ( {
24+ getShareForResource : mocks . getShareForResource ,
25+ } ) )
26+
2227import { readWorkspaceFileMetadata } from '@/lib/workspace-files/application/read-workspace-file-metadata'
2328
2429const canonical = {
@@ -43,15 +48,28 @@ const file = {
4348 updatedAt : new Date ( '2026-01-02T00:00:00Z' ) ,
4449}
4550
51+ const share = {
52+ id : 'share-1' ,
53+ token : 'share-token' ,
54+ url : 'https://example.com/f/share-token' ,
55+ isActive : true ,
56+ resourceType : 'file' as const ,
57+ resourceId : 'file-1' ,
58+ authType : 'public' as const ,
59+ hasPassword : false ,
60+ allowedEmails : [ ] ,
61+ }
62+
4663describe ( 'readWorkspaceFileMetadata' , ( ) => {
4764 beforeEach ( ( ) => {
4865 vi . clearAllMocks ( )
4966 mocks . loadContext . mockResolvedValue ( canonical )
5067 mocks . getWorkspaceFile . mockResolvedValue ( file )
68+ mocks . getShareForResource . mockResolvedValue ( share )
5169 mocks . resolvePermission . mockResolvedValue ( 'admin' )
5270 } )
5371
54- it ( 'returns the canonical active file without side effects' , async ( ) => {
72+ it ( 'returns the canonical active file and its share status without side effects' , async ( ) => {
5573 const principal = { kind : 'session' as const , userId : 'user-1' , sessionId : 'session-1' }
5674
5775 await expect (
@@ -62,14 +80,15 @@ describe('readWorkspaceFileMetadata', () => {
6280 assertedWorkspaceId : 'workspace-1' ,
6381 } ,
6482 } )
65- ) . resolves . toEqual ( { file } )
83+ ) . resolves . toEqual ( { file, share } )
6684
6785 expect ( mocks . loadContext ) . toHaveBeenCalledWith ( 'file-1' , {
6886 includeDeleted : undefined ,
6987 } )
7088 expect ( mocks . getWorkspaceFile ) . toHaveBeenCalledWith ( 'workspace-1' , 'file-1' , {
7189 throwOnError : true ,
7290 } )
91+ expect ( mocks . getShareForResource ) . toHaveBeenCalledWith ( 'file' , 'file-1' )
7392 } )
7493
7594 it ( 'fails fast if the authorized file disappears before projection' , async ( ) => {
0 commit comments