@@ -15,6 +15,8 @@ var User;
15
15
// Testing The User Model
16
16
describe ( 'User Model' , function ( ) {
17
17
18
+ var id ;
19
+ var id2 ;
18
20
19
21
before ( function ( ) { /* jslint ignore:line */
20
22
User = proxyquire ( '../models/Users' , { 'mongoose' : 'mongooseMock' } ) ;
@@ -23,12 +25,10 @@ describe('User Model',function(){
23
25
24
26
describe ( 'Test CRUDS' , function ( ) {
25
27
it ( 'should save data' , function ( done ) {
26
- var cb = sinon . spy ( ) ;
27
28
var myuser = User . create ( { name : 'femi' } ) ;
28
29
29
30
myuser . then ( function ( res ) {
30
- cb ( ) ;
31
- cb . should . have . been . calledOnce ; /* jslint ignore:line */
31
+ res . should . be . an . object ; /* jslint ignore:line */
32
32
done ( ) ;
33
33
} )
34
34
. catch ( function ( err ) {
@@ -37,12 +37,10 @@ describe('User Model',function(){
37
37
} ) ;
38
38
39
39
it ( 'should read data' , function ( done ) {
40
- var cb = sinon . spy ( ) ;
41
40
var myuser = User . findOne ( { name : 'femi' } ) ;
42
41
43
42
myuser . then ( function ( res ) {
44
- cb ( ) ;
45
- cb . should . have . been . calledOnce ; /* jslint ignore:line */
43
+ res . should . be . an . object ; /* jslint ignore:line */
46
44
done ( ) ;
47
45
} )
48
46
. catch ( function ( err ) {
@@ -51,12 +49,10 @@ describe('User Model',function(){
51
49
} ) ;
52
50
53
51
it ( 'should read all data' , function ( done ) {
54
- var cb = sinon . spy ( ) ;
55
52
var myuser = User . find ( ) ;
56
53
57
54
myuser . then ( function ( res ) {
58
- cb ( ) ;
59
- cb . should . have . been . calledOnce ; /* jslint ignore:line */
55
+ res . should . be . an . array ; /* jslint ignore:line */
60
56
done ( ) ;
61
57
} )
62
58
. catch ( function ( err ) {
@@ -93,13 +89,11 @@ describe('User Model',function(){
93
89
} ) ;
94
90
95
91
it ( 'should search data' , function ( done ) {
96
- var cb = sinon . spy ( ) ;
97
92
// Search needs more work for more accuracy
98
93
var myuser = User . search ( 'femi' ) ;
99
94
100
95
myuser . then ( function ( res ) {
101
- cb ( ) ;
102
- cb . should . have . been . calledOnce ; /* jslint ignore:line */
96
+ res . should . be . an . object ; /* jslint ignore:line */
103
97
done ( ) ;
104
98
} )
105
99
. catch ( function ( err ) {
@@ -108,14 +102,12 @@ describe('User Model',function(){
108
102
} ) ;
109
103
110
104
it ( 'should delete data' , function ( done ) {
111
- var cb = sinon . spy ( ) ;
112
105
var cb2 = sinon . spy ( ) ;
113
106
var ouruser = User . create ( [ { name :'Olaolu' } , { name : 'fola' } , { name : 'bolu' } ] ) ;
114
107
var myuser = User . deleteOne ( { name : 'bolu' } ) ;
115
108
116
109
ouruser . then ( function ( res ) {
117
- cb ( ) ;
118
- cb . should . have . been . calledOnce ; /* jslint ignore:line */
110
+ res . should . be . an . object ; /* jslint ignore:line */
119
111
return myuser ;
120
112
} ) . then ( function ( res ) {
121
113
cb2 ( ) ;
@@ -145,6 +137,7 @@ describe('User Model',function(){
145
137
var myuser = User . create ( { name : 'this is for the gods' } ) ;
146
138
147
139
myuser . then ( function ( res ) {
140
+ id = res . _id ;
148
141
res . should . have . property ( 'createdAt' ) ;
149
142
done ( ) ;
150
143
} )
@@ -155,9 +148,8 @@ describe('User Model',function(){
155
148
156
149
it ( 'should add updatedAt' , function ( done ) {
157
150
var myuser = User . create ( { name : 'i am a demigod!' } ) ;
158
- var id ;
159
151
myuser . then ( function ( res ) {
160
- id = res . _id ;
152
+ id2 = res . _id ;
161
153
return User . update ( { _id : id } , { name : 'This is the titan' } ) ;
162
154
} )
163
155
. then ( function ( res ) {
@@ -172,11 +164,102 @@ describe('User Model',function(){
172
164
} ) ;
173
165
} ) ;
174
166
175
- // it('should tag database entries properly');
167
+ it ( 'should tag database entries properly' , function ( done ) {
168
+ var myuser = User . create ( { name : 'femi' , someOtherStringData : 'random stuff' } ) ;
169
+
170
+ myuser . then ( function ( res ) {
171
+ res . tags . length . should . equal ( 2 ) ; /* jslint ignore:line */
172
+ done ( ) ;
173
+ } )
174
+ . catch ( function ( err ) {
175
+ done ( err ) ;
176
+ } ) ;
177
+ } ) ;
178
+
179
+ it ( 'should count returned records' , function ( done ) {
180
+ var myuser = User . count ( { name : 'This is the titan' } ) ;
181
+
182
+ myuser . then ( function ( res ) {
183
+ res . should . be . a . number ; /* jslint ignore:line */
184
+ done ( ) ;
185
+ } )
186
+ . catch ( function ( err ) {
187
+ done ( err ) ;
188
+ } ) ;
189
+ } ) ;
190
+
191
+ it ( 'should find a record by id' , function ( done ) {
192
+ var myuser = User . findById ( id ) ;
193
+
194
+ myuser . then ( function ( res ) {
195
+ res . should . be . an . object ; /* jslint ignore:line */
196
+ done ( ) ;
197
+ } )
198
+ . catch ( function ( err ) {
199
+ done ( err ) ;
200
+ } ) ;
201
+ } ) ;
202
+
203
+ it ( 'should find a record by id and delete' , function ( done ) {
204
+ var myuser = User . findByIdAndRemove ( id2 ) ;
176
205
177
- // it('should tag database entries properly');
206
+ myuser . then ( function ( res ) {
207
+ res . should . be . an . object ; /* jslint ignore:line */
208
+ done ( ) ;
209
+ } )
210
+ . catch ( function ( err ) {
211
+ done ( err ) ;
212
+ } ) ;
213
+ } ) ;
214
+
215
+ it ( 'should find a record by id and update' , function ( done ) {
216
+ var myuser = User . findByIdAndUpdate ( id , { name : 'fufu' } ) ;
217
+
218
+ myuser . then ( function ( res ) {
219
+ res . should . be . an . object ; /* jslint ignore:line */
220
+ done ( ) ;
221
+ } )
222
+ . catch ( function ( err ) {
223
+ done ( err ) ;
224
+ } ) ;
225
+ } ) ;
226
+
227
+ it ( 'should find the first match from a query' , function ( done ) {
228
+ var myuser = User . findOne ( { name : 'fufu' } ) ;
229
+
230
+ myuser . then ( function ( res ) {
231
+ res . should . be . an . object ; /* jslint ignore:line */
232
+ done ( ) ;
233
+ } )
234
+ . catch ( function ( err ) {
235
+ done ( err ) ;
236
+ } ) ;
237
+ } ) ;
238
+
239
+ it ( 'should find the first match from a query and update' , function ( done ) {
240
+ var myuser = User . findOneAndUpdate ( { name : 'fufu' } , { name : 'funmi' } ) ;
241
+
242
+ myuser . then ( function ( res ) {
243
+ res . should . be . an . object ; /* jslint ignore:line */
244
+ done ( ) ;
245
+ } )
246
+ . catch ( function ( err ) {
247
+ done ( err ) ;
248
+ } ) ;
249
+ } ) ;
250
+
251
+ it ( 'should find the first match from a query and delete' , function ( done ) {
252
+ var myuser = User . findOneAndRemove ( { name : 'funmi' } ) ;
253
+
254
+ myuser . then ( function ( res ) {
255
+ res . should . be . an . object ; /* jslint ignore:line */
256
+ done ( ) ;
257
+ } )
258
+ . catch ( function ( err ) {
259
+ done ( err ) ;
260
+ } ) ;
261
+ } ) ;
178
262
179
- // it('should tag database entries properly');
180
263
} ) ;
181
264
} ) ;
182
265
0 commit comments