Skip to content

Commit

Permalink
Add reproduction test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley19280 committed Feb 23, 2023
1 parent e40ae94 commit cd3603d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/Feature/RetryRequestTest.php
Expand Up @@ -263,3 +263,25 @@

$connector->sendAndRetry(new UserRequest, 0);
});


test('you can authenticate the pending request inside the retry handler', function () {
$mockClient = new MockClient([
MockResponse::make(['name' => 'Sam'], 401),
MockResponse::make(['name' => 'Gareth'], 200),
]);

$connector = new TestConnector;
$connector->withMockClient($mockClient);

$response = $connector->sendAndRetry(new UserRequest, 2, 0, function (Exception $exception, PendingRequest $pendingRequest) {

$pendingRequest->authenticate(new \Saloon\Http\Auth\TokenAuthenticator('newToken'));

return true;
});

expect($response->status())->toBe(200);
expect($response->json())->toEqual(['name' => 'Gareth']);
expect($response->getPendingRequest()->headers()->get('Authorization'))->toEqual('Bearer newToken');
});

0 comments on commit cd3603d

Please sign in to comment.