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:
65
tests/Feature/Registries/RegistryTest.php
Normal file
65
tests/Feature/Registries/RegistryTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Apoloz\AlfaBank\Data\Registries\RegistryPaymentData;
|
||||
use Apoloz\AlfaBank\Data\Registries\RegistryRequestData;
|
||||
use Apoloz\AlfaBank\Data\Registries\RegistrySignatureData;
|
||||
use Apoloz\AlfaBank\Requests\Registries\CreateRegistryRequest;
|
||||
use Apoloz\AlfaBank\Requests\Registries\SignRegistryRequest;
|
||||
use Saloon\Http\Faking\MockResponse;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
test('can create payment registry', function () {
|
||||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||||
CreateRegistryRequest::class => MockResponse::make([
|
||||
'id' => 'REG-123',
|
||||
'status' => 'CREATED'
|
||||
], 201),
|
||||
]);
|
||||
|
||||
$config = createTestConfig();
|
||||
$connector = new AlfaBankConnector($config);
|
||||
$connector->withMockClient($mockClient);
|
||||
|
||||
$payload = new RegistryRequestData(
|
||||
payments: RegistryPaymentData::collect([
|
||||
[
|
||||
'amount' => 100.0,
|
||||
'date' => '2023-10-10',
|
||||
'payeeAccount' => '40702...',
|
||||
'payeeBankBic' => '044...',
|
||||
'payeeInn' => '770...',
|
||||
'payeeName' => 'Recipient LLC',
|
||||
'payerAccount' => '40702...',
|
||||
'purpose' => 'Payment'
|
||||
]
|
||||
], DataCollection::class)
|
||||
);
|
||||
|
||||
$response = $connector->send(new CreateRegistryRequest($payload));
|
||||
|
||||
expect($response->status())->toBe(201)
|
||||
->and($response->json('id'))->toBe('REG-123');
|
||||
});
|
||||
|
||||
test('can sign payment registry', function () {
|
||||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||||
SignRegistryRequest::class => MockResponse::make([], 200),
|
||||
]);
|
||||
|
||||
$config = createTestConfig();
|
||||
$connector = new AlfaBankConnector($config);
|
||||
$connector->withMockClient($mockClient);
|
||||
|
||||
$signatures = RegistrySignatureData::collect([
|
||||
[
|
||||
'base64Encoded' => 'SIG...',
|
||||
'signatureType' => 'RSA',
|
||||
'certificateUuid' => 'CERT-123'
|
||||
]
|
||||
], DataCollection::class);
|
||||
|
||||
$response = $connector->send(new SignRegistryRequest('REG-123', $signatures));
|
||||
|
||||
expect($response->status())->toBe(200);
|
||||
});
|
||||
Reference in New Issue
Block a user