## 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
158 lines
4.8 KiB
PHP
158 lines
4.8 KiB
PHP
<?php
|
|
|
|
use App\Models\BackupItem;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
test('assignments cast works', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'assignments' => [
|
|
['id' => 'abc-123', 'target' => ['groupId' => 'group-1']],
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->assignments)->toBeArray()
|
|
->and($backupItem->assignments)->toHaveCount(1);
|
|
});
|
|
|
|
test('getAssignmentCountAttribute returns correct count', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'assignments' => [
|
|
['id' => 'abc-123', 'target' => ['groupId' => 'group-1']],
|
|
['id' => 'def-456', 'target' => ['groupId' => 'group-2']],
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->assignment_count)->toBe(2);
|
|
});
|
|
|
|
test('getAssignmentCountAttribute returns zero for null assignments', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'assignments' => null,
|
|
]);
|
|
|
|
expect($backupItem->assignment_count)->toBe(0);
|
|
});
|
|
|
|
test('hasAssignments returns true when assignments exist', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'assignments' => [
|
|
['id' => 'abc-123', 'target' => ['groupId' => 'group-1']],
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->hasAssignments())->toBeTrue();
|
|
});
|
|
|
|
test('hasAssignments returns false when assignments are null', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'assignments' => null,
|
|
]);
|
|
|
|
expect($backupItem->hasAssignments())->toBeFalse();
|
|
});
|
|
|
|
test('getGroupIdsAttribute extracts unique group IDs', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'assignments' => [
|
|
['id' => 'abc-123', 'target' => ['groupId' => 'group-1']],
|
|
['id' => 'def-456', 'target' => ['groupId' => 'group-2']],
|
|
['id' => 'ghi-789', 'target' => ['groupId' => 'group-1']], // duplicate
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->group_ids)->toHaveCount(2)
|
|
->and($backupItem->group_ids)->toContain('group-1', 'group-2');
|
|
});
|
|
|
|
test('getScopeTagIdsAttribute returns scope tag IDs from metadata', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [
|
|
'scope_tag_ids' => ['0', 'abc-123', 'def-456'],
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->scope_tag_ids)->toHaveCount(3)
|
|
->and($backupItem->scope_tag_ids)->toContain('0', 'abc-123', 'def-456');
|
|
});
|
|
|
|
test('getScopeTagIdsAttribute returns default when not in metadata', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [],
|
|
]);
|
|
|
|
expect($backupItem->scope_tag_ids)->toBe(['0']);
|
|
});
|
|
|
|
test('getScopeTagNamesAttribute returns scope tag names from metadata', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [
|
|
'scope_tag_names' => ['Default', 'HR-Admins', 'Finance'],
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->scope_tag_names)->toHaveCount(3)
|
|
->and($backupItem->scope_tag_names)->toContain('Default', 'HR-Admins', 'Finance');
|
|
});
|
|
|
|
test('getScopeTagNamesAttribute returns default when not in metadata', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [],
|
|
]);
|
|
|
|
expect($backupItem->scope_tag_names)->toBe(['Default']);
|
|
});
|
|
|
|
test('hasOrphanedAssignments returns true when flag is set', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [
|
|
'has_orphaned_assignments' => true,
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->hasOrphanedAssignments())->toBeTrue();
|
|
});
|
|
|
|
test('hasOrphanedAssignments returns false when flag is not set', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [],
|
|
]);
|
|
|
|
expect($backupItem->hasOrphanedAssignments())->toBeFalse();
|
|
});
|
|
|
|
test('assignmentsFetchFailed returns true when flag is set', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [
|
|
'assignments_fetch_failed' => true,
|
|
],
|
|
]);
|
|
|
|
expect($backupItem->assignmentsFetchFailed())->toBeTrue();
|
|
});
|
|
|
|
test('assignmentsFetchFailed returns false when flag is not set', function () {
|
|
$backupItem = BackupItem::factory()->create([
|
|
'metadata' => [],
|
|
]);
|
|
|
|
expect($backupItem->assignmentsFetchFailed())->toBeFalse();
|
|
});
|
|
|
|
test('scopeWithAssignments filters items with assignments', function () {
|
|
BackupItem::factory()->create(['assignments' => null]);
|
|
BackupItem::factory()->create(['assignments' => []]);
|
|
$withAssignments = BackupItem::factory()->create([
|
|
'assignments' => [
|
|
['id' => 'abc-123', 'target' => ['groupId' => 'group-1']],
|
|
],
|
|
]);
|
|
|
|
$result = BackupItem::withAssignments()->get();
|
|
|
|
expect($result)->toHaveCount(1)
|
|
->and($result->first()->id)->toBe($withAssignments->id);
|
|
});
|