TenantAtlas/apps/platform/tests/Unit/Badges/PolicyBadgesTest.php
ahmido feeaadd5ad feat: add provider-missing policy visibility and restore continuity (#316)
## Summary
- separate provider-missing policy presence from local ignore semantics by introducing `missing_from_provider_at`
- update policy, backup, and restore surfaces so current-state capture stays honest while historical restore continuity remains available
- add focused sync, Filament, backup, restore, localization, and badge coverage for the new provider-missing behavior

## Scope
- policy sync and model truth
- policy resource visibility, badges, labels, and action gating
- backup/export eligibility and restore continuity messaging
- spec 261 artifacts and focused tests

## Validation
- feature-specific Pest coverage is included in the branch
- validation was not re-run as part of this commit/push/PR handoff

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #316
2026-05-01 20:18:27 +00:00

76 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Support\Badges\BadgeCatalog;
use App\Support\Badges\BadgeDomain;
use App\Support\Inventory\InventoryPolicyTypeMeta;
use Illuminate\Support\Facades\App;
it('maps policy provider presence values to canonical badge semantics', function (): void {
App::setLocale('en');
$active = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'active');
expect($active->label)->toBe(__('localization.policy.badges.active'));
expect($active->color)->toBe('success');
$ignored = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'ignored_locally');
expect($ignored->label)->toBe(__('localization.policy.badges.ignored_locally'));
expect($ignored->color)->toBe('warning');
$missing = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'provider_missing');
expect($missing->label)->toBe(__('localization.policy.badges.source_unavailable'));
expect($missing->color)->toBe('warning');
$combined = BadgeCatalog::spec(BadgeDomain::PolicyProviderPresence, 'ignored_locally_provider_missing');
expect($combined->label)->toBe(__('localization.policy.badges.ignored_source_unavailable'));
expect($combined->color)->toBe('danger');
});
it('maps policy snapshot mode values to canonical badge semantics', function (): void {
App::setLocale('en');
$full = BadgeCatalog::spec(BadgeDomain::PolicySnapshotMode, 'full');
expect($full->label)->toBe(__('localization.policy.versions.snapshot_mode_full'));
expect($full->color)->toBe('success');
$metadataOnly = BadgeCatalog::spec(BadgeDomain::PolicySnapshotMode, 'metadata_only');
expect($metadataOnly->label)->toBe(__('localization.policy.versions.snapshot_mode_metadata_only'));
expect($metadataOnly->color)->toBe('warning');
});
it('maps policy restore mode values to canonical badge semantics', function (): void {
$enabled = BadgeCatalog::spec(BadgeDomain::PolicyRestoreMode, 'enabled');
expect($enabled->label)->toBe('Enabled');
expect($enabled->color)->toBe('success');
$previewOnly = BadgeCatalog::spec(BadgeDomain::PolicyRestoreMode, 'preview-only');
expect($previewOnly->label)->toBe('Preview only');
expect($previewOnly->color)->toBe('warning');
});
it('maps policy risk values to canonical badge semantics', function (): void {
$low = BadgeCatalog::spec(BadgeDomain::PolicyRisk, 'low');
expect($low->label)->toBe('Low');
expect($low->color)->toBe('gray');
$mediumHigh = BadgeCatalog::spec(BadgeDomain::PolicyRisk, 'medium-high');
expect($mediumHigh->label)->toBe('Medium-high');
expect($mediumHigh->color)->toBe('danger');
});
it('maps ignored-at presence to canonical badge semantics', function (): void {
$notIgnored = BadgeCatalog::spec(BadgeDomain::IgnoredAt, null);
expect($notIgnored->label)->toBe('No');
expect($notIgnored->color)->toBe('gray');
$ignored = BadgeCatalog::spec(BadgeDomain::IgnoredAt, '2026-01-01T00:00:00Z');
expect($ignored->label)->toBe('Yes');
expect($ignored->color)->toBe('warning');
});
it('maps RBAC foundation restore modes to preview-only metadata', function (): void {
expect(InventoryPolicyTypeMeta::restoreMode('intuneRoleDefinition'))->toBe('preview-only');
expect(InventoryPolicyTypeMeta::restoreMode('intuneRoleAssignment'))->toBe('preview-only');
});