mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-26 09:35:38 -05:00
improve sql bindings extension (#18757)
This commit is contained in:
@@ -10,11 +10,13 @@ import * as TypeMoq from 'typemoq';
|
||||
import * as utils from '../../common/utils';
|
||||
import * as constants from '../../common/constants';
|
||||
import * as azureFunctionUtils from '../../common/azureFunctionsUtils';
|
||||
import * as azureFunctionService from '../../services/azureFunctionsService';
|
||||
|
||||
import { createTestUtils, TestUtils, createTestCredentials } from '../testUtils';
|
||||
import { launchAddSqlBindingQuickpick } from '../../dialogs/addSqlBindingQuickpick';
|
||||
|
||||
let testUtils: TestUtils;
|
||||
const fileUri = vscode.Uri.file('testUri');
|
||||
describe('Add SQL Binding quick pick', () => {
|
||||
beforeEach(function (): void {
|
||||
testUtils = createTestUtils();
|
||||
@@ -25,17 +27,16 @@ describe('Add SQL Binding quick pick', () => {
|
||||
});
|
||||
|
||||
it('Should show error if the file contains no Azure Functions', async function (): Promise<void> {
|
||||
sinon.stub(utils, 'getAzureFunctionService').resolves(testUtils.azureFunctionService.object);
|
||||
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
testUtils.azureFunctionService.setup(x => x.getAzureFunctions(TypeMoq.It.isAny())).returns(async () => {
|
||||
return Promise.resolve({
|
||||
sinon.stub(azureFunctionService, 'getAzureFunctions').withArgs(fileUri.fsPath).returns(
|
||||
Promise.resolve({
|
||||
success: true,
|
||||
errorMessage: '',
|
||||
azureFunctions: []
|
||||
});
|
||||
});
|
||||
await launchAddSqlBindingQuickpick(vscode.Uri.file('testUri'));
|
||||
}));
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
await launchAddSqlBindingQuickpick(fileUri);
|
||||
|
||||
const msg = constants.noAzureFunctionsInFile;
|
||||
should(spy.calledOnce).be.true('showErrorMessage should have been called exactly once');
|
||||
@@ -43,25 +44,24 @@ describe('Add SQL Binding quick pick', () => {
|
||||
});
|
||||
|
||||
it('Should show error if adding SQL binding was not successful', async function (): Promise<void> {
|
||||
sinon.stub(utils, 'getAzureFunctionService').resolves(testUtils.azureFunctionService.object);
|
||||
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
testUtils.azureFunctionService.setup(x => x.getAzureFunctions(TypeMoq.It.isAny())).returns(async () => {
|
||||
return Promise.resolve({
|
||||
sinon.stub(azureFunctionService, 'getAzureFunctions').withArgs(fileUri.fsPath).returns(
|
||||
Promise.resolve({
|
||||
success: true,
|
||||
errorMessage: '',
|
||||
azureFunctions: ['af1', 'af2']
|
||||
});
|
||||
});
|
||||
}));
|
||||
//failure since no AFs are found in the project
|
||||
sinon.stub(azureFunctionUtils, 'getAFProjectContainingFile').resolves(undefined);
|
||||
const errormsg = 'Error inserting binding';
|
||||
testUtils.azureFunctionService.setup(x => x.addSqlBinding(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(async () => {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
errorMessage: errormsg
|
||||
});
|
||||
});
|
||||
sinon.stub(azureFunctionService, 'addSqlBinding').withArgs(
|
||||
sinon.match.any, sinon.match.any, sinon.match.any,
|
||||
sinon.match.any, sinon.match.any).returns(
|
||||
Promise.resolve({
|
||||
success: false,
|
||||
errorMessage: errormsg
|
||||
}));
|
||||
const spy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
|
||||
// select Azure function
|
||||
let quickpickStub = sinon.stub(vscode.window, 'showQuickPick').onFirstCall().resolves({ label: 'af1' });
|
||||
@@ -79,18 +79,16 @@ describe('Add SQL Binding quick pick', () => {
|
||||
});
|
||||
|
||||
it('Should show error connection profile does not connect', async function (): Promise<void> {
|
||||
sinon.stub(utils, 'getAzureFunctionService').resolves(testUtils.azureFunctionService.object);
|
||||
sinon.stub(utils, 'getVscodeMssqlApi').resolves(testUtils.vscodeMssqlIExtension.object);
|
||||
let connectionCreds = createTestCredentials();
|
||||
|
||||
sinon.stub(azureFunctionUtils, 'getAFProjectContainingFile').resolves(vscode.Uri.file('testUri'));
|
||||
testUtils.azureFunctionService.setup(x => x.getAzureFunctions(TypeMoq.It.isAny())).returns(async () => {
|
||||
return Promise.resolve({
|
||||
sinon.stub(azureFunctionService, 'getAzureFunctions').withArgs(fileUri.fsPath).returns(
|
||||
Promise.resolve({
|
||||
success: true,
|
||||
errorMessage: '',
|
||||
azureFunctions: ['af1']
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
// Mocks connect call to mssql
|
||||
let error = new Error('Connection Request Failed');
|
||||
|
||||
@@ -10,12 +10,10 @@ import * as TypeMoq from 'typemoq';
|
||||
import * as mssql from '../../../mssql/src/mssql';
|
||||
import * as vscodeMssql from 'vscode-mssql';
|
||||
import { RequestType } from 'vscode-languageclient';
|
||||
import { BindingType, GetAzureFunctionsResult } from 'sql-bindings';
|
||||
|
||||
export interface TestUtils {
|
||||
context: vscode.ExtensionContext;
|
||||
dacFxService: TypeMoq.IMock<mssql.IDacFxService>;
|
||||
azureFunctionService: TypeMoq.IMock<vscodeMssql.IAzureFunctionsService>;
|
||||
outputChannel: vscode.OutputChannel;
|
||||
vscodeMssqlIExtension: TypeMoq.IMock<vscodeMssql.IExtension>
|
||||
dacFxMssqlService: TypeMoq.IMock<vscodeMssql.IDacFxService>;
|
||||
@@ -131,17 +129,6 @@ export const mockResultStatus = {
|
||||
errorMessage: ''
|
||||
};
|
||||
|
||||
export const mockGetAzureFunctionsResult = {
|
||||
success: true,
|
||||
errorMessage: '',
|
||||
azureFunctions: []
|
||||
};
|
||||
|
||||
export class MockAzureFunctionService implements vscodeMssql.IAzureFunctionsService {
|
||||
addSqlBinding(_: BindingType, __: string, ___: string, ____: string, _____: string): Thenable<vscodeMssql.ResultStatus> { return Promise.resolve(mockResultStatus); }
|
||||
getAzureFunctions(_: string): Thenable<GetAzureFunctionsResult> { return Promise.resolve(mockGetAzureFunctionsResult); }
|
||||
}
|
||||
|
||||
export const mockDacFxMssqlOptionResult: vscodeMssql.DacFxOptionsResult = {
|
||||
success: true,
|
||||
errorMessage: '',
|
||||
@@ -249,12 +236,10 @@ export class MockVscodeMssqlIExtension implements vscodeMssql.IExtension {
|
||||
sqlToolsServicePath: string = '';
|
||||
dacFx: vscodeMssql.IDacFxService;
|
||||
schemaCompare: vscodeMssql.ISchemaCompareService;
|
||||
azureFunctions: vscodeMssql.IAzureFunctionsService;
|
||||
|
||||
constructor() {
|
||||
this.dacFx = new MockDacFxMssqlService;
|
||||
this.schemaCompare = new MockSchemaCompareService;
|
||||
this.azureFunctions = new MockAzureFunctionService;
|
||||
}
|
||||
sendRequest<P, R, E, R0>(_: RequestType<P, R, E, R0>, __?: P): Promise<R> {
|
||||
throw new Error('Method not implemented.');
|
||||
@@ -311,7 +296,6 @@ export function createTestUtils(): TestUtils {
|
||||
extension: undefined as any
|
||||
},
|
||||
dacFxService: TypeMoq.Mock.ofType(MockDacFxService),
|
||||
azureFunctionService: TypeMoq.Mock.ofType(MockAzureFunctionService),
|
||||
vscodeMssqlIExtension: TypeMoq.Mock.ofType(MockVscodeMssqlIExtension),
|
||||
dacFxMssqlService: TypeMoq.Mock.ofType(MockDacFxMssqlService),
|
||||
schemaCompareService: TypeMoq.Mock.ofType(MockSchemaCompareService),
|
||||
|
||||
Reference in New Issue
Block a user