File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Dcblogdev \MsGraph \Facades \MsGraphAdmin ;
4+ use Dcblogdev \MsGraph \MsGraphAdminAuthenticated ;
5+ use Illuminate \Support \Facades \Route ;
6+
7+ beforeEach (function () {
8+ Route::middleware (MsGraphAdminAuthenticated::class)->get ('/test-route ' , function () {
9+ return response ()->json (['message ' => 'Access granted ' ]);
10+ });
11+ });
12+
13+ test ('redirects to MsGraphAdmin::connect() when not connected ' , function () {
14+ // Mock MsGraphAdmin::isConnected() to return false
15+ MsGraphAdmin::shouldReceive ('isConnected ' )->once ()->andReturn (false );
16+ MsGraphAdmin::shouldReceive ('connect ' )->once ()->andReturn (redirect ('https://login.microsoftonline.com ' ));
17+
18+ $ response = $ this ->get ('/test-route ' );
19+
20+ $ response ->assertRedirect ('https://login.microsoftonline.com ' );
21+ });
22+
23+ test ('allows request when MsGraphAdmin is connected ' , function () {
24+ // Mock MsGraphAdmin::isConnected() to return true
25+ MsGraphAdmin::shouldReceive ('isConnected ' )->once ()->andReturn (true );
26+
27+ $ response = $ this ->get ('/test-route ' );
28+
29+ $ response ->assertOk ()
30+ ->assertJson (['message ' => 'Access granted ' ]);
31+ });
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Dcblogdev \MsGraph \Facades \MsGraph ;
4+ use Dcblogdev \MsGraph \MsGraphAuthenticated ;
5+ use Illuminate \Support \Facades \Route ;
6+
7+ beforeEach (function () {
8+ Route::middleware (MsGraphAuthenticated::class)->get ('/test-route ' , function () {
9+ return response ()->json (['message ' => 'Access granted ' ]);
10+ });
11+ });
12+
13+ test ('redirects to MsGraph::connect() when not connected ' , function () {
14+ // Mock MsGraph::isConnected() to return false
15+ MsGraph::shouldReceive ('isConnected ' )->once ()->andReturn (false );
16+ MsGraph::shouldReceive ('connect ' )->once ()->andReturn (redirect ('https://login.microsoftonline.com ' ));
17+
18+ $ response = $ this ->get ('/test-route ' );
19+
20+ $ response ->assertRedirect ('https://login.microsoftonline.com ' );
21+ });
22+
23+ test ('allows request when MsGraph is connected ' , function () {
24+ // Mock MsGraph::isConnected() to return true
25+ MsGraph::shouldReceive ('isConnected ' )->once ()->andReturn (true );
26+
27+ $ response = $ this ->get ('/test-route ' );
28+
29+ $ response ->assertOk ()
30+ ->assertJson (['message ' => 'Access granted ' ]);
31+ });
You can’t perform that action at this time.
0 commit comments