## Summary - replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership - propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths - add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - branch pushed from commit `1123b122` - browser smoke test file was added but not run in this pass Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #335
91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\ProviderCredential;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Support\Providers\ProviderNextStepsRegistry;
|
|
use App\Support\Providers\ProviderReasonCodes;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('includes an admin consent next step when provider consent is missing', function () {
|
|
$tenant = ManagedEnvironment::create([
|
|
'managed_environment_id' => 'tenant-1',
|
|
'name' => 'Contoso',
|
|
]);
|
|
|
|
$registry = app(ProviderNextStepsRegistry::class);
|
|
|
|
$steps = $registry->forReason($tenant, ProviderReasonCodes::ProviderConsentMissing);
|
|
|
|
expect($steps)->toBeArray()
|
|
->and($steps)->not->toBeEmpty()
|
|
->and($steps[0]['label'])->toBe('Grant admin consent')
|
|
->and($steps[0]['url'])->toContain('learn.microsoft.com');
|
|
});
|
|
|
|
it('links to the real admin consent endpoint when a dedicated provider connection exists', function () {
|
|
$tenant = ManagedEnvironment::factory()->create([
|
|
'app_client_id' => null,
|
|
]);
|
|
|
|
$connection = ProviderConnection::factory()->dedicated()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'provider' => 'microsoft',
|
|
'entra_tenant_id' => 'dedicated-target-tenant-id',
|
|
'is_default' => true,
|
|
]);
|
|
|
|
ProviderCredential::factory()->create([
|
|
'provider_connection_id' => (int) $connection->getKey(),
|
|
'payload' => [
|
|
'client_id' => 'derived-client-id',
|
|
'client_secret' => 'derived-client-secret',
|
|
],
|
|
]);
|
|
|
|
$registry = app(ProviderNextStepsRegistry::class);
|
|
|
|
$steps = $registry->forReason($tenant, ProviderReasonCodes::ProviderConsentMissing, $connection);
|
|
|
|
expect($steps)->toBeArray()
|
|
->and($steps)->not->toBeEmpty()
|
|
->and($steps[0]['label'])->toBe('Grant admin consent')
|
|
->and($steps[0]['url'])->toContain('login.microsoftonline.com')
|
|
->and($steps[0]['url'])->toContain('adminconsent');
|
|
});
|
|
|
|
it('surfaces review-required next steps on the provider connection detail path', function (): void {
|
|
$tenant = ManagedEnvironment::factory()->create([
|
|
'app_client_id' => null,
|
|
]);
|
|
|
|
$connection = ProviderConnection::factory()->dedicated()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'provider' => 'microsoft',
|
|
'entra_tenant_id' => (string) $tenant->graphTenantId(),
|
|
'migration_review_required' => true,
|
|
'metadata' => [
|
|
'effective_app' => [
|
|
'app_id' => null,
|
|
'source' => 'review_required',
|
|
],
|
|
],
|
|
]);
|
|
|
|
$registry = app(ProviderNextStepsRegistry::class);
|
|
|
|
$steps = $registry->forReason($tenant, ProviderReasonCodes::ProviderConnectionReviewRequired, $connection);
|
|
|
|
expect($steps)->toHaveCount(2)
|
|
->and($steps[0]['label'])->toBe('Review migration classification')
|
|
->and($steps[1]['label'])->toBe('Review effective app details')
|
|
->and($steps[0]['url'])->toContain('/provider-connections/')
|
|
->and($steps[1]['url'])->toContain('/edit');
|
|
});
|