Skip to content

Commit

Permalink
Mocha experienced a timed out error, don't know why
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyuwei70 committed Mar 29, 2017
1 parent 749778b commit a5d2400
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var db=new sqlite3.Database(__dirname+"/accounts.sqlite3").once('error',function
* 表单
* :param token 用户token
* :param account json编码的EVE账号信息 {username:<username>,password:<password>}
* :param account_owner EVE账号所属ID
* :param [account_owner=(token所指定的用户)] EVE账号所属ID
* */
//TODO:数据一致性
function addaccount(req,resp){
Expand All @@ -54,7 +54,7 @@ function addaccount(req,resp){
var newaccount={};
newaccount.username=eveacc.username;
newaccount.password=eveacc.password;
newaccount.owner=user.getID();
newaccount.owner=req.body.account_owner || req.user.getID();
rdsclient.get("account_cnt",function(err,reply){
if (err){
resp.status(500).write().end();
Expand Down
54 changes: 53 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ var should=require('should');
var sqlite3=require('sqlite3');
var redis=require('redis'),
rdsclient=redis.createClient();
var async = require("async");

describe('main.js',function () {
var loginname="root",password="root",token,token2;
before('init database',function(done){
var db=new sqlite3.Database(__dirname+"/../test.sqlite3");
db.run("DELETE FROM tokens",function () {
db.run("DELETE FROM users WHERE NOT username=\'root\'",done);
db.run("DELETE FROM users WHERE NOT username=\'root\'",function (err) {
if (err) throw err;
db.close(done);
});
});
});
describe('static-module',function () {
Expand Down Expand Up @@ -178,8 +182,56 @@ describe('main.js',function () {
});
});
describe('accounts module',function () {
var tokens=[];
var roottoken;
var users=[{username:"pibc",password:"pibc"},{username:"tga",password:"tga"},{username:"fbp",password:"fbp"}];
var db=new sqlite3.Database(__dirname+"/../test.sqlite3");
before('clear all accounts and privileges',function (done) {
async.series([
function (cb) {
db.run("DELETE FROM tokens",function (err) {
if (err) cb(err);
db.run("DELETE FROM users WHERE NOT username=\'root\'",function (err) {
if (err) cb(err);
db.close(cb);
});
})
},
function (cb) {
rdsclient.flushall(cb);
},
function (cb) {
request.post('/login').send({username:"root",password:"root"})
.expect(function (res) {
res=JSON.parse(res.text);
roottoken=res.token;
}).expect(200,cb);
},
function (cb) {
async.each(users,function (user,cb2) {
request.post('/adduser').send(Object.assign({token:roottoken},user))
.expect(200,cb2);
},cb);
},
function (cb) {
async.each(users,function (user,cb2) {
request.post('/login').send(user)
.expect(function (res) {
res=JSON.parse(res.text);
tokens.push(res.token);
}).expect(200,cb2);
},cb);
}
],function (err,res) {
if (err) throw err;
done();
});
});
it('should add eve account',function (done) {
request.post('/accounts/add').send({token:tokens[0],account:"{username:test,password:test}"})
.expect(200,done);
});
it('should get eve account');
});
describe('userinfo module',function () {

Expand Down

0 comments on commit a5d2400

Please sign in to comment.