TenantAtlas/apps/platform/tests/Unit/Support/ReasonTranslation/ProviderReasonTranslationTest.php
ahmido ad16eee591 Spec 204: harden platform core vocabulary (#234)
## Summary
- add the Spec 204 platform vocabulary foundation, including canonical glossary terms, registry ownership descriptors, canonical operation type and alias resolution, and explicit reason ownership and platform reason-family metadata
- harden platform-facing compare, snapshot, evidence, monitoring, review, and reporting surfaces so they prefer governed-subject and canonical operation semantics while preserving intentional Intune-owned terminology
- extend Spec 204 unit, feature, Filament, and architecture coverage and add the full spec artifacts, checklist, and completed task ledger

## Verification
- ran the focused recent-change Sail verification pack for the new glossary and reason-semantics work
- ran the full Spec 204 quickstart verification pack under Sail
- ran `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- ran an integrated-browser smoke pass covering tenant dashboard, operations, operation detail, baseline compare, evidence, reviews, review packs, provider connections, inventory items, backup schedules, onboarding, and the system dashboard/operations/failures/run-detail surfaces

## Notes
- provider registration is unchanged and remains in `bootstrap/providers.php`
- no new destructive actions or asset-registration changes are introduced by this branch

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #234
2026-04-14 06:09:42 +00:00

49 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\ProviderConnection;
use App\Models\Tenant;
use App\Support\Providers\ProviderReasonCodes;
use App\Support\ReasonTranslation\ReasonPresenter;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('translates provider reasons into labels, explanations, and next-step links', function (): void {
$tenant = Tenant::factory()->create();
$connection = ProviderConnection::factory()->dedicated()->create([
'tenant_id' => (int) $tenant->getKey(),
'workspace_id' => (int) $tenant->workspace_id,
'provider' => 'microsoft',
'entra_tenant_id' => (string) $tenant->graphTenantId(),
]);
$envelope = app(ReasonPresenter::class)->forProviderReason(
tenant: $tenant,
reasonCode: ProviderReasonCodes::DedicatedCredentialMissing,
connection: $connection,
surface: 'helper_copy',
);
expect($envelope)->not->toBeNull()
->and($envelope?->operatorLabel)->toBe('Dedicated credentials required')
->and($envelope?->shortExplanation)->toContain('dedicated credentials are configured')
->and($envelope?->ownerLayer())->toBe('provider_owned')
->and($envelope?->ownerNamespace())->toBe('provider.microsoft_graph')
->and($envelope?->platformReasonFamily())->toBe('prerequisite')
->and(ProviderReasonCodes::boundaryClassification(ProviderReasonCodes::DedicatedCredentialMissing))->toBe('intune_specific')
->and($envelope?->toLegacyNextSteps()[0]['label'] ?? null)->toBe('Manage dedicated connection')
->and($envelope?->toLegacyNextSteps()[0]['url'] ?? null)->toContain('/provider-connections/');
});
it('uses a bounded provider fallback for untranslated extension reasons', function (): void {
$envelope = app(\App\Support\Providers\ProviderReasonTranslator::class)->translate('ext.multiple_defaults_detected');
expect($envelope)->not->toBeNull()
->and($envelope?->operatorLabel)->toBe('Provider configuration needs review')
->and($envelope?->diagnosticCode())->toBe('ext.multiple_defaults_detected')
->and($envelope?->ownerLayer())->toBe('provider_owned')
->and($envelope?->guidanceText())->toBe('Next step: Review the provider connection before retrying.');
});