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\Enums\Plan\Slug;
use App\Models\Account;
use App\Models\Plan;
use App\Models\User;
use App\Models\Workspace;
use App\Policies\AccountPolicy;
beforeEach(function () {
$this->policy = new AccountPolicy;
$this->account = Account::factory()->create([
'plan_id' => Plan::where('slug', Slug::Workspace)->value('id'),
]);
$this->owner = User::factory()->create(['account_id' => $this->account->id]);
$this->account->update(['owner_id' => $this->owner->id]);
});
test('swapPlan allows the account owner', function () {
subscribeAccount($this->account);
$response = $this->policy->swapPlan(
$this->owner,
$this->account->fresh(),
Plan::where('slug', Slug::Workspaces)->firstOrFail(),
);
expect($response->allowed())->toBeTrue();
});
test('swapPlan denies a non-owner', function () {
subscribeAccount($this->account);
$member = User::factory()->create(['account_id' => $this->account->id]);
$response = $this->policy->swapPlan(
$member,
$this->account->fresh(),
Plan::where('slug', Slug::Workspaces)->firstOrFail(),
);
expect($response->denied())->toBeTrue();
expect($response->message())->toBe(__('billing.flash.cannot_manage'));
});
test('swapPlan denies when the account is not subscribed', function () {
$response = $this->policy->swapPlan(
$this->owner,
$this->account->fresh(),
Plan::where('slug', Slug::Workspaces)->firstOrFail(),
);
expect($response->denied())->toBeTrue();
expect($response->message())->toBe(__('billing.flash.subscription_required'));
});
test('swapPlan denies when the account holds more workspaces than the target allows', function () {
subscribeAccount($this->account);
Workspace::factory()->count(2)->create([
'account_id' => $this->account->id,
'user_id' => $this->owner->id,
]);
$response = $this->policy->swapPlan(
$this->owner,
$this->account->fresh(),
Plan::where('slug', Slug::Socials)->firstOrFail(),
);
expect($response->denied())->toBeTrue();
expect($response->message())->toBe(__('billing.flash.too_many_workspaces', [
'count' => 2,
'limit' => 1,
]));
});
test('useAi allows when subscribed', function () {
config()->set('trypost.self_hosted', false);
Workspace::factory()->create([
'account_id' => $this->account->id,
'user_id' => $this->owner->id,
]);
subscribeAccount($this->account);
$response = $this->policy->useAi($this->owner, $this->account->fresh());
expect($response->allowed())->toBeTrue();
});
test('useAi denies when there is no active subscription', function () {
config()->set('trypost.self_hosted', false);
Workspace::factory()->create([
'account_id' => $this->account->id,
'user_id' => $this->owner->id,
]);
$response = $this->policy->useAi($this->owner, $this->account->fresh());
expect($response->denied())->toBeTrue();
expect($response->message())->toBe(__('billing.flash.subscription_required'));
});
test('useAi always allows when self-hosted', function () {
config()->set('trypost.self_hosted', true);
$response = $this->policy->useAi($this->owner, $this->account);
expect($response->allowed())->toBeTrue();
});