Harden notification release regressions
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace Tests\Feature\Mcp;
|
||||
|
||||
use App\Actions\Notifications\DeliverNotificationAction;
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Enums\NotificationDeliveryStatus;
|
||||
use App\Mcp\Servers\KanbanGitServer;
|
||||
use App\Mcp\Tools\GetTicket;
|
||||
use App\Mcp\Tools\ListMyAssignedTickets;
|
||||
@@ -11,11 +13,13 @@ use App\Mcp\Tools\MoveTicketStatus;
|
||||
use App\Mcp\Tools\UpdateTicketAssignee;
|
||||
use App\Mcp\Tools\UpdateTicketDescription;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -319,6 +323,90 @@ class KanbanGitMcpTest extends TestCase
|
||||
->etc());
|
||||
}
|
||||
|
||||
public function test_mcp_status_moves_still_queue_notification_deliveries_when_actions_are_enabled(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$project = $this->project('CORE', 'Core project');
|
||||
$backlogStatus = $project->ticketStatuses()->firstOrFail();
|
||||
$doingStatus = $this->ticketStatus($project, 'Doing');
|
||||
$ticket = $this->ticket($project, $backlogStatus, [
|
||||
'ticket_key' => 'CORE-1',
|
||||
'title' => 'Move ticket',
|
||||
]);
|
||||
|
||||
$backlogStatus->allowedTargetStatuses()->sync([$doingStatus->id]);
|
||||
$this->syncProjectPermissions($project, $user, ['write']);
|
||||
|
||||
$notificationAction = NotificationAction::factory()
|
||||
->webhook()
|
||||
->for($project)
|
||||
->create();
|
||||
|
||||
KanbanGitServer::actingAs($user)
|
||||
->tool(MoveTicketStatus::class, [
|
||||
'ticket_id' => $ticket->id,
|
||||
'ticket_status_id' => $doingStatus->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStructuredContent(fn (AssertableJson $json) => $json
|
||||
->where('data.ticket.ticket_status_id', $doingStatus->id)
|
||||
->where('meta.destination_label', 'Doing')
|
||||
->where('meta.message', 'CORE-1 moved to Doing.')
|
||||
->where('meta.moved', true)
|
||||
->etc());
|
||||
|
||||
Queue::assertPushed(DeliverNotificationAction::class, function (DeliverNotificationAction $job) use ($notificationAction): bool {
|
||||
return $job->notificationActionId === $notificationAction->id
|
||||
&& $job->payload->ticketKey === 'CORE-1'
|
||||
&& $job->payload->toStatusLabel === 'Doing'
|
||||
&& $job->notificationDeliveryLogId !== null;
|
||||
});
|
||||
|
||||
$this->assertDatabaseHas('notification_delivery_logs', [
|
||||
'notification_action_id' => $notificationAction->id,
|
||||
'delivery_status' => NotificationDeliveryStatus::Pending->value,
|
||||
'attempt_count' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_mcp_no_op_status_moves_do_not_queue_notification_deliveries(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$user = User::factory()->create();
|
||||
$project = $this->project('CORE', 'Core project');
|
||||
$backlogStatus = $project->ticketStatuses()->firstOrFail();
|
||||
$ticket = $this->ticket($project, $backlogStatus, [
|
||||
'ticket_key' => 'CORE-1',
|
||||
'title' => 'Move ticket',
|
||||
]);
|
||||
|
||||
$this->syncProjectPermissions($project, $user, ['write']);
|
||||
|
||||
NotificationAction::factory()
|
||||
->webhook()
|
||||
->for($project)
|
||||
->create();
|
||||
|
||||
KanbanGitServer::actingAs($user)
|
||||
->tool(MoveTicketStatus::class, [
|
||||
'ticket_id' => $ticket->id,
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStructuredContent(fn (AssertableJson $json) => $json
|
||||
->where('data.ticket.ticket_status_id', $backlogStatus->id)
|
||||
->where('meta.destination_label', 'Backlog')
|
||||
->where('meta.message', 'CORE-1 already belongs to Backlog.')
|
||||
->where('meta.moved', false)
|
||||
->etc());
|
||||
|
||||
Queue::assertNothingPushed();
|
||||
$this->assertDatabaseCount('ticket_worklog_entries', 0);
|
||||
}
|
||||
|
||||
public function test_ambiguous_status_name_returns_mcp_error(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
Reference in New Issue
Block a user