@@ -14,6 +14,7 @@ vi.mock("@opennextjs/aws/adapters/config/index.js", () => {
1414 defaultLocale : "en" ,
1515 locales : [ "en" , "fr" ] ,
1616 } ,
17+ trailingSlash : undefined ,
1718 } ,
1819 } ;
1920} ) ;
@@ -232,6 +233,48 @@ describe("handleLocaleRedirect", () => {
232233 expect ( result ) . toBe ( false ) ;
233234 } ) ;
234235
236+ it ( "should redirect to the localized path with a query parameter" , ( ) => {
237+ const event = createEvent ( {
238+ url : "http://localhost?foo=bar" ,
239+ headers : {
240+ "accept-language" : "fr" ,
241+ } ,
242+ } ) ;
243+
244+ const result = handleLocaleRedirect ( event ) ;
245+
246+ expect ( result ) . toMatchObject ( {
247+ statusCode : 307 ,
248+ headers : {
249+ Location : "http://localhost/fr?foo=bar" ,
250+ } ,
251+ } ) ;
252+ } ) ;
253+
254+ it ( "should redirect to the localized path with a query parameter when trailingSlash is true" , ( ) => {
255+ const trailingSlashSpy = vi
256+ . spyOn ( NextConfig , "trailingSlash" , "get" )
257+ . mockReturnValue ( true ) ;
258+
259+ const event = createEvent ( {
260+ url : "http://localhost?foo=bar" ,
261+ headers : {
262+ "accept-language" : "fr" ,
263+ } ,
264+ } ) ;
265+
266+ const result = handleLocaleRedirect ( event ) ;
267+
268+ expect ( result ) . toMatchObject ( {
269+ statusCode : 307 ,
270+ headers : {
271+ Location : "http://localhost/fr/?foo=bar" ,
272+ } ,
273+ } ) ;
274+
275+ trailingSlashSpy . mockRestore ( ) ;
276+ } ) ;
277+
235278 describe ( "using domain" , ( ) => {
236279 it ( "should redirect to the preferred domain if the domain is different" , ( ) => {
237280 vi . spyOn ( NextConfig , "i18n" , "get" ) . mockReturnValue ( {
0 commit comments