TenantAtlas/database/factories/TenantOnboardingSessionFactory.php
ahmido 98e2b5acd9 feat: managed tenant onboarding draft identity and resume semantics (#167)
## Summary
- add canonical managed-tenant onboarding draft routing with explicit draft identity and landing vs concrete draft behavior
- implement draft lifecycle, authorization, attribution, picker UX, resume-stage resolution, and auditable cancel or completion semantics
- add focused feature, unit, and browser coverage plus Spec 138 artifacts for the onboarding draft resume flow

## Validation
- `vendor/bin/sail artisan test --compact tests/Feature/ManagedTenantOnboardingWizardTest.php tests/Feature/Audit/OnboardingDraftAuditTest.php tests/Feature/Onboarding/OnboardingDraftAccessTest.php tests/Feature/Onboarding/OnboardingDraftAuthorizationTest.php tests/Feature/Onboarding/OnboardingDraftLifecycleTest.php tests/Feature/Onboarding/OnboardingDraftMultiTabTest.php tests/Feature/Onboarding/OnboardingDraftPickerTest.php tests/Feature/Onboarding/OnboardingDraftRoutingTest.php tests/Feature/Onboarding/OnboardingRbacSemanticsTest.php tests/Feature/Onboarding/OnboardingVerificationClustersTest.php tests/Feature/Onboarding/OnboardingVerificationTest.php tests/Feature/Onboarding/OnboardingVerificationV1_5UxTest.php tests/Feature/Verification/VerificationReportViewerDbOnlyTest.php tests/Unit/Onboarding tests/Unit/VerificationReportSanitizerEvidenceKindsTest.php tests/Browser/OnboardingDraftRefreshTest.php tests/Browser/OnboardingDraftVerificationResumeTest.php`
- passed: 69 tests, 251 assertions

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #167
2026-03-13 23:45:23 +00:00

126 lines
3.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Database\Factories;
use App\Models\Tenant;
use App\Models\TenantOnboardingSession;
use App\Models\User;
use App\Models\Workspace;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<TenantOnboardingSession>
*/
class TenantOnboardingSessionFactory extends Factory
{
protected $model = TenantOnboardingSession::class;
public function definition(): array
{
$entraTenantId = fake()->uuid();
$tenantName = fake()->company();
return [
'workspace_id' => Workspace::factory(),
'tenant_id' => null,
'entra_tenant_id' => $entraTenantId,
'current_step' => 'identify',
'state' => [
'entra_tenant_id' => $entraTenantId,
'tenant_name' => $tenantName,
'environment' => 'prod',
],
'started_by_user_id' => User::factory(),
'updated_by_user_id' => User::factory(),
'completed_at' => null,
'cancelled_at' => null,
];
}
public function forWorkspace(Workspace $workspace): static
{
return $this->state(fn (): array => [
'workspace_id' => (int) $workspace->getKey(),
]);
}
public function forTenant(Tenant $tenant): static
{
return $this->state(fn (array $attributes): array => [
'workspace_id' => (int) $tenant->workspace_id,
'tenant_id' => (int) $tenant->getKey(),
'entra_tenant_id' => (string) $tenant->tenant_id,
'state' => array_merge(is_array($attributes['state'] ?? null) ? $attributes['state'] : [], [
'tenant_id' => (int) $tenant->getKey(),
'entra_tenant_id' => (string) $tenant->tenant_id,
'tenant_name' => (string) $tenant->name,
'environment' => (string) ($tenant->environment ?? 'prod'),
]),
]);
}
public function startedBy(User $user): static
{
return $this->state(fn (): array => [
'started_by_user_id' => (int) $user->getKey(),
]);
}
public function updatedBy(User $user): static
{
return $this->state(fn (): array => [
'updated_by_user_id' => (int) $user->getKey(),
]);
}
public function withProviderConnection(int $providerConnectionId): static
{
return $this->state(fn (array $attributes): array => [
'current_step' => 'connection',
'state' => array_merge(is_array($attributes['state'] ?? null) ? $attributes['state'] : [], [
'provider_connection_id' => $providerConnectionId,
]),
]);
}
public function withVerificationRun(int $operationRunId): static
{
return $this->state(fn (array $attributes): array => [
'current_step' => 'verify',
'state' => array_merge(is_array($attributes['state'] ?? null) ? $attributes['state'] : [], [
'verification_operation_run_id' => $operationRunId,
]),
]);
}
public function reviewReady(): static
{
return $this->state(fn (array $attributes): array => [
'current_step' => 'bootstrap',
'state' => array_merge(is_array($attributes['state'] ?? null) ? $attributes['state'] : [], [
'bootstrap_operation_types' => [],
]),
]);
}
public function completed(): static
{
return $this->state(fn (): array => [
'current_step' => 'complete',
'completed_at' => now(),
'cancelled_at' => null,
]);
}
public function cancelled(): static
{
return $this->state(fn (): array => [
'current_step' => 'cancelled',
'completed_at' => null,
'cancelled_at' => now(),
]);
}
}