TenantAtlas/tests/Feature/BackupScheduling/BackupScheduleCrudTest.php
ahmido b6343d5c3a feat: unified managed tenant onboarding wizard (#88)
Implements workspace-scoped managed tenant onboarding wizard (Filament v5 / Livewire v4) with strict RBAC (404/403 semantics), resumable sessions, provider connection selection/creation, verification OperationRun, and optional bootstrap. Removes legacy onboarding entrypoints and adds Pest coverage + spec artifacts (073).

## 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.fritz.box>
Reviewed-on: #88
2026-02-03 17:30:15 +00:00

130 lines
4.4 KiB
PHP

<?php
use App\Filament\Resources\BackupScheduleResource\Pages\CreateBackupSchedule;
use App\Filament\Resources\BackupScheduleResource\Pages\EditBackupSchedule;
use App\Models\BackupSchedule;
use App\Models\Tenant;
use Carbon\CarbonImmutable;
use Filament\Facades\Filament;
use Livewire\Livewire;
test('backup schedules listing is tenant scoped', function () {
[$user, $tenantA] = createUserWithTenant(role: 'manager');
$tenantB = Tenant::factory()->create([
'workspace_id' => $tenantA->workspace_id,
]);
createUserWithTenant(tenant: $tenantB, user: $user, role: 'manager');
BackupSchedule::query()->create([
'tenant_id' => $tenantA->id,
'name' => 'Tenant A schedule',
'is_enabled' => true,
'timezone' => 'UTC',
'frequency' => 'daily',
'time_of_day' => '01:00:00',
'days_of_week' => null,
'policy_types' => [
'deviceConfiguration',
'groupPolicyConfiguration',
'settingsCatalogPolicy',
],
'include_foundations' => true,
'retention_keep_last' => 30,
]);
BackupSchedule::query()->create([
'tenant_id' => $tenantB->id,
'name' => 'Tenant B schedule',
'is_enabled' => true,
'timezone' => 'UTC',
'frequency' => 'daily',
'time_of_day' => '02:00:00',
'days_of_week' => null,
'policy_types' => ['deviceCompliancePolicy'],
'include_foundations' => true,
'retention_keep_last' => 30,
]);
$this->actingAs($user);
// createUserWithTenant() may be called multiple times in this test; ensure the current
// workspace matches the tenant we are about to access.
session()->put(\App\Support\Workspaces\WorkspaceContext::SESSION_KEY, (int) $tenantA->workspace_id);
$this->get(route('filament.admin.resources.backup-schedules.index', filamentTenantRouteParams($tenantA)))
->assertOk()
->assertSee('Tenant A schedule')
->assertSee('Device Configuration')
->assertSee('more')
->assertDontSee('Tenant B schedule');
});
test('backup schedules listing shows next run in schedule timezone', function () {
[$user, $tenant] = createUserWithTenant(role: 'manager');
BackupSchedule::query()->create([
'tenant_id' => $tenant->id,
'name' => 'Berlin schedule',
'is_enabled' => true,
'timezone' => 'Europe/Berlin',
'frequency' => 'daily',
'time_of_day' => '10:17:00',
'days_of_week' => null,
'policy_types' => ['deviceConfiguration'],
'include_foundations' => true,
'retention_keep_last' => 30,
'next_run_at' => CarbonImmutable::create(2026, 1, 5, 9, 17, 0, 'UTC'),
]);
$this->actingAs($user);
$this->get(route('filament.admin.resources.backup-schedules.index', filamentTenantRouteParams($tenant)))
->assertOk()
->assertSee('Jan 5, 2026 10:17:00');
});
test('backup schedules pages return 404 for unauthorized tenant', function () {
[$user] = createUserWithTenant(role: 'manager');
$unauthorizedTenant = Tenant::factory()->create();
$this->actingAs($user)
->get(route('filament.admin.resources.backup-schedules.index', filamentTenantRouteParams($unauthorizedTenant)))
->assertNotFound();
});
test('manager can create and edit backup schedules via filament', function () {
[$user, $tenant] = createUserWithTenant(role: 'manager');
$this->actingAs($user);
Filament::setTenant($tenant, true);
Livewire::test(CreateBackupSchedule::class)
->fillForm([
'name' => 'Daily at 10',
'is_enabled' => true,
'timezone' => 'UTC',
'frequency' => 'daily',
'time_of_day' => '10:00',
'policy_types' => ['deviceConfiguration'],
'include_foundations' => true,
'retention_keep_last' => 30,
])
->call('create')
->assertHasNoFormErrors();
$schedule = BackupSchedule::query()->where('tenant_id', $tenant->id)->first();
expect($schedule)->not->toBeNull();
expect($schedule->next_run_at)->not->toBeNull();
Livewire::test(EditBackupSchedule::class, ['record' => $schedule->getRouteKey()])
->fillForm([
'name' => 'Daily at 11',
])
->call('save')
->assertHasNoFormErrors();
$schedule->refresh();
expect($schedule->name)->toBe('Daily at 11');
});