Add notification filters
This commit is contained in:
@@ -71,6 +71,34 @@ class TicketCreatedNotificationDispatchTest extends TestCase
|
||||
'name' => 'Status changed webhook',
|
||||
'event_type' => NotificationEventType::TicketStatusChanged,
|
||||
]);
|
||||
$filterNotExistsAction = NotificationAction::factory()
|
||||
->webhook()
|
||||
->for($project)
|
||||
->create([
|
||||
'name' => 'Ticket create without origin status',
|
||||
'event_type' => NotificationEventType::TicketCreate,
|
||||
'filters' => [
|
||||
[
|
||||
'attribute' => 'status.from.id',
|
||||
'operator' => 'not_exists',
|
||||
'value' => null,
|
||||
],
|
||||
],
|
||||
]);
|
||||
$filterExistsAction = NotificationAction::factory()
|
||||
->webhook()
|
||||
->for($project)
|
||||
->create([
|
||||
'name' => 'Ticket create with origin status',
|
||||
'event_type' => NotificationEventType::TicketCreate,
|
||||
'filters' => [
|
||||
[
|
||||
'attribute' => 'status.from.id',
|
||||
'operator' => 'exists',
|
||||
'value' => null,
|
||||
],
|
||||
],
|
||||
]);
|
||||
$foreignProjectAction = NotificationAction::factory()
|
||||
->for($otherProject)
|
||||
->create([
|
||||
@@ -100,7 +128,7 @@ class TicketCreatedNotificationDispatchTest extends TestCase
|
||||
->assertRedirect(route('projects.tickets.show', [$project, $ticket]))
|
||||
->assertSessionHas('status', 'CORE-1 was created.');
|
||||
|
||||
Queue::assertPushed(DeliverNotificationAction::class, 2);
|
||||
Queue::assertPushed(DeliverNotificationAction::class, 3);
|
||||
Queue::assertPushed(DeliverNotificationAction::class, function (DeliverNotificationAction $job) use ($webhookAction, $project, $ticket, $user, $backlogStatus): bool {
|
||||
return $job->notificationActionId === $webhookAction->id
|
||||
&& $job->payload->projectId === $project->id
|
||||
@@ -122,11 +150,15 @@ class TicketCreatedNotificationDispatchTest extends TestCase
|
||||
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $discordAction->id
|
||||
&& $job->payload->eventType === NotificationEventType::TicketCreate
|
||||
&& $job->notificationDeliveryLogId !== null);
|
||||
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $filterNotExistsAction->id
|
||||
&& $job->payload->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);
|
||||
Queue::assertNotPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $filterExistsAction->id);
|
||||
Queue::assertNotPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $foreignProjectAction->id);
|
||||
|
||||
$this->assertDatabaseCount('notification_delivery_logs', 2);
|
||||
$this->assertDatabaseCount('notification_delivery_logs', 3);
|
||||
$this->assertDatabaseHas('notification_delivery_logs', [
|
||||
'notification_action_id' => $webhookAction->id,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending->value,
|
||||
@@ -141,6 +173,13 @@ class TicketCreatedNotificationDispatchTest extends TestCase
|
||||
'attempt_count' => 0,
|
||||
'http_status' => null,
|
||||
]);
|
||||
$this->assertDatabaseHas('notification_delivery_logs', [
|
||||
'notification_action_id' => $filterNotExistsAction->id,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending->value,
|
||||
'event_type' => NotificationEventType::TicketCreate->value,
|
||||
'attempt_count' => 0,
|
||||
'http_status' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function backlogStatus(Project $project): TicketStatus
|
||||
|
||||
Reference in New Issue
Block a user