|
| 1 | +import * as assert from 'assert' |
| 2 | +import * as sinon from 'sinon' |
| 3 | +import * as vscode from 'vscode' |
| 4 | +import { executeMentionFileCommand } from '../commands' |
| 5 | + |
| 6 | +suite('Cody Commands Tests', () => { |
| 7 | + let sandbox: sinon.SinonSandbox |
| 8 | + let executeCommandStub: sinon.SinonStub |
| 9 | + let showErrorMessageStub: sinon.SinonStub |
| 10 | + |
| 11 | + setup(() => { |
| 12 | + sandbox = sinon.createSandbox() |
| 13 | + executeCommandStub = sandbox.stub(vscode.commands, 'executeCommand') |
| 14 | + showErrorMessageStub = sandbox.stub(vscode.window, 'showErrorMessage') |
| 15 | + }) |
| 16 | + |
| 17 | + teardown(() => { |
| 18 | + sandbox.restore() |
| 19 | + }) |
| 20 | + |
| 21 | + suite('executeMentionFileCommand', () => { |
| 22 | + test('should successfully execute mention file command', async () => { |
| 23 | + // Setup |
| 24 | + const testUri = vscode.Uri.file('/test/file.js') |
| 25 | + executeCommandStub.resolves(true) |
| 26 | + |
| 27 | + // Execute |
| 28 | + const result = await executeMentionFileCommand(testUri) |
| 29 | + |
| 30 | + console.log({ result }) |
| 31 | + |
| 32 | + // Verify |
| 33 | + assert.strictEqual(result, true) |
| 34 | + assert.strictEqual(executeCommandStub.calledOnce, true) |
| 35 | + assert.strictEqual(executeCommandStub.firstCall.args[0], 'cody.mention.file') |
| 36 | + assert.strictEqual(executeCommandStub.firstCall.args[1], testUri) |
| 37 | + }) |
| 38 | + |
| 39 | + test('should handle command execution failure', async () => { |
| 40 | + // Setup |
| 41 | + const testUri = vscode.Uri.file('/test/file.js') |
| 42 | + const testError = new Error('Command failed') |
| 43 | + executeCommandStub.rejects(testError) |
| 44 | + |
| 45 | + // Execute |
| 46 | + const result = await executeMentionFileCommand(testUri) |
| 47 | + |
| 48 | + // Verify |
| 49 | + assert.strictEqual(result, false) |
| 50 | + assert.strictEqual(executeCommandStub.calledOnce, true) |
| 51 | + assert.strictEqual(showErrorMessageStub.calledOnce, true) |
| 52 | + assert.strictEqual( |
| 53 | + showErrorMessageStub.firstCall.args[0], |
| 54 | + 'Failed to trigger Cody to mention file: Command failed' |
| 55 | + ) |
| 56 | + }) |
| 57 | + |
| 58 | + test('should handle invalid URI', async () => { |
| 59 | + // Setup |
| 60 | + const invalidUri = {} as vscode.Uri |
| 61 | + executeCommandStub.rejects(new Error('Invalid URI')) |
| 62 | + |
| 63 | + // Execute |
| 64 | + const result = await executeMentionFileCommand(invalidUri) |
| 65 | + |
| 66 | + // Verify |
| 67 | + assert.strictEqual(result, false) |
| 68 | + assert.strictEqual(executeCommandStub.calledOnce, true) |
| 69 | + assert.strictEqual(showErrorMessageStub.calledOnce, true) |
| 70 | + }) |
| 71 | + }) |
| 72 | +}) |
0 commit comments