From 0a6e1f7751be4e71000380183503df9ee61d0904 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Thu, 25 Dec 2025 03:23:26 +0100 Subject: [PATCH] fix: allow deleting partial restore runs Normalize RestoreRun status in isDeletable() so 'Partial'/'completed-with-errors' variants can be archived. --- app/Models/RestoreRun.php | 5 ++++- tests/Unit/RestoreRunDeletableTest.php | 30 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/Models/RestoreRun.php b/app/Models/RestoreRun.php index ce7fb50..9160725 100644 --- a/app/Models/RestoreRun.php +++ b/app/Models/RestoreRun.php @@ -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); } } diff --git a/tests/Unit/RestoreRunDeletableTest.php b/tests/Unit/RestoreRunDeletableTest.php index 0ea051c..4db56f6 100644 --- a/tests/Unit/RestoreRunDeletableTest.php +++ b/tests/Unit/RestoreRunDeletableTest.php @@ -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(); +});