diff --git a/tests/Unit/MacroTest.php b/tests/Unit/MacroTest.php index 4827938..3801418 100644 --- a/tests/Unit/MacroTest.php +++ b/tests/Unit/MacroTest.php @@ -114,7 +114,7 @@ function (Request $request) { ), [ 'scopes' => ['scope1', 'scope2'], - 'tokenType' => AccessToken::TYPE_BEARER, + 'tokenType' => AccessToken::TOKEN_TYPE_BEARER, 'authType' => Credentials::AUTH_TYPE_BASIC, 'cacheDriver' => 'file', 'cacheKey' => 'my_cache_key', diff --git a/tests/Unit/RefreshTokenTest.php b/tests/Unit/RefreshTokenTest.php index 75d71d1..ecc8f61 100644 --- a/tests/Unit/RefreshTokenTest.php +++ b/tests/Unit/RefreshTokenTest.php @@ -1,6 +1,8 @@ $httpClient->withHeader('Authorization', 'my_custom_token'); + $accessToken = app(RefreshToken::class)( 'https://example.com/oauth/token', new Credentials( @@ -94,11 +99,12 @@ scopes: ['scope1', 'scope2'], grantType: 'password_credentials', tokenType: AccessToken::TOKEN_TYPE_CUSTOM, - tokenTypeCustomCallback: fn (PendingRequest $httpClient) => $httpClient->withHeader('Authorization', 'my_custom_token'), + tokenTypeCustomCallback: $callback, ), ); - expect($accessToken->getAccessToken())->toEqual('this_is_my_access_token_from_body_refresh_token'); + expect($accessToken->getAccessToken())->toEqual('this_is_my_access_token_from_body_refresh_token') + ->and($accessToken->getCustomCallback())->toEqual($callback); Http::assertSent(static function (Request $request) { return $request->url() === 'https://example.com/oauth/token' && $request->hasHeader('Authorization', 'my_custom_token') @@ -209,4 +215,36 @@ ); }); */ + + test('throws exception with an invalid auth type', function () { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('customCallback must be set when using AUTH_TYPE_CUSTOM'); + + app(RefreshToken::class)( + 'https://example.com/oauth/token', + new Credentials(['my_token']), + new Options( + scopes: ['scope1', 'scope2'], + tokenType: AccessToken::TOKEN_TYPE_CUSTOM, + ), + ); + }); + + + test('access token getters', function () { + + $accessToken = app(RefreshToken::class)( + 'https://example.com/oauth/token', + new Credentials(['my_token']), + new Options( + scopes: ['scope1', 'scope2'], + ), + ); + + expect($accessToken->getAccessToken())->toBe('this_is_my_access_token_from_body_refresh_token') + ->and($accessToken->getExpiresIn())->toBe(3540) + ->and($accessToken->getExpiresAt())->toBeInstanceOf(Carbon::class) + ->and($accessToken->getCustomCallback())->toBeNull(); + }); + })->done(assignee: 'pelmered');