diff --git a/tests/Feature/ControllerTest.php b/tests/Feature/ControllerTest.php index f392a93..c41d5f3 100644 --- a/tests/Feature/ControllerTest.php +++ b/tests/Feature/ControllerTest.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Auth\Guard; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Session; use League\OAuth2\Client\Provider\Exception\IdentityProviderException; @@ -23,7 +24,9 @@ ->andReturn($mockGuard); $response = $this->get(route('oauth.request')); - $response->assertRedirect('/'); + + expect($response->getStatusCode())->toBe(302); + expect($response->headers->get('Location'))->toBe(Redirect::to('/')->getTargetUrl()); }); it('redirects unauthenticated users to the OAuth provider', function () { @@ -52,7 +55,8 @@ $this->assertEquals('fake_state', Session::get('oauth2-state')); $this->assertEquals('fake_pkce_code', Session::get('oauth2-pkceCode')); - $response->assertRedirect('https://example.com/oauth/authorize'); + expect($response->getStatusCode())->toBe(302); + expect($response->headers->get('Location'))->toBe('https://example.com/oauth/authorize'); }); it('redirect where the user intends to go if authenticated in the callback', function () { @@ -64,7 +68,9 @@ ->andReturn($mockGuard); $response = $this->get(route('oauth.callback')); - $response->assertRedirect('/'); + + expect($response->getStatusCode())->toBe(302); + expect($response->headers->get('Location'))->toBe(Redirect::intended()->getTargetUrl()); }); it('handles invalid or missing code in callback', function () { @@ -79,8 +85,9 @@ 'state' => 'correct_state', ]); - $response->assertRedirect(route(config('oauth.login_route_name'))) - ->assertSessionHas('message', 'Authentication failed. Please try again.'); + expect($response->getStatusCode())->toBe(302); + expect($response->headers->get('Location'))->toBe(route(config('oauth.login_route_name'))); + expect(session('message'))->toBe('Authentication failed. Please try again.'); }); it('handles invalid state in callback', function () { @@ -93,8 +100,9 @@ 'code' => 'valid_code', ])); - $response->assertRedirect(route(config('oauth.login_route_name'))) - ->assertSessionHas('message', 'Authentication failed. Please try again.'); + expect($response->getStatusCode())->toBe(302); + expect($response->headers->get('Location'))->toBe(route(config('oauth.login_route_name'))); + expect(session('message'))->toBe('Authentication failed. Please try again.'); }); it('logs in the user after a successful OAuth callback', function () { @@ -149,7 +157,8 @@ 'state' => $stateCode, ])); - $response->assertRedirect(config('oauth.redirect_route_callback_ok')); + expect($response->getStatusCode())->toBe(302); + expect($response->headers->get('Location'))->toBe(Redirect::to(config()->string('oauth.redirect_route_callback_ok'))->getTargetUrl()); }); it('renews the OAuth token if the user is authenticated and the token is expired', function () {