diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-02-04 06:00:02 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-02-04 06:00:02 +0800 |
commit | e58e2f5ee466f054405b3e90a67720254ea17ead (patch) | |
tree | 292927f3c2b7ac548376b0d42aa5e6ac67ec85c0 /test/jsonrpc.toBatchPayload.js | |
parent | 45134de7401b58f0118deb16bf0644495715fbdb (diff) | |
download | dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.tar dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.tar.gz dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.tar.bz2 dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.tar.lz dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.tar.xz dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.tar.zst dexon-e58e2f5ee466f054405b3e90a67720254ea17ead.zip |
jsonrpc.js tests && jsonrpc response validation is more strict
Diffstat (limited to 'test/jsonrpc.toBatchPayload.js')
-rw-r--r-- | test/jsonrpc.toBatchPayload.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/jsonrpc.toBatchPayload.js b/test/jsonrpc.toBatchPayload.js new file mode 100644 index 000000000..1c1aafebb --- /dev/null +++ b/test/jsonrpc.toBatchPayload.js @@ -0,0 +1,47 @@ +var assert = require('assert'); +var jsonrpc = require('../lib/jsonrpc'); + +describe('jsonrpc', function () { + describe('toBatchPayload', function () { + it('should create basic batch payload', function () { + + // given + var messages = [{ + method: 'helloworld' + }, { + method: 'test2', + params: [1] + }]; + + // when + var payload = jsonrpc.toBatchPayload(messages); + + // then + assert.equal(payload instanceof Array, true); + assert.equal(payload.length, 2); + assert.equal(payload[0].jsonrpc, '2.0'); + assert.equal(payload[1].jsonrpc, '2.0'); + assert.equal(payload[0].method, 'helloworld'); + assert.equal(payload[1].method, 'test2'); + assert.equal(payload[0].params instanceof Array, true); + assert.equal(payload[1].params.length, 1); + assert.equal(payload[1].params[0], 1); + assert.equal(typeof payload[0].id, 'number'); + assert.equal(typeof payload[1].id, 'number'); + assert.equal(payload[0].id + 1, payload[1].id); + }); + + it('should create batch payload for empty input array', function () { + + // given + var messages = []; + + // when + var payload = jsonrpc.toBatchPayload(messages); + + // then + assert.equal(payload instanceof Array, true); + assert.equal(payload.length, 0); + }); + }); +}); |