cover api/common/validate.js with tests

This commit is contained in:
Ivan Tivonenko
2015-07-29 17:15:34 +03:00
parent cecf3f3d22
commit 0977ef0ec2
2 changed files with 53 additions and 32 deletions

View File

@@ -16,9 +16,7 @@ function validateAddressAndSecret(obj) {
throw error('Parameter missing: secret');
}
try {
if (!core.Seed.from_json(secret).get_key(address)) {
throw error('secret does not match address');
}
core.Seed.from_json(secret).get_key(address);
} catch (exception) {
throw error('secret does not match address');
}

View File

@@ -629,7 +629,25 @@ describe('RippleAPI', function() {
});
it('validator', function() {
describe('validator', function() {
it('validateLedgerRange', function() {
const options = {
minLedgerVersion: 20000,
maxLedgerVersion: 10000
};
assert.throws(_.partial(validate.getTransactionsOptions, options),
this.api.errors.ValidationError);
assert.throws(_.partial(validate.getTransactionsOptions, options),
/minLedgerVersion must not be greater than maxLedgerVersion/);
});
it('addressAndSecret', function() {
const wrongSecret = {address: address,
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
};
assert.throws(_.partial(validate.addressAndSecret, wrongSecret),
this.api.errors.ValidationError);
const noSecret = {address: address};
assert.throws(_.partial(validate.addressAndSecret, noSecret),
this.api.errors.ValidationError);
@@ -644,6 +662,9 @@ describe('RippleAPI', function() {
secret: 'shzjfakiK79YQdMjy4h8cGGfQSV6u'
};
assert.doesNotThrow(_.partial(validate.addressAndSecret, goodWallet));
});
it('secret', function() {
assert.doesNotThrow(_.partial(validate.secret,
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
assert.throws(_.partial(validate.secret, 1),
@@ -661,3 +682,5 @@ describe('RippleAPI', function() {
});
});
});