Skip to content

Commit

Permalink
convert single role argument to array for card create command (hyperl…
Browse files Browse the repository at this point in the history
…edger-archives#2680)

* convert single role arg to array
* remove commented out code

Signed-off-by: andrew-coleman <[email protected]>
  • Loading branch information
andrew-coleman authored and bestbeforetoday committed Nov 10, 2017
1 parent f097553 commit d483284
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/composer-cli/lib/cmds/card/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class Create {
userName : argv.user };

if (argv.role){
metadata.roles = argv.role;
if(Array.isArray(argv.role)) {
metadata.roles = argv.role;
} else {
metadata.roles = [argv.role];
}
}

if (argv.enrollSecret){
Expand Down
31 changes: 30 additions & 1 deletion packages/composer-cli/test/card/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,34 @@ describe('composer card create CLI', function() {
readFileStub.withArgs(sinon.match(/certfile/)).returns('I am certificate');
readFileStub.withArgs(sinon.match(/keyfile/)).returns('I am keyfile');
sandbox.stub(JSON, 'parse').returns({name:'network'});
const exportSpy = sandbox.spy(Export, 'writeCardToFile');
const args = {
connectionProfileFile: 'filename',
role : ['PeerAdmin', 'Issuer', 'ChannelAdmin'],
user:'fred'
};

return CreateCmd.handler(args).then(() => {
sinon.assert.calledOnce(fs.readFileSync);
sinon.assert.calledWith(fs.readFileSync,sinon.match(/filename/));
sinon.assert.calledOnce(fs.writeFileSync);
sinon.assert.calledWith(consoleLogSpy, sinon.match(/Successfully created business network card/));
sinon.assert.calledWith(exportSpy, sinon.match.string, sinon.match((card) => {
return card.getRoles().length === 3;
}, 'Incorrect roles'));
});
});

it('create card with single role',()=>{
sandbox.stub(fs, 'writeFileSync');
let readFileStub = sandbox.stub(fs, 'readFileSync');
readFileStub.withArgs(sinon.match(/certfile/)).returns('I am certificate');
readFileStub.withArgs(sinon.match(/keyfile/)).returns('I am keyfile');
sandbox.stub(JSON, 'parse').returns({name:'network'});
const exportSpy = sandbox.spy(Export, 'writeCardToFile');
const args = {
connectionProfileFile: 'filename',
roles : 'PeerAdmin,Issuer,ChannelAdmin',
role : 'PeerAdmin',
user:'fred'
};

Expand All @@ -149,6 +174,10 @@ describe('composer card create CLI', function() {
sinon.assert.calledWith(fs.readFileSync,sinon.match(/filename/));
sinon.assert.calledOnce(fs.writeFileSync);
sinon.assert.calledWith(consoleLogSpy, sinon.match(/Successfully created business network card/));
sinon.assert.calledWith(exportSpy, sinon.match.string, sinon.match((card) => {
const roles = card.getRoles();
return Array.isArray(roles) && roles[0] === 'PeerAdmin';
}, 'Incorrect roles'));
});
});

Expand Down

0 comments on commit d483284

Please sign in to comment.