71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\BackupSet;
|
|
use App\Models\RestoreRun;
|
|
use App\Support\RestoreSafety\RestoreResultAttention;
|
|
use App\Support\RestoreSafety\RestoreSafetyResolver;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('treats preview-only restore runs as not executed', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $backupSet->id,
|
|
'is_dry_run' => true,
|
|
'status' => 'previewed',
|
|
'results' => [],
|
|
]);
|
|
|
|
$attention = app(RestoreSafetyResolver::class)->resultAttentionForRun($restoreRun);
|
|
|
|
expect($attention->state)->toBe(RestoreResultAttention::STATE_NOT_EXECUTED)
|
|
->and($attention->followUpRequired)->toBeFalse();
|
|
});
|
|
|
|
it('surfaces completed runs with skipped work as follow-up required', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'backup_set_id' => $backupSet->id,
|
|
'is_dry_run' => false,
|
|
'status' => 'completed',
|
|
'results' => [
|
|
'foundations' => [],
|
|
'items' => [
|
|
9 => [
|
|
'status' => 'applied',
|
|
'policy_identifier' => 'policy-9',
|
|
'assignment_outcomes' => [
|
|
['status' => 'skipped', 'assignment' => []],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'non_applied' => 1,
|
|
],
|
|
]);
|
|
|
|
$attention = app(RestoreSafetyResolver::class)->resultAttentionForRun($restoreRun);
|
|
|
|
expect($attention->state)->toBe(RestoreResultAttention::STATE_COMPLETED_WITH_FOLLOW_UP)
|
|
->and($attention->followUpRequired)->toBeTrue()
|
|
->and($attention->primaryNextAction)->toBe('review_skipped_items');
|
|
});
|