Add notification filters

This commit is contained in:
2026-04-24 20:02:22 +00:00
parent 5f74ddd964
commit c54df44ebe
24 changed files with 1288 additions and 7 deletions
@@ -72,6 +72,71 @@ class TicketStatusChangedNotificationDispatchTest extends TestCase
->create([
'name' => 'Disabled webhook',
]);
$filterEqualsAction = NotificationAction::factory()
->webhook()
->for($project)
->create([
'name' => 'Filtered equals webhook',
'filters' => [
[
'attribute' => 'status.to.id',
'operator' => 'equals',
'value' => (string) $doingStatus->id,
],
],
]);
$filterNotEqualsAction = NotificationAction::factory()
->webhook()
->for($project)
->create([
'name' => 'Filtered not equals webhook',
'filters' => [
[
'attribute' => 'status.to.id',
'operator' => 'not_equals',
'value' => (string) $doingStatus->id,
],
],
]);
$filterExistsAction = NotificationAction::factory()
->webhook()
->for($project)
->create([
'name' => 'Filtered exists webhook',
'filters' => [
[
'attribute' => 'actor.id',
'operator' => 'exists',
'value' => null,
],
],
]);
$filterNotExistsAction = NotificationAction::factory()
->webhook()
->for($project)
->create([
'name' => 'Filtered not exists webhook',
'filters' => [
[
'attribute' => 'actor.id',
'operator' => 'not_exists',
'value' => null,
],
],
]);
$filterInAction = NotificationAction::factory()
->webhook()
->for($project)
->create([
'name' => 'Filtered in webhook',
'filters' => [
[
'attribute' => 'ticket.key',
'operator' => 'in',
'value' => ['CORE-1', 'CORE-99'],
],
],
]);
$foreignProjectAction = NotificationAction::factory()
->for($otherProject)
->create([
@@ -101,7 +166,7 @@ class TicketStatusChangedNotificationDispatchTest extends TestCase
->assertRedirect(route('projects.backlog.index', $project))
->assertSessionHas('status', 'CORE-1 moved to Doing.');
Queue::assertPushed(DeliverNotificationAction::class, 2);
Queue::assertPushed(DeliverNotificationAction::class, 5);
Queue::assertPushed(DeliverNotificationAction::class, function (DeliverNotificationAction $job) use ($webhookAction, $project, $ticket, $user, $backlogStatus, $doingStatus): bool {
return $job->notificationActionId === $webhookAction->id
&& $job->payload->projectId === $project->id
@@ -122,10 +187,18 @@ class TicketStatusChangedNotificationDispatchTest extends TestCase
});
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $discordAction->id
&& $job->notificationDeliveryLogId !== null);
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $filterEqualsAction->id
&& $job->notificationDeliveryLogId !== null);
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $filterExistsAction->id
&& $job->notificationDeliveryLogId !== null);
Queue::assertPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $filterInAction->id
&& $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 === $filterNotEqualsAction->id);
Queue::assertNotPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $filterNotExistsAction->id);
Queue::assertNotPushed(DeliverNotificationAction::class, fn (DeliverNotificationAction $job): bool => $job->notificationActionId === $foreignProjectAction->id);
$this->assertDatabaseCount('notification_delivery_logs', 2);
$this->assertDatabaseCount('notification_delivery_logs', 5);
$this->assertDatabaseHas('notification_delivery_logs', [
'notification_action_id' => $webhookAction->id,
'delivery_status' => NotificationDeliveryStatus::Pending->value,
@@ -138,6 +211,24 @@ class TicketStatusChangedNotificationDispatchTest extends TestCase
'attempt_count' => 0,
'http_status' => null,
]);
$this->assertDatabaseHas('notification_delivery_logs', [
'notification_action_id' => $filterEqualsAction->id,
'delivery_status' => NotificationDeliveryStatus::Pending->value,
'attempt_count' => 0,
'http_status' => null,
]);
$this->assertDatabaseHas('notification_delivery_logs', [
'notification_action_id' => $filterExistsAction->id,
'delivery_status' => NotificationDeliveryStatus::Pending->value,
'attempt_count' => 0,
'http_status' => null,
]);
$this->assertDatabaseHas('notification_delivery_logs', [
'notification_action_id' => $filterInAction->id,
'delivery_status' => NotificationDeliveryStatus::Pending->value,
'attempt_count' => 0,
'http_status' => null,
]);
$this->assertDatabaseHas('ticket_worklog_entries', [
'ticket_id' => $ticket->id,