mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added disconnect funtion in connected users manager
This commit is contained in:
parent
c0a6f0b7ad
commit
4ccc56723f
2 changed files with 30 additions and 2 deletions
|
@ -8,8 +8,8 @@ rclient.auth(Settings.redis.web.password)
|
|||
|
||||
ONE_HOUR_IN_S = 60 * 60
|
||||
|
||||
buildProjectSetKey = (project_id)-> return "users_in_project:#{project_id}"
|
||||
buildUserKey = (project_id, user_id)-> return "connected_user:#{project_id}:#{user_id}"
|
||||
buildProjectSetKey = (project_id)-> return "connected_user:#{project_id}"
|
||||
|
||||
|
||||
module.exports =
|
||||
|
@ -22,6 +22,15 @@ module.exports =
|
|||
rclient.setex buildUserKey(project_id, user_id), new Date(), ONE_HOUR_IN_S * 6, cb
|
||||
], callback
|
||||
|
||||
marksUserAsDisconnected: (project_id, user_id, callback)->
|
||||
async.series [
|
||||
(cb)->
|
||||
rclient.srem buildProjectSetKey(project_id), user_id, cb
|
||||
(cb)->
|
||||
rclient.del buildUserKey(project_id, user_id), cb
|
||||
], callback
|
||||
|
||||
|
||||
|
||||
_getConnectedUser: (project_id, user_id, callback)->
|
||||
rclient.get buildUserKey(project_id, user_id), (err, result)->
|
||||
|
|
|
@ -21,6 +21,8 @@ describe "ConnectedUsersManager", ->
|
|||
setex:sinon.stub()
|
||||
sadd:sinon.stub()
|
||||
get: sinon.stub()
|
||||
srem:sinon.stub()
|
||||
del:sinon.stub()
|
||||
tk.freeze(new Date())
|
||||
|
||||
@ConnectedUsersManager = SandboxedModule.require modulePath, requires:
|
||||
|
@ -42,14 +44,31 @@ describe "ConnectedUsersManager", ->
|
|||
|
||||
it "should set a key with the date and give it a ttl", (done)->
|
||||
@ConnectedUsersManager.markUserAsConnected @project_id, @user_id, (err)=>
|
||||
console.log @rClient.setex.args[0], "connected_user:#{@project_id}:#{@user_id}"
|
||||
@rClient.setex.calledWith("connected_user:#{@project_id}:#{@user_id}", new Date(), 60 * 60 * 6).should.equal true
|
||||
done()
|
||||
|
||||
it "should push the user_id on to the project list", (done)->
|
||||
@ConnectedUsersManager.markUserAsConnected @project_id, @user_id, (err)=>
|
||||
@rClient.sadd.calledWith("connected_user:#{@project_id}", @user_id).should.equal true
|
||||
@rClient.sadd.calledWith("users_in_project:#{@project_id}", @user_id).should.equal true
|
||||
done()
|
||||
|
||||
describe "marksUserAsDisconnected", ->
|
||||
beforeEach ->
|
||||
@rClient.srem.callsArgWith(2)
|
||||
@rClient.del.callsArgWith(1)
|
||||
|
||||
it "should remove the user from the set", (done)->
|
||||
@ConnectedUsersManager.marksUserAsDisconnected @project_id, @user_id, (err)=>
|
||||
@rClient.srem.calledWith("users_in_project:#{@project_id}", @user_id).should.equal true
|
||||
done()
|
||||
|
||||
it "should delete the connected_user string", (done)->
|
||||
@ConnectedUsersManager.marksUserAsDisconnected @project_id, @user_id, (err)=>
|
||||
@rClient.del.calledWith("connected_user:#{@project_id}:#{@user_id}").should.equal true
|
||||
done()
|
||||
|
||||
|
||||
|
||||
describe "_getConnectedUser", ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue