mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Merge pull request #517 from darkdarkdragon/develop-RLJS-463
Add schema for RippleAPI constructor options
This commit is contained in:
10
src/api/common/schemas/remote-options.json
Normal file
10
src/api/common/schemas/remote-options.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "remote-options",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"trace": {"type": "boolean"},
|
||||
"servers": {"type": "array", "items": {"type": "string", "format": "uri"}}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -76,5 +76,6 @@ module.exports = {
|
||||
getTransactionOptions: _.partial(validateOptions, 'transaction-options'),
|
||||
getLedgerOptions: _.partial(validateOptions, 'ledger-options'),
|
||||
options: _.partial(validateOptions, 'options'),
|
||||
remoteOptions: _.partial(schemaValidate, 'remote-options'),
|
||||
instructions: _.partial(schemaValidate, 'instructions')
|
||||
};
|
||||
|
||||
@@ -34,6 +34,7 @@ const getLedger = require('./ledger/ledger');
|
||||
const isValidAddress = common.isValidAddress;
|
||||
|
||||
function RippleAPI(options: {}) {
|
||||
common.validate.remoteOptions(options);
|
||||
const _options = _.assign({}, options, {automatic_resubmission: false});
|
||||
this.remote = new common.core.Remote(_options);
|
||||
}
|
||||
|
||||
@@ -831,4 +831,18 @@ describe('RippleAPI - offline', function() {
|
||||
const api = new RippleAPI({servers: ['wss://s1.ripple.com']});
|
||||
});
|
||||
/* eslint-enable no-unused-vars */
|
||||
it('RippleAPI invalid options', function() {
|
||||
assert.throws(() => new RippleAPI({invalid: true}));
|
||||
});
|
||||
|
||||
it('RippleAPI valid options', function() {
|
||||
const api = new RippleAPI({trace: true, servers: ['wss://s:1']});
|
||||
assert(api.remote.trace);
|
||||
assert.deepEqual(api.remote.servers, ['wss://s:1']);
|
||||
});
|
||||
|
||||
it('RippleAPI invalid server uri', function() {
|
||||
assert.throws(() => new RippleAPI({servers: ['wss//s:1']}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user