Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
52
tests/Unit/LemonSqueezyOrderServiceTest.php
Normal file
52
tests/Unit/LemonSqueezyOrderServiceTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\LemonSqueezy\LemonSqueezyClient;
|
||||
use App\Services\LemonSqueezy\LemonSqueezyOrderService;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LemonSqueezyOrderServiceTest extends TestCase
|
||||
{
|
||||
public function test_list_for_customer_uses_expected_filters(): void
|
||||
{
|
||||
$client = Mockery::mock(LemonSqueezyClient::class);
|
||||
$client->shouldReceive('get')
|
||||
->once()
|
||||
->with('/orders', Mockery::on(function (array $payload) {
|
||||
return $payload['filter[customer_id]'] === 'ctm_123'
|
||||
&& $payload['sort'] === '-created_at';
|
||||
}))
|
||||
->andReturn(['data' => [], 'meta' => []]);
|
||||
|
||||
$this->app->instance(LemonSqueezyClient::class, $client);
|
||||
|
||||
$service = $this->app->make(LemonSqueezyOrderService::class);
|
||||
$service->listForCustomer('ctm_123');
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function test_find_by_checkout_id_uses_checkout_then_order_lookup(): void
|
||||
{
|
||||
$client = Mockery::mock(LemonSqueezyClient::class);
|
||||
$client->shouldReceive('get')
|
||||
->once()
|
||||
->with('/checkouts/chk_123', [])
|
||||
->andReturn(['data' => ['attributes' => ['order_id' => 'ord_123']]]);
|
||||
|
||||
$client->shouldReceive('get')
|
||||
->once()
|
||||
->with('/orders/ord_123', [])
|
||||
->andReturn(['data' => ['id' => 'ord_123', 'attributes' => ['status' => 'paid']]]);
|
||||
|
||||
$this->app->instance(LemonSqueezyClient::class, $client);
|
||||
|
||||
$service = $this->app->make(LemonSqueezyOrderService::class);
|
||||
$order = $service->findByCheckoutId('chk_123');
|
||||
|
||||
$this->assertIsArray($order);
|
||||
$this->assertSame('ord_123', $order['id'] ?? null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user