Files
fotospiel-app/tests/Feature/RevenueCatWebhookTest.php
Codex Agent fc3e6715db
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Add integrations health monitoring
2026-01-02 18:35:12 +01:00

71 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Jobs\ProcessRevenueCatWebhook;
use App\Models\IntegrationWebhookEvent;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Tests\TestCase;
class RevenueCatWebhookTest extends TestCase
{
use RefreshDatabase;
public function test_webhook_dispatches_job_with_valid_signature(): void
{
config()->set('services.revenuecat.webhook', 'shared-secret');
$payload = [
'event' => [
'type' => 'INITIAL_PURCHASE',
'app_user_id' => 'tenant-123',
'product_id' => 'pro_month',
],
];
$json = json_encode($payload);
$signature = base64_encode(hash_hmac('sha1', $json, 'shared-secret', true));
Bus::fake();
$response = $this->postJson('/api/v1/webhooks/revenuecat', $payload, [
'X-Event-Id' => 'evt_123',
'X-Signature' => $signature,
]);
$response->assertStatus(202)
->assertJson(['status' => 'accepted']);
$this->assertDatabaseHas('integration_webhook_events', [
'provider' => 'revenuecat',
'event_id' => 'evt_123',
'event_type' => 'INITIAL_PURCHASE',
'status' => IntegrationWebhookEvent::STATUS_RECEIVED,
]);
Bus::assertDispatched(ProcessRevenueCatWebhook::class);
}
public function test_webhook_rejects_invalid_signature(): void
{
config()->set('services.revenuecat.webhook', 'shared-secret');
Bus::fake();
$response = $this->postJson('/api/v1/webhooks/revenuecat', [
'event' => ['app_user_id' => 'tenant-123'],
], [
'X-Signature' => 'invalid-signature',
]);
$response->assertStatus(400)
->assertJsonPath('error.code', 'signature_invalid')
->assertJsonPath('error.title', 'Invalid Signature');
$this->assertDatabaseCount('integration_webhook_events', 0);
Bus::assertNotDispatched(ProcessRevenueCatWebhook::class);
}
}