update tests

This commit is contained in:
Brian Gough 2019-08-14 13:03:14 +01:00
parent d3171e4e2e
commit d57b229e17
2 changed files with 19 additions and 11 deletions

View file

@ -147,18 +147,18 @@ describe "ConnectedUsersManager", ->
describe "getConnectedUsers", ->
beforeEach ->
@users = ["1234", "5678", "9123"]
@users = ["1234", "5678", "9123", "8234"]
@rClient.smembers.callsArgWith(1, null, @users)
@ConnectedUsersManager._getConnectedUser = sinon.stub()
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[0]).callsArgWith(2, null, {connected:true, client_id:@users[0]})
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[1]).callsArgWith(2, null, {connected:false, client_id:@users[1]})
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[2]).callsArgWith(2, null, {connected:true, client_id:@users[2]})
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[0]).callsArgWith(2, null, {connected:true, client_age: 2, client_id:@users[0]})
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[1]).callsArgWith(2, null, {connected:false, client_age: 1, client_id:@users[1]})
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[2]).callsArgWith(2, null, {connected:true, client_age: 3, client_id:@users[2]})
@ConnectedUsersManager._getConnectedUser.withArgs(@project_id, @users[3]).callsArgWith(2, null, {connected:true, client_age: 11, client_id:@users[3]}) # connected but old
it "should only return the users in the list which are still in redis", (done)->
it "should only return the users in the list which are still in redis and recently updated", (done)->
@ConnectedUsersManager.getConnectedUsers @project_id, (err, users)=>
users.length.should.equal 2
users[0].should.deep.equal {client_id:@users[0], connected:true}
users[1].should.deep.equal {client_id:@users[2], connected:true}
users[0].should.deep.equal {client_id:@users[0], client_age: 2, connected:true}
users[1].should.deep.equal {client_id:@users[2], client_age: 3, connected:true}
done()

View file

@ -355,18 +355,26 @@ describe 'WebsocketController', ->
beforeEach ->
@client.params.project_id = @project_id
@users = ["mock", "users"]
@WebsocketLoadBalancer.emitToRoom = sinon.stub()
@ConnectedUsersManager.getConnectedUsers = sinon.stub().callsArgWith(1, null, @users)
describe "when authorized", ->
beforeEach ->
beforeEach (done) ->
@AuthorizationManager.assertClientCanViewProject = sinon.stub().callsArgWith(1, null)
@WebsocketController.getConnectedUsers @client, @callback
@WebsocketController.getConnectedUsers @client, (args...) =>
@callback(args...)
done()
it "should check that the client is authorized to view the project", ->
@AuthorizationManager.assertClientCanViewProject
.calledWith(@client)
.should.equal true
it "should broadcast a request to update the client list", ->
@WebsocketLoadBalancer.emitToRoom
.calledWith(@project_id, "clientTracking.refresh")
.should.equal true
it "should get the connected users for the project", ->
@ConnectedUsersManager.getConnectedUsers
.calledWith(@project_id)