@@ -31,7 +31,17 @@ private function getDriver($responseData, $htmlInterface = null)
31
31
$ htmlInterface = m::mock (Curl::class);
32
32
}
33
33
34
- return new SlackDriver ($ request , [], $ htmlInterface );
34
+ $ slackConfig = ['token ' => 'Foo ' ];
35
+ $ response = new Response ('{"ok": true,"url": "https:\/\/myteam.slack.com\/","team": "My Team","user": "cal","team_id": "T12345","user_id": "U0X12345"} ' );
36
+
37
+ $ htmlInterface ->shouldReceive ('post ' )
38
+ ->once ()
39
+ ->with ('https://slack.com/api/auth.test ' , [], $ slackConfig )
40
+ ->andReturn ($ response );
41
+
42
+ $ this ->mockUserInfoEndpoint ($ htmlInterface );
43
+
44
+ return new SlackDriver ($ request , ['slack ' => $ slackConfig ], $ htmlInterface );
35
45
}
36
46
37
47
/** @test */
@@ -183,11 +193,13 @@ public function it_returns_the_user_object()
183
193
],
184
194
];
185
195
186
- $ response =
new Response (
'{"ok":true,"user":{"id": "U0X12345","name": "botman","deleted": false,"color": "9f69e7","profile": {"avatar_hash": "ge3b51ca72de","status_emoji": ":mountain_railway:","status_text": "riding a train","first_name": "Bot","last_name": "Man","real_name": "Bot Man","email": "[email protected] ","skype": "my-skype-name","phone": "+1 (123) 456 7890","image_24": "http:\/\/via.placeholder.com\/24","image_32": "http:\/\/via.placeholder.com\/32","image_48": "http:\/\/via.placeholder.com\/48","image_72": "http:\/\/via.placeholder.com\/72","image_192": "http:\/\/via.placeholder.com\/192","image_512": "http:\/\/via.placeholder.com\/512"},"is_admin": true, "is_owner": true,"is_primary_owner": true,"is_restricted": false,"is_ultra_restricted": false,"updated": 1490054400,"has_2fa": false,"two_factor_type": "sms"}} ' );
187
-
188
196
$ html = m::mock (Curl::class);
197
+
198
+ $ this ->mockAuthTestEndpoint ($ html );
199
+
200
+ $ response =
new Response (
'{"ok":true,"user":{"id": "U0X12345","name": "botman","deleted": false,"color": "9f69e7","profile": {"bot_id":"foo", "avatar_hash": "ge3b51ca72de","status_emoji": ":mountain_railway:","status_text": "riding a train","first_name": "Bot","last_name": "Man","real_name": "Bot Man","email": "[email protected] ","skype": "my-skype-name","phone": "+1 (123) 456 7890","image_24": "http:\/\/via.placeholder.com\/24","image_32": "http:\/\/via.placeholder.com\/32","image_48": "http:\/\/via.placeholder.com\/48","image_72": "http:\/\/via.placeholder.com\/72","image_192": "http:\/\/via.placeholder.com\/192","image_512": "http:\/\/via.placeholder.com\/512"},"is_admin": true, "is_owner": true,"is_primary_owner": true,"is_restricted": false,"is_ultra_restricted": false,"updated": 1490054400,"has_2fa": false,"two_factor_type": "sms","is_bot": true}} ' );
201
+
189
202
$ html ->shouldReceive ('post ' )
190
- ->once ()
191
203
->with ('https://slack.com/api/users.info ' , [], [
192
204
'token ' => 'Foo ' ,
193
205
'user ' => 'U0X12345 ' ,
@@ -392,6 +404,10 @@ public function it_can_reply_string_messages()
392
404
];
393
405
394
406
$ html = m::mock (Curl::class);
407
+
408
+ $ this ->mockAuthTestEndpoint ($ html );
409
+ $ this ->mockUserInfoEndpoint ($ html );
410
+
395
411
$ html ->shouldReceive ('post ' )
396
412
->once ()
397
413
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -426,6 +442,9 @@ public function it_can_reply_message_objects()
426
442
];
427
443
428
444
$ html = m::mock (Curl::class);
445
+ $ this ->mockAuthTestEndpoint ($ html );
446
+ $ this ->mockUserInfoEndpoint ($ html );
447
+
429
448
$ html ->shouldReceive ('post ' )
430
449
->once ()
431
450
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -460,6 +479,9 @@ public function it_can_reply_message_objects_with_image()
460
479
];
461
480
462
481
$ html = m::mock (Curl::class);
482
+ $ this ->mockAuthTestEndpoint ($ html );
483
+ $ this ->mockUserInfoEndpoint ($ html );
484
+
463
485
$ html ->shouldReceive ('post ' )
464
486
->once ()
465
487
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -538,6 +560,9 @@ public function it_can_reply_questions_with_additional_button_parameters()
538
560
->addButton (Button::create ('Good ' ));
539
561
540
562
$ html = m::mock (Curl::class);
563
+ $ this ->mockAuthTestEndpoint ($ html );
564
+ $ this ->mockUserInfoEndpoint ($ html );
565
+
541
566
$ html ->shouldReceive ('post ' )
542
567
->once ()
543
568
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -577,6 +602,9 @@ public function it_can_reply_questions()
577
602
->addButton (Button::create ('Good ' ));
578
603
579
604
$ html = m::mock (Curl::class);
605
+ $ this ->mockAuthTestEndpoint ($ html );
606
+ $ this ->mockUserInfoEndpoint ($ html );
607
+
580
608
$ html ->shouldReceive ('post ' )
581
609
->once ()
582
610
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -612,6 +640,9 @@ public function it_can_reply_with_additional_parameters()
612
640
];
613
641
614
642
$ html = m::mock (Curl::class);
643
+ $ this ->mockAuthTestEndpoint ($ html );
644
+ $ this ->mockUserInfoEndpoint ($ html );
645
+
615
646
$ html ->shouldReceive ('post ' )
616
647
->once ()
617
648
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -658,6 +689,9 @@ public function it_can_reply_in_threads()
658
689
];
659
690
660
691
$ html = m::mock (Curl::class);
692
+ $ this ->mockAuthTestEndpoint ($ html );
693
+ $ this ->mockUserInfoEndpoint ($ html );
694
+
661
695
$ html ->shouldReceive ('post ' )
662
696
->once ()
663
697
->with ('https://slack.com/api/chat.postMessage ' , [], [
@@ -706,6 +740,9 @@ public function it_is_configured()
706
740
$ request ->shouldReceive ('getContent ' )->andReturn ('' );
707
741
$ htmlInterface = m::mock (Curl::class);
708
742
743
+ $ this ->mockAuthTestEndpoint ($ htmlInterface );
744
+ $ this ->mockUserInfoEndpoint ($ htmlInterface );
745
+
709
746
$ driver = new SlackDriver ($ request , [
710
747
'slack ' => [
711
748
'token ' => 'Foo ' ,
@@ -726,4 +763,39 @@ public function it_is_configured()
726
763
727
764
$ this ->assertFalse ($ driver ->isConfigured ());
728
765
}
766
+
767
+ /**
768
+ * Mocks the auth.test endpoint request.
769
+ *
770
+ * @param $htmlInterface
771
+ */
772
+ private function mockAuthTestEndpoint ($ htmlInterface )
773
+ {
774
+ $ response = new Response ('{"ok": true,"url": "https:\/\/myteam.slack.com\/","team": "My Team","user": "cal","team_id": "T12345","user_id": "U0X12345"} ' );
775
+
776
+ $ htmlInterface ->shouldReceive ('post ' )
777
+ ->once ()
778
+ ->with ('https://slack.com/api/auth.test ' , [], [
779
+ 'token ' => 'Foo ' ,
780
+ ])
781
+ ->andReturn ($ response );
782
+ }
783
+
784
+ /**
785
+ * Mocks the users.info endpoint request.
786
+ *
787
+ * @param $htmlInterface
788
+ */
789
+ private function mockUserInfoEndpoint ($ htmlInterface )
790
+ {
791
+ $ response =
new Response (
'{"ok":true,"user":{"id": "U0X12345","name": "botman","deleted": false,"color": "9f69e7","profile": {"avatar_hash": "ge3b51ca72de","status_emoji": ":mountain_railway:","status_text": "riding a train","first_name": "Bot","last_name": "Man","real_name": "Bot Man","email": "[email protected] ","skype": "my-skype-name","phone": "+1 (123) 456 7890","image_24": "http:\/\/via.placeholder.com\/24","image_32": "http:\/\/via.placeholder.com\/32","image_48": "http:\/\/via.placeholder.com\/48","image_72": "http:\/\/via.placeholder.com\/72","image_192": "http:\/\/via.placeholder.com\/192","image_512": "http:\/\/via.placeholder.com\/512"},"is_admin": true, "is_owner": true,"is_primary_owner": true,"is_restricted": false,"is_ultra_restricted": false,"updated": 1490054400,"has_2fa": false,"two_factor_type": "sms", "is_bot": true, "profile":{"bot_id":"foo"}}} ' );
792
+
793
+ $ htmlInterface ->shouldReceive ('post ' )
794
+ ->once ()
795
+ ->with ('https://slack.com/api/users.info ' , [], [
796
+ 'token ' => 'Foo ' ,
797
+ 'user ' => 'U0X12345 ' ,
798
+ ])
799
+ ->andReturn ($ response );
800
+ }
729
801
}
0 commit comments