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