|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Saloon\Exceptions\Request\Statuses\UnauthorizedException; |
3 | 4 | use Saloon\Helpers\OAuth2\OAuthConfig; |
| 5 | +use Saloon\Http\Faking\MockClient; |
| 6 | +use Saloon\Http\Faking\MockResponse; |
4 | 7 | use Sensson\Moneybird\Connectors\AuthConnector; |
| 8 | +use Sensson\Moneybird\Exceptions\AccessTokenRevokedException; |
| 9 | +use Sensson\Moneybird\Requests\Administrations\ListAdministrations; |
5 | 10 |
|
6 | 11 | test('auth connector has correct base url', function () { |
7 | 12 | $connector = new AuthConnector; |
|
25 | 30 | ->and($oauthConfig->getAuthorizeEndpoint())->toBe('authorize') |
26 | 31 | ->and($oauthConfig->getTokenEndpoint())->toBe('token'); |
27 | 32 | }); |
| 33 | + |
| 34 | +it('throws AccessTokenRevokedException when access token is revoked', function () { |
| 35 | + $mockClient = new MockClient([ |
| 36 | + ListAdministrations::class => MockResponse::make('access token revoked', 401), |
| 37 | + ]); |
| 38 | + |
| 39 | + $connector = (new AuthConnector)->withMockClient($mockClient); |
| 40 | + $connector->send(new ListAdministrations); |
| 41 | +})->throws(AccessTokenRevokedException::class); |
| 42 | + |
| 43 | +it('does not throw AccessTokenRevokedException for other 401 responses', function () { |
| 44 | + $mockClient = new MockClient([ |
| 45 | + ListAdministrations::class => MockResponse::make('unauthorized', 401), |
| 46 | + ]); |
| 47 | + |
| 48 | + $connector = (new AuthConnector)->withMockClient($mockClient); |
| 49 | + $connector->send(new ListAdministrations); |
| 50 | +})->throws(UnauthorizedException::class); |
0 commit comments