test(ai): guard prompt max on the editor endpoint and the wizard min boundary
- Assert GeneratePostContentRequest rejects a prompt over the shared max, so the editor's limit is pinned explicitly (not only implied by the create wizard). - Assert the create wizard accepts a prompt at exactly the minimum length, complementing the below-minimum rejection.
This commit is contained in:
parent
3dbb8e6f7e
commit
c432034dd1
2 changed files with 27 additions and 0 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue