Move notification event type onto events
linter / quality (pull_request) Successful in 1m28s
tests / ci (8.4) (pull_request) Successful in 1m46s

This commit is contained in:
2026-04-29 09:35:31 +00:00
parent 4832e7f984
commit ff5e54cad7
10 changed files with 26 additions and 29 deletions
@@ -245,7 +245,7 @@ class DeliverNotificationAction implements ShouldQueue
'attempt_count' => 0,
'channel' => $notificationAction->channel,
'delivery_status' => NotificationDeliveryStatus::Pending,
'event_type' => $this->event->payload()->eventType(),
'event_type' => $this->event->eventType(),
'notification_action_id' => $notificationAction->id,
'payload_metadata' => $this->payloadMetadata(),
]);
@@ -2,7 +2,11 @@
namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
interface NotificationEvent
{
public function eventType(): NotificationEventType;
public function payload(): NotificationEventPayload;
}
@@ -2,7 +2,6 @@
namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Support\Arrayable;
/**
@@ -10,8 +9,6 @@ use Illuminate\Contracts\Support\Arrayable;
*/
interface NotificationEventPayload extends Arrayable
{
public function eventType(): NotificationEventType;
public function projectId(): int;
/**
@@ -12,11 +12,12 @@ class QueueNotificationEventDeliveries
public function handle(NotificationEvent $event): void
{
$payload = $event->payload();
$eventType = $event->eventType();
NotificationAction::query()
->enabled()
->where('project_id', $payload->projectId())
->where('event_type', $payload->eventType()->value)
->where('event_type', $eventType->value)
->get(['channel', 'id'])
->each(function (NotificationAction $notificationAction) use ($event, $payload): void {
$notificationDeliveryLogId = null;
@@ -26,7 +27,7 @@ class QueueNotificationEventDeliveries
'attempt_count' => 0,
'channel' => $notificationAction->channel,
'delivery_status' => NotificationDeliveryStatus::Pending,
'event_type' => $payload->eventType(),
'event_type' => $event->eventType(),
'notification_action_id' => $notificationAction->id,
'payload_metadata' => $payload->deliveryMetadata(),
])->id;
@@ -2,6 +2,7 @@
namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
use Illuminate\Foundation\Events\Dispatchable;
@@ -13,6 +14,11 @@ final readonly class TicketCreated implements NotificationEvent, ShouldDispatchA
public TicketCreatedPayload $payload,
) {}
public function eventType(): NotificationEventType
{
return NotificationEventType::TicketCreate;
}
public function payload(): NotificationEventPayload
{
return $this->payload;
@@ -7,8 +7,6 @@ use Carbon\CarbonImmutable;
final readonly class TicketCreatedPayload implements NotificationEventPayload
{
public NotificationEventType $eventType;
public ?int $fromStatusId;
public ?string $fromStatusLabel;
@@ -27,16 +25,10 @@ final readonly class TicketCreatedPayload implements NotificationEventPayload
public string $toStatusLabel,
public CarbonImmutable $occurredAt,
) {
$this->eventType = NotificationEventType::TicketCreate;
$this->fromStatusId = null;
$this->fromStatusLabel = null;
}
public function eventType(): NotificationEventType
{
return $this->eventType;
}
public function projectId(): int
{
return $this->projectId;
@@ -84,7 +76,7 @@ final readonly class TicketCreatedPayload implements NotificationEventPayload
public function toArray(): array
{
return [
'event_type' => $this->eventType->value,
'event_type' => NotificationEventType::TicketCreate->value,
'project' => [
'id' => $this->projectId,
'key' => $this->projectKey,
@@ -2,6 +2,7 @@
namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
use Illuminate\Contracts\Events\ShouldDispatchAfterCommit;
use Illuminate\Foundation\Events\Dispatchable;
@@ -13,6 +14,11 @@ final readonly class TicketStatusChanged implements NotificationEvent, ShouldDis
public TicketStatusChangedPayload $payload,
) {}
public function eventType(): NotificationEventType
{
return NotificationEventType::TicketStatusChanged;
}
public function payload(): NotificationEventPayload
{
return $this->payload;
@@ -7,8 +7,6 @@ use Carbon\CarbonImmutable;
final readonly class TicketStatusChangedPayload implements NotificationEventPayload
{
public NotificationEventType $eventType;
public function __construct(
public int $projectId,
public string $projectKey,
@@ -24,14 +22,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
public int $toStatusId,
public string $toStatusLabel,
public CarbonImmutable $occurredAt,
) {
$this->eventType = NotificationEventType::TicketStatusChanged;
}
public function eventType(): NotificationEventType
{
return $this->eventType;
}
) {}
public function projectId(): int
{
@@ -80,7 +71,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
public function toArray(): array
{
return [
'event_type' => $this->eventType->value,
'event_type' => NotificationEventType::TicketStatusChanged->value,
'project' => [
'id' => $this->projectId,
'key' => $this->projectKey,
@@ -116,11 +116,11 @@ class TicketCreatedNotificationDispatchTest extends TestCase
&& $job->event->payload()->fromStatusLabel === null
&& $job->event->payload()->toStatusId === $backlogStatus->id
&& $job->event->payload()->toStatusLabel === 'Backlog'
&& $job->event->payload()->eventType() === NotificationEventType::TicketCreate
&& $job->event->eventType() === NotificationEventType::TicketCreate
&& $job->notificationDeliveryLogId !== null;
});
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $discordAction->id
&& $job->event->payload()->eventType() === NotificationEventType::TicketCreate
&& $job->event->eventType() === NotificationEventType::TicketCreate
&& $job->notificationDeliveryLogId !== null);
Queue::assertNotPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $disabledAction->id);
Queue::assertNotPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $statusChangedAction->id);
@@ -117,7 +117,7 @@ class TicketStatusChangedNotificationDispatchTest extends TestCase
&& $job->event->payload()->fromStatusLabel === 'Backlog'
&& $job->event->payload()->toStatusId === $doingStatus->id
&& $job->event->payload()->toStatusLabel === 'Doing'
&& $job->event->payload()->eventType() === NotificationEventType::TicketStatusChanged
&& $job->event->eventType() === NotificationEventType::TicketStatusChanged
&& $job->notificationDeliveryLogId !== null;
});
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $discordAction->id