TenantAtlas/apps/platform/tests/Unit/Providers/PlatformProviderIdentityResolverTest.php
Ahmed Darrazi 19132dc433
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 1m28s
feat: normalize provider connection scope contracts
2026-05-07 21:27:15 +02:00

44 lines
2.1 KiB
PHP

<?php
use App\Services\Providers\PlatformProviderIdentityResolver;
use App\Support\Providers\ProviderConnectionType;
use App\Support\Providers\ProviderReasonCodes;
it('resolves the central platform identity from config', function (): void {
config()->set('graph.client_id', 'platform-client-id');
config()->set('graph.client_secret', 'platform-client-secret');
config()->set('graph.managed_environment_id', 'platform-home-tenant-id');
$resolution = app(PlatformProviderIdentityResolver::class)->resolve('customer-tenant-id');
expect($resolution->resolved)->toBeTrue()
->and($resolution->connectionType)->toBe(ProviderConnectionType::Platform)
->and(property_exists($resolution, 'tenantContext'))->toBeFalse()
->and($resolution->targetScopeIdentifier())->toBe('customer-tenant-id')
->and($resolution->effectiveClientId)->toBe('platform-client-id')
->and($resolution->credentialSource)->toBe('platform_config')
->and($resolution->clientSecret)->toBe('platform-client-secret')
->and($resolution->authorityTenant)->toBe('platform-home-tenant-id')
->and($resolution->redirectUri)->toBe(route('admin.consent.callback'));
});
it('blocks platform identity resolution when the platform client id is missing', function (): void {
config()->set('graph.client_id', '');
config()->set('graph.client_secret', 'platform-client-secret');
$resolution = app(PlatformProviderIdentityResolver::class)->resolve('customer-tenant-id');
expect($resolution->resolved)->toBeFalse()
->and($resolution->effectiveReasonCode())->toBe(ProviderReasonCodes::PlatformIdentityMissing);
});
it('blocks platform identity resolution when the platform secret is missing', function (): void {
config()->set('graph.client_id', 'platform-client-id');
config()->set('graph.client_secret', '');
$resolution = app(PlatformProviderIdentityResolver::class)->resolve('customer-tenant-id');
expect($resolution->resolved)->toBeFalse()
->and($resolution->effectiveReasonCode())->toBe(ProviderReasonCodes::PlatformIdentityIncomplete);
});