forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifyWebhookTestResultTest.php
More file actions
59 lines (47 loc) · 1.52 KB
/
Copy pathNotifyWebhookTestResultTest.php
File metadata and controls
59 lines (47 loc) · 1.52 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
54
55
56
57
58
59
<?php
use App\Models\User;
use Filament\Notifications\DatabaseNotification;
use Illuminate\Support\Facades\Notification;
use Spatie\WebhookServer\Events\FinalWebhookCallFailedEvent;
use Spatie\WebhookServer\Events\WebhookCallSucceededEvent;
beforeEach(function () {
Notification::fake();
});
function testWebhookEvent(string $class, array $meta): object
{
return new $class(
httpVerb: 'post',
webhookUrl: 'https://example.com/hook',
payload: [],
headers: [],
meta: $meta,
tags: [],
attempt: 1,
response: null,
errorType: null,
errorMessage: 'Connection refused',
uuid: 'test-uuid',
transferStats: null,
);
}
it('notifies the user on a successful test delivery', function () {
$user = User::factory()->create();
event(testWebhookEvent(WebhookCallSucceededEvent::class, [
'webhook_test' => true,
'user_id' => $user->id,
]));
Notification::assertSentTo($user, DatabaseNotification::class);
});
it('notifies the user on a failed test delivery', function () {
$user = User::factory()->create();
event(testWebhookEvent(FinalWebhookCallFailedEvent::class, [
'webhook_test' => true,
'user_id' => $user->id,
]));
Notification::assertSentTo($user, DatabaseNotification::class);
});
it('ignores webhook events that are not tests', function () {
User::factory()->create();
event(testWebhookEvent(WebhookCallSucceededEvent::class, []));
Notification::assertNothingSent();
});