71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Tenant;
|
|
|
|
use App\Models\Package;
|
|
use App\Services\PayPal\PayPalOrderService;
|
|
use Mockery;
|
|
|
|
class TenantPayPalCheckoutTest extends TenantTestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_tenant_can_create_paypal_checkout(): void
|
|
{
|
|
$package = Package::factory()->create([
|
|
'price' => 129,
|
|
]);
|
|
|
|
$checkoutService = Mockery::mock(PayPalOrderService::class);
|
|
$checkoutService->shouldReceive('createOrder')
|
|
->once()
|
|
->withArgs(function ($session, $payloadPackage, array $payload) use ($package) {
|
|
return $session->tenant?->is($this->tenant)
|
|
&& $payloadPackage->is($package)
|
|
&& array_key_exists('return_url', $payload)
|
|
&& array_key_exists('cancel_url', $payload)
|
|
&& array_key_exists('request_id', $payload);
|
|
})
|
|
->andReturn([
|
|
'id' => 'order_test_123',
|
|
'status' => 'CREATED',
|
|
'links' => [
|
|
[
|
|
'rel' => 'approve',
|
|
'href' => 'https://paypal.test/checkout/123',
|
|
],
|
|
],
|
|
]);
|
|
$checkoutService->shouldReceive('resolveApproveUrl')
|
|
->once()
|
|
->andReturn('https://paypal.test/checkout/123');
|
|
$this->instance(PayPalOrderService::class, $checkoutService);
|
|
|
|
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/packages/paypal-checkout', [
|
|
'package_id' => $package->id,
|
|
]);
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('approve_url', 'https://paypal.test/checkout/123')
|
|
->assertJsonPath('order_id', 'order_test_123')
|
|
->assertJsonStructure(['checkout_session_id']);
|
|
}
|
|
|
|
public function test_paypal_checkout_requires_package_id(): void
|
|
{
|
|
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/packages/paypal-checkout', []);
|
|
|
|
$response->assertStatus(422)
|
|
->assertJsonStructure([
|
|
'errors' => [
|
|
'package_id' => [],
|
|
],
|
|
]);
|
|
}
|
|
}
|