## Summary <!-- Kurz: Was ändert sich und warum? --> ## Spec-Driven Development (SDD) - [ ] Es gibt eine Spec unter `specs/<NNN>-<feature>/` - [ ] Enthaltene Dateien: `plan.md`, `tasks.md`, `spec.md` - [ ] Spec beschreibt Verhalten/Acceptance Criteria (nicht nur Implementation) - [ ] Wenn sich Anforderungen während der Umsetzung geändert haben: Spec/Plan/Tasks wurden aktualisiert ## Implementation - [ ] Implementierung entspricht der Spec - [ ] Edge cases / Fehlerfälle berücksichtigt - [ ] Keine unbeabsichtigten Änderungen außerhalb des Scopes ## Tests - [ ] Tests ergänzt/aktualisiert (Pest/PHPUnit) - [ ] Relevante Tests lokal ausgeführt (`./vendor/bin/sail artisan test` oder `php artisan test`) ## Migration / Config / Ops (falls relevant) - [ ] Migration(en) enthalten und getestet - [ ] Rollback bedacht (rückwärts kompatibel, sichere Migration) - [ ] Neue Env Vars dokumentiert (`.env.example` / Doku) - [ ] Queue/cron/storage Auswirkungen geprüft ## UI (Filament/Livewire) (falls relevant) - [ ] UI-Flows geprüft - [ ] Screenshots/Notizen hinzugefügt ## Notes <!-- Links, Screenshots, Follow-ups, offene Punkte --> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #5
108 lines
3.2 KiB
PHP
108 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Jobs\BulkBackupSetForceDeleteJob;
|
|
use App\Models\BackupItem;
|
|
use App\Models\BackupSet;
|
|
use App\Models\BulkOperationRun;
|
|
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 force delete job permanently deletes archived sets and their items', function () {
|
|
$tenant = Tenant::factory()->create(['is_current' => true]);
|
|
$user = User::factory()->create();
|
|
|
|
$set = BackupSet::create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Backup',
|
|
'status' => 'completed',
|
|
'item_count' => 1,
|
|
]);
|
|
|
|
$item = BackupItem::create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $set->id,
|
|
'policy_id' => null,
|
|
'policy_identifier' => 'policy-1',
|
|
'policy_type' => 'deviceConfiguration',
|
|
'platform' => 'windows10',
|
|
'payload' => ['id' => 'policy-1'],
|
|
'metadata' => null,
|
|
]);
|
|
|
|
$set->delete();
|
|
|
|
$service = app(BulkOperationService::class);
|
|
$run = BulkOperationRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'user_id' => $user->id,
|
|
'resource' => 'backup_set',
|
|
'action' => 'force_delete',
|
|
'status' => 'pending',
|
|
'total_items' => 1,
|
|
'item_ids' => [$set->id],
|
|
'failures' => [],
|
|
]);
|
|
|
|
(new BulkBackupSetForceDeleteJob($run->id))->handle($service);
|
|
|
|
expect(BackupSet::withTrashed()->find($set->id))->toBeNull();
|
|
expect(BackupItem::withTrashed()->find($item->id))->toBeNull();
|
|
|
|
$run->refresh();
|
|
expect($run->status)->toBe('completed')
|
|
->and($run->succeeded)->toBe(1)
|
|
->and($run->skipped)->toBe(0)
|
|
->and($run->failed)->toBe(0);
|
|
});
|
|
|
|
test('bulk backup set force delete job skips sets referenced by restore runs', function () {
|
|
$tenant = Tenant::factory()->create(['is_current' => true]);
|
|
$user = User::factory()->create();
|
|
|
|
$set = BackupSet::create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Backup',
|
|
'status' => 'completed',
|
|
'item_count' => 0,
|
|
]);
|
|
|
|
$set->delete();
|
|
|
|
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 = BulkOperationRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'user_id' => $user->id,
|
|
'resource' => 'backup_set',
|
|
'action' => 'force_delete',
|
|
'status' => 'pending',
|
|
'total_items' => 1,
|
|
'item_ids' => [$set->id],
|
|
'failures' => [],
|
|
]);
|
|
|
|
(new BulkBackupSetForceDeleteJob($run->id))->handle($service);
|
|
|
|
$run->refresh();
|
|
expect($run->status)->toBe('completed')
|
|
->and($run->succeeded)->toBe(0)
|
|
->and($run->skipped)->toBe(1)
|
|
->and($run->failed)->toBe(0);
|
|
|
|
expect(BackupSet::withTrashed()->find($set->id)?->trashed())->toBeTrue();
|
|
expect(collect($run->failures)->pluck('reason')->all())->toContain('Referenced by restore runs');
|
|
});
|