mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
test revokeAllUserSessions
This commit is contained in:
parent
dfcb47fb5c
commit
699ba21032
1 changed files with 59 additions and 0 deletions
|
@ -17,12 +17,14 @@ describe 'UserSessionsManager', ->
|
||||||
multi: sinon.stub()
|
multi: sinon.stub()
|
||||||
exec: sinon.stub()
|
exec: sinon.stub()
|
||||||
get: sinon.stub()
|
get: sinon.stub()
|
||||||
|
del: sinon.stub()
|
||||||
sadd: sinon.stub()
|
sadd: sinon.stub()
|
||||||
srem: sinon.stub()
|
srem: sinon.stub()
|
||||||
smembers: sinon.stub()
|
smembers: sinon.stub()
|
||||||
expire: sinon.stub()
|
expire: sinon.stub()
|
||||||
@rclient.multi.returns(@rclient)
|
@rclient.multi.returns(@rclient)
|
||||||
@rclient.get.returns(@rclient)
|
@rclient.get.returns(@rclient)
|
||||||
|
@rclient.del.returns(@rclient)
|
||||||
@rclient.sadd.returns(@rclient)
|
@rclient.sadd.returns(@rclient)
|
||||||
@rclient.srem.returns(@rclient)
|
@rclient.srem.returns(@rclient)
|
||||||
@rclient.smembers.returns(@rclient)
|
@rclient.smembers.returns(@rclient)
|
||||||
|
@ -242,3 +244,60 @@ describe 'UserSessionsManager', ->
|
||||||
@call (err) =>
|
@call (err) =>
|
||||||
@_checkSessions.callCount.should.equal 0
|
@_checkSessions.callCount.should.equal 0
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
##
|
||||||
|
describe 'revokeAllUserSessions', ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
@sessionKeys = ['one', 'two']
|
||||||
|
@rclient.smembers.callsArgWith(1, null, @sessionKeys)
|
||||||
|
@rclient.exec.callsArgWith(0, null)
|
||||||
|
@call = (callback) =>
|
||||||
|
@UserSessionsManager.revokeAllUserSessions @user, callback
|
||||||
|
|
||||||
|
it 'should not produce an error', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
expect(err).to.not.be.instanceof Error
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should call the appropriate redis methods', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@rclient.smembers.callCount.should.equal 1
|
||||||
|
@rclient.multi.callCount.should.equal 1
|
||||||
|
@rclient.del.callCount.should.equal 1
|
||||||
|
@rclient.del.firstCall.args[0].should.deep.equal(@sessionKeys)
|
||||||
|
@rclient.srem.callCount.should.equal 1
|
||||||
|
@rclient.srem.firstCall.args[1].should.deep.equal(@sessionKeys)
|
||||||
|
@rclient.exec.callCount.should.equal 1
|
||||||
|
done()
|
||||||
|
|
||||||
|
describe 'when rclient produces an error', ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
@rclient.exec.callsArgWith(0, new Error('woops'))
|
||||||
|
|
||||||
|
it 'should produce an error', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
expect(err).to.be.instanceof Error
|
||||||
|
done()
|
||||||
|
|
||||||
|
describe 'when no user is supplied', ->
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
@call = (callback) =>
|
||||||
|
@UserSessionsManager.revokeAllUserSessions null, callback
|
||||||
|
|
||||||
|
it 'should not produce an error', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
expect(err).to.not.be.instanceof Error
|
||||||
|
expect(err).to.equal null
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should not call the appropriate redis methods', (done) ->
|
||||||
|
@call (err) =>
|
||||||
|
@rclient.smembers.callCount.should.equal 0
|
||||||
|
@rclient.multi.callCount.should.equal 0
|
||||||
|
@rclient.del.callCount.should.equal 0
|
||||||
|
@rclient.srem.callCount.should.equal 0
|
||||||
|
@rclient.exec.callCount.should.equal 0
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue