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.isValidResponse.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.isValidResponse.js')
-rw-r--r-- | test/jsonrpc.isValidResponse.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/test/jsonrpc.isValidResponse.js b/test/jsonrpc.isValidResponse.js new file mode 100644 index 000000000..2fe200496 --- /dev/null +++ b/test/jsonrpc.isValidResponse.js @@ -0,0 +1,128 @@ +var assert = require('assert'); +var jsonrpc = require('../lib/jsonrpc'); + +describe('jsonrpc', function () { + describe('isValidResponse', function () { + it('should validate basic jsonrpc response', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1, + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, true); + }); + + it('should validate basic undefined response', function () { + + // given + var response = undefined; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response without jsonrpc field', function () { + + // given + var response = { + id: 1, + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response with wrong jsonrpc version', function () { + + // given + var response = { + jsonrpc: '1.0', + id: 1, + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response without id number', function () { + + // given + var response = { + jsonrpc: '2.0', + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response with wrong id field', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 'x', + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response without result field', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1 + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response with result field === false', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1, + result: false + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, true); + }); + + }); +}); |