Skip to content

Commit

Permalink
Fixing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
laileni-aws committed Dec 12, 2024
1 parent 5428d8d commit 33b7ec4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/amazonq/test/unit/codewhisperer/util/zipUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import vscode from 'vscode'
import sinon from 'sinon'
import { join } from 'path'
import { getTestWorkspaceFolder } from 'aws-core-vscode/test'
import { CodeAnalysisScope, ZipUtil } from 'aws-core-vscode/codewhisperer'
import { CodeAnalysisScope, FeatureUseCase, ZipUtil } from 'aws-core-vscode/codewhisperer'
import { codeScanTruncDirPrefix } from 'aws-core-vscode/codewhisperer'
import { ToolkitError } from 'aws-core-vscode/shared'
import { LspClient } from 'aws-core-vscode/amazonq'
Expand Down Expand Up @@ -116,6 +116,8 @@ describe('zipUtil', function () {
})

it('should handle path with repeated project name for file scan', async function () {
const mockCodeScan = 'CODE_SCAN'
sinon.stub(FeatureUseCase, 'CODE_SCAN').value(mockCodeScan)
const zipMetadata = await zipUtil.generateZip(
vscode.Uri.file(appCodePathWithRepeatedProjectName),
CodeAnalysisScope.FILE_ON_DEMAND
Expand All @@ -125,9 +127,19 @@ describe('zipUtil', function () {
const zip = await JSZip.loadAsync(zipFileData)
const files = Object.keys(zip.files)
assert.ok(files.includes(join('workspaceFolder', 'workspaceFolder', 'App.java')))

// Verify that the mocked FeatureUseCase.CODE_SCAN was used
assert.ok(zipMetadata.rootDir.includes(mockCodeScan))
assert.ok(zipMetadata.zipFilePath.includes(mockCodeScan))

// Restore the original FeatureUseCase.CODE_SCAN
sinon.restore()
})

it('should handle path with repeated project name for project scan', async function () {
const mockCodeScan = 'CODE_SCAN'
sinon.stub(FeatureUseCase, 'CODE_SCAN').value(mockCodeScan)

const zipMetadata = await zipUtil.generateZip(
vscode.Uri.file(appCodePathWithRepeatedProjectName),
CodeAnalysisScope.PROJECT
Expand All @@ -137,6 +149,11 @@ describe('zipUtil', function () {
const zip = await JSZip.loadAsync(zipFileData)
const files = Object.keys(zip.files)
assert.ok(files.includes(join('workspaceFolder', 'workspaceFolder', 'App.java')))

assert.ok(zipMetadata.rootDir.includes(mockCodeScan))
assert.ok(zipMetadata.zipFilePath.includes(mockCodeScan))

sinon.restore()
})
})

Expand Down

0 comments on commit 33b7ec4

Please sign in to comment.