@@ -19,7 +19,7 @@ describe('Query parameter array limit', () => {
1919 if ( app ) await app . stop ( ) ;
2020 } ) ;
2121
22- context ( 'with default arrayLimit (20 )' , ( ) => {
22+ context ( 'with default arrayLimit (100 )' , ( ) => {
2323 beforeEach ( async ( ) => {
2424 app = givenApplication ( ) ;
2525 await app . start ( ) ;
@@ -34,16 +34,29 @@ describe('Query parameter array limit', () => {
3434 expect ( response . body . ids ) . to . eql ( ids ) ;
3535 } ) ;
3636
37- it ( 'converts arrays with 21+ items to objects (qs default behavior) ' , async ( ) => {
37+ it ( 'parses arrays with 21 items correctly ' , async ( ) => {
3838 const ids = Array . from ( { length : 21 } , ( _ , i ) => ( i + 1 ) . toString ( ) ) ;
3939 const query = ids . map ( id => `ids=${ id } ` ) . join ( '&' ) ;
4040
4141 const response = await client . get ( `/test?${ query } ` ) . expect ( 200 ) ;
42+ expect ( response . body . ids ) . to . eql ( ids ) ;
43+ expect ( Array . isArray ( response . body . ids ) ) . to . be . true ( ) ;
44+ } ) ;
45+
46+ it ( 'parses arrays with 100 items correctly' , async ( ) => {
47+ const ids = Array . from ( { length : 100 } , ( _ , i ) => ( i + 1 ) . toString ( ) ) ;
48+ const query = ids . map ( id => `ids=${ id } ` ) . join ( '&' ) ;
4249
43- expect ( response . body . ids ) . to . be . Object ( ) ;
44- expect ( Array . isArray ( response . body . ids ) ) . to . be . false ( ) ;
45- expect ( response . body . ids ) . to . have . property ( '0' , '1' ) ;
46- expect ( response . body . ids ) . to . have . property ( '20' , '21' ) ;
50+ const response = await client . get ( `/test?${ query } ` ) . expect ( 200 ) ;
51+ expect ( response . body . ids ) . to . eql ( ids ) ;
52+ expect ( Array . isArray ( response . body . ids ) ) . to . be . true ( ) ;
53+ } ) ;
54+
55+ it ( 'converts arrays with 101+ items to objects (exceeds default limit)' , async ( ) => {
56+ const ids = Array . from ( { length : 101 } , ( _ , i ) => ( i + 1 ) . toString ( ) ) ;
57+ const query = ids . map ( id => `ids=${ id } ` ) . join ( '&' ) ;
58+
59+ await client . get ( `/test?${ query } ` ) . expect ( 400 ) ;
4760 } ) ;
4861 } ) ;
4962
@@ -91,35 +104,7 @@ describe('Query parameter array limit', () => {
91104 const ids = Array . from ( { length : 101 } , ( _ , i ) => ( i + 1 ) . toString ( ) ) ;
92105 const query = ids . map ( id => `ids=${ id } ` ) . join ( '&' ) ;
93106
94- const response = await client . get ( `/test?${ query } ` ) . expect ( 200 ) ;
95-
96- expect ( response . body . ids ) . to . be . Object ( ) ;
97- expect ( Array . isArray ( response . body . ids ) ) . to . be . false ( ) ;
98- expect ( response . body . ids ) . to . have . property ( '0' , '1' ) ;
99- expect ( response . body . ids ) . to . have . property ( '100' , '101' ) ;
100- } ) ;
101- } ) ;
102-
103- context ( 'with arrayLimit set to 1000' , ( ) => {
104- beforeEach ( async ( ) => {
105- app = givenApplication ( {
106- rest : {
107- queryParser : {
108- arrayLimit : 1000 ,
109- } ,
110- } ,
111- } ) ;
112- await app . start ( ) ;
113- client = createRestAppClient ( app ) ;
114- } ) ;
115-
116- it ( 'parses arrays with 500 items correctly' , async ( ) => {
117- const ids = Array . from ( { length : 500 } , ( _ , i ) => ( i + 1 ) . toString ( ) ) ;
118- const query = ids . map ( id => `ids=${ id } ` ) . join ( '&' ) ;
119-
120- const response = await client . get ( `/test?${ query } ` ) . expect ( 200 ) ;
121- expect ( response . body . ids ) . to . eql ( ids ) ;
122- expect ( Array . isArray ( response . body . ids ) ) . to . be . true ( ) ;
107+ await client . get ( `/test?${ query } ` ) . expect ( 400 ) ;
123108 } ) ;
124109 } ) ;
125110
0 commit comments