Skip to content

Commit e052db8

Browse files
committed
test: Add extra tests for case where lambda quick edit dir is empty
1 parent 4d68eef commit e052db8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/core/src/test/lambda/commands/editLambda.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('editLambda', function () {
4040
let existsDirStub: sinon.SinonStub
4141
let mkdirStub: sinon.SinonStub
4242
let promptDeployStub: sinon.SinonStub
43+
let readdirStub: sinon.SinonStub
4344

4445
beforeEach(function () {
4546
mockLambda = {
@@ -71,12 +72,12 @@ describe('editLambda', function () {
7172
executeCommandStub = sinon.stub(vscode.commands, 'executeCommand').resolves()
7273
existsDirStub = sinon.stub(fs, 'existsDir').resolves(true)
7374
mkdirStub = sinon.stub(fs, 'mkdir').resolves()
75+
readdirStub = sinon.stub(fs, 'readdir').resolves([['file', vscode.FileType.File]])
7476
promptDeployStub = sinon.stub().resolves(true)
7577
sinon.replace(require('../../../lambda/commands/editLambda'), 'promptDeploy', promptDeployStub)
7678

7779
// Other stubs
7880
sinon.stub(utils, 'getLambdaDetails').returns({ fileName: 'index.js', functionName: 'test-function' })
79-
sinon.stub(fs, 'readdir').resolves([])
8081
sinon.stub(fs, 'delete').resolves()
8182
sinon.stub(fs, 'stat').resolves({ ctime: Date.now() } as any)
8283
sinon.stub(vscode.workspace, 'saveAll').resolves(true)
@@ -126,6 +127,26 @@ describe('editLambda', function () {
126127
assert(openLambdaFileStub.calledOnce)
127128
})
128129

130+
it('downloads lambda when directory exists but is empty', async function () {
131+
getFunctionInfoStub.resolves('old-sha')
132+
readdirStub.resolves([])
133+
134+
await editLambda(mockLambda)
135+
136+
assert(downloadLambdaStub.calledOnce)
137+
assert(showConfirmationMessageStub.notCalled)
138+
})
139+
140+
it('downloads lambda when directory does not exist', async function () {
141+
getFunctionInfoStub.resolves('old-sha')
142+
existsDirStub.resolves(false)
143+
144+
await editLambda(mockLambda)
145+
146+
assert(downloadLambdaStub.calledOnce)
147+
assert(showConfirmationMessageStub.notCalled)
148+
})
149+
129150
it('sets up file watcher after download', async function () {
130151
const watcherStub = {
131152
onDidChange: sinon.stub(),

0 commit comments

Comments
 (0)