TenantAtlas/tests/Feature/TenantReview/TenantReviewLifecycleTest.php
2026-03-21 23:02:02 +01:00

45 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\TenantReviews\TenantReviewLifecycleService;
use App\Services\TenantReviews\TenantReviewReadinessGate;
use App\Support\TenantReviewStatus;
it('blocks publication when required review sections are missing from the anchored evidence basis', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$review = composeTenantReviewForTest($tenant, $user, seedTenantReviewEvidence(
tenant: $tenant,
permissionPayload: [
'required_count' => 11,
'granted_count' => 7,
],
operationRunCount: 0,
));
expect(app(TenantReviewReadinessGate::class)->canPublish($review))->toBeFalse()
->and($review->publishBlockers())->not->toBeEmpty();
expect(fn () => app(TenantReviewLifecycleService::class)->publish($review, $user))
->toThrow(\InvalidArgumentException::class);
});
it('publishes ready tenant reviews and archives them without mutating the published evidence history', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$review = composeTenantReviewForTest($tenant, $user);
$published = app(TenantReviewLifecycleService::class)->publish($review, $user);
$publishedAt = $published->published_at?->toIso8601String();
expect($published->status)->toBe(TenantReviewStatus::Published->value)
->and($published->published_by_user_id)->toBe((int) $user->getKey())
->and($publishedAt)->not->toBeNull();
$archived = app(TenantReviewLifecycleService::class)->archive($published, $user);
expect($archived->status)->toBe(TenantReviewStatus::Archived->value)
->and($archived->archived_at)->not->toBeNull()
->and($archived->published_at?->toIso8601String())->toBe($publishedAt);
});