TenantAtlas/apps/platform/tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php
ahmido 0c7adefe5b Spec 330: environment dashboard baseline compare productization (#392)
## Summary
- add the baseline compare landing experience for the environment dashboard productization flow
- expand the environment dashboard overview and summary-building logic to support richer baseline comparison states and assessments
- update the supporting Blade templates for the new compare and overview presentation
- add English and German translations for the baseline compare surface
- include the Spec 330 planning and task artifacts alongside the implementation

## Tests
- touched browser, feature, and unit coverage for the new baseline compare flow
- updated test files include `Spec330EnvironmentDashboardBaselineCompareSmokeTest`, `BaselineCompareLandingWhyNoFindingsTest`, `Spec330EnvironmentDashboardBaselineCompareProductizationTest`, `HeaderContextBarTest`, and `ManagedEnvironmentModelTest`
- no additional test run was performed as part of this commit/push/PR workflow

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #392
2026-05-20 20:32:39 +00:00

90 lines
3.4 KiB
PHP

<?php
use App\Models\ManagedEnvironment;
use App\Models\ProviderConnection;
use App\Models\Workspace;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Schema;
uses(RefreshDatabase::class);
it('owns workspace relation, slug route binding, and selectable lifecycle truth', function (): void {
$workspace = Workspace::factory()->create();
$environment = ManagedEnvironment::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'name' => 'Contoso Production',
'display_name' => 'Contoso Prod',
'slug' => 'contoso-prod',
'kind' => 'production',
'lifecycle_status' => ManagedEnvironment::STATUS_ACTIVE,
]);
expect($workspace->managedEnvironments()->whereKey($environment->getKey())->exists())->toBeTrue()
->and($workspace->tenants()->whereKey($environment->getKey())->exists())->toBeTrue()
->and($environment->workspace->is($workspace))->toBeTrue()
->and($environment->getRouteKeyName())->toBe('slug')
->and((new ManagedEnvironment)->resolveRouteBinding('contoso-prod')->is($environment))->toBeTrue()
->and($environment->isSelectableAsContext())->toBeTrue()
->and($environment->getFilamentName())->toBe('Contoso Prod');
});
it('keeps archived environments resolvable by route key but unavailable as active context', function (): void {
$environment = ManagedEnvironment::factory()->archived()->create([
'slug' => 'archived-environment',
]);
$resolved = (new ManagedEnvironment)->resolveRouteBinding('archived-environment');
expect($resolved)->toBeInstanceOf(ManagedEnvironment::class)
->and($resolved->is($environment))->toBeTrue()
->and($resolved->isSelectableAsContext())->toBeFalse();
});
it('keeps provider-specific identity off managed environment columns', function (): void {
$columns = Schema::getColumnListing('managed_environments');
expect($columns)->not->toContain(
'external_id',
'tenant_id',
'managed_environment_id',
'status',
'environment',
'app_client_id',
'app_client_secret',
'app_certificate_thumbprint',
'app_notes',
'app_status',
'domain',
'entra_tenant_id',
'graph_tenant_id',
);
});
it('resolves Microsoft tenant identity through provider-owned seams only', function (): void {
$environment = ManagedEnvironment::factory()->create([
'slug' => 'provider-neutral-root',
]);
ProviderConnection::factory()->platform()->consentGranted()->create([
'managed_environment_id' => (int) $environment->getKey(),
'workspace_id' => (int) $environment->workspace_id,
'provider' => 'microsoft',
'entra_tenant_id' => '11111111-1111-1111-1111-111111111111',
'is_default' => true,
]);
expect($environment->refresh()->graphTenantId())->toBe('11111111-1111-1111-1111-111111111111')
->and(fn () => $environment->graphOptions())->toThrow(BadMethodCallException::class);
});
it('treats managed_environment_id as a write-through alias for slug', function (): void {
$environment = ManagedEnvironment::factory()->create([
'managed_environment_id' => 'alias-slug',
]);
expect($environment->slug)->toBe('alias-slug')
->and($environment->managed_environment_id)->toBe('alias-slug')
->and($environment->external_id)->toBe('alias-slug');
});