Skip to content

Commit

Permalink
test: migrate event and remote-proxy tests
Browse files Browse the repository at this point in the history
Refs: metarhia/jstp#145
Refs: metarhia/jstp#146
Refs: metarhia/jstp#53
PR-URL: metarhia/jstp#199
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
  • Loading branch information
nechaido committed Jun 2, 2017
1 parent 501286d commit 6b2fef4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 69 deletions.
47 changes: 0 additions & 47 deletions test/unit/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
22 changes: 0 additions & 22 deletions test/unit/remote-proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 6b2fef4

Please sign in to comment.