Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

2.6 KB
Raw Blame
<?php

declare(strict_types=1);

use App\Enums\Post\PublishStatus;
use App\Enums\Post\Status as PostStatus;
use App\Models\Post;
use App\Support\PostStatusRules;

test('blocks editing for terminal statuses', function (PostStatus $status) {
    $post = Post::factory()->make(['status' => $status]);

    expect(PostStatusRules::blocksEditing($post))->toBeTrue();
})->with([
    PostStatus::Publishing,
    PostStatus::Published,
    PostStatus::Failed,
]);

test('allows editing for non terminal statuses', function (PostStatus $status) {
    $post = Post::factory()->make(['status' => $status]);

    expect(PostStatusRules::blocksEditing($post))->toBeFalse();
})->with([
    PostStatus::Draft,
    PostStatus::Scheduled,
]);

test('blocks deletion for sent and failed statuses', function (PostStatus $status) {
    $post = Post::factory()->make(['status' => $status]);

    expect(PostStatusRules::blocksDeletion($post))->toBeTrue();
})->with([
    PostStatus::Publishing,
    PostStatus::Published,
    PostStatus::Failed,
]);

test('allows deletion for draft, scheduled and failed statuses', function (PostStatus $status) {
    $post = Post::factory()->make(['status' => $status]);

    expect(PostStatusRules::blocksDeletion($post))->toBeFalse();
})->with([
    PostStatus::Draft,
    PostStatus::Scheduled,
]);

test('requires explicit schedule when status is scheduled and post has no usable schedule', function (?string $scheduledAt, bool $expected) {
    $post = Post::factory()->make([
        'scheduled_at' => $scheduledAt,
    ]);

    expect(PostStatusRules::requiresExplicitSchedule($post, PostStatus::Scheduled->value))->toBe($expected);
})->with([
    'missing schedule' => [null, true],
    'past schedule' => [now()->subHour()->toDateTimeString(), true],
    'future schedule' => [now()->addDay()->toDateTimeString(), false],
]);

test('does not require explicit schedule for non scheduled statuses', function () {
    $post = Post::factory()->make(['scheduled_at' => null]);

    expect(PostStatusRules::requiresExplicitSchedule($post, PostStatus::Draft->value))->toBeFalse()
        ->and(PostStatusRules::requiresExplicitSchedule(null, PostStatus::Scheduled->value))->toBeTrue();
});

test('allows deleting a published post the network deleted, but not one still publishing', function (PostStatus $status, bool $blocked) {
    $post = Post::factory()->make(['status' => $status, 'publish_status' => PublishStatus::Deleted]);

    expect(PostStatusRules::blocksDeletion($post))->toBe($blocked);
})->with([
    'published' => [PostStatus::Published, false],
    'publishing' => [PostStatus::Publishing, true],
]);