Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
61
tests/Unit/LemonSqueezyCheckoutServiceTest.php
Normal file
61
tests/Unit/LemonSqueezyCheckoutServiceTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Models\Tenant;
|
||||
use App\Services\LemonSqueezy\LemonSqueezyCheckoutService;
|
||||
use App\Services\LemonSqueezy\LemonSqueezyClient;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LemonSqueezyCheckoutServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_checkout_sends_custom_data_payload(): void
|
||||
{
|
||||
$tenant = Tenant::factory()->create([
|
||||
'contact_email' => 'buyer@example.com',
|
||||
]);
|
||||
|
||||
$package = Package::factory()->create([
|
||||
'lemonsqueezy_variant_id' => 'pri_123',
|
||||
]);
|
||||
|
||||
config()->set('lemonsqueezy.store_id', 'store_123');
|
||||
|
||||
$client = Mockery::mock(LemonSqueezyClient::class);
|
||||
$client->shouldReceive('post')
|
||||
->once()
|
||||
->with('/checkouts', Mockery::on(function (array $payload) use ($tenant, $package) {
|
||||
$data = $payload['data'] ?? [];
|
||||
$attributes = $data['attributes'] ?? [];
|
||||
$custom = $attributes['checkout_data']['custom'] ?? [];
|
||||
|
||||
return ($data['type'] ?? null) === 'checkouts'
|
||||
&& ($data['relationships']['variant']['data']['id'] ?? null) === 'pri_123'
|
||||
&& ($data['relationships']['store']['data']['id'] ?? null) === 'store_123'
|
||||
&& ($custom['tenant_id'] ?? null) === (string) $tenant->id
|
||||
&& ($custom['package_id'] ?? null) === (string) $package->id
|
||||
&& ($custom['source'] ?? null) === 'test'
|
||||
&& ($custom['success_url'] ?? null) === 'https://example.test/success'
|
||||
&& ($custom['return_url'] ?? null) === 'https://example.test/cancel';
|
||||
}))
|
||||
->andReturn(['data' => ['attributes' => ['url' => 'https://lemonsqueezy.test/checkout/123'], 'id' => 'chk_123']]);
|
||||
|
||||
$this->app->instance(LemonSqueezyClient::class, $client);
|
||||
|
||||
$service = $this->app->make(LemonSqueezyCheckoutService::class);
|
||||
|
||||
$checkout = $service->createCheckout($tenant, $package, [
|
||||
'success_url' => 'https://example.test/success',
|
||||
'return_url' => 'https://example.test/cancel',
|
||||
'metadata' => ['source' => 'test'],
|
||||
]);
|
||||
|
||||
$this->assertSame('https://lemonsqueezy.test/checkout/123', $checkout['checkout_url']);
|
||||
$this->assertSame('chk_123', $checkout['id']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user