## 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
64 lines
2.6 KiB
PHP
64 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Support\Providers\ProviderConnectionType;
|
|
use App\Support\Providers\ProviderConsentStatus;
|
|
use App\Support\Providers\ProviderReasonCodes;
|
|
use App\Support\Providers\ProviderVerificationStatus;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('stores a successful callback as a platform connection with separate consent and verification states', function (): void {
|
|
$tenant = ManagedEnvironment::factory()->create([
|
|
'managed_environment_id' => 'tenant-platform-ok',
|
|
'name' => 'Contoso Platform',
|
|
]);
|
|
|
|
$this->get(route('admin.consent.callback', [
|
|
'tenant' => $tenant->managed_environment_id,
|
|
'admin_consent' => 'true',
|
|
]))->assertOk();
|
|
|
|
$connection = ProviderConnection::query()
|
|
->where('managed_environment_id', (int) $tenant->getKey())
|
|
->where('provider', 'microsoft')
|
|
->where('entra_tenant_id', $tenant->graphTenantId())
|
|
->firstOrFail();
|
|
|
|
expect($connection->connection_type)->toBe(ProviderConnectionType::Platform)
|
|
->and($connection->is_enabled)->toBeTrue()
|
|
->and($connection->consent_status)->toBe(ProviderConsentStatus::Granted)
|
|
->and($connection->verification_status)->toBe(ProviderVerificationStatus::Unknown)
|
|
->and($connection->credential()->exists())->toBeFalse()
|
|
->and($connection->last_error_reason_code)->toBeNull();
|
|
});
|
|
|
|
it('stores callback failures without promoting the platform connection to a verified state', function (): void {
|
|
$tenant = ManagedEnvironment::factory()->create([
|
|
'managed_environment_id' => 'tenant-platform-error',
|
|
'name' => 'Fabrikam Platform',
|
|
]);
|
|
|
|
$this->get(route('admin.consent.callback', [
|
|
'tenant' => $tenant->managed_environment_id,
|
|
'error' => 'access_denied',
|
|
]))->assertOk();
|
|
|
|
$connection = ProviderConnection::query()
|
|
->where('managed_environment_id', (int) $tenant->getKey())
|
|
->where('provider', 'microsoft')
|
|
->where('entra_tenant_id', $tenant->graphTenantId())
|
|
->firstOrFail();
|
|
|
|
expect($connection->connection_type)->toBe(ProviderConnectionType::Platform)
|
|
->and($connection->is_enabled)->toBeTrue()
|
|
->and($connection->consent_status)->toBe(ProviderConsentStatus::Failed)
|
|
->and($connection->verification_status)->toBe(ProviderVerificationStatus::Unknown)
|
|
->and($connection->last_error_reason_code)->toBe(ProviderReasonCodes::ProviderAuthFailed)
|
|
->and($connection->credential()->exists())->toBeFalse();
|
|
});
|