Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
49
tests/Feature/LemonSqueezyRegisterWebhooksCommandTest.php
Normal file
49
tests/Feature/LemonSqueezyRegisterWebhooksCommandTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Services\LemonSqueezy\LemonSqueezyClient;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LemonSqueezyRegisterWebhooksCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_registers_webhook_with_configured_events(): void
|
||||
{
|
||||
config([
|
||||
'lemonsqueezy.webhook_events' => ['order_created', 'subscription_created'],
|
||||
'lemonsqueezy.store_id' => 'store_123',
|
||||
'lemonsqueezy.webhook_secret' => 'secret_123',
|
||||
]);
|
||||
|
||||
$client = Mockery::mock(LemonSqueezyClient::class);
|
||||
$client->shouldReceive('post')
|
||||
->once()
|
||||
->with('/webhooks', Mockery::on(function (array $payload): bool {
|
||||
$attributes = $payload['data']['attributes'] ?? [];
|
||||
$store = $payload['data']['relationships']['store']['data']['id'] ?? null;
|
||||
|
||||
return ($attributes['url'] ?? null) === 'https://example.test/lemonsqueezy/webhook'
|
||||
&& ($attributes['events'] ?? []) === ['order_created', 'subscription_created']
|
||||
&& ($attributes['secret'] ?? null) === 'secret_123'
|
||||
&& $store === 'store_123';
|
||||
}))
|
||||
->andReturn(['data' => ['id' => 'wh_123']]);
|
||||
|
||||
$this->app->instance(LemonSqueezyClient::class, $client);
|
||||
|
||||
$this->artisan('lemonsqueezy:webhooks:register', [
|
||||
'--url' => 'https://example.test/lemonsqueezy/webhook',
|
||||
])->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user