@@ -17,9 +17,9 @@ public function tearDown()
17
17
$ this ->http = null ;
18
18
}
19
19
20
- public function testGetUsers ( )
20
+ protected function deleteItem ( $ id )
21
21
{
22
- $ response = $ this ->http ->request ('GET ' , 'users ' , [
22
+ $ response = $ this ->http ->request ('DELETE ' , 'users/delete/ ' . $ id , [
23
23
'headers ' => [
24
24
'Authorization ' => 'Bearer ' . $ this ->credentials ,
25
25
]]);
@@ -28,10 +28,10 @@ public function testGetUsers()
28
28
$ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
29
29
$ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
30
30
$ json = json_decode ($ response ->getBody (), true );
31
- $ this ->assertEquals ('common.SUCCESSFUL_REQUEST ' , $ json ['messages ' ]);
31
+ $ this ->assertEquals ('common.DELETED_SUCCESSFULLY ' , $ json ['messages ' ]);
32
32
}
33
33
34
- public function testCreateUser ()
34
+ protected function createItem ()
35
35
{
36
36
$ response = $ this ->http ->request ('POST ' , 'users/create ' , [
37
37
'headers ' => [
@@ -59,9 +59,12 @@ public function testCreateUser()
59
59
$ json = json_decode ($ response ->getBody (), true );
60
60
$ this ->assertEquals ('common.CREATED_SUCCESSFULLY ' , $ json ['messages ' ]);
61
61
$ id = $ json ['data ' ]['id ' ];
62
+ return $ id ;
63
+ }
62
64
63
- // Delete just created item
64
- $ response = $ this ->http ->request ('DELETE ' , 'users/delete/ ' . $ id , [
65
+ public function testGetUsers ()
66
+ {
67
+ $ response = $ this ->http ->request ('GET ' , 'users ' , [
65
68
'headers ' => [
66
69
'Authorization ' => 'Bearer ' . $ this ->credentials ,
67
70
]]);
@@ -70,37 +73,22 @@ public function testCreateUser()
70
73
$ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
71
74
$ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
72
75
$ json = json_decode ($ response ->getBody (), true );
73
- $ this ->assertEquals ('common.DELETED_SUCCESSFULLY ' , $ json ['messages ' ]);
76
+ $ this ->assertEquals ('common.SUCCESSFUL_REQUEST ' , $ json ['messages ' ]);
74
77
}
75
78
76
- public function testCannotCreateDuplicatedUser ()
79
+ public function testCreateUser ()
77
80
{
78
- $ response = $ this ->http ->request ('POST ' , 'users/create ' , [
79
- 'headers ' => [
80
- 'Authorization ' => 'Bearer ' . $ this ->credentials ,
81
- ],
82
- 'form_params ' => [
83
- 'email ' => 'another@email.com ' ,
84
- 'new_password ' => 'test123 ' ,
85
- 'username ' => 'admintest ' ,
86
- 'firstname ' => 'My name ' ,
87
- 'lastname ' => 'My last name ' ,
88
- 'level ' => 'Superuser ' ,
89
- 'phone ' => '12312312 ' ,
90
- 'mobile ' => '31312312 ' ,
91
- 'address ' => 'Calle 10 ' ,
92
- 'city ' => 'Bogotá ' ,
93
- 'country ' => 'Colombia ' ,
94
- 'birthday ' => '1979-01-01 ' ,
95
- 'authorised ' => '1 ' ,
96
- ]]);
81
+ // Create new item
82
+ $ id = $ this ->createItem ();
97
83
98
- $ this ->assertEquals (201 , $ response ->getStatusCode ());
99
- $ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
100
- $ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
101
- $ json = json_decode ($ response ->getBody (), true );
102
- $ this ->assertEquals ('common.CREATED_SUCCESSFULLY ' , $ json ['messages ' ]);
103
- $ id = $ json ['data ' ]['id ' ];
84
+ // Delete just created item
85
+ $ this ->deleteItem ($ id );
86
+ }
87
+
88
+ public function testCannotCreateDuplicatedUser ()
89
+ {
90
+ // Create new item
91
+ $ id = $ this ->createItem ();
104
92
105
93
// creates duplicated
106
94
$ response = $ this ->http ->request ('POST ' , 'users/create ' , [
@@ -130,16 +118,7 @@ public function testCannotCreateDuplicatedUser()
130
118
$ this ->assertEquals ('profile.ANOTHER_USER_ALREADY_REGISTERED_WITH_THIS_USERNAME ' , $ json ['messages ' ]);
131
119
132
120
// Delete just created item
133
- $ response = $ this ->http ->request ('DELETE ' , 'users/delete/ ' . $ id , [
134
- 'headers ' => [
135
- 'Authorization ' => 'Bearer ' . $ this ->credentials ,
136
- ]]);
137
-
138
- $ this ->assertEquals (200 , $ response ->getStatusCode ());
139
- $ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
140
- $ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
141
- $ json = json_decode ($ response ->getBody (), true );
142
- $ this ->assertEquals ('common.DELETED_SUCCESSFULLY ' , $ json ['messages ' ]);
121
+ $ this ->deleteItem ($ id );
143
122
}
144
123
145
124
public function testGetUserById ()
@@ -158,33 +137,8 @@ public function testGetUserById()
158
137
159
138
public function testUpdateUser ()
160
139
{
161
- // Create user
162
- $ response = $ this ->http ->request ('POST ' , 'users/create ' , [
163
- 'headers ' => [
164
- 'Authorization ' => 'Bearer ' . $ this ->credentials ,
165
- ],
166
- 'form_params ' => [
167
- 'email ' => 'another@email.com ' ,
168
- 'new_password ' => 'test123 ' ,
169
- 'username ' => 'admintest ' ,
170
- 'firstname ' => 'My name ' ,
171
- 'lastname ' => 'My last name ' ,
172
- 'level ' => 'Superuser ' ,
173
- 'phone ' => '12312312 ' ,
174
- 'mobile ' => '31312312 ' ,
175
- 'address ' => 'Calle 10 ' ,
176
- 'city ' => 'Bogotá ' ,
177
- 'country ' => 'Colombia ' ,
178
- 'birthday ' => '1979-01-01 ' ,
179
- 'authorised ' => '1 ' ,
180
- ]]);
181
-
182
- $ this ->assertEquals (201 , $ response ->getStatusCode ());
183
- $ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
184
- $ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
185
- $ json = json_decode ($ response ->getBody (), true );
186
- $ this ->assertEquals ('common.CREATED_SUCCESSFULLY ' , $ json ['messages ' ]);
187
- $ id = $ json ['data ' ]['id ' ];
140
+ // Create new item
141
+ $ id = $ this ->createItem ();
188
142
189
143
// updates user
190
144
$ response = $ this ->http ->request ('PATCH ' , 'users/update/ ' . $ id , [
@@ -214,57 +168,15 @@ public function testUpdateUser()
214
168
$ this ->assertEquals ('onemore@email.com ' , $ json ['data ' ]['email ' ]);
215
169
216
170
// Delete just created item
217
- $ response = $ this ->http ->request ('DELETE ' , 'users/delete/ ' . $ id , [
218
- 'headers ' => [
219
- 'Authorization ' => 'Bearer ' . $ this ->credentials ,
220
- ]]);
221
-
222
- $ this ->assertEquals (200 , $ response ->getStatusCode ());
223
- $ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
224
- $ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
225
- $ json = json_decode ($ response ->getBody (), true );
226
- $ this ->assertEquals ('common.DELETED_SUCCESSFULLY ' , $ json ['messages ' ]);
171
+ $ this ->deleteItem ($ id );
227
172
}
228
173
229
174
public function testDeleteUser ()
230
175
{
231
- $ response = $ this ->http ->request ('POST ' , 'users/create ' , [
232
- 'headers ' => [
233
- 'Authorization ' => 'Bearer ' . $ this ->credentials ,
234
- ],
235
- 'form_params ' => [
236
- 'email ' => 'another@email.com ' ,
237
- 'new_password ' => 'test123 ' ,
238
- 'username ' => 'admintest ' ,
239
- 'firstname ' => 'My name ' ,
240
- 'lastname ' => 'My last name ' ,
241
- 'level ' => 'Superuser ' ,
242
- 'phone ' => '12312312 ' ,
243
- 'mobile ' => '31312312 ' ,
244
- 'address ' => 'Calle 10 ' ,
245
- 'city ' => 'Bogotá ' ,
246
- 'country ' => 'Colombia ' ,
247
- 'birthday ' => '1979-01-01 ' ,
248
- 'authorised ' => '1 ' ,
249
- ]]);
250
-
251
- $ this ->assertEquals (201 , $ response ->getStatusCode ());
252
- $ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
253
- $ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
254
- $ json = json_decode ($ response ->getBody (), true );
255
- $ this ->assertEquals ('common.CREATED_SUCCESSFULLY ' , $ json ['messages ' ]);
256
- $ id = $ json ['data ' ]['id ' ];
176
+ // Create new item
177
+ $ id = $ this ->createItem ();
257
178
258
179
// Delete just created item
259
- $ response = $ this ->http ->request ('DELETE ' , 'users/delete/ ' . $ id , [
260
- 'headers ' => [
261
- 'Authorization ' => 'Bearer ' . $ this ->credentials ,
262
- ]]);
263
-
264
- $ this ->assertEquals (200 , $ response ->getStatusCode ());
265
- $ contentType = $ response ->getHeaders ()["Content-Type " ][0 ];
266
- $ this ->assertEquals ("application/json; charset=UTF-8 " , $ contentType );
267
- $ json = json_decode ($ response ->getBody (), true );
268
- $ this ->assertEquals ('common.DELETED_SUCCESSFULLY ' , $ json ['messages ' ]);
180
+ $ this ->deleteItem ($ id );
269
181
}
270
182
}
0 commit comments