forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'composer card delete' command (hyperledger-archives#2410)
Signed-off-by: Mark S. Lewis <[email protected]>
- Loading branch information
1 parent
9b2a3c4
commit 3b51118
Showing
5 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Delete = require ('./lib/delete.js'); | ||
|
||
module.exports.command = 'delete [options]'; | ||
module.exports.describe = 'Delete a business network card'; | ||
module.exports.builder = { | ||
name: { alias: 'n', required: true, describe: 'The name of the card to delete', type: 'string' } | ||
}; | ||
|
||
module.exports.handler = (argv) => { | ||
return argv.thePromise = Delete.handler(argv); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const cmdUtil = require('../../utils/cmdutils'); | ||
|
||
/** | ||
* Composer "card delete" command | ||
* @private | ||
*/ | ||
class Delete { | ||
/** | ||
* Command implementation. | ||
* @param {Object} args argument list from composer command | ||
* @return {Promise} promise when command complete | ||
*/ | ||
static handler(args) { | ||
return cmdUtil.createAdminConnection().deleteCard(args.name).then(() => { | ||
console.log('Deleted Business Network Card: ' + args.name); | ||
}); | ||
} | ||
|
||
} | ||
|
||
module.exports = Delete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const AdminConnection = require('composer-admin').AdminConnection; | ||
const CmdUtil = require('../../lib/cmds/utils/cmdutils.js'); | ||
const DeleteCmd = require('../../lib/cmds/card/deleteCommand.js'); | ||
|
||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
|
||
describe('composer card delete CLI', function() { | ||
const sandbox = sinon.sandbox.create(); | ||
let adminConnectionStub; | ||
let consoleLogSpy; | ||
|
||
beforeEach(function() { | ||
adminConnectionStub = sinon.createStubInstance(AdminConnection); | ||
sandbox.stub(CmdUtil, 'createAdminConnection').returns(adminConnectionStub); | ||
consoleLogSpy = sandbox.spy(console, 'log'); | ||
sandbox.stub(process, 'exit'); | ||
}); | ||
|
||
afterEach(function() { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('should delete existing card', function() { | ||
adminConnectionStub.deleteCard.resolves(); | ||
const cardName = 'CARD_NAME'; | ||
const args = { name: cardName }; | ||
return DeleteCmd.handler(args).then(() => { | ||
sinon.assert.calledOnce(adminConnectionStub.deleteCard); | ||
sinon.assert.calledWith(adminConnectionStub.deleteCard, cardName); | ||
sinon.assert.calledWith(consoleLogSpy, sinon.match(cardName)); | ||
}); | ||
}); | ||
|
||
it('should fail deleting non-existent card', function() { | ||
const errorText = 'ERROR_MESSAGE'; | ||
adminConnectionStub.deleteCard.rejects(new Error(errorText)); | ||
const cardName = 'CARD_NAME'; | ||
const args = { name: cardName }; | ||
return DeleteCmd.handler(args).then((result) => { | ||
sinon.assert.fail('Expected command to fail but it succeeded'); | ||
}, (error) => { | ||
sinon.assert.calledOnce(adminConnectionStub.deleteCard); | ||
sinon.assert.calledWith(adminConnectionStub.deleteCard, cardName); | ||
error.toString().should.include(errorText); | ||
}); | ||
}); | ||
|
||
}); |