Skip to content

Commit

Permalink
add tests for disableStats option
Browse files Browse the repository at this point in the history
  • Loading branch information
James Lees committed Feb 10, 2020
1 parent a4b3045 commit 34f4b38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions spec/javascripts/unit/core/pusher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,17 @@ describe("Pusher", function() {

describe("metrics", function() {
var timelineSender;
var pusher;

beforeEach(function() {
jasmine.Clock.useMock();

timelineSender = Mocks.getTimelineSender();
spyOn(Factory, "createTimelineSender").andReturn(timelineSender);

pusher = new Pusher("foo", { enableStats: true });
});

it("should be sent to stats.pusher.com", function() {
var pusher = new Pusher("foo", { enableStats: true });
expect(Factory.createTimelineSender.calls.length).toEqual(1);
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
pusher.timeline, { host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
Expand All @@ -512,13 +511,35 @@ describe("Pusher", function() {
expect(timelineSender.send.calls.length).toEqual(0);
});

it("should be sent if disableStats set to false", function() {
var pusher = new Pusher("foo", { disableStats: false });
pusher.connect();
pusher.connection.options.timeline.info({});
expect(Factory.createTimelineSender.calls.length).toEqual(1);
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
pusher.timeline, { host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
);
});

it("should honour enableStats setting if enableStats and disableStats set", function() {
var pusher = new Pusher("foo", { disableStats: true, enableStats: true });
pusher.connect();
pusher.connection.options.timeline.info({});
expect(Factory.createTimelineSender.calls.length).toEqual(1);
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
pusher.timeline, { host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
);
});

it("should not be sent before calling connect", function() {
var pusher = new Pusher("foo", { enableStats: true });
pusher.connection.options.timeline.info({});
jasmine.Clock.tick(1000000);
expect(timelineSender.send.calls.length).toEqual(0);
});

it("should be sent every 60 seconds after calling connect", function() {
var pusher = new Pusher("foo", { enableStats: true });
pusher.connect();
expect(Factory.createTimelineSender.calls.length).toEqual(1);

Expand All @@ -533,6 +554,7 @@ describe("Pusher", function() {
});

it("should be sent after connecting", function() {
var pusher = new Pusher("foo", { enableStats: true });
pusher.connect();
pusher.connection.options.timeline.info({});

Expand All @@ -543,6 +565,7 @@ describe("Pusher", function() {
});

it("should not be sent after disconnecting", function() {
var pusher = new Pusher("foo", { enableStats: true });
pusher.connect();
pusher.disconnect();

Expand All @@ -553,6 +576,7 @@ describe("Pusher", function() {
});

it("should be sent without TLS if connection is not using TLS", function() {
var pusher = new Pusher("foo", { enableStats: true });
pusher.connection.isUsingTLS.andReturn(false);

pusher.connect();
Expand All @@ -565,6 +589,7 @@ describe("Pusher", function() {
});

it("should be sent with TLS if connection is over TLS", function() {
var pusher = new Pusher("foo", { enableStats: true });
pusher.connection.isUsingTLS.andReturn(true);

pusher.connect();
Expand Down
2 changes: 1 addition & 1 deletion src/core/pusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class Pusher {
}
if ('disableStats' in options) {
Logger.warn(
'The disableStats option is deprecated, stats are now disabled by default'
'The disableStats option is deprecated in favor of enableStats'
);
if (!('enableStats' in options)) {
options.enableStats = !options.disableStats;
Expand Down

0 comments on commit 34f4b38

Please sign in to comment.