## 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: #4
182 lines
5.6 KiB
PHP
182 lines
5.6 KiB
PHP
<?php
|
|
|
|
use App\Models\RestoreRun;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
test('group_mapping cast works', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
'source-group-2' => 'target-group-2',
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->group_mapping)->toBeArray()
|
|
->and($restoreRun->group_mapping)->toHaveCount(2);
|
|
});
|
|
|
|
test('hasGroupMapping returns true when mapping exists', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->hasGroupMapping())->toBeTrue();
|
|
});
|
|
|
|
test('hasGroupMapping returns false when mapping is null', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => null,
|
|
]);
|
|
|
|
expect($restoreRun->hasGroupMapping())->toBeFalse();
|
|
});
|
|
|
|
test('getMappedGroupId returns mapped group ID', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->getMappedGroupId('source-group-1'))->toBe('target-group-1');
|
|
});
|
|
|
|
test('getMappedGroupId returns null for unmapped group', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->getMappedGroupId('source-group-2'))->toBeNull();
|
|
});
|
|
|
|
test('isGroupSkipped returns true for skipped group', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'SKIP',
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->isGroupSkipped('source-group-1'))->toBeTrue();
|
|
});
|
|
|
|
test('isGroupSkipped returns false for mapped group', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->isGroupSkipped('source-group-1'))->toBeFalse();
|
|
});
|
|
|
|
test('getUnmappedGroupIds returns groups without mapping', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
$unmapped = $restoreRun->getUnmappedGroupIds(['source-group-1', 'source-group-2', 'source-group-3']);
|
|
|
|
expect($unmapped)->toHaveCount(2)
|
|
->and($unmapped)->toContain('source-group-2', 'source-group-3');
|
|
});
|
|
|
|
test('addGroupMapping adds new mapping', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
$restoreRun->addGroupMapping('source-group-2', 'target-group-2');
|
|
|
|
expect($restoreRun->group_mapping)->toHaveCount(2)
|
|
->and($restoreRun->group_mapping['source-group-2'])->toBe('target-group-2');
|
|
});
|
|
|
|
test('addGroupMapping overwrites existing mapping', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'group_mapping' => [
|
|
'source-group-1' => 'target-group-1',
|
|
],
|
|
]);
|
|
|
|
$restoreRun->addGroupMapping('source-group-1', 'target-group-new');
|
|
|
|
expect($restoreRun->group_mapping)->toHaveCount(1)
|
|
->and($restoreRun->group_mapping['source-group-1'])->toBe('target-group-new');
|
|
});
|
|
|
|
test('getAssignmentRestoreOutcomes returns outcomes from results', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'results' => [
|
|
'assignment_outcomes' => [
|
|
['status' => 'success', 'assignment' => []],
|
|
['status' => 'failed', 'assignment' => []],
|
|
],
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->getAssignmentRestoreOutcomes())->toHaveCount(2);
|
|
});
|
|
|
|
test('getAssignmentRestoreOutcomes returns empty array when not set', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'results' => [],
|
|
]);
|
|
|
|
expect($restoreRun->getAssignmentRestoreOutcomes())->toBeEmpty();
|
|
});
|
|
|
|
test('getSuccessfulAssignmentsCount returns correct count', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'results' => [
|
|
'assignment_outcomes' => [
|
|
['status' => 'success', 'assignment' => []],
|
|
['status' => 'success', 'assignment' => []],
|
|
['status' => 'failed', 'assignment' => []],
|
|
['status' => 'skipped', 'assignment' => []],
|
|
],
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->getSuccessfulAssignmentsCount())->toBe(2);
|
|
});
|
|
|
|
test('getFailedAssignmentsCount returns correct count', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'results' => [
|
|
'assignment_outcomes' => [
|
|
['status' => 'success', 'assignment' => []],
|
|
['status' => 'failed', 'assignment' => []],
|
|
['status' => 'failed', 'assignment' => []],
|
|
],
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->getFailedAssignmentsCount())->toBe(2);
|
|
});
|
|
|
|
test('getSkippedAssignmentsCount returns correct count', function () {
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'results' => [
|
|
'assignment_outcomes' => [
|
|
['status' => 'success', 'assignment' => []],
|
|
['status' => 'skipped', 'assignment' => []],
|
|
['status' => 'skipped', 'assignment' => []],
|
|
['status' => 'skipped', 'assignment' => []],
|
|
],
|
|
],
|
|
]);
|
|
|
|
expect($restoreRun->getSkippedAssignmentsCount())->toBe(3);
|
|
});
|