mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
writen getUserIdFromToken
This commit is contained in:
parent
9f901fb1ba
commit
1ffd19099b
2 changed files with 22 additions and 0 deletions
|
@ -18,3 +18,9 @@ module.exports =
|
|||
callback(err, token)
|
||||
|
||||
getUserIdFromToken: (token, callback)->
|
||||
multi = rclient.multi()
|
||||
multi.get token
|
||||
multi.del token
|
||||
multi.exec (err, results)->
|
||||
callback err, results[0]
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ describe "TokenGenerator", ->
|
|||
web:{}
|
||||
@redisMulti =
|
||||
set:sinon.stub()
|
||||
get:sinon.stub()
|
||||
del:sinon.stub()
|
||||
expire:sinon.stub()
|
||||
exec:sinon.stub()
|
||||
@uuid = v4 : -> return @stubbedToken
|
||||
|
@ -46,3 +48,17 @@ describe "TokenGenerator", ->
|
|||
@TokenGenerator.getNewToken @user_id, (err, token)=>
|
||||
err.should.exist
|
||||
done()
|
||||
|
||||
|
||||
describe "getUserIdFromToken", ->
|
||||
|
||||
it "should get and delete the token", (done)->
|
||||
@redisMulti.exec.callsArgWith(0, null, [@user_id])
|
||||
@TokenGenerator.getUserIdFromToken @stubbedToken, (err, user_id)=>
|
||||
user_id.should.equal @user_id
|
||||
@redisMulti.get.calledWith(@stubbedToken).should.equal true
|
||||
@redisMulti.del.calledWith(@stubbedToken).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue