@@ -613,6 +613,33 @@ describe('CodeExtractor', () => {
613
613
assert . strictEqual ( file1Content , overridenFileContent , `${ file1Path } :File content should be overriden` )
614
614
} )
615
615
616
+ it ( 'should throw error if user picks Cancel when collision occurs' , async ( ) => {
617
+ const error = new Error ( 'Download code bindings cancelled' )
618
+ sandbox . stub ( codeExtractor , 'confirmOverwriteCollisions' ) . returns ( Promise . reject ( error ) )
619
+
620
+ const fileName1 = 'test.txt'
621
+ const zipFileName = path . join ( destinationDirectory , 'test.zip' )
622
+ const expectedFileContent = 'First file content'
623
+
624
+ // Initialize a destination directory and file
625
+ const zipHandler = createZipFileInTempDirectory ( fileName1 , expectedFileContent , zipFileName )
626
+ zipHandler . extractAllTo ( destinationDirectory )
627
+
628
+ //same file name - collision occurs
629
+ const fileName2 = fileName1
630
+ const zip = new admZip ( )
631
+ zip . addFile ( fileName2 , Buffer . from ( 'Second file content' ) )
632
+ const buffer = zip . toBuffer ( )
633
+
634
+ const err = await assertThrowsError ( async ( ) => codeExtractor . extractAndPlace ( buffer , request ) )
635
+ assert . strictEqual ( err . message , 'Download code bindings cancelled' , 'Should fail for expected error' )
636
+
637
+ const file1Path = path . join ( destinationDirectory , fileName1 )
638
+ const file1Content = fs . readFileSync ( file1Path , { encoding : 'utf8' } )
639
+
640
+ assert . strictEqual ( file1Content , expectedFileContent , `${ file1Path } :File content should not be overriden` )
641
+ } )
642
+
616
643
it ( 'should return coreCodeFilePath if it exists inside zip content' , async ( ) => {
617
644
//grab the title from schemaName
618
645
const title = testSchemaName . split ( '.' ) . pop ( )
0 commit comments