mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-13 07:01:20 +08:00
some test of /account
This commit is contained in:
@@ -103,7 +103,8 @@ Account = mongoose.Schema
|
||||
type: Object
|
||||
default: {}
|
||||
|
||||
Account.plugin mongooseUniqueValidator
|
||||
Account.plugin mongooseUniqueValidator,
|
||||
message: 'unique_validation_error'
|
||||
|
||||
Account.path('email').validate (email) ->
|
||||
return utils.rx.email.test email
|
||||
|
||||
@@ -42,7 +42,7 @@ exports.post '/register', (req, res) ->
|
||||
id: account._id
|
||||
|
||||
exports.post '/login', (req, res) ->
|
||||
Account.search req.body.username, (err, account) ->
|
||||
Account.search req.body.username, (account) ->
|
||||
unless account
|
||||
return res.error 'wrong_password'
|
||||
|
||||
@@ -58,7 +58,7 @@ exports.post '/login', (req, res) ->
|
||||
res.cookie 'token', token,
|
||||
expires: new Date(Date.now() + config.account.cookie_time)
|
||||
|
||||
res.cookie 'language', account.settings.language,
|
||||
res.cookie 'language', account.preferences.language,
|
||||
expires: new Date(Date.now() + config.account.cookie_time)
|
||||
|
||||
res.json
|
||||
|
||||
@@ -187,6 +187,9 @@ describe 'model/Account', ->
|
||||
util.account.inGroup('group_not_exist').should.not.ok
|
||||
|
||||
describe 'model/Token', ->
|
||||
describe 'validators should be work', ->
|
||||
it 'unique_validation_error'
|
||||
|
||||
describe 'revoke', ->
|
||||
it 'should success', (done) ->
|
||||
util.account.createToken 'full_access', {}, (err, token) ->
|
||||
|
||||
@@ -3,6 +3,7 @@ describe 'router/account', ->
|
||||
utils = null
|
||||
csrf_token = null
|
||||
|
||||
account_id = null
|
||||
username = null
|
||||
email = null
|
||||
password = null
|
||||
@@ -52,9 +53,41 @@ describe 'router/account', ->
|
||||
.expect 'set-cookie', /token=/
|
||||
.end (err, res) ->
|
||||
res.body.id.should.have.length 24
|
||||
account_id = res.body.id
|
||||
done err
|
||||
|
||||
it 'POST login'
|
||||
it 'POST register with existed username', (done) ->
|
||||
agent.post '/account/register'
|
||||
.send
|
||||
csrf_token: csrf_token
|
||||
username: username
|
||||
email: "#{utils.randomString 20}@gmail.com"
|
||||
password: password
|
||||
.expect 400
|
||||
.end (err, res) ->
|
||||
res.body.error.should.be.equal 'username_exist'
|
||||
done err
|
||||
|
||||
it 'POST register with invalid email'
|
||||
|
||||
it 'POST login', (done) ->
|
||||
agent.post '/account/login'
|
||||
.send
|
||||
csrf_token: csrf_token
|
||||
username: username
|
||||
password: password
|
||||
.expect 200
|
||||
.expect 'set-cookie', /token=/
|
||||
.end (err, res) ->
|
||||
res.body.id.should.be.equal account_id
|
||||
res.body.token.should.be.exist
|
||||
done err
|
||||
|
||||
it 'POST login with email'
|
||||
|
||||
it 'POST login with username does not exist'
|
||||
|
||||
it 'POST login with invalid password'
|
||||
|
||||
it 'GET preferences'
|
||||
|
||||
|
||||
@@ -49,4 +49,7 @@ exports.pickErrorName = (error) ->
|
||||
|
||||
err = error.errors[_.first(_.keys(error.errors))]
|
||||
|
||||
if err.message == 'unique_validation_error'
|
||||
return "#{err.path}_exist"
|
||||
|
||||
return err.message
|
||||
|
||||
Reference in New Issue
Block a user