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.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
<?php
declare(strict_types=1);
use App\Actions\Post\CreatePosts;
use App\Enums\Post\Status as PostStatus;
use App\Enums\PostPlatform\ContentType;
use App\Enums\User\TimeFormat;
use App\Jobs\PublishPost;
use App\Models\Post;
use App\Models\SocialAccount;
use App\Models\User;
use App\Models\Workspace;
use App\Support\PostingSchedule;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Queue;
/**
* @return array{0: User, 1: Workspace, 2: SocialAccount, 3: User}
*/
function approvalsBrowserSetup(): array
{
$owner = User::factory()->create(['timezone' => 'UTC']);
$workspace = Workspace::factory()->create(['user_id' => $owner->id, 'account_id' => $owner->account_id]);
$workspace->members()->attach($owner->id, membershipPivot('admin'));
$owner->update(['current_workspace_id' => $workspace->id]);
subscribeAccount($owner->account);
$time = now()->utc()->addHours(6)->format('H:00');
$schedule = PostingSchedule::empty();
foreach (range(0, 6) as $day) {
$schedule = $schedule->withTime($day, $time);
}
$channel = SocialAccount::factory()->linkedin()->create([
'workspace_id' => $workspace->id,
'timezone' => 'UTC',
'posting_schedule' => $schedule,
]);
return [$owner->fresh(), $workspace, $channel, workspaceMember($workspace, 'approval', ['timezone' => 'UTC'])];
}
/**
* @param array<string, mixed> $overrides
*/
function approvalsBrowserRequest(Workspace $workspace, User $author, SocialAccount $channel, array $overrides = []): Post
{
return CreatePosts::execute($workspace, $author, [
'status' => 'scheduled',
'queue' => 'next',
'content' => 'Waiting for a green light',
'media' => [],
'label_ids' => [],
'destinations' => [[
'social_account_id' => $channel->id,
'content_type' => ContentType::LinkedInPost->value,
'meta' => [],
]],
...$overrides,
])->sole();
}
test('an approver adds a queue request to the queue and rejects another', function () {
[$owner, $workspace, $channel, $requester] = approvalsBrowserSetup();
$queued = approvalsBrowserRequest($workspace, $requester, $channel);
$timed = approvalsBrowserRequest($workspace, $requester, $channel, [
'queue' => null,
'scheduled_at' => now()->addDay()->startOfHour()->toIso8601String(),
]);
$this->actingAs($owner);
$page = visit(route('app.posts.index', ['tab' => 'approvals']));
waitFor($page, "@post-approve-{$queued->id}");
$page->assertSeeIn('@publish-tab-count-approvals', '2')
->assertMissing("@post-approval-badge-{$queued->id}")
->assertSeeIn("@post-no-time-{$queued->id}", 'Next slot')
->assertSeeIn("@post-approve-{$queued->id}", 'Add to queue')
->assertSeeIn("@post-approve-{$timed->id}", 'Schedule')
->click("@post-approve-{$queued->id}");
waitForGone($page, "@post-card-{$queued->id}");
$page->click("@post-reject-{$timed->id}");
waitForGone($page, "@post-card-{$timed->id}");
expect($queued->fresh()->status)->toBe(PostStatus::Scheduled)
->and($queued->fresh()->approved_by)->toBe($owner->id)
->and($timed->fresh()->status)->toBe(PostStatus::Draft);
$page->assertSeeIn('@publish-tab-count-approvals', '0')
->assertNoJavaScriptErrors();
});
test('a request whose time has passed asks for a new time or publish now', function () {
Queue::fake([PublishPost::class]);
[$owner, $workspace, $channel, $requester] = approvalsBrowserSetup();
$late = Post::factory()->forAccount($channel)->pendingApproval()->create([
'user_id' => $requester->id,
'content' => 'Too late',
'scheduled_at' => now()->subHour(),
]);
$this->actingAs($owner);
$page = visit(route('app.posts.index', ['tab' => 'approvals']));
waitFor($page, "@post-time-passed-{$late->id}");
$page->assertSeeIn("@post-approve-{$late->id}", 'Approve')
->click("@post-approve-{$late->id}");
waitFor($page, "@post-approve-publish-now-{$late->id}");
$page->assertVisible("@post-approve-picker-{$late->id}")
->click("@post-approve-publish-now-{$late->id}");
waitForGone($page, "@post-card-{$late->id}");
expect($late->fresh()->status)->toBe(PostStatus::Publishing);
$page->assertNoJavaScriptErrors();
});
test('a requester sees only their own requests and can revert them', function () {
[, $workspace, $channel, $requester] = approvalsBrowserSetup();
$own = approvalsBrowserRequest($workspace, $requester, $channel);
$others = approvalsBrowserRequest($workspace, workspaceMember($workspace, 'approval'), $channel);
$this->actingAs($requester);
$page = visit(route('app.posts.index', ['tab' => 'approvals']));
waitFor($page, "@post-revert-{$own->id}");
$page->assertSeeIn('@publish-tab-count-approvals', '1')
->assertMissing("@post-card-{$others->id}")
->assertMissing("@post-approve-{$own->id}")
->assertMissing("@post-reject-{$own->id}")
->click("@post-revert-{$own->id}");
waitForGone($page, "@post-card-{$own->id}");
expect($own->fresh()->status)->toBe(PostStatus::Draft);
$page->assertNoJavaScriptErrors();
});
test('a requester adding a draft to the queue is told it awaits approval', function () {
[, $workspace, $channel, $requester] = approvalsBrowserSetup();
$draft = approvalsBrowserRequest($workspace, $requester, $channel, ['status' => 'draft', 'queue' => null]);
$this->actingAs($requester);
$page = visit(route('app.posts.index', ['tab' => 'drafts']));
waitFor($page, "@post-add-to-queue-{$draft->id}");
$page->click("@post-add-to-queue-{$draft->id}");
waitFor($page, '@flash-success-toast');
$page->assertSeeIn('@flash-success-toast', 'Approval requested')
->assertDontSee('added to the queue')
->assertNoJavaScriptErrors();
expect($draft->fresh()->status)->toBe(PostStatus::PendingApproval);
});
test('a new time for a late request is typed in the channel zone', function () {
[$owner, $workspace, $channel, $requester] = approvalsBrowserSetup();
$owner->update(['timezone' => 'Asia/Tokyo', 'time_format' => TimeFormat::TwentyFourHour]);
$channel->update(['timezone' => 'America/Sao_Paulo']);
$late = Post::factory()->forAccount($channel)->pendingApproval()->create([
'user_id' => $requester->id,
'content' => 'Too late',
'scheduled_at' => now()->subHour(),
]);
$this->actingAs($owner);
$page = visit(route('app.posts.index', ['tab' => 'approvals']));
waitFor($page, "@post-approve-{$late->id}");
$page->click("@post-approve-{$late->id}");
waitFor($page, '@composer-schedule-timezone');
expect(trim((string) $page->script('document.querySelector("[data-testid=composer-schedule-timezone]").textContent')))->toBe('America/Sao Paulo');
$query = '[...document.querySelectorAll("[data-testid^=composer-schedule-day-]")].find((day) => !day.hasAttribute("data-disabled") && !day.hasAttribute("data-outside-view") && !day.hasAttribute("data-zone-today"))?.dataset.testid.replace("composer-schedule-day-", "") ?? null';
$day = $page->script($query);
if ($day === null) {
$page->click('@composer-schedule-calendar-next');
$day = $page->script($query);
}
$page->click("@composer-schedule-day-{$day}")
->fill('@composer-schedule-time-input', '1000')
->click('@composer-schedule-done');
waitForGone($page, "@post-card-{$late->id}");
expect($late->fresh()->scheduled_at->toIso8601String())
->toBe(CarbonImmutable::parse("{$day} 10:00", 'America/Sao_Paulo')->utc()->toIso8601String());
$page->assertNoJavaScriptErrors();
});
test('a request for the top of the queue says so where the time goes', function () {
[$owner, $workspace, $channel, $requester] = approvalsBrowserSetup();
$top = approvalsBrowserRequest($workspace, $requester, $channel, ['queue' => 'top']);
$this->actingAs($owner);
$page = visit(route('app.posts.index', ['tab' => 'approvals']));
waitFor($page, "@post-no-time-{$top->id}");
$page->assertSeeIn("@post-no-time-{$top->id}", __('posts.publish.pending_slot.top'))
->assertNoJavaScriptErrors();
});