refactor with promise

This commit is contained in:
jysperm
2015-03-30 00:13:46 +08:00
parent 2f9386f033
commit 2d303e1e3f
38 changed files with 606 additions and 574 deletions

View File

@@ -5,13 +5,13 @@ global._ = require 'underscore'
global.fs = require 'fs'
if fs.existsSync "#{__dirname}/../config.coffee"
config = require '../config'
global.config = require '../config'
else
config = require '../sample/core.config.coffee'
global.config = require '../sample/core.config.coffee'
global.Q = require 'q'
global.chai = require 'chai'
global.async = require 'async'
global.config = config
global.supertest = require 'supertest'
if process.env.COV_TEST == 'true'

View File

@@ -1,4 +1,4 @@
utils = require '../core/utils'
global.utils = require '../core/utils'
createAgent = (callback) ->
agent = supertest.agent app.express
@@ -9,6 +9,9 @@ createAgent = (callback) ->
agent: agent
csrf_token: res.body.csrf_token
cleanUpByAccount = ({account_id}, callback) ->
app.models.Account.findByIdAndRemove account_id, callback
createLoggedAgent = (callback) ->
createAgent (err, {agent, csrf_token}) ->
username = 'test' + utils.randomString(8).toLowerCase()
@@ -22,6 +25,9 @@ createLoggedAgent = (callback) ->
email: email
password: password
.end (err, res) ->
after (done) ->
cleanUpByAccount res.body.account_id, done
callback err,
agent: agent
username: username
@@ -32,4 +38,5 @@ createLoggedAgent = (callback) ->
_.extend global,
createAgent: createAgent
cleanUpByAccount: cleanUpByAccount
createLoggedAgent: createLoggedAgent