@@ -129,7 +129,7 @@ public function it_logs_out_the_discourse_user_when_triggered()
129
129
->andReturn (json_encode (['user ' => $ this ->user_mock ]));
130
130
131
131
$ this ->response_mock ->shouldReceive ('getStatusCode ' )
132
- ->once ()
132
+ ->twice ()
133
133
->andReturn (200 );
134
134
135
135
$ this ->guzzle_mock ->shouldReceive ('get ' )
@@ -138,7 +138,7 @@ public function it_logs_out_the_discourse_user_when_triggered()
138
138
->andReturn ($ this ->response_mock );
139
139
140
140
$ this ->guzzle_mock ->shouldReceive ('post ' )
141
- ->with ('admin/users/1/log_out ' )
141
+ ->with ('admin/users/1/log_out ' , $ configs )
142
142
->andReturn ($ this ->response_mock );
143
143
144
144
$ this ->listener ->handle ($ this ->event_mock );
@@ -160,13 +160,12 @@ public function if_it_receives_no_user_it_does_nothing_and_returns()
160
160
/**
161
161
* @test
162
162
*/
163
- public function if_discourse_response_code_is_not_200_log_a_notice_with_the_status_code ()
163
+ public function on_getting_user_if_discourse_response_code_is_not_200_log_a_warning_with_the_status_code ()
164
164
{
165
165
$ this ->user_mock ->id = 1 ;
166
166
$ this ->event_mock ->user = $ this ->user_mock ;
167
167
168
- $ this ->logger_mock ->shouldReceive ('notice ' )->once ();
169
-
168
+ $ this ->logger_mock ->shouldReceive ('warning ' )->once ();
170
169
171
170
$ configs = [
172
171
'base_uri ' => 'http://discourse.example.com ' ,
@@ -191,9 +190,53 @@ public function if_discourse_response_code_is_not_200_log_a_notice_with_the_stat
191
190
->once ()
192
191
->andReturn ($ configs ['headers ' ]['Api-Username ' ]);
193
192
194
- $ this ->response_mock ->shouldReceive ('getBody ' )
193
+ $ this ->response_mock ->shouldReceive ('getStatusCode ' )
194
+ ->andReturn (500 );
195
+
196
+ $ this ->response_mock ->shouldReceive ('getReasonPhrase ' )
195
197
->once ()
196
- ->andReturn (json_encode (['user ' => $ this ->user_mock ]));
198
+ ->andReturn ('Server error ' );
199
+
200
+ $ this ->guzzle_mock ->shouldReceive ('get ' )
201
+ ->with ('users/by-external/1.json ' , $ configs )
202
+ ->once ()
203
+ ->andReturn ($ this ->response_mock );
204
+
205
+ $ this ->listener ->handle ($ this ->event_mock );
206
+ }
207
+
208
+ /**
209
+ * @test
210
+ */
211
+ public function on_user_logout_if_discourse_response_code_is_not_200_log_a_notice_with_the_status_code ()
212
+ {
213
+ $ this ->user_mock ->id = 1 ;
214
+ $ this ->event_mock ->user = $ this ->user_mock ;
215
+
216
+ $ this ->logger_mock ->shouldReceive ('notice ' )->once ();
217
+
218
+ $ configs = [
219
+ 'base_uri ' => 'http://discourse.example.com ' ,
220
+ 'headers ' => [
221
+ 'Api-Key ' => 'testkey ' ,
222
+ 'Api-Username ' => 'testuser ' ,
223
+ ],
224
+ ];
225
+
226
+ $ this ->config_mock ->shouldReceive ('get ' )
227
+ ->with ('services.discourse.url ' )
228
+ ->once ()
229
+ ->andReturn ($ configs ['base_uri ' ]);
230
+
231
+ $ this ->config_mock ->shouldReceive ('get ' )
232
+ ->with ('services.discourse.api.key ' )
233
+ ->once ()
234
+ ->andReturn ($ configs ['headers ' ]['Api-Key ' ]);
235
+
236
+ $ this ->config_mock ->shouldReceive ('get ' )
237
+ ->with ('services.discourse.api.user ' )
238
+ ->once ()
239
+ ->andReturn ($ configs ['headers ' ]['Api-Username ' ]);
197
240
198
241
$ this ->response_mock ->shouldReceive ('getStatusCode ' )
199
242
->andReturn (500 );
@@ -202,13 +245,23 @@ public function if_discourse_response_code_is_not_200_log_a_notice_with_the_stat
202
245
->once ()
203
246
->andReturn ('Server error ' );
204
247
248
+ $ good_response = Mockery::mock (Response::class);
249
+
250
+ $ good_response ->shouldReceive ('getStatusCode ' )
251
+ ->once ()
252
+ ->andReturn (200 );
253
+
254
+ $ good_response ->shouldReceive ('getBody ' )
255
+ ->once ()
256
+ ->andReturn (json_encode (['user ' => $ this ->user_mock ]));
257
+
205
258
$ this ->guzzle_mock ->shouldReceive ('get ' )
206
259
->with ('users/by-external/1.json ' , $ configs )
207
260
->once ()
208
- ->andReturn ($ this -> response_mock );
261
+ ->andReturn ($ good_response );
209
262
210
263
$ this ->guzzle_mock ->shouldReceive ('post ' )
211
- ->with ('admin/users/1/log_out ' )
264
+ ->with ('admin/users/1/log_out ' , $ configs )
212
265
->andReturn ($ this ->response_mock );
213
266
214
267
$ this ->listener ->handle ($ this ->event_mock );
0 commit comments