1
1
'use strict' ;
2
- global . DATABASE_URL = 'mongodb://localhost/jwt-auth-demo-test' ;
2
+
3
3
const chai = require ( 'chai' ) ;
4
4
const chaiHttp = require ( 'chai-http' ) ;
5
5
6
- const { app, runServer, closeServer} = require ( '../server' ) ;
7
- const { User} = require ( '../users' ) ;
6
+ const { app, runServer, closeServer } = require ( '../server' ) ;
7
+ const { User } = require ( '../users' ) ;
8
+ const { TEST_DATABASE_URL } = require ( '../config' ) ;
8
9
9
10
const expect = chai . expect ;
10
11
@@ -13,7 +14,7 @@ const expect = chai.expect;
13
14
// see: https://github.com/chaijs/chai-http
14
15
chai . use ( chaiHttp ) ;
15
16
16
- describe ( '/api/user' , function ( ) {
17
+ describe ( '/api/user' , function ( ) {
17
18
const username = 'exampleUser' ;
18
19
const password = 'examplePass' ;
19
20
const firstName = 'Example' ;
@@ -23,23 +24,23 @@ describe('/api/user', function() {
23
24
const firstNameB = 'ExampleB' ;
24
25
const lastNameB = 'UserB' ;
25
26
26
- before ( function ( ) {
27
- return runServer ( ) ;
27
+ before ( function ( ) {
28
+ return runServer ( TEST_DATABASE_URL ) ;
28
29
} ) ;
29
30
30
- after ( function ( ) {
31
+ after ( function ( ) {
31
32
return closeServer ( ) ;
32
33
} ) ;
33
34
34
- beforeEach ( function ( ) { } ) ;
35
+ beforeEach ( function ( ) { } ) ;
35
36
36
- afterEach ( function ( ) {
37
+ afterEach ( function ( ) {
37
38
return User . remove ( { } ) ;
38
39
} ) ;
39
40
40
- describe ( '/api/users' , function ( ) {
41
- describe ( 'POST' , function ( ) {
42
- it ( 'Should reject users with missing username' , function ( ) {
41
+ describe ( '/api/users' , function ( ) {
42
+ describe ( 'POST' , function ( ) {
43
+ it ( 'Should reject users with missing username' , function ( ) {
43
44
return chai
44
45
. request ( app )
45
46
. post ( '/api/users' )
@@ -63,7 +64,7 @@ describe('/api/user', function() {
63
64
expect ( res . body . location ) . to . equal ( 'username' ) ;
64
65
} ) ;
65
66
} ) ;
66
- it ( 'Should reject users with missing password' , function ( ) {
67
+ it ( 'Should reject users with missing password' , function ( ) {
67
68
return chai
68
69
. request ( app )
69
70
. post ( '/api/users' )
@@ -87,7 +88,7 @@ describe('/api/user', function() {
87
88
expect ( res . body . location ) . to . equal ( 'password' ) ;
88
89
} ) ;
89
90
} ) ;
90
- it ( 'Should reject users with non-string username' , function ( ) {
91
+ it ( 'Should reject users with non-string username' , function ( ) {
91
92
return chai
92
93
. request ( app )
93
94
. post ( '/api/users' )
@@ -114,7 +115,7 @@ describe('/api/user', function() {
114
115
expect ( res . body . location ) . to . equal ( 'username' ) ;
115
116
} ) ;
116
117
} ) ;
117
- it ( 'Should reject users with non-string password' , function ( ) {
118
+ it ( 'Should reject users with non-string password' , function ( ) {
118
119
return chai
119
120
. request ( app )
120
121
. post ( '/api/users' )
@@ -141,7 +142,7 @@ describe('/api/user', function() {
141
142
expect ( res . body . location ) . to . equal ( 'password' ) ;
142
143
} ) ;
143
144
} ) ;
144
- it ( 'Should reject users with non-string first name' , function ( ) {
145
+ it ( 'Should reject users with non-string first name' , function ( ) {
145
146
return chai
146
147
. request ( app )
147
148
. post ( '/api/users' )
@@ -168,7 +169,7 @@ describe('/api/user', function() {
168
169
expect ( res . body . location ) . to . equal ( 'firstName' ) ;
169
170
} ) ;
170
171
} ) ;
171
- it ( 'Should reject users with non-string last name' , function ( ) {
172
+ it ( 'Should reject users with non-string last name' , function ( ) {
172
173
return chai
173
174
. request ( app )
174
175
. post ( '/api/users' )
@@ -195,7 +196,7 @@ describe('/api/user', function() {
195
196
expect ( res . body . location ) . to . equal ( 'lastName' ) ;
196
197
} ) ;
197
198
} ) ;
198
- it ( 'Should reject users with non-trimmed username' , function ( ) {
199
+ it ( 'Should reject users with non-trimmed username' , function ( ) {
199
200
return chai
200
201
. request ( app )
201
202
. post ( '/api/users' )
@@ -222,7 +223,7 @@ describe('/api/user', function() {
222
223
expect ( res . body . location ) . to . equal ( 'username' ) ;
223
224
} ) ;
224
225
} ) ;
225
- it ( 'Should reject users with non-trimmed password' , function ( ) {
226
+ it ( 'Should reject users with non-trimmed password' , function ( ) {
226
227
return chai
227
228
. request ( app )
228
229
. post ( '/api/users' )
@@ -249,7 +250,7 @@ describe('/api/user', function() {
249
250
expect ( res . body . location ) . to . equal ( 'password' ) ;
250
251
} ) ;
251
252
} ) ;
252
- it ( 'Should reject users with empty username' , function ( ) {
253
+ it ( 'Should reject users with empty username' , function ( ) {
253
254
return chai
254
255
. request ( app )
255
256
. post ( '/api/users' )
@@ -276,7 +277,7 @@ describe('/api/user', function() {
276
277
expect ( res . body . location ) . to . equal ( 'username' ) ;
277
278
} ) ;
278
279
} ) ;
279
- it ( 'Should reject users with password less than ten characters' , function ( ) {
280
+ it ( 'Should reject users with password less than ten characters' , function ( ) {
280
281
return chai
281
282
. request ( app )
282
283
. post ( '/api/users' )
@@ -303,7 +304,7 @@ describe('/api/user', function() {
303
304
expect ( res . body . location ) . to . equal ( 'password' ) ;
304
305
} ) ;
305
306
} ) ;
306
- it ( 'Should reject users with password greater than 72 characters' , function ( ) {
307
+ it ( 'Should reject users with password greater than 72 characters' , function ( ) {
307
308
return chai
308
309
. request ( app )
309
310
. post ( '/api/users' )
@@ -330,7 +331,7 @@ describe('/api/user', function() {
330
331
expect ( res . body . location ) . to . equal ( 'password' ) ;
331
332
} ) ;
332
333
} ) ;
333
- it ( 'Should reject users with duplicate username' , function ( ) {
334
+ it ( 'Should reject users with duplicate username' , function ( ) {
334
335
// Create an initial user
335
336
return User . create ( {
336
337
username,
@@ -364,7 +365,7 @@ describe('/api/user', function() {
364
365
expect ( res . body . location ) . to . equal ( 'username' ) ;
365
366
} ) ;
366
367
} ) ;
367
- it ( 'Should create a new user' , function ( ) {
368
+ it ( 'Should create a new user' , function ( ) {
368
369
return chai
369
370
. request ( app )
370
371
. post ( '/api/users' )
@@ -399,7 +400,7 @@ describe('/api/user', function() {
399
400
expect ( passwordIsCorrect ) . to . be . true ;
400
401
} ) ;
401
402
} ) ;
402
- it ( 'Should trim firstName and lastName' , function ( ) {
403
+ it ( 'Should trim firstName and lastName' , function ( ) {
403
404
return chai
404
405
. request ( app )
405
406
. post ( '/api/users' )
@@ -432,15 +433,15 @@ describe('/api/user', function() {
432
433
} ) ;
433
434
} ) ;
434
435
435
- describe ( 'GET' , function ( ) {
436
- it ( 'Should return an empty array initially' , function ( ) {
436
+ describe ( 'GET' , function ( ) {
437
+ it ( 'Should return an empty array initially' , function ( ) {
437
438
return chai . request ( app ) . get ( '/api/users' ) . then ( res => {
438
439
expect ( res ) . to . have . status ( 200 ) ;
439
440
expect ( res . body ) . to . be . an ( 'array' ) ;
440
441
expect ( res . body ) . to . have . length ( 0 ) ;
441
442
} ) ;
442
443
} ) ;
443
- it ( 'Should return an array of users' , function ( ) {
444
+ it ( 'Should return an array of users' , function ( ) {
444
445
return User . create (
445
446
{
446
447
username,
0 commit comments