diff --git a/tests/Feature/Ai/PostAiCreateTest.php b/tests/Feature/Ai/PostAiCreateTest.php index 91e27642..ec296325 100644 --- a/tests/Feature/Ai/PostAiCreateTest.php +++ b/tests/Feature/Ai/PostAiCreateTest.php @@ -44,6 +44,19 @@ 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 ae775dfc..a80f44e6 100644 --- a/tests/Feature/Ai/PostAiGenerateTest.php +++ b/tests/Feature/Ai/PostAiGenerateTest.php @@ -7,6 +7,7 @@ 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 @@ ->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();