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\Queue\ReflowChannelQueue;
use App\Enums\Post\QueuePosition;
use App\Enums\Post\ScheduleMode;
use App\Enums\Post\Status as PostStatus;
use App\Enums\SocialAccount\Platform;
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;
beforeEach(function () {
Queue::fake();
$this->travelTo(CarbonImmutable::parse('2026-10-05 08:00', 'UTC'));
$this->user = User::factory()->create();
$this->workspace = Workspace::factory()->create(['account_id' => $this->user->account_id, 'user_id' => $this->user->id]);
$this->workspace->members()->attach($this->user->id, membershipPivot('admin'));
$this->user->update(['current_workspace_id' => $this->workspace->id]);
$this->channel = SocialAccount::factory()->create([
'workspace_id' => $this->workspace->id,
'platform' => Platform::LinkedIn,
'timezone' => 'UTC',
'posting_schedule' => PostingSchedule::empty()->withTime(1, '09:00')->withTime(3, '09:00')->withTime(5, '09:00'),
]);
});
function scheduleActionPost(SocialAccount $channel, User $user, array $attributes = []): Post
{
return Post::factory()->forAccount($channel)->create(array_merge([
'user_id' => $user->id,
'content' => 'A caption',
'status' => PostStatus::Draft,
'schedule_mode' => null,
'scheduled_at' => null,
], $attributes))->refresh();
}
function scheduleActionQueued(SocialAccount $channel, User $user): Post
{
$post = scheduleActionPost($channel, $user, ['status' => PostStatus::Scheduled, 'schedule_mode' => ScheduleMode::Queue]);
ReflowChannelQueue::handle($channel, $post, QueuePosition::Next);
return $post->refresh();
}
test('draft on a queued post unqueues it and the rest of the queue keeps its slots', function () {
$first = scheduleActionQueued($this->channel, $this->user);
$second = scheduleActionQueued($this->channel, $this->user);
$freedSlot = $first->scheduled_at->toIso8601String();
$secondSlot = $second->scheduled_at->toIso8601String();
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $first), ['action' => 'draft'])
->assertSessionHasNoErrors()
->assertRedirect();
$drafted = $first->fresh();
expect($drafted->status)->toBe(PostStatus::Draft)
->and($drafted->schedule_mode)->toBeNull()
->and($drafted->scheduled_at?->toIso8601String())->toBe($freedSlot)
->and($second->fresh()->scheduled_at->toIso8601String())->toBe($secondSlot);
});
test('queue next on a draft adds it to the queue', function () {
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $draft), ['action' => 'queue_next'])
->assertSessionHasNoErrors()
->assertRedirect()
->assertSessionMissing('flash.banner');
$draft->refresh();
expect($draft->status)->toBe(PostStatus::Scheduled)
->and($draft->schedule_mode)->toBe(ScheduleMode::Queue)
->and($draft->scheduled_at->toIso8601String())->toBe(CarbonImmutable::parse('2026-10-05 09:00', 'UTC')->toIso8601String());
});
test('queue next on a channel without posting times is rejected and the draft stays a draft', function () {
$this->channel->update(['posting_schedule' => null]);
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->putJson(route('app.posts.schedule.update', $draft), ['action' => 'queue_next'])
->assertUnprocessable()
->assertJsonValidationErrors(['queue' => __('posts.errors.queue_requires_schedule')]);
$draft->refresh();
expect($draft->status)->toBe(PostStatus::Draft)
->and($draft->schedule_mode)->toBeNull()
->and($draft->scheduled_at)->toBeNull();
});
test('queue next without posting times on the inertia path returns a session error', function () {
$this->channel->update(['posting_schedule' => null]);
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $draft), ['action' => 'queue_next'])
->assertRedirect()
->assertSessionHasErrors(['queue' => __('posts.errors.queue_requires_schedule')]);
expect($draft->fresh()->status)->toBe(PostStatus::Draft);
});
test('queue top moves the last queued post to the front', function () {
$first = scheduleActionQueued($this->channel, $this->user);
$second = scheduleActionQueued($this->channel, $this->user);
$last = scheduleActionQueued($this->channel, $this->user);
$firstSlot = $first->scheduled_at->toIso8601String();
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $last), ['action' => 'queue_top'])
->assertSessionHasNoErrors()
->assertRedirect();
expect($last->fresh()->scheduled_at->toIso8601String())->toBe($firstSlot)
->and($first->fresh()->scheduled_at->isAfter($last->fresh()->scheduled_at))->toBeTrue()
->and($second->fresh()->scheduled_at->isAfter($first->fresh()->scheduled_at))->toBeTrue();
});
test('publish now dispatches the publish job', function () {
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $draft), ['action' => 'publish_now'])
->assertSessionHasNoErrors()
->assertRedirect();
expect($draft->fresh()->status)->toBe(PostStatus::Publishing);
Queue::assertPushed(PublishPost::class, fn (PublishPost $job): bool => $job->post->is($draft));
});
test('publish now on a post without a channel is rejected', function () {
$post = Post::factory()->create([
'workspace_id' => $this->workspace->id,
'user_id' => $this->user->id,
'content' => 'A caption',
'status' => PostStatus::Draft,
]);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $post), ['action' => 'publish_now'])
->assertRedirect()
->assertSessionHasErrors('social_account_id');
expect($post->fresh()->status)->toBe(PostStatus::Draft);
Queue::assertNotPushed(PublishPost::class);
});
test('a user outside the workspace cannot change a post schedule', function () {
$outsider = workspaceOutsider($this->workspace);
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($outsider)
->putJson(route('app.posts.schedule.update', $draft), ['action' => 'queue_next'])
->assertForbidden();
expect($draft->fresh()->status)->toBe(PostStatus::Draft);
});
test('an unknown action is rejected', function () {
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->putJson(route('app.posts.schedule.update', $draft), ['action' => 'archive'])
->assertUnprocessable()
->assertJsonValidationErrors('action');
});
test('a post of another workspace is not found', function () {
$other = User::factory()->create();
$otherWorkspace = Workspace::factory()->create(['account_id' => $other->account_id, 'user_id' => $other->id]);
$otherChannel = SocialAccount::factory()->create(['workspace_id' => $otherWorkspace->id, 'platform' => Platform::LinkedIn]);
$post = scheduleActionPost($otherChannel, $other);
$this->actingAs($this->user)
->putJson(route('app.posts.schedule.update', $post), ['action' => 'draft'])
->assertNotFound();
expect($post->fresh()->status)->toBe(PostStatus::Draft);
});
test('publish now from any tab of the publish list goes to the queue tab', function (string $tab) {
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->from(route('app.posts.index', ['tab' => $tab, 'tz' => 'UTC']))
->put(route('app.posts.schedule.update', $draft), ['action' => 'publish_now'])
->assertRedirect(route('app.posts.index', ['tab' => 'queue', 'tz' => 'UTC']));
})->with(['drafts', 'sent', 'approvals', 'queue']);
test('publish now from a channel page goes to that channel queue tab', function () {
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->from(route('app.channels.publish', ['account' => $this->channel, 'tab' => 'drafts']))
->put(route('app.posts.schedule.update', $draft), ['action' => 'publish_now'])
->assertRedirect(route('app.channels.publish', ['account' => $this->channel, 'tab' => 'queue']));
});
test('publish now from the calendar stays on the calendar', function () {
$draft = scheduleActionPost($this->channel, $this->user);
$calendar = route('app.calendar', ['view' => 'month']);
$this->actingAs($this->user)
->from($calendar)
->put(route('app.posts.schedule.update', $draft), ['action' => 'publish_now'])
->assertRedirect($calendar);
});
test('a member who needs approval stays on the tab after publish now, since the post only goes to approval', function () {
$member = User::factory()->create(['account_id' => $this->user->account_id]);
$this->workspace->members()->attach($member->id, membershipPivot('approval'));
$member->update(['current_workspace_id' => $this->workspace->id]);
$draft = scheduleActionPost($this->channel, $member);
$drafts = route('app.posts.index', ['tab' => 'drafts']);
$this->actingAs($member)
->from($drafts)
->put(route('app.posts.schedule.update', $draft), ['action' => 'publish_now'])
->assertRedirect($drafts);
expect($draft->fresh()->status)->toBe(PostStatus::PendingApproval);
});
test('moving a post to drafts stays on the tab it was moved from', function () {
$queued = scheduleActionPost($this->channel, $this->user, ['status' => PostStatus::Scheduled, 'scheduled_at' => now()->addDay(), 'schedule_mode' => 'custom']);
$queue = route('app.posts.index', ['tab' => 'queue']);
$this->actingAs($this->user)
->from($queue)
->put(route('app.posts.schedule.update', $queued), ['action' => 'draft'])
->assertRedirect($queue);
});
test('adding a draft to the queue from its card stays on the tab it was added from', function (string $action, bool $onChannelPage) {
$this->channel->update(['posting_schedule' => PostingSchedule::empty()->withTime(1, '10:00')]);
$draft = scheduleActionPost($this->channel, $this->user);
$drafts = $onChannelPage
? route('app.channels.publish', ['account' => $this->channel, 'tab' => 'drafts'])
: route('app.posts.index', ['tab' => 'drafts']);
$this->actingAs($this->user)
->from($drafts)
->put(route('app.posts.schedule.update', $draft), ['action' => $action])
->assertSessionHasNoErrors()
->assertRedirect($drafts);
expect($draft->fresh()->status)->toBe(PostStatus::Scheduled);
})->with(['queue_next', 'queue_top'])->with([
'the drafts tab' => false,
'a channel drafts tab' => true,
]);
test('queue next toasts that the post was added, with a link to its details', function () {
$draft = scheduleActionPost($this->channel, $this->user);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $draft), ['action' => 'queue_next'])
->assertSessionHas('flash.success', trans_choice('posts.composer.queue.added', 1, ['count' => 1]))
->assertSessionHas('flash.link', [
'label' => __('posts.actions.view'),
'url' => route('app.posts.index', ['post' => $draft->id]),
]);
});
test('moving a post to drafts toasts nothing', function () {
$queued = scheduleActionQueued($this->channel, $this->user);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $queued), ['action' => 'draft'])
->assertSessionMissing('flash.success')
->assertSessionMissing('flash.link');
});
test('moving a queued post to the top toasts that it went to the top, not that it was added', function () {
scheduleActionQueued($this->channel, $this->user);
$second = scheduleActionQueued($this->channel, $this->user);
$this->actingAs($this->user)
->put(route('app.posts.schedule.update', $second), ['action' => 'queue_top'])
->assertSessionHas('flash.success', __('posts.composer.queue.moved_to_top'))
->assertSessionHas('flash.link.url', route('app.posts.index', ['post' => $second->id]));
});
test('a member who needs approval is told the queue request awaits approval', function () {
$member = workspaceMember($this->workspace, 'approval');
$draft = scheduleActionPost($this->channel, $member);
$this->actingAs($member)
->put(route('app.posts.schedule.update', $draft), ['action' => 'queue_next'])
->assertSessionHas('flash.success', __('posts.approvals.requested'))
->assertSessionHas('flash.link.url', route('app.posts.index', ['post' => $draft->id]));
});
test('the toast reaches a partial reload that does not ask for it', function () {
$page = $this->actingAs($this->user)->get(route('app.posts.index'))->assertOk()->viewData('page');
$this->withSession(['flash' => ['success' => 'Your post was added to the queue.']])
->withHeaders([
'X-Inertia' => 'true',
'X-Inertia-Version' => (string) data_get($page, 'version'),
'X-Inertia-Partial-Component' => data_get($page, 'component'),
'X-Inertia-Partial-Data' => 'posts',
])
->get(route('app.posts.index'))
->assertOk()
->assertJsonPath('props.flash.success', 'Your post was added to the queue.');
});