Skip to content

Commit

Permalink
[FAB-4187] Clean up unit test of sdk-node
Browse files Browse the repository at this point in the history
Unit test scripts of fabric-sdk-node needs to be cleaned up.
There are some test codes which require to fix as follows:
 - Unused args, variables and methods
 - Duplicated test case
 - inconsistency between test name and test code

This patch fixes the problem above.

Change-Id: I07a3c495cc04f8bbe2e268715b567cfd8dd3c4db
Signed-off-by: Yuki Kondo <yuki.kondo@hal.hitachi.com>
  • Loading branch information
yuki-kon committed May 26, 2017
1 parent b7eb1d4 commit e5f04ef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 55 deletions.
19 changes: 1 addition & 18 deletions test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,23 +679,6 @@ test('\n\n ** Channel sendInstantiateProposal() tests **\n\n', function (t) {
});

c.addPeer(peer);
var p5 = c.sendInstantiateProposal({
targets: [new Peer('grpc://localhost:7051')],
chaincodePath: 'blah',
chaincodeId: 'blah',
chaincodeVersion: 'blah',
fcn: 'init',
args: ['a', '100', 'b', '200']
}).then(function () {
t.fail('Should not have been able to resolve the promise because of missing "txId" parameter');
}).catch(function (err) {
if (err.message.indexOf('Missing "txId" parameter in the proposal request') >= 0) {
t.pass('Successfully caught missing txId error');
} else {
t.fail('Failed to catch the missing txId error. Error: ' + err.stack ? err.stack : err);
}
});

var p7 = c.sendInstantiateProposal().then(function () {
t.fail('Should not have been able to resolve the promise because of missing request parameter');
}).catch(function (err) {
Expand Down Expand Up @@ -1194,4 +1177,4 @@ test('\n\n ** test related APIs for update channel **\n\n', function (t) {
);

t.end();
});
});
38 changes: 1 addition & 37 deletions test/unit/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,6 @@ test('\n\n ** client installChaincode() tests **\n\n', function (t) {
targets: [peer],
chaincodeId: 'blah',
chaincodeVersion: 'blah',
fcn: 'init',
args: ['a', '100', 'b', '200']
}).then(function () {
t.fail('Should not have been able to resolve the promise because of missing "chaincodePath" parameter');
}).catch(function (err) {
Expand All @@ -410,8 +408,6 @@ test('\n\n ** client installChaincode() tests **\n\n', function (t) {
targets: [peer],
chaincodeId: 'blahp1a',
chaincodePath: 'blah',
fcn: 'init',
args: ['a', '100', 'b', '200']
}).then(function () {
t.fail('Should not have been able to resolve the promise because of missing "chaincodeVersion" parameter');
}).catch(function (err) {
Expand Down Expand Up @@ -665,38 +661,6 @@ test('\n\n ** createUser error path - missing required mspid **\n\n', function (
});
});

test('\n\n ** createUser error path - missing required mspid **\n\n', function (t) {
var msg = 'Client.createUser parameter \'opts mspid\' is required.';

var userOrg = 'org1';
var keyStoreOpts = {path: path.join(testutil.getTempDir(), caImport.orgs[userOrg].storePath)};

var client = new Client();

return utils.newKeyValueStore(keyStoreOpts)
.then((store) => {
logger.info('store: %s',store);
client.setStateStore(store);
return '';
}).then(() => {
return client.createUser({username: 'anyone'});
}, (err) => {
logger.error(err.stack ? err.stack : err);
throw new Error('Failed createUser.');
}).then((user) => {
t.fail('Should not have gotten user.');
t.end();
}).catch((err) => {
if (err.message.indexOf(msg) > -1) {
t.pass('Should throw '+msg);
t.end;
} else {
t.fail('Expected error message: '+msg+'\n but got '+err.message);
t.end;
}
});
});

test('\n\n ** createUser error path - missing required cryptoContent **\n\n', function (t) {
var msg = 'Client.createUser parameter \'opts cryptoContent\' is required.';

Expand Down Expand Up @@ -825,7 +789,7 @@ test('\n\n ** createUser error path - missing required cryptoContent signedCert
});
});

test('\n\n ** createUser error path - missing required cryptoContent privateKeyPEM **\n\n', function (t) {
test('\n\n ** createUser error path - missing required cryptoContent privateKey **\n\n', function (t) {
var msg = 'Client.createUser both parameters \'opts cryptoContent privateKey and signedCert\' files are required.';

var userOrg = 'org1';
Expand Down

0 comments on commit e5f04ef

Please sign in to comment.