mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-08 09:58:37 +02:00
WIP fixing tests to work with new relation
This commit is contained in:
parent
00889a8004
commit
e4221bc606
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
@ -10,13 +11,15 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
*/
|
||||
class WebhookEvent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function webhookConfigurationEvent(): BelongsToMany
|
||||
public function configurations(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(WebhookConfiguration::class, 'webhook_configurations_events', 'event_id', 'configuration_id');
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ class WebhookConfigurationFactory extends Factory
|
||||
return [
|
||||
'endpoint' => fake()->url(),
|
||||
'description' => fake()->sentence(),
|
||||
'events' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
18
database/Factories/WebhookEventFactory.php
Normal file
18
database/Factories/WebhookEventFactory.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\WebhookEvent;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class WebhookEventFactory extends Factory
|
||||
{
|
||||
protected $model = WebhookEvent::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->word,
|
||||
];
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ use App\Jobs\ProcessWebhook;
|
||||
use App\Models\Server;
|
||||
use App\Models\Webhook;
|
||||
use App\Models\WebhookConfiguration;
|
||||
use App\Models\WebhookEvent;
|
||||
use App\Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
||||
use Illuminate\Http\Client\Request;
|
||||
@ -26,9 +27,10 @@ class ProcessWebhooksTest extends TestCase
|
||||
|
||||
public function test_it_sends_a_single_webhook(): void
|
||||
{
|
||||
$webhook = WebhookConfiguration::factory()->create([
|
||||
'events' => [$eventName = 'eloquent.created: '.Server::class],
|
||||
]);
|
||||
$eventName = 'eloquent.created: '.Server::class;
|
||||
$webhook = WebhookConfiguration::factory()
|
||||
->has(WebhookEvent::factory()->state(['name' => $eventName]), 'webhookEvents')
|
||||
->create(['events' => []]);
|
||||
|
||||
Http::fake([$webhook->endpoint => Http::response()]);
|
||||
|
||||
@ -67,7 +69,7 @@ class ProcessWebhooksTest extends TestCase
|
||||
[$data],
|
||||
);
|
||||
|
||||
$this->assertCount(1, cache()->get("webhooks.$eventName"));
|
||||
$this->assertCount(1, cache()->get("webhooks.$eventName", []));
|
||||
$this->assertEquals($webhook->id, cache()->get("webhooks.$eventName")->first()->id);
|
||||
|
||||
Http::assertSentCount(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user