test for Account.search

This commit is contained in:
jysperm
2014-10-24 03:00:36 +08:00
parent 59d654ab23
commit eca4a6a2d3
3 changed files with 35 additions and 1 deletions

View File

@@ -147,7 +147,7 @@ Account.statics.search = (stuff, callback) ->
if account
return callback account
exports.findById stuff, (err, account) ->
@findById stuff, (err, account) ->
callback account
_.extend app.models,

View File

@@ -1,12 +1,21 @@
utils = null
Account = null
test_account = null
created_account_ids = []
describe 'model/account', ->
before ->
require '../../../app'
{utils} = app
{Account} = app.models
after (done) ->
Account.remove
_id:
$in: created_account_ids
, done
describe 'validators should be work', ->
it 'invalid_email', (done) ->
account = new Account
@@ -43,4 +52,28 @@ describe 'model/account', ->
account.email.should.be.equal email.toLowerCase()
account.password.should.have.length 64
created_account_ids.push account._id
test_account = account
done()
describe 'search', ->
it 'should work with username', (done) ->
Account.search test_account.username, (result) ->
result.email.should.be.equal test_account.email
done()
it 'should work with email', (done) ->
Account.search test_account.email, (result) ->
result.username.should.be.equal test_account.username
done()
it 'should work with id', (done) ->
Account.search test_account.id, (result) ->
result.username.should.be.equal test_account.username
done()
it 'should not exist', (done) ->
Account.search 'username_not_exist', (result) ->
expect(result).to.not.exist
done()

View File

@@ -4,6 +4,7 @@ describe 'utils', ->
describe 'rx', ->
it 'username', ->
utils.rx.username.test('jysperm').should.be.ok
utils.rx.username.test('jy_sperm').should.be.ok
utils.rx.username.test('JYSPERM').should.not.be.ok
utils.rx.username.test('s').should.not.be.ok
utils.rx.username.test('root-panel').should.not.be.ok