Implement webhook inspector
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\WebhookEndpoint;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<WebhookEndpoint>
|
||||
*/
|
||||
class WebhookEndpointFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$token = Str::random(48);
|
||||
|
||||
return [
|
||||
'user_id' => null,
|
||||
'name' => 'Test endpoint',
|
||||
'token' => $token,
|
||||
'token_hash' => WebhookEndpoint::tokenHash($token),
|
||||
'is_public' => true,
|
||||
'is_active' => true,
|
||||
'expires_at' => now()->addDays((int) config('webhooks.anonymous_ttl_days', 7)),
|
||||
'response_status' => 200,
|
||||
'response_headers' => ['Content-Type' => 'application/json'],
|
||||
'response_body' => '{}',
|
||||
'last_request_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function ownedBy(User $user): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'user_id' => $user->getKey(),
|
||||
'name' => 'Private endpoint',
|
||||
'is_public' => false,
|
||||
'expires_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function expired(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'expires_at' => now()->subMinute(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function inactive(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes): array => [
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user