fix: allow deleting partial restore runs

Normalize RestoreRun status in isDeletable() so 'Partial'/'completed-with-errors' variants can be archived.
This commit is contained in:
Ahmed Darrazi 2025-12-25 03:23:26 +01:00
parent eef9618889
commit 0a6e1f7751
2 changed files with 34 additions and 1 deletions

View File

@ -41,6 +41,9 @@ public function scopeDeletable($query)
public function isDeletable(): bool
{
return in_array($this->status, ['completed', 'failed', 'aborted', 'completed_with_errors', 'partial'], true);
$status = strtolower(trim((string) $this->status));
$status = str_replace([' ', '-'], '_', $status);
return in_array($status, ['completed', 'failed', 'aborted', 'completed_with_errors', 'partial'], true);
}
}

View File

@ -54,3 +54,33 @@
'partial',
]);
});
test('isDeletable accepts partial even if status casing/format differs', function () {
$tenant = Tenant::factory()->create();
$backupSet = BackupSet::create([
'tenant_id' => $tenant->id,
'name' => 'Backup',
'status' => 'completed',
'item_count' => 0,
]);
$partial = RestoreRun::create([
'tenant_id' => $tenant->id,
'backup_set_id' => $backupSet->id,
'status' => 'Partial',
'is_dry_run' => true,
'requested_by' => 'tester@example.com',
]);
$completedWithErrors = RestoreRun::create([
'tenant_id' => $tenant->id,
'backup_set_id' => $backupSet->id,
'status' => 'completed-with-errors',
'is_dry_run' => true,
'requested_by' => 'tester@example.com',
]);
expect($partial->isDeletable())->toBeTrue();
expect($completedWithErrors->isDeletable())->toBeTrue();
});