pelican-panel-mirror/tests/Feature/Webhooks/DispatchWebhooksTest.php
Charles 2525af8f02
Revert "Listen to more framework webhook events (#728)" (#866)
This reverts commit 7a4c4ce02a8e55413ebee4c470a8245c1a767f1f.
2025-01-05 19:07:01 -05:00

96 lines
2.3 KiB
PHP

<?php
namespace App\Tests\Feature\Webhooks;
use App\Jobs\ProcessWebhook;
use App\Models\Server;
use App\Models\WebhookConfiguration;
use App\Tests\TestCase;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Queue;
class DispatchWebhooksTest extends TestCase
{
use LazilyRefreshDatabase;
public function setUp(): void
{
parent::setUp();
Queue::fake();
}
public function test_it_sends_a_single_webhook(): void
{
WebhookConfiguration::factory()->create([
'events' => ['eloquent.created: '.Server::class],
]);
$this->createServer();
Queue::assertPushed(ProcessWebhook::class);
}
public function test_sends_multiple_webhooks()
{
WebhookConfiguration::factory(2)
->create(['events' => ['eloquent.created: '.Server::class]]);
$this->createServer();
Queue::assertPushed(ProcessWebhook::class, 2);
}
public function test_it_sends_no_webhooks()
{
WebhookConfiguration::factory()->create();
$this->createServer();
Queue::assertNothingPushed();
}
public function test_it_sends_some_webhooks()
{
WebhookConfiguration::factory(2)
->sequence(
['events' => ['eloquent.created: '.Server::class]],
['events' => ['eloquent.deleted: '.Server::class]]
)->create();
$this->createServer();
Queue::assertPushed(ProcessWebhook::class, 1);
}
public function test_it_does_not_call_removed_events()
{
$webhookConfig = WebhookConfiguration::factory()->create([
'events' => ['eloquent.created: '.Server::class],
]);
$webhookConfig->update(['events' => 'eloquent.deleted: '.Server::class]);
$this->createServer();
Queue::assertNothingPushed();
}
public function test_it_does_not_call_deleted_webhooks()
{
$webhookConfig = WebhookConfiguration::factory()->create([
'events' => ['eloquent.created: '.Server::class],
]);
$webhookConfig->delete();
$this->createServer();
Queue::assertNothingPushed();
}
public function createServer(): Server
{
return Server::factory()->withNode()->create();
}
}