Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Aug 8, 2017
1 parent 3841602 commit 86f376e
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions test/unit/transit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const FakeTransporter = require("../../src/transporters/fake");
const { ValidationError } = require("../../src/errors");
const P = require("../../src/packets");
//const lolex = require("lolex");
const _ = require("lodash");

describe("Test Transporter constructor", () => {

Expand Down Expand Up @@ -624,6 +625,7 @@ describe("Test Transit node & heartbeat handling", () => {
const broker = new ServiceBroker({ nodeID: "node1", transporter: new FakeTransporter(), internalActions: false });
const transit = broker.transit;
broker.registerRemoteService = jest.fn();
broker.unregisterServicesByNode = jest.fn();
broker.emitLocal = jest.fn();

let remoteService = {
Expand Down Expand Up @@ -654,7 +656,7 @@ describe("Test Transit node & heartbeat handling", () => {
expect(broker.registerRemoteService).toHaveBeenCalledWith("server-1", remoteService);
});

it("should not emit event because node is exist but register remote actions again", () => {
it("should emit a node.info event because node is exist but not register remote actions again", () => {
broker.emitLocal.mockClear();
broker.registerRemoteService.mockClear();

Expand All @@ -664,10 +666,33 @@ describe("Test Transit node & heartbeat handling", () => {

expect(node.id).toBe("server-1");

expect(broker.emitLocal).toHaveBeenCalledTimes(0);
expect(broker.emitLocal).toHaveBeenCalledTimes(1);
expect(broker.emitLocal).toHaveBeenCalledWith("node.info", { node });

expect(broker.registerRemoteService).toHaveBeenCalledTimes(0);
});

it("should emit a node.info event because node is exist but not register remote actions again", () => {
broker.emitLocal.mockClear();
broker.registerRemoteService.mockClear();
broker.unregisterServicesByNode.mockClear();

let newNodeInfo = _.cloneDeep(nodeInfo);
newNodeInfo.services[0].version = 2;
transit.processNodeInfo("server-1", newNodeInfo);

let node = transit.nodes.get("server-1");

expect(node.id).toBe("server-1");

expect(broker.emitLocal).toHaveBeenCalledTimes(1);
expect(broker.emitLocal).toHaveBeenCalledWith("node.info", { node });

expect(broker.unregisterServicesByNode).toHaveBeenCalledTimes(1);
expect(broker.unregisterServicesByNode).toHaveBeenCalledWith("server-1");

expect(broker.registerRemoteService).toHaveBeenCalledTimes(1);
expect(broker.registerRemoteService).toHaveBeenCalledWith("server-1", remoteService);
expect(broker.registerRemoteService).toHaveBeenCalledWith("server-1", newNodeInfo.services[0]);
});

it("should not process info if nodeID is null", () => {
Expand Down

0 comments on commit 86f376e

Please sign in to comment.