trypost/tests/Unit/Actions/Post/PostStatusGuardTest.php
Paulo Castellano 7854596579 refactor(posts): centralize post editing status checks with PostStatusGuard
- Replaced direct status checks in multiple controllers and actions with the PostStatusGuard utility, improving code readability and maintainability.
- Updated error messages to utilize a centralized method for consistency across the application.
- Removed the BrandImagePalette class, consolidating color resolution logic into the AiImageClient for better organization and type safety.
2026-05-21 19:27:19 -03:00

47 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Post\PostStatusGuard;
use App\Enums\Post\Status as PostStatus;
use App\Models\Post;
test('blocks editing for terminal statuses', function (PostStatus $status) {
$post = Post::factory()->make(['status' => $status]);
expect(PostStatusGuard::blocksEditing($post))->toBeTrue();
})->with([
PostStatus::Publishing,
PostStatus::Published,
PostStatus::PartiallyPublished,
PostStatus::Failed,
]);
test('allows editing for non terminal statuses', function (PostStatus $status) {
$post = Post::factory()->make(['status' => $status]);
expect(PostStatusGuard::blocksEditing($post))->toBeFalse();
})->with([
PostStatus::Draft,
PostStatus::Scheduled,
]);
test('blocks deletion for published statuses', function (PostStatus $status) {
$post = Post::factory()->make(['status' => $status]);
expect(PostStatusGuard::blocksDeletion($post))->toBeTrue();
})->with([
PostStatus::Publishing,
PostStatus::Published,
PostStatus::PartiallyPublished,
]);
test('allows deletion for draft, scheduled and failed statuses', function (PostStatus $status) {
$post = Post::factory()->make(['status' => $status]);
expect(PostStatusGuard::blocksDeletion($post))->toBeFalse();
})->with([
PostStatus::Draft,
PostStatus::Scheduled,
PostStatus::Failed,
]);