Summary Consolidates the “Tenant Operate Hub” work (Spec 085) and the follow-up adjustments from the 086 session merge into a single branch ready to merge into dev. Primary focus: stabilize Ops/Operate Hub UX flows, tighten/align authorization semantics, and make the full Sail test suite green. Key Changes Ops UX / Verification Readonly members can view verification operation runs (reports) while starting verification remains restricted. Normalized failure reason-code handling and aligned UX expectations with the provider reason-code taxonomy. Onboarding wizard UX “Start verification” CTA is hidden while a verification run is active; “Refresh” is shown during in-progress runs. Treats provider_permission_denied as a blocking reason (while keeping legacy compatibility). Test + fixture hardening Standardized use of default provider connection fixtures in tests where sync/restore flows require it. Fixed multiple Filament URL/tenant-context test cases to avoid 404s and reduce tenancy routing brittleness. Policy sync / restore safety Enrollment configuration type collision classification tests now exercise the real sync path (with required provider connection present). Restore edge-case safety tests updated to reflect current provider-connection requirements. Testing vendor/bin/sail artisan test --compact (green) vendor/bin/sail bin pint --dirty (green) Notes Includes merged 086 session work already (no separate PR needed). Co-authored-by: Ahmed Darrazi <ahmeddarrazi@ebc83aaa-d947-4a08-b88e-bd72ac9645f7.fritz.box> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.fritz.box> Reviewed-on: #103
139 lines
5.2 KiB
PHP
139 lines
5.2 KiB
PHP
<?php
|
|
|
|
use App\Filament\Resources\BackupScheduleResource\Pages\ListBackupSchedules;
|
|
use App\Filament\Resources\EntraGroupResource\Pages\ListEntraGroups;
|
|
use App\Filament\Resources\InventoryItemResource\Pages\ListInventoryItems;
|
|
use App\Jobs\EntraGroupSyncJob;
|
|
use App\Jobs\RunBackupScheduleJob;
|
|
use App\Models\InventorySyncRun;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\BackupScheduleRun;
|
|
use App\Models\EntraGroupSyncRun;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Services\Inventory\InventorySyncService;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Livewire\Livewire;
|
|
|
|
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
|
|
|
it('rejects cross-tenant run starts (403) with no run records created', function () {
|
|
Queue::fake();
|
|
|
|
[$user, $tenantA] = createUserWithTenant(role: 'owner');
|
|
$tenantB = Tenant::factory()->create();
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenantA, true);
|
|
|
|
$sync = app(InventorySyncService::class);
|
|
$allTypes = $sync->defaultSelectionPayload()['policy_types'];
|
|
|
|
Livewire::test(ListInventoryItems::class)
|
|
->callAction('run_inventory_sync', data: ['tenant_id' => $tenantB->getKey(), 'policy_types' => $allTypes])
|
|
->assertSuccessful();
|
|
|
|
Queue::assertNothingPushed();
|
|
|
|
expect(InventorySyncRun::query()->where('tenant_id', $tenantB->id)->exists())->toBeFalse();
|
|
expect(OperationRun::query()->where('tenant_id', $tenantB->id)->exists())->toBeFalse();
|
|
});
|
|
|
|
it('prevents run creation when a readonly member tries to start inventory sync', function () {
|
|
Queue::fake();
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$sync = app(InventorySyncService::class);
|
|
$allTypes = $sync->defaultSelectionPayload()['policy_types'];
|
|
|
|
Livewire::test(ListInventoryItems::class)
|
|
->assertActionVisible('run_inventory_sync')
|
|
->assertActionDisabled('run_inventory_sync')
|
|
->callAction('run_inventory_sync', data: ['tenant_id' => $tenant->getKey(), 'policy_types' => $allTypes]);
|
|
|
|
Queue::assertNothingPushed();
|
|
expect(InventorySyncRun::query()->where('tenant_id', $tenant->id)->exists())->toBeFalse();
|
|
expect(OperationRun::query()->where('tenant_id', $tenant->id)->exists())->toBeFalse();
|
|
});
|
|
|
|
it('prevents run creation when a readonly member tries to start directory group sync', function () {
|
|
Queue::fake();
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ListEntraGroups::class)
|
|
->assertActionVisible('sync_groups')
|
|
->assertActionDisabled('sync_groups')
|
|
->callAction('sync_groups');
|
|
|
|
Queue::assertNotPushed(EntraGroupSyncJob::class);
|
|
expect(EntraGroupSyncRun::query()->where('tenant_id', $tenant->id)->exists())->toBeFalse();
|
|
expect(OperationRun::query()->where('tenant_id', $tenant->id)->exists())->toBeFalse();
|
|
});
|
|
|
|
it('prevents run creation when a readonly member tries to run a backup schedule now', function () {
|
|
Queue::fake([RunBackupScheduleJob::class]);
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$schedule = BackupSchedule::query()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Nightly',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '01:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
]);
|
|
|
|
Livewire::test(ListBackupSchedules::class)
|
|
->assertTableActionVisible('runNow', $schedule)
|
|
->assertTableActionDisabled('runNow', $schedule)
|
|
->callTableAction('runNow', $schedule);
|
|
|
|
Queue::assertNothingPushed();
|
|
expect(BackupScheduleRun::query()->where('backup_schedule_id', $schedule->id)->exists())->toBeFalse();
|
|
expect(OperationRun::query()->where('tenant_id', $tenant->id)->exists())->toBeFalse();
|
|
});
|
|
|
|
it('prevents run creation when a readonly member tries to retry a backup schedule', function () {
|
|
Queue::fake([RunBackupScheduleJob::class]);
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$schedule = BackupSchedule::query()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Nightly',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '01:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
]);
|
|
|
|
Livewire::test(ListBackupSchedules::class)
|
|
->assertTableActionVisible('retry', $schedule)
|
|
->assertTableActionDisabled('retry', $schedule)
|
|
->callTableAction('retry', $schedule);
|
|
|
|
Queue::assertNothingPushed();
|
|
expect(BackupScheduleRun::query()->where('backup_schedule_id', $schedule->id)->exists())->toBeFalse();
|
|
expect(OperationRun::query()->where('tenant_id', $tenant->id)->exists())->toBeFalse();
|
|
});
|