From cb12e1c6f6574b0c1f6558fef7385e7ac7f6dfe0 Mon Sep 17 00:00:00 2001 From: Chrystal Griffiths Date: Fri, 8 Feb 2019 15:39:51 +0000 Subject: [PATCH] Send an empty string for every nameless user --- .../app/coffee/WebsocketController.coffee | 36 +++++++++---------- .../coffee/WebsocketControllerTests.coffee | 34 ++++++++++++++---- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/services/real-time/app/coffee/WebsocketController.coffee b/services/real-time/app/coffee/WebsocketController.coffee index b51e86c495..734dfc3005 100644 --- a/services/real-time/app/coffee/WebsocketController.coffee +++ b/services/real-time/app/coffee/WebsocketController.coffee @@ -145,26 +145,24 @@ module.exports = WebsocketController = cursorData.id = client.id cursorData.user_id = user_id if user_id? cursorData.email = email if email? - if first_name or last_name - 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, - email: email, - _id: user_id - }, { - row: cursorData.row, - column: cursorData.column, - doc_id: cursorData.doc_id - }, callback) + cursorData.name = if first_name && last_name + "#{first_name} #{last_name}" + else if first_name + first_name + else if last_name + last_name else - cursorData.name = "Anonymous" - callback() + "" + ConnectedUsersManager.updateUserPosition(project_id, client.id, { + first_name: first_name, + last_name: last_name, + email: email, + _id: user_id + }, { + row: cursorData.row, + column: cursorData.column, + doc_id: cursorData.doc_id + }, callback) WebsocketLoadBalancer.emitToRoom(project_id, "clientTracking.clientUpdated", cursorData) getConnectedUsers: (client, callback = (error, users) ->) -> diff --git a/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee b/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee index b6a4069c67..0a0bd50843 100644 --- a/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee +++ b/services/real-time/test/unit/coffee/WebsocketControllerTests.coffee @@ -426,7 +426,7 @@ describe 'WebsocketController', -> 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 @@ -509,6 +509,30 @@ 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 names set", -> + beforeEach -> + @clientParams = { + project_id: @project_id + first_name: undefined + last_name: undefined + email: @email = "joe@example.com" + user_id: @user_id = "user-id-123" + } + @client.get = (param, callback) => callback null, @clientParams[param] + @WebsocketController.updateClientPosition @client, @update + + it "should send the update to the project name with no name", -> + @WebsocketLoadBalancer.emitToRoom + .calledWith(@project_id, "clientTracking.clientUpdated", { + doc_id: @doc_id, + id: @client.id, + user_id: @user_id, + name: "", + row: @row, + column: @column, + email: @email + }) + .should.equal true describe "with an anonymous user", -> @@ -519,20 +543,16 @@ describe 'WebsocketController', -> @client.get = (param, callback) => callback null, @clientParams[param] @WebsocketController.updateClientPosition @client, @update - it "should send the update to the project room with an anonymous name", -> + it "should send the update to the project room with no name", -> @WebsocketLoadBalancer.emitToRoom .calledWith(@project_id, "clientTracking.clientUpdated", { doc_id: @doc_id, id: @client.id - name: "Anonymous" + name: "" row: @row column: @column }) .should.equal true - - it "should not send cursor data to the connected user manager", (done)-> - @ConnectedUsersManager.updateUserPosition.called.should.equal false - done() describe "applyOtUpdate", -> beforeEach ->