@@ -2,6 +2,7 @@ import { expect, test, describe, beforeAll, afterAll } from 'vitest'
22
33import { post } from '@/tests/helpers/e2etest'
44import { startMockServer , stopMockServer } from '@/tests/mocks/start-mock-server'
5+ import { MAX_QUERY_LENGTH } from '@/search/lib/ai-search-constants'
56
67describe ( 'AI Search Routes' , ( ) => {
78 beforeAll ( ( ) => {
@@ -183,6 +184,23 @@ describe('AI Search Routes', () => {
183184 expect ( responseBody . errors [ 0 ] . message ) . toBe ( "Invalid 'query' in request body. Must be a string" )
184185 } )
185186
187+ test ( 'should reject queries longer than the maximum allowed length' , async ( ) => {
188+ const longQuery = 'a' . repeat ( MAX_QUERY_LENGTH + 1 )
189+ const response = await post ( '/api/ai-search/v1' , {
190+ body : JSON . stringify ( { query : longQuery , version : 'dotcom' } ) ,
191+ headers : { 'Content-Type' : 'application/json' } ,
192+ } )
193+
194+ const responseBody = JSON . parse ( response . body )
195+
196+ expect ( response . statusCode ) . toBe ( 413 )
197+ expect ( responseBody . upstreamStatus ) . toBe ( 413 )
198+ expect ( responseBody . errors ) . toBeDefined ( )
199+ expect ( responseBody . errors [ 0 ] . message ) . toBe (
200+ `Query exceeds maximum length of ${ MAX_QUERY_LENGTH } characters` ,
201+ )
202+ } )
203+
186204 test ( 'should handle malformed JSON in request body' , async ( ) => {
187205 const response = await post ( '/api/ai-search/v1' , {
188206 body : '{ invalid json }' ,
0 commit comments