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
109 lines
3.7 KiB
PHP
109 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Jobs\RunBackupScheduleJob;
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\OperationRun;
|
|
use App\Services\BackupScheduling\BackupScheduleDispatcher;
|
|
use App\Services\OperationRunService;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Support\Facades\Bus;
|
|
|
|
it('dispatching the same slot twice creates only one run', function () {
|
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 5, 10, 0, 30, 'UTC'));
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
BackupSchedule::query()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Daily 10:00',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '10:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
'next_run_at' => null,
|
|
]);
|
|
|
|
Bus::fake();
|
|
|
|
$dispatcher = app(BackupScheduleDispatcher::class);
|
|
|
|
$dispatcher->dispatchDue([$tenant->external_id]);
|
|
$dispatcher->dispatchDue([$tenant->external_id]);
|
|
|
|
expect(\App\Models\BackupScheduleRun::query()->count())->toBe(0);
|
|
|
|
expect(OperationRun::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->where('type', 'backup_schedule.scheduled')
|
|
->count())->toBe(1);
|
|
|
|
Bus::assertDispatchedTimes(RunBackupScheduleJob::class, 1);
|
|
|
|
Bus::assertDispatched(RunBackupScheduleJob::class, function (RunBackupScheduleJob $job) use ($tenant): bool {
|
|
return $job->backupScheduleId !== null
|
|
&& $job->backupScheduleRunId === 0
|
|
&& $job->operationRun?->tenant_id === $tenant->getKey()
|
|
&& $job->operationRun?->type === 'backup_schedule.scheduled';
|
|
});
|
|
});
|
|
|
|
it('treats an existing canonical run as already-dispatched and advances next_run_at', function () {
|
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 5, 10, 0, 30, 'UTC'));
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$schedule = BackupSchedule::query()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'name' => 'Daily 10:00',
|
|
'is_enabled' => true,
|
|
'timezone' => 'UTC',
|
|
'frequency' => 'daily',
|
|
'time_of_day' => '10:00:00',
|
|
'days_of_week' => null,
|
|
'policy_types' => ['deviceConfiguration'],
|
|
'include_foundations' => true,
|
|
'retention_keep_last' => 30,
|
|
'next_run_at' => null,
|
|
]);
|
|
|
|
/** @var OperationRunService $operationRunService */
|
|
$operationRunService = app(OperationRunService::class);
|
|
|
|
$operationRunService->ensureRunWithIdentityStrict(
|
|
tenant: $tenant,
|
|
type: 'backup_schedule.scheduled',
|
|
identityInputs: [
|
|
'backup_schedule_id' => (int) $schedule->id,
|
|
'scheduled_for' => CarbonImmutable::now('UTC')->startOfMinute()->toDateTimeString(),
|
|
],
|
|
context: [
|
|
'backup_schedule_id' => (int) $schedule->id,
|
|
'scheduled_for' => CarbonImmutable::now('UTC')->startOfMinute()->toDateTimeString(),
|
|
'trigger' => 'scheduled',
|
|
],
|
|
);
|
|
|
|
Bus::fake();
|
|
|
|
$dispatcher = app(BackupScheduleDispatcher::class);
|
|
$dispatcher->dispatchDue([$tenant->external_id]);
|
|
|
|
expect(\App\Models\BackupScheduleRun::query()->count())->toBe(0);
|
|
Bus::assertNotDispatched(RunBackupScheduleJob::class);
|
|
|
|
expect(OperationRun::query()
|
|
->where('tenant_id', $tenant->getKey())
|
|
->where('type', 'backup_schedule.scheduled')
|
|
->count())->toBe(1);
|
|
|
|
$schedule->refresh();
|
|
expect($schedule->next_run_at)->not->toBeNull();
|
|
expect($schedule->next_run_at->toDateTimeString())->toBe('2026-01-06 10:00:00');
|
|
});
|