forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatchWebhooksTest.php
More file actions
53 lines (39 loc) · 1.69 KB
/
Copy pathDispatchWebhooksTest.php
File metadata and controls
53 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
use App\Enums\WebhookEvent;
use App\Events\SpeedtestCompleted;
use App\Models\Result;
use App\Models\Webhook;
use Illuminate\Support\Facades\Bus;
use Spatie\WebhookServer\CallWebhookJob;
beforeEach(function () {
Bus::fake();
});
it('dispatches only enabled webhooks subscribed to the fired event', function () {
Webhook::factory()->create(['events' => [WebhookEvent::Completed->value]]);
Webhook::factory()->create(['events' => [WebhookEvent::Failed->value]]);
Webhook::factory()->disabled()->create(['events' => [WebhookEvent::Completed->value]]);
SpeedtestCompleted::dispatch(Result::factory()->create());
Bus::assertDispatchedTimes(CallWebhookJob::class, 1);
});
it('dispatches a webhook subscribed to multiple events for each matching event', function () {
Webhook::factory()->create([
'events' => [WebhookEvent::Completed->value, WebhookEvent::Failed->value],
]);
SpeedtestCompleted::dispatch(Result::factory()->create());
Bus::assertDispatched(CallWebhookJob::class, function (CallWebhookJob $job) {
return $job->webhookUrl !== null;
});
});
it('does not dispatch when no webhook subscribes to the event', function () {
Webhook::factory()->create(['events' => [WebhookEvent::Failed->value]]);
SpeedtestCompleted::dispatch(Result::factory()->create());
Bus::assertNotDispatched(CallWebhookJob::class);
});
it('dispatches a signed webhook when a secret is set', function () {
Webhook::factory()->create([
'events' => [WebhookEvent::Completed->value],
'secret' => 'super-secret',
]);
SpeedtestCompleted::dispatch(Result::factory()->create());
Bus::assertDispatchedTimes(CallWebhookJob::class, 1);
});