@@ -189,6 +189,10 @@ describe('File', () => {
189189 let File : any ;
190190 // eslint-disable-next-line @typescript-eslint/no-explicit-any
191191 let file : any ;
192+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
193+ let activeFile : any = null ;
194+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
195+ let originalCopy : any ;
192196
193197 const FILE_NAME = 'file-name.png' ;
194198 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -228,6 +232,18 @@ describe('File', () => {
228232 './signer' : fakeSigner ,
229233 zlib : fakeZlib ,
230234 } ) . File ;
235+
236+ originalCopy = File . prototype . copy ;
237+ File . prototype . copy = function ( dest : any , options : any , callback : any ) {
238+ activeFile = this ;
239+ return originalCopy . call ( this , dest , options , callback ) ;
240+ } ;
241+ } ) ;
242+
243+ after ( ( ) => {
244+ if ( originalCopy ) {
245+ File . prototype . copy = originalCopy ;
246+ }
231247 } ) ;
232248
233249 beforeEach ( ( ) => {
@@ -274,6 +290,19 @@ describe('File', () => {
274290 specialCharsFile = new File ( BUCKET , "special/azAZ!*'()*%/file.jpg" ) ;
275291 specialCharsFile . request = util . noop ;
276292
293+ activeFile = null ;
294+ BUCKET . request = function ( reqOpts : any , callback : any ) {
295+ if ( activeFile && typeof activeFile . request === 'function' && ( activeFile . request as any ) !== util . noop ) {
296+ const prefix = `/o/${ encodeURIComponent ( activeFile . name ) } ` ;
297+ const modifiedReqOpts = { ...reqOpts } ;
298+ if ( modifiedReqOpts . uri . startsWith ( prefix ) ) {
299+ modifiedReqOpts . uri = modifiedReqOpts . uri . substring ( prefix . length ) ;
300+ }
301+ return activeFile . request ( modifiedReqOpts , callback ) ;
302+ }
303+ return Bucket . prototype . request . call ( this , reqOpts , callback ) ;
304+ } ;
305+
277306 createGunzipOverride = null ;
278307 handleRespOverride = null ;
279308 makeWritableStreamOverride = null ;
@@ -507,6 +536,7 @@ describe('File', () => {
507536 } ) ;
508537
509538 describe ( 'copy' , ( ) => {
539+
510540 it ( 'should throw if no destination is provided' , ( ) => {
511541 assert . throws ( ( ) => {
512542 file . copy ( ) ;
0 commit comments