Skip to content

Commit

Permalink
Change unit tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
MeenaAlfons committed Aug 11, 2022
1 parent 1eaa87b commit 23410ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Errors = require('core/errors');
var Factory = require('core/utils/factory').default;
var Mocks = require("mocks");
var flatPromise = require("core/utils/flat_promise").default;
var { setTimeout } = require("timers/promises").default;
var { setTimeout } = require("../../../helpers/timers/promises").default;

describe("PresenceChannel", function() {
var pusher;
Expand Down
12 changes: 6 additions & 6 deletions spec/javascripts/unit/core/user_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("Pusher (User)", function () {
});

pusher.connection.state = "connected";
pusher.connection.emit('connected');
pusher.connection.emit('state_change', {previous:'connecting', current:'connected'});

expect(pusher.config.userAuthenticator).toHaveBeenCalledWith(
{ socketId: "1.23" },
Expand Down Expand Up @@ -116,11 +116,11 @@ describe("Pusher (User)", function () {
pusher.config.userAuthenticator.calls.reset()

pusher.connection.state == "disconnected";
pusher.connection.emit("disconnected");
pusher.connection.emit('state_change', {previous:'connected', current:'disconnected'});
pusher.connection.state == "connecting";
pusher.connection.emit("connecting");
pusher.connection.emit('state_change', {previous:'disconnected', current:'connecting'});
pusher.connection.state == "connected";
pusher.connection.emit("connected");
pusher.connection.emit('state_change', {previous:'connecting', current:'connected'});

expect(pusher.config.userAuthenticator).toHaveBeenCalledWith(
{ socketId: "1.23" },
Expand All @@ -134,7 +134,7 @@ describe("Pusher (User)", function () {

it("should not signin when the connection is connected if signin() was never called", function () {
pusher.connection.state = "connected";
pusher.connection.emit('connected');
pusher.connection.emit('state_change', {previous:'connecting', current:'connected'});
expect(pusher.config.userAuthenticator).not.toHaveBeenCalled();
})

Expand Down Expand Up @@ -292,7 +292,7 @@ describe("Pusher (User)", function () {
expect(pusher.user.serverToUserChannel.subscribed).toBe(true);

// Disconnect
pusher.connection.emit('disconnected');
pusher.connection.emit('state_change', {previous:'connected', current:'disconnected'});

expect(pusher.user.user_data).toEqual(null);
expect(pusher.user.serverToUserChannel).toEqual(null);
Expand Down
6 changes: 3 additions & 3 deletions src/core/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default class UserFacade extends EventsDispatcher {
Logger.debug('No callbacks on user for ' + eventName);
});
this.pusher = pusher;
this.pusher.connection.bind('state_change', ({previous, current}) => {
if (previous !=='connected' && current === 'connected') {
this.pusher.connection.bind('state_change', ({ previous, current }) => {
if (previous !== 'connected' && current === 'connected') {
this._signin();
}
if (previous ==='connected' && current !== 'connected') {
if (previous === 'connected' && current !== 'connected') {
this._cleanup();
this._newSigninPromiseIfNeeded();
}
Expand Down

0 comments on commit 23410ae

Please sign in to comment.