mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 09:35:39 -05:00
Connection Store Refactor (#4632)
* various clean ups * formatting * remove linting * formatting * IConfigurationService is even better * messing with connection config tests * update tests * formatting * foramtting * remove unused code * add more tests * working through tests * formatting * more factoring of connection store and increase code coverage * formatting * fix tests
This commit is contained in:
@@ -5,23 +5,20 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ConnectionConfig, ISaveGroupResult } from 'sql/platform/connection/common/connectionConfig';
|
||||
import { IConnectionProfile, IConnectionProfileStore } from 'sql/platform/connection/common/interfaces';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import * as assert from 'assert';
|
||||
import { ProviderFeatures, ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import * as azdata from 'azdata';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { ICapabilitiesService, ProviderFeatures } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { ConnectionConfig, ISaveGroupResult } from 'sql/platform/connection/common/connectionConfig';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { IConnectionProfile, IConnectionProfileStore } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { deepFreeze, deepClone } from 'vs/base/common/objects';
|
||||
import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { deepClone, deepFreeze } from 'vs/base/common/objects';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
suite('ConnectionConfig', () => {
|
||||
let capabilitiesService: TypeMoq.Mock<ICapabilitiesService>;
|
||||
@@ -234,9 +231,9 @@ suite('ConnectionConfig', () => {
|
||||
|
||||
test('getAllGroups should merge user and workspace settings correctly', () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups).slice(0, 3), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(0, 3), ConfigurationTarget.USER);
|
||||
// we intentionally overlap these values with the expectation that the function to should return each group once
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups).slice(2, testGroups.length), ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(2, testGroups.length), ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allGroups = config.getAllGroups();
|
||||
@@ -245,7 +242,7 @@ suite('ConnectionConfig', () => {
|
||||
assert.ok(groupsAreEqual(allGroups, testGroups), 'the groups returned did not match expectation');
|
||||
});
|
||||
|
||||
test('addConnection should add the new profile to user settings if does not exist', async () => {
|
||||
test('addConnection should add the new profile to user settings', async () => {
|
||||
let newProfile: IConnectionProfile = {
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
@@ -265,15 +262,15 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let savedConnectionProfile = await config.addConnection(connectionProfile);
|
||||
|
||||
assert.ok(!isUndefinedOrNull(savedConnectionProfile.id));
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length + 1);
|
||||
assert.ok(!!savedConnectionProfile.id);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length + 1);
|
||||
});
|
||||
|
||||
test('addConnection should not add the new profile to user settings if already exists', async () => {
|
||||
@@ -297,8 +294,8 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = existingConnection.options['databaseName'];
|
||||
@@ -307,7 +304,7 @@ suite('ConnectionConfig', () => {
|
||||
let savedConnectionProfile = await config.addConnection(connectionProfile);
|
||||
|
||||
assert.equal(savedConnectionProfile.id, existingConnection.id);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length);
|
||||
});
|
||||
|
||||
test('addConnection should add the new group to user settings if does not exist', async () => {
|
||||
@@ -330,21 +327,21 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.addConnection(connectionProfile);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length + 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionGroupsArrayName).user.length, testGroups.length + 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length + 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connectionGroups').user.length, testGroups.length + 1);
|
||||
});
|
||||
|
||||
test('getConnections should return connections from user and workspace settings given getWorkspaceConnections set to true', () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(0, 1), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(1, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(0, 1), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(1, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allConnections = config.getConnections(true);
|
||||
@@ -353,8 +350,8 @@ suite('ConnectionConfig', () => {
|
||||
|
||||
test('getConnections should return connections from user settings given getWorkspaceConnections set to false', () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(0, 2), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(2, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(0, 2), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(2, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allConnections = config.getConnections(false);
|
||||
@@ -371,8 +368,8 @@ suite('ConnectionConfig', () => {
|
||||
return c;
|
||||
});
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, userConnections, ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, workspaceConnections, ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue('datasource.connections', userConnections, ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', workspaceConnections, ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allConnections = config.getConnections(false);
|
||||
@@ -381,7 +378,7 @@ suite('ConnectionConfig', () => {
|
||||
let userConnection = testConnections.find(u => u.options['serverName'] === connection.serverName);
|
||||
if (userConnection !== undefined) {
|
||||
assert.notEqual(connection.id, connection.getOptionsKey());
|
||||
assert.ok(!isUndefinedOrNull(connection.id));
|
||||
assert.ok(!!connection.id);
|
||||
} else {
|
||||
let workspaceConnection = workspaceConnections.find(u => u.options['serverName'] === connection.serverName);
|
||||
assert.notEqual(connection.id, connection.getOptionsKey());
|
||||
@@ -397,7 +394,7 @@ suite('ConnectionConfig', () => {
|
||||
let color: string = 'red';
|
||||
|
||||
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
|
||||
assert.ok(!isUndefinedOrNull(result));
|
||||
assert.ok(!!result);
|
||||
assert.equal(result.groups.length, testGroups.length + 2, 'The result groups length is invalid');
|
||||
let newGroup = result.groups.find(g => g.name === 'new-group2');
|
||||
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
|
||||
@@ -410,7 +407,7 @@ suite('ConnectionConfig', () => {
|
||||
let color: string = 'red';
|
||||
|
||||
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
|
||||
assert.ok(!isUndefinedOrNull(result));
|
||||
assert.ok(!!result);
|
||||
assert.equal(result.groups.length, testGroups.length + 1, 'The result groups length is invalid');
|
||||
let newGroup = result.groups.find(g => g.name === 'g2-5');
|
||||
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
|
||||
@@ -423,7 +420,7 @@ suite('ConnectionConfig', () => {
|
||||
let color: string = 'red';
|
||||
|
||||
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
|
||||
assert.ok(!isUndefinedOrNull(result));
|
||||
assert.ok(!!result);
|
||||
assert.equal(result.groups.length, testGroups.length, 'The result groups length is invalid');
|
||||
let newGroup = result.groups.find(g => g.name === 'g2-1');
|
||||
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
|
||||
@@ -448,7 +445,7 @@ suite('ConnectionConfig', () => {
|
||||
connectionName: undefined
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
@@ -456,7 +453,7 @@ suite('ConnectionConfig', () => {
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.deleteConnection(connectionProfile);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length - 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length - 1);
|
||||
});
|
||||
|
||||
test('deleteConnectionGroup should remove the children connections and subgroups from config', async () => {
|
||||
@@ -478,8 +475,8 @@ suite('ConnectionConfig', () => {
|
||||
connectionName: undefined
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
@@ -492,8 +489,8 @@ suite('ConnectionConfig', () => {
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.deleteGroup(connectionProfileGroup);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length - 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user.length, testGroups.length - 2);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length - 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user.length, testGroups.length - 2);
|
||||
});
|
||||
|
||||
test('deleteConnection should not throw error for connection not in config', async () => {
|
||||
@@ -515,34 +512,34 @@ suite('ConnectionConfig', () => {
|
||||
connectionName: undefined
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.deleteConnection(connectionProfile);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length);
|
||||
});
|
||||
|
||||
test('renameGroup should change group name', async () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfileGroup = new ConnectionProfileGroup('g-renamed', undefined, 'g2', undefined, undefined);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.editGroup(connectionProfileGroup);
|
||||
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
|
||||
assert.equal(editedGroups.length, testGroups.length);
|
||||
let editedGroup = editedGroups.find(group => group.id === 'g2');
|
||||
assert.ok(!isUndefinedOrNull(editedGroup));
|
||||
assert.ok(!!editedGroup);
|
||||
assert.equal(editedGroup.name, 'g-renamed');
|
||||
});
|
||||
|
||||
test('edit group should throw if there is a confliction', async () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let sameNameGroup = new ConnectionProfileGroup('g3', undefined, 'g2', undefined, undefined);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
@@ -551,27 +548,27 @@ suite('ConnectionConfig', () => {
|
||||
await config.editGroup(sameNameGroup);
|
||||
assert.fail();
|
||||
} catch (e) {
|
||||
let groups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
let groups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
let originalGroup = groups.find(g => g.id === 'g2');
|
||||
assert.ok(!isUndefinedOrNull(originalGroup));
|
||||
assert.ok(!!originalGroup);
|
||||
assert.equal(originalGroup.name, 'g2');
|
||||
}
|
||||
});
|
||||
|
||||
test('change group(parent) for connection group', async () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let sourceProfileGroup = new ConnectionProfileGroup('g2', undefined, 'g2', undefined, undefined);
|
||||
let targetProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.changeGroupIdForConnectionGroup(sourceProfileGroup, targetProfileGroup);
|
||||
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
|
||||
assert.equal(editedGroups.length, testGroups.length);
|
||||
let editedGroup = editedGroups.find(group => group.id === 'g2');
|
||||
assert.ok(!isUndefinedOrNull(editedGroup));
|
||||
assert.ok(!!editedGroup);
|
||||
assert.equal(editedGroup.parentId, 'g3');
|
||||
});
|
||||
|
||||
@@ -615,7 +612,7 @@ suite('ConnectionConfig', () => {
|
||||
let _testConnections = deepClone(testConnections).concat([existingProfile, changingProfile]);
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, _testConnections, ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', _testConnections, ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, changingProfile);
|
||||
|
||||
@@ -624,11 +621,11 @@ suite('ConnectionConfig', () => {
|
||||
await config.changeGroupIdForConnection(connectionProfile, 'test');
|
||||
assert.fail();
|
||||
} catch (e) {
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user;
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user;
|
||||
// two
|
||||
assert.equal(editedConnections.length, _testConnections.length);
|
||||
let editedConnection = editedConnections.find(con => con.id === 'server3-2');
|
||||
assert.ok(!isUndefinedOrNull(editedConnection));
|
||||
assert.ok(!!editedConnection);
|
||||
assert.equal(editedConnection.groupId, 'g3');
|
||||
}
|
||||
});
|
||||
@@ -653,7 +650,7 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let newId = 'newid';
|
||||
@@ -661,18 +658,18 @@ suite('ConnectionConfig', () => {
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.changeGroupIdForConnection(connectionProfile, newId);
|
||||
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user;
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user;
|
||||
assert.equal(editedConnections.length, testConnections.length);
|
||||
let editedConnection = editedConnections.find(con => con.id === 'server3');
|
||||
assert.ok(!isUndefinedOrNull(editedConnection));
|
||||
assert.ok(!!editedConnection);
|
||||
assert.equal(editedConnection.groupId, 'newid');
|
||||
});
|
||||
|
||||
test('addConnection should not move the connection when editing', async () => {
|
||||
// Set up the connection config
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
|
||||
// Clone a connection and modify an option
|
||||
@@ -702,13 +699,13 @@ suite('ConnectionConfig', () => {
|
||||
description: 'new group'
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
|
||||
await config.addGroup(newGroup);
|
||||
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
|
||||
assert.equal(editGroups.length, testGroups.length + 1);
|
||||
});
|
||||
@@ -722,14 +719,14 @@ suite('ConnectionConfig', () => {
|
||||
description: 'new group'
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
const config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
try {
|
||||
await config.addGroup(existingGroupName);
|
||||
assert.fail();
|
||||
} catch (e) {
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
|
||||
assert.equal(editGroups.length, testGroups.length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user