fix(resources): dispatch deletion cleanup after response
This commit is contained in:
parent
e0d233f933
commit
e514a2d61f
2 changed files with 25 additions and 9 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\DeleteResourceJob;
|
||||
use App\Livewire\Project\Shared\Danger;
|
||||
use App\Models\Application;
|
||||
use App\Models\Environment;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
|
|
@ -18,7 +20,7 @@
|
|||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
InstanceSettings::create(['id' => 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 () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue