TenantAtlas/apps/platform/tests/Unit/Baselines/SnapshotRendering/BaselineSnapshotPresenterTest.php
ahmido ce0615a9c1 Spec 182: relocate Laravel platform to apps/platform (#213)
## Summary
- move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling
- update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location
- add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation`
- integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404`

## Remaining Rollout Checks
- validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout
- confirm web, queue, and scheduler processes all start from the expected working directory in staging/production
- verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #213
2026-04-08 08:40:47 +00:00

115 lines
4.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\BaselineProfile;
use App\Models\BaselineSnapshot;
use App\Models\BaselineSnapshotItem;
use App\Services\Baselines\SnapshotRendering\BaselineSnapshotPresenter;
use App\Services\Baselines\SnapshotRendering\Renderers\DeviceComplianceSnapshotTypeRenderer;
use App\Services\Baselines\SnapshotRendering\Renderers\FallbackSnapshotTypeRenderer;
use App\Services\Baselines\SnapshotRendering\Renderers\IntuneRoleDefinitionSnapshotTypeRenderer;
use App\Services\Baselines\SnapshotRendering\SnapshotTypeRendererRegistry;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
it('builds summary rows and grouped output for mixed snapshot types', function (): void {
$presenter = new BaselineSnapshotPresenter(
new SnapshotTypeRendererRegistry(
renderers: [
new IntuneRoleDefinitionSnapshotTypeRenderer,
new DeviceComplianceSnapshotTypeRenderer,
],
fallbackRenderer: new FallbackSnapshotTypeRenderer,
),
);
$snapshot = new BaselineSnapshot([
'id' => 130,
'snapshot_identity_hash' => 'snapshot-hash-130',
'captured_at' => now(),
'summary_jsonb' => [
'total_items' => 3,
'policy_type_counts' => [
'intuneRoleDefinition' => 1,
'deviceCompliancePolicy' => 1,
'mysteryPolicyType' => 1,
],
'fidelity_counts' => [
'content' => 2,
'meta' => 1,
],
'gaps' => [
'count' => 1,
'by_reason' => ['missing_evidence' => 1],
],
],
]);
$snapshot->setRelation('baselineProfile', new BaselineProfile(['name' => 'Security Baseline']));
$snapshot->setRelation('items', new EloquentCollection([
new BaselineSnapshotItem([
'id' => 1,
'policy_type' => 'intuneRoleDefinition',
'subject_key' => hash('sha256', 'intuneRoleDefinition|security-reader'),
'subject_external_id' => hash('sha256', 'intuneRoleDefinition|security-reader'),
'meta_jsonb' => [
'display_name' => 'Security Reader',
'evidence' => [
'fidelity' => 'content',
'source' => 'policy_version',
'observed_at' => '2026-03-09T12:00:00+00:00',
],
'identity' => ['strategy' => 'external_id'],
'rbac' => [
'is_built_in' => false,
'role_permission_count' => 2,
],
'version_reference' => ['policy_version_id' => 42],
],
]),
new BaselineSnapshotItem([
'id' => 2,
'policy_type' => 'deviceCompliancePolicy',
'subject_key' => 'bitlocker require',
'subject_external_id' => hash('sha256', 'deviceCompliancePolicy|bitlocker require'),
'meta_jsonb' => [
'display_name' => 'Bitlocker Require',
'platform' => 'windows',
'assignment_target_count' => 3,
'evidence' => [
'fidelity' => 'meta',
'source' => 'inventory',
'observed_at' => '2026-03-09T11:00:00+00:00',
],
],
]),
new BaselineSnapshotItem([
'id' => 3,
'policy_type' => 'mysteryPolicyType',
'subject_key' => 'mystery policy',
'subject_external_id' => hash('sha256', 'mysteryPolicyType|mystery policy'),
'meta_jsonb' => [
'display_name' => 'Mystery Policy',
'category' => 'Other',
'platform' => 'windows',
'evidence' => [
'fidelity' => 'content',
'source' => 'policy_version',
'observed_at' => '2026-03-09T10:00:00+00:00',
],
],
]),
]));
$rendered = $presenter->present($snapshot)->toArray();
expect(data_get($rendered, 'snapshot.snapshotId'))->toBe(130)
->and(data_get($rendered, 'snapshot.baselineProfileName'))->toBe('Security Baseline')
->and(data_get($rendered, 'snapshot.overallFidelity'))->toBe('partial')
->and(data_get($rendered, 'snapshot.overallGapCount'))->toBe(1)
->and($rendered['summaryRows'])->toHaveCount(3)
->and(collect($rendered['groups'])->pluck('label')->all())
->toContain('Intune RBAC Role Definition', 'Device Compliance', 'Mystery Policy Type')
->and(data_get($rendered, 'technicalDetail.defaultCollapsed'))->toBeTrue();
});