From 6b2fef466c4da8bbe6f0b0557bf5944736522646 Mon Sep 17 00:00:00 2001 From: Dmytro Nechai Date: Tue, 30 May 2017 19:04:57 +0300 Subject: [PATCH] test: migrate event and remote-proxy tests Refs: https://github.com/metarhia/jstp/issues/145 Refs: https://github.com/metarhia/jstp/issues/146 Refs: https://github.com/metarhia/jstp/issues/53 PR-URL: https://github.com/metarhia/jstp/pull/199 Reviewed-By: Denys Otrishko Reviewed-By: Mykola Bilochub Reviewed-By: Alexey Orlenko --- test/unit/connection.test.js | 47 ---------------------------------- test/unit/remote-proxy.test.js | 22 ---------------- 2 files changed, 69 deletions(-) diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index b60a2ba..ec112e9 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -135,53 +135,6 @@ describe('JSTP Connection', () => { }); }); - describe('event', () => { - testPacketSending('event', (connection, transport) => { - const eventArgs = [ 'value' ]; - - const sendSpy = chai.spy((data) => { - const packet = jstp.parse(data); - expect(packet).to.have.all.keys(['event', constants.TEST_EVENT]); - - expect(packet.event).to.be.an('array'); - expect(packet.event[0]).to.be.a('number'); - expect(packet.event[1]).to.equal(constants.TEST_INTERFACE); - - expect(packet[constants.TEST_EVENT]).to.eql(eventArgs); - }); - - transport.on('dataSent', sendSpy); - - connection.emitRemoteEvent(constants.TEST_INTERFACE, - constants.TEST_EVENT, eventArgs); - - expect(sendSpy).to.have.been.called(); - }); - - it('must process event packets', () => { - const payload = { key: 'value' }; - - const event = { - event: [-1, constants.TEST_INTERFACE] - }; - - event[constants.TEST_EVENT] = payload; - - const handler = chai.spy((eventArgs) => { - expect(eventArgs.interfaceName).to.equal(constants.TEST_INTERFACE); - expect(eventArgs.remoteEventName).to.equal(constants.TEST_EVENT); - expect(eventArgs.remoteEventArgs).to.eql(payload); - }); - - clientConnection.on('event', handler); - - performHandshakeFromClient(() => { - clientTransportMock.emitPacket(event); - expect(handler).to.be.called(); - }); - }); - }); - describe('state', () => { testPacketSending('state', (connection, transport) => { const sendSpy = chai.spy((data) => { diff --git a/test/unit/remote-proxy.test.js b/test/unit/remote-proxy.test.js index 1c821f6..5741f63 100644 --- a/test/unit/remote-proxy.test.js +++ b/test/unit/remote-proxy.test.js @@ -60,26 +60,4 @@ describe('RemoteProxy', () => { expect(callback2).to.have.been.called.exactly(1); expect(callback2).to.have.been.called.with('result2'); }); - - it('must emit events through the network and locally', () => { - const handler = chai.spy(); - proxy.on('testEvent', handler); - proxy.emit('testEvent', 'payload1', 'payload2'); - - expect(eventSpy).to.have.been.called.exactly(1); - expect(eventSpy).to.have.been.called.with( - 'testInterface', 'testEvent', ['payload1', 'payload2']); - - expect(handler).to.have.been.called.exactly(1); - expect(handler).to.have.been.called.with('payload1', 'payload2'); - }); - - it('must not re-emit events back', () => { - const handler = chai.spy(); - proxy.on('testEvent', handler); - connectionMock.processEventPacket(); - - expect(handler).to.have.been.called.with('payload1', 'payload2'); - expect(eventSpy).to.not.have.been.called(); - }); });