writen getUserIdFromToken

This commit is contained in:
Henry Oswald 2014-05-15 17:20:42 +01:00
parent 9f901fb1ba
commit 1ffd19099b
2 changed files with 22 additions and 0 deletions

View file

@ -18,3 +18,9 @@ module.exports =
callback(err, token) callback(err, token)
getUserIdFromToken: (token, callback)-> getUserIdFromToken: (token, callback)->
multi = rclient.multi()
multi.get token
multi.del token
multi.exec (err, results)->
callback err, results[0]

View file

@ -17,6 +17,8 @@ describe "TokenGenerator", ->
web:{} web:{}
@redisMulti = @redisMulti =
set:sinon.stub() set:sinon.stub()
get:sinon.stub()
del:sinon.stub()
expire:sinon.stub() expire:sinon.stub()
exec:sinon.stub() exec:sinon.stub()
@uuid = v4 : -> return @stubbedToken @uuid = v4 : -> return @stubbedToken
@ -46,3 +48,17 @@ describe "TokenGenerator", ->
@TokenGenerator.getNewToken @user_id, (err, token)=> @TokenGenerator.getNewToken @user_id, (err, token)=>
err.should.exist err.should.exist
done() 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()