Harden notification release regressions
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
namespace Tests\Feature\Api;
|
||||
|
||||
use App\Actions\Git\GitProviderKey;
|
||||
use App\Actions\Notifications\DeliverNotificationAction;
|
||||
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
|
||||
use App\Enums\NotificationDeliveryStatus;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\NotificationAction;
|
||||
use App\Models\Project;
|
||||
use App\Models\RepositoryConnection;
|
||||
use App\Models\Ticket;
|
||||
@@ -14,6 +17,7 @@ use App\Models\User;
|
||||
use App\Models\UserGitConnection;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TicketApiTest extends TestCase
|
||||
@@ -122,6 +126,80 @@ class TicketApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_status_moves_still_queue_notification_deliveries_over_the_api(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
[$user, $project] = $this->projectContext();
|
||||
|
||||
$backlogStatus = $project->ticketStatuses()->firstOrFail();
|
||||
$boardColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Doing',
|
||||
'position' => 1,
|
||||
]);
|
||||
$doingStatus = TicketStatus::factory()
|
||||
->for($project)
|
||||
->for($boardColumn)
|
||||
->create([
|
||||
'name' => 'Doing',
|
||||
'position' => 1,
|
||||
]);
|
||||
$backlogStatus->allowedTargetStatuses()->sync([$doingStatus->id]);
|
||||
|
||||
$ticket = $this->ticket($project, $backlogStatus);
|
||||
$notificationAction = NotificationAction::factory()
|
||||
->webhook()
|
||||
->for($project)
|
||||
->create();
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->patchJson(route('api.projects.tickets.status.update', [$project, $ticket]), [
|
||||
'ticket_status_id' => $doingStatus->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.ticket_status_id', $doingStatus->id)
|
||||
->assertJsonPath('meta.message', 'CORE-1 moved to Doing.');
|
||||
|
||||
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_no_op_status_moves_keep_the_existing_api_response_and_do_not_queue_notifications(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
[$user, $project] = $this->projectContext();
|
||||
|
||||
$backlogStatus = $project->ticketStatuses()->firstOrFail();
|
||||
$ticket = $this->ticket($project, $backlogStatus);
|
||||
|
||||
NotificationAction::factory()
|
||||
->webhook()
|
||||
->for($project)
|
||||
->create();
|
||||
|
||||
$this->withApplicationKey($user)
|
||||
->patchJson(route('api.projects.tickets.status.update', [$project, $ticket]), [
|
||||
'ticket_status_id' => $backlogStatus->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.ticket_status_id', $backlogStatus->id)
|
||||
->assertJsonPath('meta.message', 'CORE-1 already belongs to Backlog.');
|
||||
|
||||
Queue::assertNothingPushed();
|
||||
$this->assertDatabaseCount('ticket_worklog_entries', 0);
|
||||
}
|
||||
|
||||
public function test_ticket_links_and_branch_endpoints_are_available(): void
|
||||
{
|
||||
Http::preventStrayRequests();
|
||||
|
||||
Reference in New Issue
Block a user