refactor(backups): centralize storage deletion guard

This commit is contained in:
Andras Bacsai committed 2026-07-19 23:20:46 +02:00
1 parent 4e03be755d
commit bf72fd5d88
6 files changed
+38 -21

No files matched your search

+21
View File
@@ -37,6 +37,7 @@ use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Symfony\Component\HttpKernel\Exception\HttpException;
uses(RefreshDatabase::class);
@@ -1456,6 +1457,26 @@ it('prevents a volume with tracked backup archives from being deleted', function
expect($volume->fresh())->not->toBeNull();
});
it('aborts storage deletion when scheduled backups exist', function () {
$team = Team::factory()->create();
[$application, $volume] = createVolumeBackupApplication($team);
$directory = createApplicationBackupDirectory($application);
$volume->scheduledBackups()->create([
'team_id' => $team->id,
'frequency' => 'daily',
]);
$directory->scheduledBackups()->create([
'team_id' => $team->id,
'frequency' => 'daily',
]);
expect(fn () => $volume->abortIfScheduledBackupsExist())
->toThrow(HttpException::class, 'Delete this volume backup schedule and its archives before deleting the volume.')
->and(fn () => $directory->abortIfScheduledBackupsExist())
->toThrow(HttpException::class, 'Delete this directory backup schedule and its archives before deleting the directory.');
});
it('deletes disabled volume backup archives before deleting their application', function () {
Process::fake();
Queue::fake();