TenantAtlas/apps/platform/tests/Unit/Providers/ProviderConnectionTargetScopeDescriptorTest.php
ahmido e64bae9cfc feat: cut over tenant core to managed environments (#335)
## 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
2026-05-07 06:38:14 +00:00

64 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\ProviderConnection;
use App\Support\Providers\TargetScope\ProviderConnectionSurfaceSummary;
use App\Support\Providers\TargetScope\ProviderConnectionTargetScopeDescriptor;
use App\Support\Providers\TargetScope\ProviderConnectionTargetScopeNormalizer;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('normalizes provider connections into neutral target-scope descriptors with contextual Microsoft metadata', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
$connection = ProviderConnection::factory()->create([
'workspace_id' => (int) $tenant->workspace_id,
'managed_environment_id' => (int) $tenant->getKey(),
'provider' => 'microsoft',
'entra_tenant_id' => '11111111-1111-1111-1111-111111111111',
'display_name' => 'Primary connection',
]);
$descriptor = app(ProviderConnectionTargetScopeNormalizer::class)
->descriptorForConnection($connection->fresh(['tenant']));
$summary = ProviderConnectionSurfaceSummary::forConnection($connection->fresh(['tenant']));
expect($user)->not->toBeNull()
->and($descriptor->provider)->toBe('microsoft')
->and($descriptor->scopeKind)->toBe(ProviderConnectionTargetScopeDescriptor::SCOPE_KIND_TENANT)
->and($descriptor->scopeIdentifier)->toBe('11111111-1111-1111-1111-111111111111')
->and($descriptor->sharedLabel)->toBe('Target scope')
->and($descriptor->summary())->toContain((string) $tenant->name)
->and($summary->targetScopeSummary())->toContain('11111111-1111-1111-1111-111111111111')
->and($summary->contextualIdentityDetails)->toHaveCount(1)
->and($summary->contextualIdentityDetails[0]->detailLabel)->toBe('Microsoft tenant ID');
});
it('blocks unsupported provider-scope combinations explicitly instead of inheriting Microsoft defaults', function (): void {
$result = app(ProviderConnectionTargetScopeNormalizer::class)->normalizeInput(
provider: 'unknown-provider',
scopeKind: ProviderConnectionTargetScopeDescriptor::SCOPE_KIND_TENANT,
scopeIdentifier: 'scope-1',
scopeDisplayName: 'Scope 1',
);
expect($result['status'])->toBe(ProviderConnectionTargetScopeNormalizer::STATUS_BLOCKED)
->and($result['failure_code'])->toBe(ProviderConnectionTargetScopeNormalizer::FAILURE_UNSUPPORTED_PROVIDER_SCOPE_COMBINATION)
->and($result['message'])->toContain('not supported');
});
it('blocks missing target-scope context with neutral validation language', function (): void {
$result = app(ProviderConnectionTargetScopeNormalizer::class)->normalizeInput(
provider: 'microsoft',
scopeKind: ProviderConnectionTargetScopeDescriptor::SCOPE_KIND_TENANT,
scopeIdentifier: '',
scopeDisplayName: 'Missing scope',
);
expect($result['status'])->toBe(ProviderConnectionTargetScopeNormalizer::STATUS_BLOCKED)
->and($result['failure_code'])->toBe(ProviderConnectionTargetScopeNormalizer::FAILURE_MISSING_PROVIDER_CONTEXT)
->and($result['message'])->toBe('A target scope identifier is required for this provider connection.');
});