Skip to content

Commit 75e3fc6

Browse files
committed
尝试新东西
1 parent c2dbd4b commit 75e3fc6

File tree

5 files changed

+83
-11
lines changed

5 files changed

+83
-11
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"connect-flash": "*",
1414
"socket.io": "*",
1515
"gm": "*",
16-
"async":"*"
16+
"async":"*",
17+
"redis":"*",
18+
"request":"*"
1719
},
1820
"devDependencies": {
1921
"grunt": "~0.4.2",

routes/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var crypto = require('crypto'), //密码加密模块
99
setting = require('./setting'),
1010
talk = require('./talk'),
1111
stockroom = require('./stockroom');
12+
test = require('./test'),
1213

1314
module.exports = function(app){
1415
app.get('/',function(req,res){
@@ -137,4 +138,8 @@ module.exports = function(app){
137138
app.get('/atmeTopic',function(req,res){
138139
talk.atmeTopic(req,res);
139140
});
141+
142+
app.get('/test',function(req,res){
143+
test.redis(req,res);
144+
});
140145
};

routes/test.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var request = require('request');
2+
3+
4+
5+
var test={};
6+
7+
module.exports = test;
8+
9+
test.redis=function(req,res){
10+
// var request = request.defaults({jar: true})
11+
// request('http://www.google.com', function () {
12+
// request('http://images.google.com');
13+
// })
14+
}

test/rount/login.js

+56-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var should = require('should');
33

44
var request = require('supertest');
55
var app = require('../../app');
6+
var Stoc = require('../../models/stoc');
67

78
var http;
89
var cookie;
@@ -14,33 +15,58 @@ describe('login rount', function(){
1415
// var name2="test"
1516
// var user2=new User({name:name2,password:1,admin:100});
1617

18+
var teststock=new Stoc({
19+
beWatch:{
20+
name: "testname",
21+
top: "2"
22+
},
23+
name: "测试股票",
24+
uid: "sh999999",
25+
top: "1"
26+
});
27+
1728
//先创建测试用户
18-
before(function (done) {
19-
request(app).post('/loginAjax').send({name:"tang",password:"1234"}).end(function(err,res){
20-
//res.should.have.status(200);
21-
cookie = res.headers['set-cookie'];
22-
done();
23-
});
29+
before(function (done) {
30+
// request(app).post('/loginAjax').send({name:"testuser",password:"1"}).end(function(err,res){
31+
// //res.should.have.status(200);
32+
// cookie = res.headers['set-cookie'];
33+
// done();
34+
// });
35+
36+
//创建一个测试股票
37+
//teststock.watch(function (user) {});
38+
//创建一个测试用户,并且保存cookie
39+
request(app).post('/sign').send({name:"testuser",password:"1",repassword:"1"}).expect(200,function(err,res){
40+
cookie = res.headers['set-cookie'];
41+
done();
42+
});
2443
});
2544
//删除测试股票
2645
after(function () {
2746
//app.close();
47+
//删除测试用户
48+
global.db.collection('user',function(err,collection){
49+
collection.remove({name:"testuser"},function(err){});
50+
});
51+
//删除测试股票
52+
global.db.collection('sto',function(err,collection){
53+
collection.remove({uid:'sh999999'},function(err){});
54+
});
2855
});
2956

57+
//测试访问首页
3058
describe('login get /', function(){
3159
it('user is login', function (done) {
3260
request(app).get('/').set('cookie', cookie).expect(200,function(err,res){
3361
if(err) {
3462
if(res.status==302){
3563
should.not.exist(res.header.location);
36-
//res.body.isOk.should.equal(true);
3764
done();
3865
}else{
3966
done(err);
4067
}
4168
} else {
4269
should.not.exist(res.header.location);
43-
//res.body.isOk.should.equal(true);
4470
done();
4571
}
4672
})
@@ -97,7 +123,7 @@ describe('login rount', function(){
97123
});
98124
});
99125

100-
126+
//访问设置页面
101127
describe('get /setting', function(){
102128
it('get /setting', function (done) {
103129
request(app).get('/setting').set('cookie', cookie).expect(200,function(err,res){
@@ -116,6 +142,27 @@ describe('login rount', function(){
116142
});
117143
});
118144

145+
//关注股票
146+
describe('get /watchStock', function(){
147+
//关注股票并且新建股票
148+
it('watch stock and creat stock', function (done) {
149+
request(app).get('/watchStock?uid=sh999999&name=测试股票&beWatchName=testuser&beWatchTop=1&add=1').set('cookie', cookie).expect(200,function(err,res){
150+
if(err) {
151+
if(res.status==302){
152+
res.body.ok.should.equal(true);
153+
done();
154+
}else{
155+
done(err);
156+
}
157+
} else {
158+
res.body.ok.should.equal(true);
159+
done();
160+
}
161+
})
162+
});
163+
});
164+
165+
119166

120167

121168

test/rount/rount.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ describe('nologin rount', function(){
1414
//删除测试股票
1515
after(function () {
1616
//app.close();
17+
//删除测试用户
18+
global.db.collection('user',function(err,collection){
19+
collection.remove({name:"testuser"},function(err){});
20+
});
1721
});
1822

1923
//访问首页
@@ -206,7 +210,7 @@ describe('nologin rount', function(){
206210
});
207211
});
208212

209-
//异步登录
213+
//异步登录测试
210214
describe('ajax post /loginAjax', function(){
211215
it('ajax err user', function (done) {
212216
http.post('/loginAjax').send({name:"tang111",password:"1234"}).expect(200,function(err,res){

0 commit comments

Comments
 (0)