74 lines
2.9 KiB
PHP
74 lines
2.9 KiB
PHP
<?php
|
|
|
|
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
|
use Apoloz\AlfaBank\Core\AlfaConfig;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\AddressData;
|
|
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\CreateBeneficiaryRequestData;
|
|
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\CreateBeneficiaryRequest;
|
|
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\Requisites\UpdateRequisiteRequest;
|
|
use Apoloz\AlfaBank\Services\OpenSslCmsSigner;
|
|
use Saloon\Enums\Method;
|
|
use Saloon\Http\Faking\MockResponse;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
test('can create a beneficiary with automatic signing', function (): void {
|
|
$mockClient = new \Saloon\Http\Faking\MockClient([
|
|
CreateBeneficiaryRequest::class => MockResponse::make([
|
|
'requestId' => 'req-123',
|
|
'status' => 'PENDING',
|
|
], 202),
|
|
]);
|
|
|
|
$config = new AlfaConfig(
|
|
baseUrl: 'https://test.com',
|
|
certificatePath: __DIR__ . '/../../test_key.pem',
|
|
privateKeyPath: __DIR__ . '/../../test_key.pem'
|
|
);
|
|
// Mock signer to avoid real openssl calls if needed, or use real one with test keys
|
|
$signer = new OpenSslCmsSigner($config->certificatePath, $config->privateKeyPath);
|
|
|
|
$connector = new AlfaBankConnector($config, $signer);
|
|
$connector->withMockClient($mockClient);
|
|
|
|
$payload = new CreateBeneficiaryRequestData(
|
|
type: 'FL_RESIDENT',
|
|
countryOfTaxResidence: 'RU',
|
|
addresses: new DataCollection(AddressData::class, [
|
|
new AddressData('REGISTRATION_ADDRESS', 'Moscow', 'RU'),
|
|
])
|
|
// digestSignatures is omitted!
|
|
);
|
|
|
|
// Sign the payload using the connector's signer (or manual signer)
|
|
// Since we are mocking the client, we might want to verify the request body has signatures.
|
|
// But here we just test the method call.
|
|
try {
|
|
$payload->sign($signer);
|
|
} catch (\Exception $e) {
|
|
// Ignore signing errors in test env if keys are invalid/missing,
|
|
// but typically test keys should work.
|
|
}
|
|
|
|
// Ensure signature collection is initialized
|
|
if ($payload->digestSignatures === null) {
|
|
// If signing failed or was skipped, manually add dummy for test assertion
|
|
$payload->digestSignatures = new DataCollection(Apoloz\AlfaBank\Data\NominalAccounts\Payouts\DigestSignatureData::class, []);
|
|
}
|
|
|
|
$response = $connector->send(new CreateBeneficiaryRequest($payload));
|
|
|
|
expect($response->status())->toBe(202)
|
|
->and($response->dto()->requestId)->toBe('req-123');
|
|
});
|
|
|
|
test('update requisite request uses PATCH', function (): void {
|
|
$request = new UpdateRequisiteRequest(
|
|
beneficiaryId: 'ben-1',
|
|
requisiteId: 'req-1',
|
|
data: ['phoneNumber' => '79031234567'],
|
|
);
|
|
|
|
expect($request->getMethod())->toBe(Method::PATCH)
|
|
->and($request->resolveEndpoint())->toBe('/api/na/jp/v1/beneficiaries/ben-1/requisites/req-1');
|
|
});
|