Skip to content

Commit 4136553

Browse files
authored
Cancel download code bindings operation when user picks Cancel in the collision promompt (#1109)
1 parent cce6366 commit 4136553

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
"AWS.message.error.schemas.viewSchema.could_not_open": "Could not fetch and display schema {0} contents",
180180
"AWS.message.error.schemas.downloadCodeBindings.failed_to_download": "Unable to download schema code",
181181
"AWS.message.error.schemas.downloadCodeBindings.failed_to_generate": "Unable to generate schema code",
182+
"AWS.message.error.schemas.downloadCodeBindings.cancelled:": "Download code bindings cancelled",
182183
"AWS.message.error.schemas.downloadCodeBindings.invalid_code_generation_status": "Invalid Code generation status {0}",
183184
"AWS.message.error.schemas.downloadCodeBindings.timout": "Failed to download code for schema {0} before timeout. Please try again later",
184185
"AWS.message.info.schemas.downloadCodeBindings.start": "Downloading code for schema {0}...",

src/eventSchemas/commands/downloadSchemaItemCode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ export class CodeExtractor {
373373
responseYes,
374374
responseNo
375375
)
376+
377+
if (!userResponse)
378+
throw new UserNotifiedError(
379+
localize('AWS.message.error.schemas.downloadCodeBindings.cancelled', 'Download code bindings cancelled')
380+
)
381+
376382
return userResponse === responseYes
377383
}
378384

src/test/eventSchemas/commands/downloadSchemaItemCode.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,33 @@ describe('CodeExtractor', () => {
613613
assert.strictEqual(file1Content, overridenFileContent, `${file1Path} :File content should be overriden`)
614614
})
615615

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+
616643
it('should return coreCodeFilePath if it exists inside zip content', async () => {
617644
//grab the title from schemaName
618645
const title = testSchemaName.split('.').pop()

0 commit comments

Comments
 (0)