- Add BulkBackupSetDeleteJob with tenant isolation and skip reasons - Add BackupSetResource bulk archive action with 10+ type-to-confirm - Add unit + feature tests and mark Phase 9 tasks complete
92 lines
2.9 KiB
PHP
92 lines
2.9 KiB
PHP
<?php
|
|
|
|
use App\Jobs\BulkBackupSetDeleteJob;
|
|
use App\Models\BackupItem;
|
|
use App\Models\BackupSet;
|
|
use App\Models\RestoreRun;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\BulkOperationService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
test('bulk backup set delete job archives sets and cascades to backup items', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
$set = BackupSet::create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Backup',
|
|
'status' => 'completed',
|
|
'item_count' => 2,
|
|
]);
|
|
|
|
$items = collect(range(1, 2))->map(function (int $i) use ($tenant, $set) {
|
|
return BackupItem::create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $set->id,
|
|
'policy_id' => null,
|
|
'policy_identifier' => 'policy-'.$i,
|
|
'policy_type' => 'deviceConfiguration',
|
|
'platform' => 'windows10',
|
|
'payload' => ['id' => 'policy-'.$i],
|
|
'metadata' => null,
|
|
]);
|
|
});
|
|
|
|
$service = app(BulkOperationService::class);
|
|
$run = $service->createRun($tenant, $user, 'backup_set', 'delete', [$set->id], 1);
|
|
|
|
(new BulkBackupSetDeleteJob($run->id))->handle($service);
|
|
|
|
$run->refresh();
|
|
expect($run->status)->toBe('completed')
|
|
->and($run->processed_items)->toBe(1)
|
|
->and($run->succeeded)->toBe(1)
|
|
->and($run->failed)->toBe(0)
|
|
->and($run->skipped)->toBe(0);
|
|
|
|
expect(BackupSet::withTrashed()->find($set->id)?->trashed())->toBeTrue();
|
|
|
|
$items->each(function (BackupItem $item) {
|
|
expect(BackupItem::withTrashed()->find($item->id)?->trashed())->toBeTrue();
|
|
});
|
|
});
|
|
|
|
test('bulk backup set delete job skips sets referenced by restore runs', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
$set = BackupSet::create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Backup',
|
|
'status' => 'completed',
|
|
'item_count' => 0,
|
|
]);
|
|
|
|
RestoreRun::create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $set->id,
|
|
'status' => 'completed',
|
|
'is_dry_run' => true,
|
|
'requested_by' => 'tester@example.com',
|
|
]);
|
|
|
|
$service = app(BulkOperationService::class);
|
|
$run = $service->createRun($tenant, $user, 'backup_set', 'delete', [$set->id], 1);
|
|
|
|
(new BulkBackupSetDeleteJob($run->id))->handle($service);
|
|
|
|
$run->refresh();
|
|
expect($run->status)->toBe('completed')
|
|
->and($run->processed_items)->toBe(1)
|
|
->and($run->succeeded)->toBe(0)
|
|
->and($run->failed)->toBe(0)
|
|
->and($run->skipped)->toBe(1);
|
|
|
|
expect(collect($run->failures)->pluck('reason')->join(' '))->toContain('restore runs');
|
|
expect(BackupSet::withTrashed()->find($set->id)?->trashed())->toBeFalse();
|
|
});
|