@@ -82,4 +82,43 @@ describe("uploadLocalFiles", () => {
8282
8383 await expect ( uploadLocalFiles ( args , inputs , mockClient ) ) . rejects . toThrow ( "File not found" ) ;
8484 } ) ;
85+
86+ it ( "passes the file's sha256 checksum so the server can dedup" , async ( ) => {
87+ const localPath = createTempFile ( "video.mp4" , "fake" ) ;
88+ const mockUpload = mock ( ( _data : Uint8Array , _options : { checksum ?: string } ) =>
89+ Promise . resolve ( { url : "https://cdn.rendobar.com/uploads/abc.mp4" } ) ,
90+ ) ;
91+ const mockClient = { uploads : { create : mockUpload } } as unknown as Parameters < typeof uploadLocalFiles > [ 2 ] ;
92+
93+ await uploadLocalFiles ( [ "-i" , localPath , "out.mp4" ] , [ { index : 1 , value : localPath , isLocal : true } ] , mockClient ) ;
94+
95+ // Hash of the same content, computed independently of the code under test.
96+ const expected = new Bun . CryptoHasher ( "sha256" ) . update ( "fake" ) . digest ( "hex" ) ;
97+ expect ( mockUpload . mock . calls [ 0 ] ! [ 1 ] . checksum ) . toBe ( expected ) ;
98+ } ) ;
99+
100+ it ( "forwards SDK progress events to onFileProgress with file context" , async ( ) => {
101+ const localPath = createTempFile ( "video.mp4" , "fake-bytes" ) ;
102+ const mockUpload = mock (
103+ async ( _data : Uint8Array , options : { onProgress ?: ( p : { loaded : number ; total : number } ) => void } ) => {
104+ options . onProgress ?.( { loaded : 5 , total : 10 } ) ;
105+ options . onProgress ?.( { loaded : 10 , total : 10 } ) ;
106+ return { url : "https://cdn.rendobar.com/uploads/abc.mp4" } ;
107+ } ,
108+ ) ;
109+ const mockClient = { uploads : { create : mockUpload } } as unknown as Parameters < typeof uploadLocalFiles > [ 2 ] ;
110+
111+ const events : unknown [ ] [ ] = [ ] ;
112+ await uploadLocalFiles (
113+ [ "-i" , localPath , "out.mp4" ] ,
114+ [ { index : 1 , value : localPath , isLocal : true } ] ,
115+ mockClient ,
116+ { onFileProgress : ( ...args ) => events . push ( args ) } ,
117+ ) ;
118+
119+ expect ( events ) . toEqual ( [
120+ [ "video.mp4" , 5 , 10 , 0 , 1 ] ,
121+ [ "video.mp4" , 10 , 10 , 0 , 1 ] ,
122+ ] ) ;
123+ } ) ;
85124} ) ;
0 commit comments