Add notification action foundation
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Enums\NotificationChannel;
|
||||
use App\Enums\NotificationDeliveryStatus;
|
||||
use App\Models\NotificationDeliveryLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotificationDeliveryLogTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure delivery log factories create related notification actions with consistent casts.
|
||||
*/
|
||||
public function test_delivery_log_factory_creates_a_related_notification_action(): void
|
||||
{
|
||||
$deliveryLog = NotificationDeliveryLog::factory()->create();
|
||||
|
||||
$this->assertTrue($deliveryLog->notificationAction()->exists());
|
||||
$this->assertTrue($deliveryLog->notificationAction->is($deliveryLog->fresh()->notificationAction));
|
||||
$this->assertSame(NotificationChannel::Webhook, $deliveryLog->fresh()->channel);
|
||||
$this->assertSame(NotificationDeliveryStatus::Pending, $deliveryLog->fresh()->delivery_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure delivery logs can represent every supported delivery state.
|
||||
*/
|
||||
public function test_delivery_logs_support_pending_succeeded_failed_and_retryable_statuses(): void
|
||||
{
|
||||
NotificationDeliveryLog::factory()->pending()->create();
|
||||
NotificationDeliveryLog::factory()->succeeded()->create();
|
||||
NotificationDeliveryLog::factory()->failed()->create();
|
||||
NotificationDeliveryLog::factory()->retryable()->create();
|
||||
|
||||
$this->assertSame(
|
||||
[
|
||||
NotificationDeliveryStatus::Pending,
|
||||
NotificationDeliveryStatus::Succeeded,
|
||||
NotificationDeliveryStatus::Failed,
|
||||
NotificationDeliveryStatus::Retryable,
|
||||
],
|
||||
NotificationDeliveryLog::query()->orderBy('id')->get()->pluck('delivery_status')->all(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure delivery logs cast metadata and attempt information for later delivery tracking.
|
||||
*/
|
||||
public function test_delivery_logs_cast_metadata_and_attempt_information(): void
|
||||
{
|
||||
$deliveryLog = NotificationDeliveryLog::factory()->succeeded()->create([
|
||||
'payload_metadata' => [
|
||||
'project_key' => 'CORE',
|
||||
'ticket_key' => 'CORE-27',
|
||||
],
|
||||
])->fresh();
|
||||
|
||||
$this->assertSame('CORE-27', $deliveryLog->payload_metadata['ticket_key']);
|
||||
$this->assertSame(204, $deliveryLog->http_status);
|
||||
$this->assertNotNull($deliveryLog->last_attempted_at);
|
||||
$this->assertNotNull($deliveryLog->delivered_at);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user