API 测试框架

This commit is contained in:
jysperm
2014-04-13 16:08:41 +08:00
parent 484e340da3
commit 78c0a2d4d8
7 changed files with 79 additions and 3 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ node_modules
*.css
/.DS_Store
/config.codekit
/reports/*

View File

@@ -4,12 +4,14 @@ passwd: '53673f434686ce045477f066f30eded55a9bb535a6cec7b73a60972ccafddb2a'
passwd_salt: '53673f434686b535a6cec7b73a60ce045477f066f30eded55a9b972ccafddb2a'
email: 'jysperm@gmail.com'
signup_at: ISODate('2013-02-22T03:03:37.312Z')
group: ['root', 'stduser']
setting:
language: 'zh_CN'
QQ: '184300584'
attribute:
expired: ISODate('2013-02-22T03:03:37.312Z')
tokens: [
token: 'b535a6cec7b73a60c53673f434686e04972ccafddb2a5477f066f30eded55a9b'
available: true

View File

@@ -0,0 +1,15 @@
frisby = require 'frisby'
config = require '../../core/config'
baseUrl = "http://127.0.0.1:#{config.web.port}"
frisby.create '/account/signup'
.post "#{baseUrl}/account/signup/",
username: 'test'
email: 'test@jysperm.me'
passwd: 'password'
.expectStatus 200
.expectJSONTypes
id: String
.toss()

49
TEST/API/init.coffee Normal file
View File

@@ -0,0 +1,49 @@
async = require 'async'
db = require '../../core/db'
module.exports = (callback) ->
cAccount = db.collection 'accounts'
async.parallel [
(callback) ->
cAccount.remove
username: $in: ['test', 'test_main']
, callback
(callback) ->
cAccount.remove
email: 'test@jysperm.me'
, callback
(callback) ->
cAccount.insert
_id: db.ObjectID('533b0cb894f6c673123e33a3')
username: 'test_main'
password: 'a75b5ef8038c8bd6f623beaee94fd429e522d6f00f94183c0023655e723cf123'
password_salt: '891bad13e24d964bc7a95b97b6762926719fec8739d2ca23e6b1089d4ca273a9'
email: 'test_main@jysperm.me'
singup_at: new Date()
group: []
setting: {}
attribute: {}
token: [
token: 'token'
available: true
created_at: new Date()
updated_at: new Date()
attribute: {}
]
, callback
], ->
callback()
unless module.parent
db.connect ->
module.exports ->
process.exit()

View File

@@ -39,7 +39,7 @@ module.exports =
expires: new Date(Date.now() + config.account.cookie_time)
return res.json
id: account.data._id
id: account._id
login: (req, res) ->
mAccount.byUsernameOrEmail req.body.username, (account) ->
@@ -54,7 +54,7 @@ module.exports =
expires: new Date(Date.now() + config.account.cookie_time)
return res.json
id: account.data._id
id: account._id
token: token
logout: (req, res) ->

View File

@@ -50,7 +50,7 @@ exports.buildModel = (that, mongo) ->
that.insert = (data, options, callback = null) ->
mongo.insert data, options, (err, result) ->
if _.isArray result
if _.isArray data
callback result
else
callback result[0]

8
run-test.bash Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
node node_modules/coffee-script/bin/coffee app.coffee &
SERVER_PID="$!"
sleep 1s
node node_modules/coffee-script/bin/coffee TEST/API/init.coffee
node node_modules/jasmine-node/bin/jasmine-node --junitreport TEST/API
kill "$SERVER_PID"