nimuli/tests/Feature/Webhook/WebhookDispatchTest.php

26 lines
794 B
PHP

<?php
use App\Domains\Webhook\Jobs\DeliverWebhookJob;
use App\Domains\Webhook\Models\Webhook;
use Illuminate\Support\Facades\Http;
it('dispatches webhook with HMAC signature', function () {
Http::fake(['*' => Http::response('ok', 200)]);
$webhook = Webhook::factory()->create([
'url' => 'https://example.com/hook',
'secret' => 'mysecret',
'events' => ['click.recorded'],
'is_active' => true,
]);
// Run the job synchronously to test HTTP call
$job = new DeliverWebhookJob($webhook, 'click.recorded', ['link_id' => 1]);
$job->handle();
Http::assertSent(function ($request) {
return $request->hasHeader('X-Nimuli-Signature')
&& str_starts_with($request->header('X-Nimuli-Signature')[0], 'sha256=');
});
});