aboutsummaryrefslogtreecommitdiffstats
path: root/test/jsonrpc.toPayload.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-02-04 06:00:02 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-02-04 06:00:02 +0800
commite58e2f5ee466f054405b3e90a67720254ea17ead (patch)
tree292927f3c2b7ac548376b0d42aa5e6ac67ec85c0 /test/jsonrpc.toPayload.js
parent45134de7401b58f0118deb16bf0644495715fbdb (diff)
downloaddexon-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.toPayload.js')
-rw-r--r--test/jsonrpc.toPayload.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/jsonrpc.toPayload.js b/test/jsonrpc.toPayload.js
new file mode 100644
index 000000000..6d6f003bb
--- /dev/null
+++ b/test/jsonrpc.toPayload.js
@@ -0,0 +1,40 @@
+var assert = require('assert');
+var jsonrpc = require('../lib/jsonrpc');
+
+describe('jsonrpc', function () {
+ describe('toPayload', function () {
+ it('should create basic payload', function () {
+
+ // given
+ var method = 'helloworld';
+
+ // when
+ var payload = jsonrpc.toPayload(method);
+
+ // then
+ assert.equal(payload.jsonrpc, '2.0');
+ assert.equal(payload.method, method);
+ assert.equal(payload.params instanceof Array, true);
+ assert.equal(payload.params.length, 0);
+ assert.equal(typeof payload.id, 'number');
+ });
+
+ it('should create payload with params', function () {
+
+ // given
+ var method = 'helloworld1';
+ var params = [123, 'test'];
+
+ // when
+ var payload = jsonrpc.toPayload(method, params);
+
+ // then
+ assert.equal(payload.jsonrpc, '2.0');
+ assert.equal(payload.method, method);
+ assert.equal(payload.params.length, 2);
+ assert.equal(payload.params[0], params[0]);
+ assert.equal(payload.params[1], params[1]);
+ assert.equal(typeof payload.id, 'number');
+ });
+ });
+});