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.

test(ai): guard prompt max on the editor endpoint and the wizard min boundary

Paulo Castellanoc432034dd151
diff --git a/tests/Feature/Ai/PostAiCreateTest.php b/tests/Feature/Ai/PostAiCreateTest.php
index 91e276428..ec2963253 100644
--- a/tests/Feature/Ai/PostAiCreateTest.php
+++ b/tests/Feature/Ai/PostAiCreateTest.php
@@ -44,6 +44,19 @@ test('start rejects a prompt shorter than the minimum length', function () {
Bus::assertNotDispatched(StreamPostCreation::class);
});
+test('start accepts a prompt at the minimum length', function () {
+ Bus::fake();
+
+ $this->actingAs($this->user)
+ ->postJson(route('app.posts.ai.create'), [
+ 'prompt' => str_repeat('a', AiPromptRules::PROMPT_MIN_LENGTH),
+ 'format' => 'x_post',
+ ])
+ ->assertStatus(Response::HTTP_ACCEPTED);
+
+ Bus::assertDispatched(StreamPostCreation::class);
+});
+
test('start rejects a prompt longer than the maximum length', function () {
Bus::fake();
diff --git a/tests/Feature/Ai/PostAiGenerateTest.php b/tests/Feature/Ai/PostAiGenerateTest.php
index ae775dfc1..a80f44e64 100644
--- a/tests/Feature/Ai/PostAiGenerateTest.php
+++ b/tests/Feature/Ai/PostAiGenerateTest.php
@@ -7,6 +7,7 @@ use App\Jobs\Ai\StreamPostContent;
use App\Models\Post;
use App\Models\User;
use App\Models\Workspace;
+use App\Support\AiPromptRules;
use Illuminate\Support\Facades\Bus;
use Symfony\Component\HttpFoundation\Response;
@@ -34,6 +35,19 @@ test('endpoint validates prompt is required', function () {
->assertJsonValidationErrors(['prompt']);
});
+test('endpoint rejects a prompt longer than the maximum length', function () {
+ Bus::fake();
+
+ $this->actingAs($this->user)
+ ->postJson(route('app.posts.ai.generate', $this->post), [
+ 'prompt' => str_repeat('a', AiPromptRules::PROMPT_MAX_LENGTH + 1),
+ ])
+ ->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY)
+ ->assertJsonValidationErrors(['prompt']);
+
+ Bus::assertNotDispatched(StreamPostContent::class);
+});
+
test('endpoint blocks access to other workspace posts', function () {
Bus::fake();
$otherWorkspace = Workspace::factory()->create();