forked from apoloz/alfa-bank-sdk
refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
28
tests/Feature/Auth/UserInfoTest.php
Normal file
28
tests/Feature/Auth/UserInfoTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Apoloz\AlfaBank\Core\AlfaConfig;
|
||||
use Apoloz\AlfaBank\Requests\Auth\UserInfo\GetUserInfoRequest;
|
||||
use Saloon\Http\Faking\MockResponse;
|
||||
|
||||
test('can get user info from JWT', function () {
|
||||
// Create a dummy JWT
|
||||
$header = base64_encode(json_encode(['alg' => 'none']));
|
||||
$payload = base64_encode(json_encode(['sub' => 'user-123', 'name' => 'John Doe']));
|
||||
$signature = '';
|
||||
$jwt = "$header.$payload.$signature";
|
||||
|
||||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||||
GetUserInfoRequest::class => MockResponse::make($jwt, 200, ['Content-Type' => 'application/jwt']),
|
||||
]);
|
||||
|
||||
$config = createTestConfig();
|
||||
$connector = new AlfaBankConnector($config);
|
||||
$connector->withMockClient($mockClient);
|
||||
|
||||
$response = $connector->send(new GetUserInfoRequest());
|
||||
|
||||
expect($response->status())->toBe(200)
|
||||
->and($response->dto()->sub)->toBe('user-123')
|
||||
->and($response->dto()->name)->toBe('John Doe');
|
||||
});
|
||||
Reference in New Issue
Block a user