[misc] WebsocketControllerTests: always pass cb to updateClientPosition

...and fix the inconsistent async behaviour for logged-in vs anonymous
 users in the app.
This commit is contained in:
Jakob Ackermann 2020-06-29 18:11:33 +01:00
parent 4d01c02946
commit a77222470b
2 changed files with 44 additions and 22 deletions

View file

@ -380,7 +380,8 @@ module.exports = WebsocketController = {
// Don't store anonymous users in redis to avoid influx
if (!user_id || user_id === 'anonymous-user') {
cursorData.name = ''
callback()
// consistent async behaviour
setTimeout(callback)
} else {
cursorData.name =
first_name && last_name

View file

@ -78,7 +78,9 @@ describe('WebsocketController', function () {
}
}
this.privilegeLevel = 'owner'
this.ConnectedUsersManager.updateUserPosition = sinon.stub().callsArg(4)
this.ConnectedUsersManager.updateUserPosition = sinon
.stub()
.callsArgAsync(4)
this.isRestrictedUser = true
this.WebApiManager.joinProject = sinon
.stub()
@ -213,7 +215,9 @@ describe('WebsocketController', function () {
}
}
this.privilegeLevel = 'owner'
this.ConnectedUsersManager.updateUserPosition = sinon.stub().callsArg(4)
this.ConnectedUsersManager.updateUserPosition = sinon
.stub()
.callsArgAsync(4)
this.isRestrictedUser = true
this.WebApiManager.joinProject = sinon
.stub()
@ -964,7 +968,7 @@ describe('WebsocketController', function () {
this.WebsocketLoadBalancer.emitToRoom = sinon.stub()
this.ConnectedUsersManager.updateUserPosition = sinon
.stub()
.callsArgWith(4)
.callsArgAsync(4)
this.AuthorizationManager.assertClientCanViewProjectAndDoc = sinon
.stub()
.callsArgWith(2, null)
@ -976,7 +980,7 @@ describe('WebsocketController', function () {
})
describe('with a logged in user', function () {
beforeEach(function () {
beforeEach(function (done) {
this.client.ol_context = {
project_id: this.project_id,
first_name: (this.first_name = 'Douglas'),
@ -984,9 +988,8 @@ describe('WebsocketController', function () {
email: (this.email = 'joe@example.com'),
user_id: (this.user_id = 'user-id-123')
}
this.WebsocketController.updateClientPosition(this.client, this.update)
return (this.populatedCursorData = {
this.populatedCursorData = {
doc_id: this.doc_id,
id: this.client.publicId,
name: `${this.first_name} ${this.last_name}`,
@ -994,7 +997,12 @@ describe('WebsocketController', function () {
column: this.column,
email: this.email,
user_id: this.user_id
})
}
this.WebsocketController.updateClientPosition(
this.client,
this.update,
done
)
})
it("should send the update to the project room with the user's name", function () {
@ -1036,7 +1044,7 @@ describe('WebsocketController', function () {
})
describe('with a logged in user who has no last_name set', function () {
beforeEach(function () {
beforeEach(function (done) {
this.client.ol_context = {
project_id: this.project_id,
first_name: (this.first_name = 'Douglas'),
@ -1044,9 +1052,8 @@ describe('WebsocketController', function () {
email: (this.email = 'joe@example.com'),
user_id: (this.user_id = 'user-id-123')
}
this.WebsocketController.updateClientPosition(this.client, this.update)
return (this.populatedCursorData = {
this.populatedCursorData = {
doc_id: this.doc_id,
id: this.client.publicId,
name: `${this.first_name}`,
@ -1054,7 +1061,12 @@ describe('WebsocketController', function () {
column: this.column,
email: this.email,
user_id: this.user_id
})
}
this.WebsocketController.updateClientPosition(
this.client,
this.update,
done
)
})
it("should send the update to the project room with the user's name", function () {
@ -1096,7 +1108,7 @@ describe('WebsocketController', function () {
})
describe('with a logged in user who has no first_name set', function () {
beforeEach(function () {
beforeEach(function (done) {
this.client.ol_context = {
project_id: this.project_id,
first_name: undefined,
@ -1104,9 +1116,8 @@ describe('WebsocketController', function () {
email: (this.email = 'joe@example.com'),
user_id: (this.user_id = 'user-id-123')
}
this.WebsocketController.updateClientPosition(this.client, this.update)
return (this.populatedCursorData = {
this.populatedCursorData = {
doc_id: this.doc_id,
id: this.client.publicId,
name: `${this.last_name}`,
@ -1114,7 +1125,12 @@ describe('WebsocketController', function () {
column: this.column,
email: this.email,
user_id: this.user_id
})
}
this.WebsocketController.updateClientPosition(
this.client,
this.update,
done
)
})
it("should send the update to the project room with the user's name", function () {
@ -1155,7 +1171,7 @@ describe('WebsocketController', function () {
})
})
describe('with a logged in user who has no names set', function () {
beforeEach(function () {
beforeEach(function (done) {
this.client.ol_context = {
project_id: this.project_id,
first_name: undefined,
@ -1165,7 +1181,8 @@ describe('WebsocketController', function () {
}
return this.WebsocketController.updateClientPosition(
this.client,
this.update
this.update,
done
)
})
@ -1185,13 +1202,14 @@ describe('WebsocketController', function () {
})
describe('with an anonymous user', function () {
beforeEach(function () {
beforeEach(function (done) {
this.client.ol_context = {
project_id: this.project_id
}
return this.WebsocketController.updateClientPosition(
this.client,
this.update
this.update,
done
)
})
@ -1214,13 +1232,16 @@ describe('WebsocketController', function () {
})
return describe('when the client has disconnected', function () {
beforeEach(function () {
beforeEach(function (done) {
this.client.disconnected = true
this.AuthorizationManager.assertClientCanViewProjectAndDoc = sinon.stub()
return this.WebsocketController.updateClientPosition(
this.client,
this.update,
this.callback
(...args) => {
this.callback(...args)
done(args[0])
}
)
})