TenantAtlas/apps/platform/tests/Feature/EnvironmentReview/EnvironmentReviewCreationTest.php
ahmido 292d555eac refactor: consolidate internal tenant model naming (#355)
## Summary
- consolidate internal platform naming from `Tenant` to `Environment` / `ManagedEnvironment` across models, controllers, services, and Filament resources
- rename environment-scoped UI surfaces such as dashboards, chooser flows, navigation, and related widgets to match the updated environment-first domain language
- align middleware, onboarding/review lifecycle services, jobs, and route/context controllers with the new environment-scoped architecture

## Validation
- not rerun as part of this commit/push/PR request

## Notes
- branch is 1 commit ahead of `platform-dev`
- main commit: `refactor: consolidate internal tenant model naming`

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #355
2026-05-14 11:13:28 +00:00

60 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Finding;
use App\Services\Evidence\EvidenceSnapshotService;
use App\Support\EnvironmentReviewCompletenessState;
use App\Support\EnvironmentReviewStatus;
it('creates an anchored environment review from a chosen evidence snapshot and keeps that basis stable after live data changes', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$snapshot = seedEnvironmentReviewEvidence($tenant);
$review = composeEnvironmentReviewForTest($tenant, $user, $snapshot);
expect($review->evidence_snapshot_id)->toBe((int) $snapshot->getKey())
->and($review->sections)->toHaveCount(7)
->and($review->sections->pluck('section_key')->all())->toBe([
'executive_summary',
'control_interpretation',
'open_risks',
'accepted_risks',
'permission_posture',
'baseline_drift_posture',
'operations_health',
])
->and($review->summary['evidence_basis']['snapshot_id'])->toBe((int) $snapshot->getKey());
Finding::factory()->create([
'managed_environment_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'severity' => Finding::SEVERITY_CRITICAL,
]);
$newSnapshotPayload = app(EvidenceSnapshotService::class)->buildSnapshotPayload($tenant);
expect($review->fresh()->evidence_snapshot_id)->toBe((int) $snapshot->getKey())
->and($review->fresh()->summary['evidence_basis']['snapshot_fingerprint'])->toBe((string) $snapshot->fingerprint)
->and($newSnapshotPayload['fingerprint'])->not->toBe((string) $snapshot->fingerprint);
});
it('records completeness and publish blockers when the evidence basis is partial or missing', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$snapshot = seedEnvironmentReviewEvidence(
tenant: $tenant,
permissionPayload: [
'required_count' => 10,
'granted_count' => 7,
],
operationRunCount: 0,
);
$review = composeEnvironmentReviewForTest($tenant, $user, $snapshot);
expect($review->completeness_state)->toBe(EnvironmentReviewCompletenessState::Missing->value)
->and($review->status)->toBe(EnvironmentReviewStatus::Draft->value)
->and($review->publishBlockers())->not->toBeEmpty();
});