From 4d01c02946c9f8372b822af54c53bef29f084fa6 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 29 Jun 2020 17:15:29 +0100 Subject: [PATCH] [misc] WebsocketControllerTests: explicitly pass a cb to leaveProject ...and fix the stubbing of `io.sockets.clients`. We were running the assertions prior to the actual completion of the leaveProject. Which in turn shadowed the broken test setup -- `io.sockets.clients()` was returning the `this.clientsInRoom=[]` from a previous context. --- .../test/unit/js/WebsocketControllerTests.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/services/real-time/test/unit/js/WebsocketControllerTests.js b/services/real-time/test/unit/js/WebsocketControllerTests.js index 8d8a39bb74..3cf4100951 100644 --- a/services/real-time/test/unit/js/WebsocketControllerTests.js +++ b/services/real-time/test/unit/js/WebsocketControllerTests.js @@ -42,6 +42,7 @@ describe('WebsocketController', function () { leave: sinon.stub() } return (this.WebsocketController = SandboxedModule.require(modulePath, { + globals: { console }, requires: { './WebApiManager': (this.WebApiManager = {}), './AuthorizationManager': (this.AuthorizationManager = {}), @@ -393,9 +394,19 @@ describe('WebsocketController', function () { }) describe('when the project is not empty', function () { - beforeEach(function () { + beforeEach(function (done) { this.clientsInRoom = ['mock-remaining-client'] - return this.WebsocketController.leaveProject(this.io, this.client) + this.io = { + sockets: { + clients: (room_id) => { + if (room_id !== this.project_id) { + throw 'expected room_id to be project_id' + } + return this.clientsInRoom + } + } + } + return this.WebsocketController.leaveProject(this.io, this.client, done) }) return it('should not flush the project in the document updater', function () {