TenantAtlas/tests/Unit/Badges/GovernanceArtifactTruthTest.php
2026-03-23 01:06:25 +01:00

73 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Tenant;
use App\Support\Badges\BadgeCatalog;
use App\Support\Badges\BadgeDomain;
use App\Support\Ui\GovernanceArtifactTruth\ArtifactTruthPresenter;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\Feature\Concerns\BuildsGovernanceArtifactTruthFixtures;
uses(RefreshDatabase::class, BuildsGovernanceArtifactTruthFixtures::class);
it('maps each curated governance-artifact truth badge to a known label', function (BadgeDomain $domain, string $state): void {
$spec = BadgeCatalog::spec($domain, $state);
expect($spec->label)->not->toBe('Unknown')
->and($spec->icon)->not->toBeNull();
})->with([
'healthy baseline artifact' => [BadgeDomain::GovernanceArtifactContent, 'trusted'],
'false-green baseline artifact' => [BadgeDomain::GovernanceArtifactExistence, 'created_but_not_usable'],
'historical baseline trace' => [BadgeDomain::GovernanceArtifactExistence, 'historical_only'],
'healthy evidence snapshot' => [BadgeDomain::GovernanceArtifactContent, 'trusted'],
'partial evidence snapshot' => [BadgeDomain::GovernanceArtifactContent, 'partial'],
'stale evidence snapshot' => [BadgeDomain::GovernanceArtifactFreshness, 'stale'],
'internal tenant review' => [BadgeDomain::GovernanceArtifactPublicationReadiness, 'internal_only'],
'blocked tenant review' => [BadgeDomain::GovernanceArtifactPublicationReadiness, 'blocked'],
'publishable tenant review' => [BadgeDomain::GovernanceArtifactPublicationReadiness, 'publishable'],
'historical review pack' => [BadgeDomain::GovernanceArtifactExistence, 'historical_only'],
'blocked review pack' => [BadgeDomain::GovernanceArtifactPublicationReadiness, 'blocked'],
'artifact requires action' => [BadgeDomain::GovernanceArtifactActionability, 'required'],
]);
it('separates review existence from publication readiness', function (): void {
$tenant = Tenant::factory()->create();
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
$snapshot = $this->makeArtifactTruthEvidenceSnapshot($tenant);
$review = $this->makeArtifactTruthReview(
tenant: $tenant,
user: $user,
snapshot: $snapshot,
reviewOverrides: [
'status' => 'draft',
'completeness_state' => 'complete',
],
summaryOverrides: [
'publish_blockers' => ['Review the missing approval note before publication.'],
],
);
$truth = app(ArtifactTruthPresenter::class)->forTenantReview($review);
expect($truth->artifactExistence)->toBe('created')
->and($truth->publicationReadiness)->toBe('blocked')
->and($truth->primaryLabel)->toBe('Blocked')
->and($truth->nextStepText())->toContain('Resolve');
});
it('marks ready review packs as publishable only when their source review stays publishable', function (): void {
$tenant = Tenant::factory()->create();
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
$snapshot = $this->makeArtifactTruthEvidenceSnapshot($tenant);
$review = $this->makeArtifactTruthReview($tenant, $user, $snapshot);
$pack = $this->makeArtifactTruthReviewPack($tenant, $user, $snapshot, $review);
$truth = app(ArtifactTruthPresenter::class)->forReviewPack($pack);
expect($truth->artifactExistence)->toBe('created')
->and($truth->publicationReadiness)->toBe('publishable')
->and($truth->primaryLabel)->toBe('Publishable')
->and($truth->nextStepText())->toBe('No action needed');
});