@@ -3,164 +3,154 @@ var helpers_1 = require("../../config/tests/config/helpers");
3
3
var jwt = require ( "jwt-simple" ) ;
4
4
var HTTPStatus = require ( "http-status" ) ;
5
5
var model = require ( '../../models' ) ;
6
- if ( process . env . TRAVIS == 'true' ) {
7
- model . sequelize . sync ( ) . then ( function ( ) {
8
- test ( ) ;
9
- } ) ;
10
- }
11
- else {
12
- test ( ) ;
13
- }
14
- function test ( ) {
15
- describe ( '## User Tests' , function ( ) {
16
- 'use strict' ;
17
- var config = require ( '../../config/env/config' ) ( ) ;
18
- var id ;
19
- var token ;
20
- var userDefault = {
21
- id : 1 ,
22
- name : 'Test User' ,
23
- email : 'test@mail.com' ,
24
- password : 'testPassword'
25
- } ;
26
- beforeEach ( function ( done ) {
6
+ model . sequelize . sync ( ) . then ( function ( ) { } ) ;
7
+ describe ( '## User Tests' , function ( ) {
8
+ 'use strict' ;
9
+ var config = require ( '../../config/env/config' ) ( ) ;
10
+ var id ;
11
+ var token ;
12
+ var userDefault = {
13
+ id : 1 ,
14
+ name : 'Test User' ,
15
+ email : 'test@mail.com' ,
16
+ password : 'testPassword'
17
+ } ;
18
+ beforeEach ( function ( done ) {
19
+ model
20
+ . User
21
+ . destroy ( {
22
+ where : { }
23
+ } )
24
+ . then ( function ( ) { return model . User . create ( {
25
+ id : 50 ,
26
+ name : 'Raphael' ,
27
+ email : 'raphael@email.com' ,
28
+ password : '123456'
29
+ } ) ; } )
30
+ . then ( function ( user ) {
27
31
model
28
32
. User
29
- . destroy ( {
30
- where : { }
31
- } )
32
- . then ( function ( ) { return model . User . create ( {
33
- id : 50 ,
34
- name : 'Raphael' ,
35
- email : 'raphael@email.com' ,
36
- password : '123456'
37
- } ) ; } )
38
- . then ( function ( user ) {
39
- model
40
- . User
41
- . create ( userDefault )
42
- . then ( function ( ) {
43
- token = jwt . encode ( { id : user . id } , config . secret ) ;
44
- done ( ) ;
45
- } ) ;
33
+ . create ( userDefault )
34
+ . then ( function ( ) {
35
+ token = jwt . encode ( { id : user . id } , config . secret ) ;
36
+ done ( ) ;
46
37
} ) ;
47
- done ( ) ;
48
38
} ) ;
49
- describe ( 'GET /api/users/all' , function ( ) {
50
- it ( 'Should return a array of Users ', function ( done ) {
51
- helpers_1 . request ( helpers_1 . app )
52
- . get ( '/api/users/all' )
53
- . set ( 'Content-Type' , 'application/json ')
54
- . set ( 'Authorization ' , "JWT " + token )
55
- . end ( function ( error , res ) {
56
- helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
57
- helpers_1 . expect ( res . body . payload ) . to . be . an ( 'array' ) ;
58
- helpers_1 . expect ( res . body . payload [ 0 ] . name ) . to . be . equal ( 'Raphael ') ;
59
- helpers_1 . expect ( res . body . payload [ 0 ] . email ) . to . be . equal ( 'raphael@email.com ' ) ;
60
- done ( error ) ;
61
- } ) ;
39
+ } ) ;
40
+ describe ( 'GET /api/users/all ', function ( ) {
41
+ it ( 'Should return a array of Users' , function ( done ) {
42
+ helpers_1 . request ( helpers_1 . app )
43
+ . get ( '/api/users/all ')
44
+ . set ( 'Content-Type ' , 'application/json' )
45
+ . set ( 'Authorization' , "JWT " + token )
46
+ . end ( function ( error , res ) {
47
+ helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
48
+ helpers_1 . expect ( res . body . payload ) . to . be . an ( 'array ') ;
49
+ helpers_1 . expect ( res . body . payload [ 0 ] . name ) . to . be . equal ( 'Raphael ' ) ;
50
+ helpers_1 . expect ( res . body . payload [ 0 ] . email ) . to . be . equal ( 'raphael@email.com' ) ;
51
+ done ( error ) ;
62
52
} ) ;
63
53
} ) ;
64
- describe ( 'POST /token' , function ( ) {
65
- it ( 'Should receive a JWT ', function ( done ) {
66
- var credentials = {
67
- email : 'raphael@email.com' ,
68
- password : '123456'
69
- } ;
70
- helpers_1 . request ( helpers_1 . app )
71
- . post ( '/token' )
72
- . send ( credentials )
73
- . end ( function ( error , res ) {
74
- helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
75
- helpers_1 . expect ( res . body . token ) . to . equal ( "" + token ) ;
76
- done ( error ) ;
77
- } ) ;
54
+ } ) ;
55
+ describe ( 'POST /token ', function ( ) {
56
+ it ( 'Should receive a JWT' , function ( done ) {
57
+ var credentials = {
58
+ email : 'raphael@email.com' ,
59
+ password : '123456'
60
+ } ;
61
+ helpers_1 . request ( helpers_1 . app )
62
+ . post ( '/token' )
63
+ . send ( credentials )
64
+ . end ( function ( error , res ) {
65
+ helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
66
+ helpers_1 . expect ( res . body . token ) . to . equal ( "" + token ) ;
67
+ done ( error ) ;
78
68
} ) ;
79
- it ( 'Should not receive a JWT' , function ( done ) {
80
- var credentials = {
81
- email : 'email@email.com' ,
82
- password : '123321'
83
- } ;
84
- helpers_1 . request ( helpers_1 . app )
85
- . post ( '/token' )
86
- . send ( credentials )
87
- . end ( function ( error , res ) {
88
- helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . UNAUTHORIZED ) ;
89
- helpers_1 . expect ( res . body ) . to . empty ;
90
- done ( error ) ;
91
- } ) ;
69
+ } ) ;
70
+ it ( 'Should not receive a JWT' , function ( done ) {
71
+ var credentials = {
72
+ email : 'email@email.com' ,
73
+ password : '123321'
74
+ } ;
75
+ helpers_1 . request ( helpers_1 . app )
76
+ . post ( '/token' )
77
+ . send ( credentials )
78
+ . end ( function ( error , res ) {
79
+ helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . UNAUTHORIZED ) ;
80
+ helpers_1 . expect ( res . body ) . to . empty ;
81
+ done ( error ) ;
92
82
} ) ;
93
83
} ) ;
94
- describe ( 'POST /api/users/create' , function ( ) {
95
- it ( 'Should create a new user ', function ( done ) {
96
- var user = {
97
- id : 2 ,
98
- name : 'User Created' ,
99
- email : 'newUser@mail.com ' ,
100
- password : 'newUserPwd ' ,
101
- } ;
102
- helpers_1 . request ( helpers_1 . app )
103
- . post ( '/api/users/create' )
104
- . set ( 'Authorization' , "JWT " + token )
105
- . send ( user )
106
- . end ( function ( error , res ) {
107
- helpers_1 . expect ( res . body . payload . id ) . to . eql ( user . id ) ;
108
- helpers_1 . expect ( res . body . payload . name ) . to . eql ( user . name ) ;
109
- helpers_1 . expect ( res . body . payload . email ) . to . eql ( user . email ) ;
110
- done ( error ) ;
111
- } ) ;
84
+ } ) ;
85
+ describe ( 'POST /api/users/ create', function ( ) {
86
+ it ( 'Should create a new user' , function ( done ) {
87
+ var user = {
88
+ id : 2 ,
89
+ name : 'User Created ' ,
90
+ email : 'newUser@mail.com ' ,
91
+ password : 'newUserPwd' ,
92
+ } ;
93
+ helpers_1 . request ( helpers_1 . app )
94
+ . post ( '/api/users/create' )
95
+ . set ( 'Authorization' , "JWT " + token )
96
+ . send ( user )
97
+ . end ( function ( error , res ) {
98
+ helpers_1 . expect ( res . body . payload . id ) . to . eql ( user . id ) ;
99
+ helpers_1 . expect ( res . body . payload . name ) . to . eql ( user . name ) ;
100
+ helpers_1 . expect ( res . body . payload . email ) . to . eql ( user . email ) ;
101
+ done ( error ) ;
112
102
} ) ;
113
103
} ) ;
114
- describe ( 'GET /api/users/:id' , function ( ) {
115
- it ( 'Should return an User by its ID ', function ( done ) {
116
- helpers_1 . request ( helpers_1 . app )
117
- . get ( "/api/users/" + userDefault . id )
118
- . set ( 'Authorization' , "JWT " + token )
119
- . end ( function ( error , res ) {
120
- helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
121
- helpers_1 . expect ( res . body . payload . id ) . to . equal ( userDefault . id ) ;
122
- helpers_1 . expect ( res . body . payload ) . to . have . all . keys ( [
123
- 'id' ,
124
- 'name ',
125
- 'email ',
126
- 'password'
127
- ] ) ;
128
- id = res . body . payload . id ;
129
- done ( error ) ;
130
- } ) ;
104
+ } ) ;
105
+ describe ( 'GET /api/users/:id ', function ( ) {
106
+ it ( 'Should return an User by its ID' , function ( done ) {
107
+ helpers_1 . request ( helpers_1 . app )
108
+ . get ( "/api/users/ " + userDefault . id )
109
+ . set ( 'Authorization' , "JWT " + token )
110
+ . end ( function ( error , res ) {
111
+ helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
112
+ helpers_1 . expect ( res . body . payload . id ) . to . equal ( userDefault . id ) ;
113
+ helpers_1 . expect ( res . body . payload ) . to . have . all . keys ( [
114
+ 'id ',
115
+ 'name ',
116
+ 'email' ,
117
+ 'password'
118
+ ] ) ;
119
+ id = res . body . payload . id ;
120
+ done ( error ) ;
131
121
} ) ;
132
122
} ) ;
133
- describe ( 'PUT /api/users/:id/update' , function ( ) {
134
- it ( 'Should update an User ', function ( done ) {
135
- var updatedUser = {
136
- name : 'UpdatedName' ,
137
- email : 'update@updated.com'
138
- } ;
139
- helpers_1 . request ( helpers_1 . app )
140
- . put ( "/api/users/" + userDefault . id + "/update" )
141
- . set ( 'Authorization' , "JWT " + token )
142
- . send ( updatedUser )
143
- . end ( function ( error , res ) {
144
- helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
145
- helpers_1 . expect ( res . body . payload [ 0 ] ) . to . eql ( 1 ) ;
146
- helpers_1 . expect ( res . body . payload [ 1 ] [ 0 ] . id ) . to . eql ( userDefault . id ) ;
147
- helpers_1 . expect ( res . body . payload [ 1 ] [ 0 ] . name ) . to . eql ( updatedUser . name ) ;
148
- helpers_1 . expect ( res . body . payload [ 1 ] [ 0 ] . email ) . to . eql ( updatedUser . email ) ;
149
- done ( error ) ;
150
- } ) ;
123
+ } ) ;
124
+ describe ( 'PUT /api/users/:id/ update', function ( ) {
125
+ it ( 'Should update an User' , function ( done ) {
126
+ var updatedUser = {
127
+ name : 'UpdatedName' ,
128
+ email : 'update@updated.com'
129
+ } ;
130
+ helpers_1 . request ( helpers_1 . app )
131
+ . put ( "/api/users/ " + userDefault . id + "/update" )
132
+ . set ( 'Authorization' , "JWT " + token )
133
+ . send ( updatedUser )
134
+ . end ( function ( error , res ) {
135
+ helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
136
+ helpers_1 . expect ( res . body . payload [ 0 ] ) . to . eql ( 1 ) ;
137
+ helpers_1 . expect ( res . body . payload [ 1 ] [ 0 ] . id ) . to . eql ( userDefault . id ) ;
138
+ helpers_1 . expect ( res . body . payload [ 1 ] [ 0 ] . name ) . to . eql ( updatedUser . name ) ;
139
+ helpers_1 . expect ( res . body . payload [ 1 ] [ 0 ] . email ) . to . eql ( updatedUser . email ) ;
140
+ done ( error ) ;
151
141
} ) ;
152
142
} ) ;
153
- describe ( 'DELETE /api/users/:id/destroy' , function ( ) {
154
- it ( 'Should delete an User ', function ( done ) {
155
- helpers_1 . request ( helpers_1 . app )
156
- . del ( "/api/users/" + userDefault . id + "/destroy" )
157
- . set ( 'Authorization' , "JWT " + token )
158
- . end ( function ( error , res ) {
159
- helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
160
- helpers_1 . expect ( res . body . payload ) . to . eql ( 1 ) ;
161
- done ( error ) ;
162
- } ) ;
143
+ } ) ;
144
+ describe ( 'DELETE /api/users/:id/destroy ', function ( ) {
145
+ it ( 'Should delete an User' , function ( done ) {
146
+ helpers_1 . request ( helpers_1 . app )
147
+ . del ( "/api/users/ " + userDefault . id + "/destroy" )
148
+ . set ( 'Authorization' , "JWT " + token )
149
+ . end ( function ( error , res ) {
150
+ helpers_1 . expect ( res . status ) . to . equal ( HTTPStatus . OK ) ;
151
+ helpers_1 . expect ( res . body . payload ) . to . eql ( 1 ) ;
152
+ done ( error ) ;
163
153
} ) ;
164
154
} ) ;
165
155
} ) ;
166
- }
156
+ } ) ;
0 commit comments