feat(KAN-45): rebuild project notification settings
This commit is contained in:
@@ -430,4 +430,66 @@ class ProjectNotificationSettingsControllerTest extends TestCase
|
||||
->missing('notificationActions.0.delivery_url'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_editor_accepts_array_filters_and_can_clear_discord_mentions(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
$notificationAction = NotificationAction::factory()->discord()->for($project)->create([
|
||||
'channel_configuration' => ['allowed_mentions' => ['users']],
|
||||
'delivery_url' => 'https://discord.com/api/webhooks/123456/original-secret',
|
||||
]);
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.settings.notifications.update', [$project, $notificationAction]), [
|
||||
'name' => 'Paused alerts',
|
||||
'event_type' => NotificationEventType::TicketAssigneeChanged->value,
|
||||
'channel' => NotificationChannel::Discord->value,
|
||||
'enabled' => false,
|
||||
'delivery_url' => null,
|
||||
'message_template' => '$ticket_key: $url',
|
||||
'channel_configuration' => ['allowed_mentions' => []],
|
||||
'filters' => [
|
||||
['attribute' => 'ticket.key', 'operator' => 'in', 'value' => ['CORE-1', 'CORE-2']],
|
||||
['attribute' => 'actor.name', 'operator' => 'exists', 'value' => null],
|
||||
],
|
||||
])
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('projects.settings.notifications', $project));
|
||||
|
||||
$notificationAction->refresh();
|
||||
$this->assertFalse($notificationAction->enabled);
|
||||
$this->assertSame(['allowed_mentions' => []], $notificationAction->channel_configuration);
|
||||
$this->assertSame('https://discord.com/api/webhooks/123456/original-secret', $notificationAction->delivery_url);
|
||||
$this->assertSame([
|
||||
['attribute' => 'ticket.key', 'operator' => 'in', 'value' => ['CORE-1', 'CORE-2']],
|
||||
['attribute' => 'actor.name', 'operator' => 'exists', 'value' => null],
|
||||
], $notificationAction->filters);
|
||||
}
|
||||
|
||||
public function test_invalid_editor_update_does_not_change_saved_configuration(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
$notificationAction = NotificationAction::factory()->discord()->for($project)->create();
|
||||
$original = $notificationAction->fresh()->getRawOriginal();
|
||||
$this->syncProjectPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('projects.settings.notifications', $project))
|
||||
->patch(route('projects.settings.notifications.update', [$project, $notificationAction]), [
|
||||
'name' => 'Invalid update',
|
||||
'event_type' => NotificationEventType::TicketCreate->value,
|
||||
'channel' => NotificationChannel::Discord->value,
|
||||
'enabled' => false,
|
||||
'delivery_url' => 'invalid-url',
|
||||
'message_template' => '',
|
||||
'channel_configuration' => ['allowed_mentions' => ['unsupported']],
|
||||
'filters' => [['attribute' => 'ticket.key', 'operator' => 'in', 'value' => []]],
|
||||
])
|
||||
->assertSessionHasErrors(['delivery_url', 'message_template', 'channel_configuration.allowed_mentions.0', 'filters.0.value']);
|
||||
|
||||
$this->assertSame($original, $notificationAction->fresh()->getRawOriginal());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user