summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-05-28 00:42:05 +0200
committerErik Larkö <erik@mullvad.net>2017-05-28 17:15:08 +0200
commit7daa29b0b7d6fca52515bcbe9b43be5e6b63279d (patch)
tree21bd9b9bc28aa62f32024c321395700d78435c73 /test
parenta99e3585e0f06657d0813ec65d8bab7423379d2d (diff)
downloadmullvadvpn-7daa29b0b7d6fca52515bcbe9b43be5e6b63279d.tar.xz
mullvadvpn-7daa29b0b7d6fca52515bcbe9b43be5e6b63279d.zip
JSONRPC communication tests
Diffstat (limited to 'test')
-rw-r--r--test/ipc.spec.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ipc.spec.js b/test/ipc.spec.js
index afac3ad704..07421ce839 100644
--- a/test/ipc.spec.js
+++ b/test/ipc.spec.js
@@ -3,6 +3,7 @@
import Ipc from '../app/lib/jsonrpc-ws-ipc.js';
import jsonrpc from 'jsonrpc-lite';
import { expect } from 'chai';
+import assert from 'assert';
import type { JsonRpcMessage } from '../app/lib/jsonrpc-ws-ipc.js';
describe('The IPC server', () => {
@@ -26,6 +27,37 @@ describe('The IPC server', () => {
return p;
});
+
+ it('should reject failed jsonrpc requests', () => {
+ const { ws, ipc } = setupIpc();
+ ws.on('WHAT_IS_THIS', (msg) => {
+ ws.replyFail(msg.id, 'Method not found', -32601);
+ });
+
+ return ipc.send('WHAT_IS_THIS')
+ .catch((e) => {
+ expect(e.code).to.equal(-32601);
+ expect(e.message).to.contain('Method not found');
+ });
+ });
+
+ it('should route reply to correct promise', () => {
+ const { ws, ipc } = setupIpc();
+
+ ws.on('a message', (msg) => ws.replyOk(msg.id, 'a reply'));
+
+ const decoy = ipc.send('a decoy')
+ .then(() => assert(false, 'Should not be called'))
+ .catch(e => {
+ if (e.name !== 'TimeOutError') {
+ throw e;
+ }
+ });
+ const message = ipc.send('a message')
+ .then((reply) => expect(reply).to.equal('a reply'));
+
+ return Promise.all([message, decoy]);
+ });
});
function mockWebsocket() {