diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.php index d79532e6e8..14b2881cf3 100644 --- a/app/Livewire/Project/Shared/Danger.php +++ b/app/Livewire/Project/Shared/Danger.php @@ -115,6 +115,8 @@ class Danger extends Component try { $this->authorize('delete', $this->resource); + // Soft delete first, so the environment page after the redirect does not list the resource. + $this->resource->delete(); DeleteResourceJob::dispatch( $this->resource, $this->delete_volumes, diff --git a/tests/v4/Feature/DangerDeleteResourceTest.php b/tests/v4/Feature/DangerDeleteResourceTest.php index 64dd56ede9..3f0bbfc91a 100644 --- a/tests/v4/Feature/DangerDeleteResourceTest.php +++ b/tests/v4/Feature/DangerDeleteResourceTest.php @@ -64,7 +64,7 @@ test('delete returns error string when password is incorrect', function () { expect(Application::find($this->application->id))->not->toBeNull(); }); -test('delete redirects before dispatching resource cleanup after the response', function () { +test('delete hides the resource before the redirect and dispatches cleanup after the response', function () { $service = Service::factory()->create([ 'environment_id' => $this->environment->id, 'server_id' => $this->server->id, @@ -84,7 +84,9 @@ test('delete redirects before dispatching resource cleanup after the response', expect($component->effects)->toHaveKey('redirectUsingNavigate', true); - expect(Service::find($service->id))->not->toBeNull(); + // The redirected environment page must not list the resource while the cleanup job still runs. + expect(Service::find($service->id))->toBeNull() + ->and(Service::withTrashed()->find($service->id))->not->toBeNull(); Queue::assertPushed(DeleteResourceJob::class, fn (DeleteResourceJob $job) => $job->resource->is($service)); });