From 675814f1b1dbc4243da7e48e3c4a96e42cd9ff3d Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Wed, 13 Dec 2017 10:28:35 +0000 Subject: [PATCH] Handle the case where the user has only a last_name set --- .../app/coffee/WebsocketController.coffee | 8 ++-- .../coffee/WebsocketControllerTests.coffee | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/services/real-time/app/coffee/WebsocketController.coffee b/services/real-time/app/coffee/WebsocketController.coffee index 885524e3f2..e0614eb153 100644 --- a/services/real-time/app/coffee/WebsocketController.coffee +++ b/services/real-time/app/coffee/WebsocketController.coffee @@ -146,10 +146,12 @@ module.exports = WebsocketController = cursorData.user_id = user_id if user_id? cursorData.email = email if email? if first_name? or last_name? - cursorData.name = if !last_name? - first_name - else + cursorData.name = if first_name && last_name "#{first_name} #{last_name}" + else if first_name + first_name + else if last_name + last_name ConnectedUsersManager.updateUserPosition(project_id, client.id, { first_name: first_name, last_name: last_name, diff --git a/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee b/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee index 5427b9cd10..b6a4069c67 100644 --- a/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee +++ b/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee @@ -470,6 +470,47 @@ describe 'WebsocketController', -> it "should increment the update-client-position metric at 0.1 frequency", -> @metrics.inc.calledWith("editor.update-client-position", 0.1).should.equal true + describe "with a logged in user who has no first_name set", -> + beforeEach -> + @clientParams = { + project_id: @project_id + first_name: undefined + last_name: @last_name = "Adams" + email: @email = "joe@example.com" + user_id: @user_id = "user-id-123" + } + @client.get = (param, callback) => callback null, @clientParams[param] + @WebsocketController.updateClientPosition @client, @update + + @populatedCursorData = + doc_id: @doc_id, + id: @client.id + name: "#{@last_name}" + row: @row + column: @column + email: @email + user_id: @user_id + + it "should send the update to the project room with the user's name", -> + @WebsocketLoadBalancer.emitToRoom.calledWith(@project_id, "clientTracking.clientUpdated", @populatedCursorData).should.equal true + + it "should send the cursor data to the connected user manager", (done)-> + @ConnectedUsersManager.updateUserPosition.calledWith(@project_id, @client.id, { + _id: @user_id, + email: @email, + first_name: undefined, + last_name: @last_name + }, { + row: @row + column: @column + doc_id: @doc_id + }).should.equal true + done() + + it "should increment the update-client-position metric at 0.1 frequency", -> + @metrics.inc.calledWith("editor.update-client-position", 0.1).should.equal true + + describe "with an anonymous user", -> beforeEach -> @clientParams = {