@@ -3,6 +3,7 @@ var should = require('should');
3
3
4
4
var request = require ( 'supertest' ) ;
5
5
var app = require ( '../../app' ) ;
6
+ var Stoc = require ( '../../models/stoc' ) ;
6
7
7
8
var http ;
8
9
var cookie ;
@@ -14,33 +15,58 @@ describe('login rount', function(){
14
15
// var name2="test"
15
16
// var user2=new User({name:name2,password:1,admin:100});
16
17
18
+ var teststock = new Stoc ( {
19
+ beWatch :{
20
+ name : "testname" ,
21
+ top : "2"
22
+ } ,
23
+ name : "测试股票" ,
24
+ uid : "sh999999" ,
25
+ top : "1"
26
+ } ) ;
27
+
17
28
//先创建测试用户
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
+ } ) ;
24
43
} ) ;
25
44
//删除测试股票
26
45
after ( function ( ) {
27
46
//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
+ } ) ;
28
55
} ) ;
29
56
57
+ //测试访问首页
30
58
describe ( 'login get /' , function ( ) {
31
59
it ( 'user is login' , function ( done ) {
32
60
request ( app ) . get ( '/' ) . set ( 'cookie' , cookie ) . expect ( 200 , function ( err , res ) {
33
61
if ( err ) {
34
62
if ( res . status == 302 ) {
35
63
should . not . exist ( res . header . location ) ;
36
- //res.body.isOk.should.equal(true);
37
64
done ( ) ;
38
65
} else {
39
66
done ( err ) ;
40
67
}
41
68
} else {
42
69
should . not . exist ( res . header . location ) ;
43
- //res.body.isOk.should.equal(true);
44
70
done ( ) ;
45
71
}
46
72
} )
@@ -97,7 +123,7 @@ describe('login rount', function(){
97
123
} ) ;
98
124
} ) ;
99
125
100
-
126
+ //访问设置页面
101
127
describe ( 'get /setting' , function ( ) {
102
128
it ( 'get /setting' , function ( done ) {
103
129
request ( app ) . get ( '/setting' ) . set ( 'cookie' , cookie ) . expect ( 200 , function ( err , res ) {
@@ -116,6 +142,27 @@ describe('login rount', function(){
116
142
} ) ;
117
143
} ) ;
118
144
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
+
119
166
120
167
121
168
0 commit comments