Files
InvoiceShelf/tests/Feature/Admin/BackupTest.php
Darko Gjorgjijoski 20085cab5d Refactor FileDisk system with per-disk unique names and disk assignments UI
Major changes to the file disk subsystem:

- Each FileDisk now gets a unique Laravel disk name (disk_{id}) instead
  of temp_{driver}, fixing the bug where multiple local disks with
  different roots overwrote each other's config.

- Move disk registration logic from FileDisk model to FileDiskService
  (registerDisk, getDiskName). Model keeps only getDecodedCredentials
  and a deprecated setConfig() wrapper.

- Add Disk Assignments admin UI (File Disk tab) with three purpose
  dropdowns: Media Storage, PDF Storage, Backup Storage. Stored as
  settings (media_disk_id, pdf_disk_id, backup_disk_id).

- Backup tab now uses the assigned backup disk instead of a per-backup
  dropdown. BackupsController refactored to use BackupService which
  centralizes disk resolution. Removed stale 4-second cache.

- Add local_public disk to config/filesystems.php so system disks
  are properly defined.

- Local disk roots stored relative to storage/app/ with hint text
  in the admin modal explaining the convention.

- Fix BaseModal watchEffect -> watch to prevent infinite request
  loops on the File Disk page.

- Fix string/number comparison for disk purpose IDs from settings.

- Add safeguards: prevent deleting disks with files, warn on
  purpose change, prevent deleting system disks.
2026-04-07 02:04:57 +02:00

57 lines
1.3 KiB
PHP

<?php
use App\Jobs\CreateBackupJob;
use App\Models\FileDisk;
use App\Models\User;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Queue;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get backups', function () {
$disk = FileDisk::factory()->create([
'set_as_default' => true,
]);
$response = getJson("/api/v1/backups?disk={$disk->driver}&&file_disk_id={$disk->id}");
$response->assertOk();
});
test('create backup', function () {
Queue::fake();
$disk = FileDisk::factory()->create();
$data = [
'option' => 'full',
'file_disk_id' => $disk->id,
];
$response = postJson('/api/v1/backups', $data);
Queue::assertPushed(CreateBackupJob::class);
$response = getJson("/api/v1/backups?disk={$disk->driver}&&file_disk_id={$disk->id}");
$response->assertStatus(200)->assertJsonStructure([
'backups',
]);
});