summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-05-28 22:02:27 +0200
committerErik Larkö <erik@mullvad.net>2017-05-28 22:02:27 +0200
commitfdb86c8ab71493cd10d176505653bb411a6921e2 (patch)
tree7ffc0c8554790f03794f29d8c78aa16d7a7f0819
parent6daf4bb8d27251a298558f1823d5d198d7c0538e (diff)
parent51af2702156304fcad1f18a37710686a0267797d (diff)
downloadmullvadvpn-fdb86c8ab71493cd10d176505653bb411a6921e2.tar.xz
mullvadvpn-fdb86c8ab71493cd10d176505653bb411a6921e2.zip
Merge branch 'ipc-notifications-test'
-rw-r--r--app/lib/jsonrpc-ws-ipc.js4
-rw-r--r--test/ipc.spec.js20
2 files changed, 22 insertions, 2 deletions
diff --git a/app/lib/jsonrpc-ws-ipc.js b/app/lib/jsonrpc-ws-ipc.js
index f3850c430c..3d028c5a23 100644
--- a/app/lib/jsonrpc-ws-ipc.js
+++ b/app/lib/jsonrpc-ws-ipc.js
@@ -74,14 +74,14 @@ export default class Ipc {
this._sendTimeoutMillis = millis;
}
- on(event: string, listener: (any) => void) {
+ on(event: string, listener: (any) => void): Promise<*> {
// We're currently not actually using the event parameter.
// This is because we aren't sure if the backend will use
// one subscription per event or one subscription per
// event source.
log.info('Adding a listener to', event);
- this.send('event_subscribe')
+ return this.send('event_subscribe')
.then(subscriptionId => this._subscriptions[subscriptionId] = listener);
}
diff --git a/test/ipc.spec.js b/test/ipc.spec.js
index 43a17b4911..ae9c5ab815 100644
--- a/test/ipc.spec.js
+++ b/test/ipc.spec.js
@@ -69,6 +69,26 @@ describe('The IPC server', () => {
expect(e.message).to.contain('timed out');
});
});
+
+ it('should route notifications', (done) => {
+ const { ws, ipc } = setupIpc();
+
+ const eventListener = (event) => {
+ try {
+ expect(event).to.equal('an event!');
+ done();
+ } catch (ex) {
+ done(ex);
+ }
+ };
+
+ ws.on('event_subscribe', (msg) => ws.replyOk(msg.id, 1));
+ ipc.on('event', eventListener)
+ .then(() => {
+ ws.reply(jsonrpc.notification('event', {subscription:1, result: 'an event!'}));
+ })
+ .catch((e) => done(e));
+ });
});
function mockWebsocket() {