Files
fotospiel-app/tests/Feature/LemonSqueezyRegisterWebhooksCommandTest.php
2026-02-03 10:59:54 +01:00

50 lines
1.6 KiB
PHP

<?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);
}
}