Use dedicated assignee notification payload
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Actions\Notifications;
|
namespace App\Actions\Notifications;
|
||||||
|
|
||||||
use App\Enums\NotificationEventType;
|
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
use App\Models\TicketStatus;
|
use App\Models\TicketStatus;
|
||||||
@@ -20,11 +19,10 @@ class BuildTicketAssigneeChangedPayload
|
|||||||
?int $toAssigneeId,
|
?int $toAssigneeId,
|
||||||
?string $toAssigneeName,
|
?string $toAssigneeName,
|
||||||
CarbonImmutable $occurredAt,
|
CarbonImmutable $occurredAt,
|
||||||
): TicketStatusChangedPayload {
|
): TicketAssigneeChangedPayload {
|
||||||
$ticket->loadMissing('ticketStatus.boardColumn');
|
$ticket->loadMissing('ticketStatus.boardColumn');
|
||||||
|
|
||||||
return new TicketStatusChangedPayload(
|
return new TicketAssigneeChangedPayload(
|
||||||
eventType: NotificationEventType::TicketAssigneeChanged,
|
|
||||||
projectId: $project->id,
|
projectId: $project->id,
|
||||||
projectKey: $project->key,
|
projectKey: $project->key,
|
||||||
projectName: $project->name,
|
projectName: $project->name,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ final readonly class TicketAssigneeChanged implements NotificationEvent, ShouldD
|
|||||||
use Dispatchable;
|
use Dispatchable;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public TicketStatusChangedPayload $payload,
|
public TicketAssigneeChangedPayload $payload,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function eventType(): NotificationEventType
|
public function eventType(): NotificationEventType
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Notifications;
|
||||||
|
|
||||||
|
use App\Enums\NotificationEventType;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
|
||||||
|
final readonly class TicketAssigneeChangedPayload implements NotificationEventPayload
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $projectId,
|
||||||
|
public string $projectKey,
|
||||||
|
public string $projectName,
|
||||||
|
public int $ticketId,
|
||||||
|
public string $ticketKey,
|
||||||
|
public string $ticketTitle,
|
||||||
|
public string $ticketUrl,
|
||||||
|
public ?int $actorId,
|
||||||
|
public ?string $actorName,
|
||||||
|
public ?int $fromStatusId,
|
||||||
|
public ?string $fromStatusLabel,
|
||||||
|
public int $toStatusId,
|
||||||
|
public string $toStatusLabel,
|
||||||
|
public CarbonImmutable $occurredAt,
|
||||||
|
public ?int $fromAssigneeId,
|
||||||
|
public ?string $fromAssigneeName,
|
||||||
|
public ?int $toAssigneeId,
|
||||||
|
public ?string $toAssigneeName,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function projectId(): int
|
||||||
|
{
|
||||||
|
return $this->projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, scalar|null>
|
||||||
|
*/
|
||||||
|
public function deliveryMetadata(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'project_key' => $this->projectKey,
|
||||||
|
'ticket_key' => $this->ticketKey,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function discordTemplateVariables(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'$url' => $this->ticketUrl,
|
||||||
|
'$ticket_key' => $this->ticketKey,
|
||||||
|
'$ticket_title' => $this->ticketTitle,
|
||||||
|
'$project_name' => $this->projectName,
|
||||||
|
'$status_from' => $this->fromStatusLabel ?? '',
|
||||||
|
'$status_to' => $this->toStatusLabel,
|
||||||
|
'$actor_name' => $this->actorName ?? '',
|
||||||
|
'$assignee_from' => $this->fromAssigneeName ?? '',
|
||||||
|
'$assignee_to' => $this->toAssigneeName ?? '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* event_type: string,
|
||||||
|
* project: array{id: int, key: string, name: string},
|
||||||
|
* ticket: array{id: int, key: string, title: string},
|
||||||
|
* actor: array{id: int, name: string}|null,
|
||||||
|
* assignee: array{
|
||||||
|
* from: array{id: int, name: string}|null,
|
||||||
|
* to: array{id: int, name: string}|null
|
||||||
|
* },
|
||||||
|
* from: array{id: int, label: string}|null,
|
||||||
|
* to: array{id: int, label: string},
|
||||||
|
* ticket_url: string,
|
||||||
|
* occurred_at: string
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'event_type' => NotificationEventType::TicketAssigneeChanged->value,
|
||||||
|
'project' => [
|
||||||
|
'id' => $this->projectId,
|
||||||
|
'key' => $this->projectKey,
|
||||||
|
'name' => $this->projectName,
|
||||||
|
],
|
||||||
|
'ticket' => [
|
||||||
|
'id' => $this->ticketId,
|
||||||
|
'key' => $this->ticketKey,
|
||||||
|
'title' => $this->ticketTitle,
|
||||||
|
],
|
||||||
|
'actor' => $this->actorId === null || $this->actorName === null
|
||||||
|
? null
|
||||||
|
: [
|
||||||
|
'id' => $this->actorId,
|
||||||
|
'name' => $this->actorName,
|
||||||
|
],
|
||||||
|
'assignee' => [
|
||||||
|
'from' => $this->fromAssigneeId === null || $this->fromAssigneeName === null
|
||||||
|
? null
|
||||||
|
: [
|
||||||
|
'id' => $this->fromAssigneeId,
|
||||||
|
'name' => $this->fromAssigneeName,
|
||||||
|
],
|
||||||
|
'to' => $this->toAssigneeId === null || $this->toAssigneeName === null
|
||||||
|
? null
|
||||||
|
: [
|
||||||
|
'id' => $this->toAssigneeId,
|
||||||
|
'name' => $this->toAssigneeName,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'from' => $this->fromStatusId === null || $this->fromStatusLabel === null
|
||||||
|
? null
|
||||||
|
: [
|
||||||
|
'id' => $this->fromStatusId,
|
||||||
|
'label' => $this->fromStatusLabel,
|
||||||
|
],
|
||||||
|
'to' => [
|
||||||
|
'id' => $this->toStatusId,
|
||||||
|
'label' => $this->toStatusLabel,
|
||||||
|
],
|
||||||
|
'ticket_url' => $this->ticketUrl,
|
||||||
|
'occurred_at' => $this->occurredAt->toISOString(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,16 +17,11 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
|
|||||||
public string $ticketUrl,
|
public string $ticketUrl,
|
||||||
public ?int $actorId,
|
public ?int $actorId,
|
||||||
public ?string $actorName,
|
public ?string $actorName,
|
||||||
public ?int $fromStatusId,
|
public int $fromStatusId,
|
||||||
public ?string $fromStatusLabel,
|
public string $fromStatusLabel,
|
||||||
public int $toStatusId,
|
public int $toStatusId,
|
||||||
public string $toStatusLabel,
|
public string $toStatusLabel,
|
||||||
public CarbonImmutable $occurredAt,
|
public CarbonImmutable $occurredAt,
|
||||||
public ?int $fromAssigneeId = null,
|
|
||||||
public ?string $fromAssigneeName = null,
|
|
||||||
public ?int $toAssigneeId = null,
|
|
||||||
public ?string $toAssigneeName = null,
|
|
||||||
public NotificationEventType $eventType = NotificationEventType::TicketStatusChanged,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function projectId(): int
|
public function projectId(): int
|
||||||
@@ -55,11 +50,9 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
|
|||||||
'$ticket_key' => $this->ticketKey,
|
'$ticket_key' => $this->ticketKey,
|
||||||
'$ticket_title' => $this->ticketTitle,
|
'$ticket_title' => $this->ticketTitle,
|
||||||
'$project_name' => $this->projectName,
|
'$project_name' => $this->projectName,
|
||||||
'$status_from' => $this->fromStatusLabel ?? '',
|
'$status_from' => $this->fromStatusLabel,
|
||||||
'$status_to' => $this->toStatusLabel,
|
'$status_to' => $this->toStatusLabel,
|
||||||
'$actor_name' => $this->actorName ?? '',
|
'$actor_name' => $this->actorName ?? '',
|
||||||
'$assignee_from' => $this->fromAssigneeName ?? '',
|
|
||||||
'$assignee_to' => $this->toAssigneeName ?? '',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,11 +62,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
|
|||||||
* project: array{id: int, key: string, name: string},
|
* project: array{id: int, key: string, name: string},
|
||||||
* ticket: array{id: int, key: string, title: string},
|
* ticket: array{id: int, key: string, title: string},
|
||||||
* actor: array{id: int, name: string}|null,
|
* actor: array{id: int, name: string}|null,
|
||||||
* assignee: array{
|
* from: array{id: int, label: string},
|
||||||
* from: array{id: int, name: string}|null,
|
|
||||||
* to: array{id: int, name: string}|null
|
|
||||||
* },
|
|
||||||
* from: array{id: int, label: string}|null,
|
|
||||||
* to: array{id: int, label: string},
|
* to: array{id: int, label: string},
|
||||||
* ticket_url: string,
|
* ticket_url: string,
|
||||||
* occurred_at: string
|
* occurred_at: string
|
||||||
@@ -82,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,
|
||||||
@@ -99,23 +88,7 @@ final readonly class TicketStatusChangedPayload implements NotificationEventPayl
|
|||||||
'id' => $this->actorId,
|
'id' => $this->actorId,
|
||||||
'name' => $this->actorName,
|
'name' => $this->actorName,
|
||||||
],
|
],
|
||||||
'assignee' => [
|
'from' => [
|
||||||
'from' => $this->fromAssigneeId === null || $this->fromAssigneeName === null
|
|
||||||
? null
|
|
||||||
: [
|
|
||||||
'id' => $this->fromAssigneeId,
|
|
||||||
'name' => $this->fromAssigneeName,
|
|
||||||
],
|
|
||||||
'to' => $this->toAssigneeId === null || $this->toAssigneeName === null
|
|
||||||
? null
|
|
||||||
: [
|
|
||||||
'id' => $this->toAssigneeId,
|
|
||||||
'name' => $this->toAssigneeName,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'from' => $this->fromStatusId === null || $this->fromStatusLabel === null
|
|
||||||
? null
|
|
||||||
: [
|
|
||||||
'id' => $this->fromStatusId,
|
'id' => $this->fromStatusId,
|
||||||
'label' => $this->fromStatusLabel,
|
'label' => $this->fromStatusLabel,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -558,10 +558,6 @@ class DeliverNotificationActionTest extends TestCase
|
|||||||
* project: array{id: int, key: string, name: string},
|
* project: array{id: int, key: string, name: string},
|
||||||
* ticket: array{id: int, key: string, title: string},
|
* ticket: array{id: int, key: string, title: string},
|
||||||
* actor: array{id: int, name: string},
|
* actor: array{id: int, name: string},
|
||||||
* assignee: array{
|
|
||||||
* from: array{id: int, name: string}|null,
|
|
||||||
* to: array{id: int, name: string}|null
|
|
||||||
* },
|
|
||||||
* from: array{id: int, label: string},
|
* from: array{id: int, label: string},
|
||||||
* to: array{id: int, label: string},
|
* to: array{id: int, label: string},
|
||||||
* ticket_url: string,
|
* ticket_url: string,
|
||||||
@@ -586,10 +582,6 @@ class DeliverNotificationActionTest extends TestCase
|
|||||||
'id' => 7,
|
'id' => 7,
|
||||||
'name' => 'Erica Example',
|
'name' => 'Erica Example',
|
||||||
],
|
],
|
||||||
'assignee' => [
|
|
||||||
'from' => null,
|
|
||||||
'to' => null,
|
|
||||||
],
|
|
||||||
'from' => [
|
'from' => [
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'label' => 'Backlog',
|
'label' => 'Backlog',
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
namespace Tests\Feature\Notifications;
|
namespace Tests\Feature\Notifications;
|
||||||
|
|
||||||
use App\Actions\Notifications\RenderDiscordMessageTemplate;
|
use App\Actions\Notifications\RenderDiscordMessageTemplate;
|
||||||
use App\Actions\Notifications\TicketStatusChanged;
|
use App\Actions\Notifications\TicketAssigneeChanged;
|
||||||
use App\Actions\Notifications\TicketStatusChangedPayload;
|
use App\Actions\Notifications\TicketAssigneeChangedPayload;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -80,9 +80,9 @@ class RenderDiscordMessageTemplateTest extends TestCase
|
|||||||
$this->assertSame('[CORE-42] $unknown moved to Doing', $renderedMessage);
|
$this->assertSame('[CORE-42] $unknown moved to Doing', $renderedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function event(): TicketStatusChanged
|
private function event(): TicketAssigneeChanged
|
||||||
{
|
{
|
||||||
return new TicketStatusChanged(new TicketStatusChangedPayload(
|
return new TicketAssigneeChanged(new TicketAssigneeChangedPayload(
|
||||||
projectId: 10,
|
projectId: 10,
|
||||||
projectKey: 'CORE',
|
projectKey: 'CORE',
|
||||||
projectName: 'Core Platform',
|
projectName: 'Core Platform',
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Feature\Notifications;
|
namespace Tests\Feature\Notifications;
|
||||||
|
|
||||||
use App\Actions\Notifications\DeliverNotificationAction;
|
use App\Actions\Notifications\DeliverNotificationAction;
|
||||||
|
use App\Actions\Notifications\TicketAssigneeChangedPayload;
|
||||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||||
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklistMapper;
|
use App\Actions\Tickets\Support\AcceptanceCriteriaChecklistMapper;
|
||||||
use App\Enums\NotificationDeliveryStatus;
|
use App\Enums\NotificationDeliveryStatus;
|
||||||
@@ -158,6 +159,7 @@ class TicketAssigneeChangedNotificationDispatchTest extends TestCase
|
|||||||
$payload = $job->event->payload();
|
$payload = $job->event->payload();
|
||||||
|
|
||||||
return $job->notificationActionId === $webhookAction->id
|
return $job->notificationActionId === $webhookAction->id
|
||||||
|
&& $payload instanceof TicketAssigneeChangedPayload
|
||||||
&& $payload->projectId === $project->id
|
&& $payload->projectId === $project->id
|
||||||
&& $payload->projectKey === 'CORE'
|
&& $payload->projectKey === 'CORE'
|
||||||
&& $payload->projectName === 'Core Platform'
|
&& $payload->projectName === 'Core Platform'
|
||||||
@@ -175,7 +177,7 @@ class TicketAssigneeChangedNotificationDispatchTest extends TestCase
|
|||||||
&& $payload->fromAssigneeName === 'Alex Analyst'
|
&& $payload->fromAssigneeName === 'Alex Analyst'
|
||||||
&& $payload->toAssigneeId === $toAssignee->id
|
&& $payload->toAssigneeId === $toAssignee->id
|
||||||
&& $payload->toAssigneeName === 'Priya Planner'
|
&& $payload->toAssigneeName === 'Priya Planner'
|
||||||
&& $payload->eventType === NotificationEventType::TicketAssigneeChanged
|
&& $payload->toArray()['event_type'] === NotificationEventType::TicketAssigneeChanged->value
|
||||||
&& $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