@@ -14,151 +14,161 @@ chai.use(chaiHttp);
14
14
* Add mockTodo into storage
15
15
*/
16
16
function addTodoToStorage ( name , cb ) {
17
- chai . request ( server )
18
- . post ( '/api/v1/todo' )
19
- . send ( { name } )
20
- . end ( ( err , res ) => {
21
- if ( cb ) {
22
- cb ( err , res ) ;
23
- }
24
- } ) ;
17
+ chai
18
+ . request ( server )
19
+ . post ( '/api/v1/todo' )
20
+ . send ( { name } )
21
+ . end ( ( err , res ) => {
22
+ if ( cb ) {
23
+ cb ( err , res ) ;
24
+ }
25
+ } ) ;
25
26
}
26
27
27
28
describe ( 'Todos' , ( ) => {
28
- before ( ( done ) => {
29
- mongoose . disconnect ( ) ;
30
- mockgoose . helper . reset ( ) ;
31
- mockgoose . prepareStorage ( )
32
- . then ( ( ) => {
33
- mongoose . connect ( config . db , ( err ) => {
34
- done ( err ) ;
35
- } )
36
- } )
29
+ before ( done => {
30
+ mongoose . disconnect ( ) ;
31
+ mockgoose . helper . reset ( ) ;
32
+ mockgoose . prepareStorage ( ) . then ( ( ) => {
33
+ mongoose . connect (
34
+ config . db ,
35
+ err => {
36
+ done ( err ) ;
37
+ }
38
+ ) ;
37
39
} ) ;
40
+ } ) ;
38
41
39
-
40
- describe ( '/GET todo' , ( ) => {
41
- it ( 'it should get a empty list of todos' , ( done ) => {
42
- chai . request ( server )
43
- . get ( '/api/v1/todo' )
44
- . end ( ( err , res ) => {
45
- res . should . have . status ( 200 ) ;
46
- res . body . should . be . a ( 'array' ) . with . lengthOf ( 0 ) ;
47
- done ( ) ;
48
- } )
42
+ describe ( '/GET todo' , ( ) => {
43
+ it ( 'it should get a empty list of todos' , done => {
44
+ chai
45
+ . request ( server )
46
+ . get ( '/api/v1/todo' )
47
+ . end ( ( err , res ) => {
48
+ res . should . have . status ( 200 ) ;
49
+ res . body . should . be . a ( 'array' ) . with . lengthOf ( 0 ) ;
50
+ done ( ) ;
49
51
} ) ;
52
+ } ) ;
50
53
51
- it ( 'it should get a list of todos' , ( done ) => {
52
- addTodoToStorage ( 'Mock Todo' , ( err , res ) => {
53
- chai . request ( server )
54
- . get ( '/api/v1/todo' )
55
- . end ( ( err , res ) => {
56
- res . should . have . status ( 200 ) ;
57
- res . body . should . be . a ( 'array' ) . with . lengthOf ( 1 ) ;
58
- res . body . should . to . deep . equal ( [ res . body [ 0 ] ] ) ;
59
- done ( ) ;
60
- } )
61
- } ) ;
62
- } ) ;
54
+ it ( 'it should get a list of todos' , done => {
55
+ addTodoToStorage ( 'Mock Todo' , ( err , res ) => {
56
+ chai
57
+ . request ( server )
58
+ . get ( '/api/v1/todo' )
59
+ . end ( ( err , res ) => {
60
+ res . should . have . status ( 200 ) ;
61
+ res . body . should . be . a ( 'array' ) . with . lengthOf ( 1 ) ;
62
+ res . body . should . to . deep . equal ( [ res . body [ 0 ] ] ) ;
63
+ done ( ) ;
64
+ } ) ;
65
+ } ) ;
63
66
} ) ;
67
+ } ) ;
64
68
65
- describe ( '/POST todo' , ( ) => {
66
- it ( 'should create a todo with a name property' , ( done ) => {
67
- const payload = { name : 'Just another todo' } ;
68
- chai . request ( server )
69
- . post ( '/api/v1/todo' )
70
- . send ( payload )
71
- . end ( ( err , res ) => {
72
- res . should . have . status ( 200 ) ;
73
- res . body . should . be . a ( 'object' ) ;
74
- res . body . should . have . property ( 'name' ) . eql ( payload . name ) ;
75
- res . body . should . have . property ( 'completed ' ) . eql ( false ) ;
76
- done ( ) ;
77
- } ) ;
69
+ describe ( '/POST todo' , ( ) => {
70
+ it ( 'should create a todo with a name property' , done => {
71
+ const payload = { name : 'Just another todo' } ;
72
+ chai
73
+ . request ( server )
74
+ . post ( '/api/v1/todo' )
75
+ . send ( payload )
76
+ . end ( ( err , res ) => {
77
+ res . should . have . status ( 200 ) ;
78
+ res . body . should . be . a ( 'object' ) ;
79
+ res . body . should . have . property ( 'name ' ) . eql ( payload . name ) ;
80
+ res . body . should . have . property ( 'completed' ) . eql ( false ) ;
81
+ done ( ) ;
78
82
} ) ;
83
+ } ) ;
79
84
80
- it ( 'should not create a todo with a missing name property' , ( done ) => {
81
- chai . request ( server )
82
- . post ( '/api/v1/todo' )
83
- . end ( ( err , res ) => {
84
- res . should . have . status ( 422 ) ;
85
- done ( ) ;
86
- } ) ;
85
+ it ( 'should not create a todo with a missing name property' , done => {
86
+ chai
87
+ . request ( server )
88
+ . post ( '/api/v1/todo' )
89
+ . end ( ( err , res ) => {
90
+ res . should . have . status ( 422 ) ;
91
+ done ( ) ;
87
92
} ) ;
88
93
} ) ;
94
+ } ) ;
89
95
90
- describe ( '/PUT todo/:id' , ( ) => {
91
- let todoMock ;
96
+ describe ( '/PUT todo/:id' , ( ) => {
97
+ let todoMock ;
92
98
93
- before ( ( done ) => {
94
- addTodoToStorage ( 'Mock Todo Name for Modification' , ( err , res ) => {
95
- todoMock = res . body ;
96
- done ( ) ;
97
- } ) ;
98
- } ) ;
99
+ before ( done => {
100
+ addTodoToStorage ( 'Mock Todo Name for Modification' , ( err , res ) => {
101
+ todoMock = res . body ;
102
+ done ( ) ;
103
+ } ) ;
104
+ } ) ;
99
105
100
- it ( 'should update a todo' , ( done ) => {
101
- const update = {
102
- name : 'Renamed Todo' , completed : true
103
- } ;
104
-
105
- chai . request ( server )
106
- . put ( '/api/v1/todo/' + todoMock . _id )
107
- . send ( update )
108
- . end ( ( err , res ) => {
109
- res . should . have . status ( 200 ) ;
110
- done ( ) ;
111
- } ) ;
112
- } ) ;
106
+ it ( 'should update a todo' , done => {
107
+ const update = {
108
+ name : 'Renamed Todo' ,
109
+ completed : true
110
+ } ;
113
111
114
- it ( 'should return a 422 status if body is missing' , ( done ) => {
115
- chai . request ( server )
116
- . put ( '/api/v1/todo/' + todoMock . _id )
117
- . end ( ( err , res ) => {
118
- res . should . have . status ( 422 ) ;
119
- done ( ) ;
120
- } ) ;
112
+ chai
113
+ . request ( server )
114
+ . put ( '/api/v1/todo/' + todoMock . _id )
115
+ . send ( update )
116
+ . end ( ( err , res ) => {
117
+ res . should . have . status ( 200 ) ;
118
+ done ( ) ;
121
119
} ) ;
120
+ } ) ;
122
121
123
- it ( 'should return a 422 status if id is wrong' , ( done ) => {
124
- chai . request ( server )
125
- . put ( '/api/v1/todo/A-WRONG-ID' )
126
- . send ( { name : 'Test' } )
127
- . end ( ( err , res ) => {
128
- res . should . have . status ( 422 ) ;
129
- done ( ) ;
130
- } ) ;
122
+ it ( 'should return a 422 status if body is missing' , done => {
123
+ chai
124
+ . request ( server )
125
+ . put ( '/api/v1/todo/' + todoMock . _id )
126
+ . end ( ( err , res ) => {
127
+ res . should . have . status ( 422 ) ;
128
+ done ( ) ;
131
129
} ) ;
130
+ } ) ;
132
131
132
+ it ( 'should return a 422 status if id is wrong' , done => {
133
+ chai
134
+ . request ( server )
135
+ . put ( '/api/v1/todo/A-WRONG-ID' )
136
+ . send ( { name : 'Test' } )
137
+ . end ( ( err , res ) => {
138
+ res . should . have . status ( 422 ) ;
139
+ done ( ) ;
140
+ } ) ;
133
141
} ) ;
142
+ } ) ;
134
143
135
- describe ( '/DELETE todo/:id' , ( ) => {
136
- let todoMock ;
144
+ describe ( '/DELETE todo/:id' , ( ) => {
145
+ let todoMock ;
137
146
138
- before ( ( done ) => {
139
- addTodoToStorage ( 'Mock Todo Name to delete' , ( err , res ) => {
140
- todoMock = res . body ;
141
- done ( ) ;
142
- } ) ;
143
- } ) ;
147
+ before ( done => {
148
+ addTodoToStorage ( 'Mock Todo Name to delete' , ( err , res ) => {
149
+ todoMock = res . body ;
150
+ done ( ) ;
151
+ } ) ;
152
+ } ) ;
144
153
145
- it ( 'should delete a todo' , ( done ) => {
146
- chai . request ( server )
147
- . delete ( '/api/v1/todo/' + todoMock . _id )
148
- . end ( ( err , res ) => {
149
- res . should . have . status ( 200 ) ;
150
- done ( ) ;
151
- } ) ;
154
+ it ( 'should delete a todo' , done => {
155
+ chai
156
+ . request ( server )
157
+ . delete ( '/api/v1/todo/' + todoMock . _id )
158
+ . end ( ( err , res ) => {
159
+ res . should . have . status ( 200 ) ;
160
+ done ( ) ;
152
161
} ) ;
162
+ } ) ;
153
163
154
- it ( 'should return a 422 status if id is wrong' , ( done ) => {
155
- chai . request ( server )
156
- . put ( '/api/v1/todo/A-WRONG-ID' )
157
- . end ( ( err , res ) => {
158
- res . should . have . status ( 422 ) ;
159
- done ( ) ;
160
- } ) ;
164
+ it ( 'should return a 422 status if id is wrong' , done => {
165
+ chai
166
+ . request ( server )
167
+ . put ( '/api/v1/todo/A-WRONG-ID' )
168
+ . end ( ( err , res ) => {
169
+ res . should . have . status ( 422 ) ;
170
+ done ( ) ;
161
171
} ) ;
162
172
} ) ;
163
-
173
+ } ) ;
164
174
} ) ;
0 commit comments