mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-29 03:55:42 +08:00
test for Account.authenticate
This commit is contained in:
@@ -177,6 +177,22 @@ Account.statics.generateToken = (callback) ->
|
||||
else
|
||||
callback token
|
||||
|
||||
# @param callback(Token, Account)
|
||||
Account.statics.authenticate = (token, callback) ->
|
||||
unless token
|
||||
return callback()
|
||||
|
||||
@findOneAndUpdate
|
||||
'tokens.token': token
|
||||
,
|
||||
$set:
|
||||
'tokens.$.updated_at': new Date()
|
||||
, (err, account) ->
|
||||
matched_token = _.findWhere account?.tokens,
|
||||
token: token
|
||||
|
||||
callback matched_token, account
|
||||
|
||||
# @param callback(err, Token)
|
||||
Account.methods.createToken = (type, payload, callback) ->
|
||||
models.Account.generateToken (token) =>
|
||||
|
||||
@@ -115,6 +115,28 @@ describe 'model/Account', ->
|
||||
err.should.be.exist
|
||||
done()
|
||||
|
||||
describe 'authenticate', ->
|
||||
it 'should success', (done) ->
|
||||
Account.authenticate util.token, (token, account) ->
|
||||
token.token.should.equal util.token
|
||||
account.id.should.equal util.account.id
|
||||
|
||||
done()
|
||||
|
||||
it 'should fail with no token', (done) ->
|
||||
Account.authenticate '', (token, account) ->
|
||||
expect(token).to.not.exist
|
||||
expect(account).to.not.exist
|
||||
|
||||
done()
|
||||
|
||||
it 'should fail with invalid token', (done) ->
|
||||
Account.authenticate 'invalid token', (token, account) ->
|
||||
expect(token).to.not.exist
|
||||
expect(account).to.not.exist
|
||||
|
||||
done()
|
||||
|
||||
describe 'matchPassword', ->
|
||||
it 'should be matched', ->
|
||||
util.account.matchPassword(util.password).should.be.ok
|
||||
|
||||
Reference in New Issue
Block a user