Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
Associate multiple nodes \n Added functionality and tests to associat…
Browse files Browse the repository at this point in the history
…e multiple nodes at once using checkbox

Signed-off-by: Akshat Shah <[email protected]>
  • Loading branch information
Akshat Shah committed Oct 18, 2019
1 parent 212a0c8 commit 997e99c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cucumber/helpers/environmentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class EnvironmentHelper {
this.userInputUtilHelper.showWalletsQuickPickStub.resolves({ label: walletName, data: walletReigstryEntry });
this.userInputUtilHelper.showIdentitiesQuickPickStub.resolves(identityName);
this.userInputUtilHelper.showQuickPickStub.resolves('Use ID and secret to enroll a new identity');
this.userInputUtilHelper.showQuickPickStub.withArgs('Do you want to associate the same identity with another node?').resolves('No');
this.userInputUtilHelper.showYesNoQuickPick.withArgs('Do you want to associate the same identity with another node?').resolves(UserInputUtil.NO);
this.userInputUtilHelper.inputBoxStub.withArgs('Provide a name for the identity').resolves(identityName);
this.userInputUtilHelper.inputBoxStub.withArgs('Enter MSPID').resolves('Org1MSP');

Expand Down
31 changes: 17 additions & 14 deletions extension/commands/associateIdentityWithNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,31 @@ export async function associateIdentityWithNode(replace: boolean = false, enviro
break;
}

const items: string[] = otherNodes.map((_node: FabricNode) => {
return `Yes, ${_node.name}`;
});
const yesnoPick: string = await UserInputUtil.showQuickPickYesNo('Do you want to associate the same identity with another node?');

items.push('No');
const nodeName: string = await UserInputUtil.showQuickPick('Do you want to associate the same identity with another node?', items) as string;

if (!nodeName || nodeName === 'No') {
if (!yesnoPick || yesnoPick === UserInputUtil.NO) {
askAgain = false;
} else {
const foundNode: FabricNode = otherNodes.find((_node: FabricNode) => nodeName.endsWith(_node.name));
const nodes: IBlockchainQuickPickItem<FabricNode>[] = await UserInputUtil.showFabricNodeQuickPick('Choose the nodes you wish to associate with this identity', environmentRegistryEntry.name, [], false, true) as IBlockchainQuickPickItem<FabricNode>[];

foundNode.wallet = walletName;
foundNode.identity = identityName;
if (!nodes || nodes.length === 0) {
return;
}

await environment.updateNode(foundNode);
for (const _node of nodes) {
const foundNode: FabricNode = otherNodes.find((Fnode: FabricNode) => Fnode.name === _node.data.name);

vscode.commands.executeCommand(ExtensionCommands.CONNECT_TO_ENVIRONMENT, environmentRegistryEntry);
outputAdapter.log(LogType.SUCCESS, `Successfully associated identity ${foundNode.identity} from wallet ${foundNode.wallet} with node ${foundNode.name}`);
foundNode.wallet = walletName;
foundNode.identity = identityName;

await environment.updateNode(foundNode);

vscode.commands.executeCommand(ExtensionCommands.CONNECT_TO_ENVIRONMENT, environmentRegistryEntry);
}
outputAdapter.log(LogType.SUCCESS, `Successfully associated identities`);
askAgain = false;
}
} while (askAgain && otherNodes.length > 1);
} while (askAgain);
} catch (error) {
outputAdapter.log(LogType.ERROR, `Failed to associate identity with node ${error.message}`, `Failed to associate identity with node ${error.toString()}`);
}
Expand Down
38 changes: 33 additions & 5 deletions test/commands/associateIdentityWithNodeCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('AssociateIdentityWithNodeCommand', () => {
let showIdentityQuickPickStub: sinon.SinonStub;
let showInputBoxStub: sinon.SinonStub;
let showQuickPickStub: sinon.SinonStub;
let showQuickPickYesNoStub: sinon.SinonStub;
let environmentRegistryEntry: FabricEnvironmentRegistryEntry;
let peerNode: FabricNode;
let caNodeWithoutCreds: FabricNode;
Expand Down Expand Up @@ -114,7 +115,7 @@ describe('AssociateIdentityWithNodeCommand', () => {

showIdentityQuickPickStub = mySandBox.stub(UserInputUtil, 'showIdentitiesQuickPickBox').resolves('identityOne');
showQuickPickStub = mySandBox.stub(UserInputUtil, 'showQuickPick').resolves('Choose an existing identity');
showQuickPickStub.withArgs('Do you want to associate the same identity with another node?').resolves('No');
showQuickPickYesNoStub = mySandBox.stub(UserInputUtil, 'showQuickPickYesNo').withArgs('Do you want to associate the same identity with another node?').resolves(UserInputUtil.NO);
showInputBoxStub = mySandBox.stub(UserInputUtil, 'showInputBox');
showInputBoxStub.onFirstCall().resolves('identityOne');
showInputBoxStub.onSecondCall().resolves('org1MSP');
Expand Down Expand Up @@ -238,7 +239,9 @@ describe('AssociateIdentityWithNodeCommand', () => {
});

it('should associate identity with multiple nodes', async () => {
showQuickPickStub.withArgs('Do you want to associate the same identity with another node?').onFirstCall().resolves('Yes, orderer.example.com');
showFabricNodeQuickPickStub.withArgs('Choose the nodes you wish to associate with this identity').resolves([{label: ordererNode.name, data: ordererNode}]);
showQuickPickYesNoStub.withArgs('Do you want to associate the same identity with another node?').resolves(UserInputUtil.YES);

await vscode.commands.executeCommand(ExtensionCommands.ASSOCIATE_IDENTITY_NODE, ...[environmentRegistryEntry, peerNode]);

peerNode.identity = 'identityOne';
Expand All @@ -253,11 +256,36 @@ describe('AssociateIdentityWithNodeCommand', () => {

logSpy.getCall(0).should.have.been.calledWithExactly(LogType.INFO, undefined, 'associate identity with node');
logSpy.getCall(1).should.have.been.calledWithExactly(LogType.SUCCESS, `Successfully associated identity ${peerNode.identity} from wallet ${peerNode.wallet} with node ${peerNode.name}`);
logSpy.getCall(2).should.have.been.calledWithExactly(LogType.SUCCESS, `Successfully associated identity ${ordererNode.identity} from wallet ${ordererNode.wallet} with node ${ordererNode.name}`);
logSpy.getCall(2).should.have.been.calledWithExactly(LogType.SUCCESS, `Successfully associated identities`);
});

it('should associate identity with multiple nodes by allowing user to select multiple nodes using a checkbox', async () => {
showFabricNodeQuickPickStub.withArgs('Choose the nodes you wish to associate with this identity').resolves([{label: ordererNode.name, data: ordererNode}, {label: caNodeWithoutCreds.name, data: caNodeWithoutCreds}]);
showQuickPickYesNoStub.withArgs('Do you want to associate the same identity with another node?').resolves(UserInputUtil.YES);

await vscode.commands.executeCommand(ExtensionCommands.ASSOCIATE_IDENTITY_NODE, ...[environmentRegistryEntry, peerNode]);

peerNode.identity = 'identityOne';
peerNode.wallet = 'blueWallet';
ordererNode.identity = 'identityOne';
ordererNode.wallet = 'blueWallet';
caNodeWithoutCreds.identity = 'identityOne';
caNodeWithoutCreds.wallet = 'blueWallet';
updateStub.should.have.been.calledThrice;
updateStub.firstCall.should.have.been.calledWith(peerNode);
updateStub.secondCall.should.have.been.calledWith(ordererNode);
updateStub.thirdCall.should.have.been.calledWith(caNodeWithoutCreds);

commandsStub.should.have.been.calledWith(ExtensionCommands.CONNECT_TO_ENVIRONMENT, environmentRegistryEntry);

logSpy.getCall(0).should.have.been.calledWithExactly(LogType.INFO, undefined, 'associate identity with node');
logSpy.getCall(1).should.have.been.calledWithExactly(LogType.SUCCESS, `Successfully associated identity ${peerNode.identity} from wallet ${peerNode.wallet} with node ${peerNode.name}`);
logSpy.getCall(2).should.have.been.calledWithExactly(LogType.SUCCESS, `Successfully associated identities`);
});

it('should handle cancel when choosing to asscoiate more identities', async () => {
showQuickPickStub.withArgs('Do you want to associate the same identity with another node?').onFirstCall().resolves();
it('should handle cancel when choosing to associate more identities', async () => {
showQuickPickYesNoStub.withArgs('Do you want to associate the same identity with another node?').onFirstCall().resolves(UserInputUtil.YES);
showFabricNodeQuickPickStub.withArgs('Choose the nodes you wish to associate with this identity').resolves([]);
await vscode.commands.executeCommand(ExtensionCommands.ASSOCIATE_IDENTITY_NODE, ...[environmentRegistryEntry, peerNode]);

peerNode.identity = 'identityOne';
Expand Down

0 comments on commit 997e99c

Please sign in to comment.