From e514a2d61f26012928e4fc58e926edd686344cc4 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sun, 30 Aug 2026 20:37:05 +0200 Subject: [PATCH] fix(resources): dispatch deletion cleanup after response --- app/Livewire/Project/Shared/Danger.php | 3 +- tests/v4/Feature/DangerDeleteResourceTest.php | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.php index 7f0d3b173..d2420a029 100644 --- a/app/Livewire/Project/Shared/Danger.php +++ b/app/Livewire/Project/Shared/Danger.php @@ -106,14 +106,13 @@ public function delete($password, $selectedActions = []) try { $this->authorize('delete', $this->resource); - $this->resource->delete(); DeleteResourceJob::dispatch( $this->resource, $this->delete_volumes, $this->delete_connected_networks, $this->delete_configurations, $this->docker_cleanup - ); + )->afterResponse(); return redirectRoute($this, 'project.resource.index', [ 'project_uuid' => $this->projectUuid, diff --git a/tests/v4/Feature/DangerDeleteResourceTest.php b/tests/v4/Feature/DangerDeleteResourceTest.php index 7a73f5979..af409a3c4 100644 --- a/tests/v4/Feature/DangerDeleteResourceTest.php +++ b/tests/v4/Feature/DangerDeleteResourceTest.php @@ -1,11 +1,13 @@ 0]); + InstanceSettings::forceCreate(['id' => 0]); Queue::fake(); $this->user = User::factory()->create([ @@ -61,13 +63,28 @@ expect(Application::find($this->application->id))->not->toBeNull(); }); -test('delete succeeds with correct password and redirects', function () { - Livewire::test(Danger::class, ['resource' => $this->application]) - ->call('delete', 'test-password') - ->assertHasNoErrors(); +test('delete redirects before dispatching resource cleanup after the response', function () { + $service = Service::factory()->create([ + 'environment_id' => $this->environment->id, + 'server_id' => $this->server->id, + 'destination_id' => $this->destination->id, + 'destination_type' => $this->destination->getMorphClass(), + ]); - // Resource should be soft-deleted - expect(Application::find($this->application->id))->toBeNull(); + $component = Livewire::test(Danger::class, ['resource' => $service]) + ->set('projectUuid', $this->project->uuid) + ->set('environmentUuid', $this->environment->uuid) + ->call('delete', 'test-password') + ->assertHasNoErrors() + ->assertRedirectToRoute('project.resource.index', [ + 'project_uuid' => $this->project->uuid, + 'environment_uuid' => $this->environment->uuid, + ]); + + expect($component->effects)->toHaveKey('redirectUsingNavigate', true); + + expect(Service::find($service->id))->not->toBeNull(); + Queue::assertPushed(DeleteResourceJob::class, fn (DeleteResourceJob $job) => $job->resource->is($service)); }); test('delete applies selectedActions from checkbox state', function () {