@@ -38,6 +38,7 @@ describe(``, () => {
38
38
let queryParamSortBy : string | undefined ,
39
39
queryParamCount : string | undefined ,
40
40
queryParamLimit : number | undefined ,
41
+ queryParamValues : any [ ] | undefined ,
41
42
queryParamShowAll : boolean | undefined ,
42
43
queryParamFilter : Record < string , any > | undefined ;
43
44
let queryParams1 : { [ key : string ] : any } | undefined ,
@@ -239,6 +240,30 @@ describe(``, () => {
239
240
return `<html><body>${ limit } </body></html>` ;
240
241
}
241
242
243
+ @Get ( '/photos-query-param-string-array' )
244
+ getPhotosWithMultipleStringValuesRequired (
245
+ @QueryParam ( 'multipleStringValues' , { required : true } ) values : string [ ]
246
+ ) : string {
247
+ queryParamValues = values ;
248
+ return `<html><body>${ values } </body></html>` ;
249
+ }
250
+
251
+ @Get ( '/photos-query-param-number-array' )
252
+ getPhotosWithMultipleNumberValuesRequired (
253
+ @QueryParam ( 'multipleNumberValues' , { required : true , type : Number , isArray : true } ) values : number [ ]
254
+ ) : string {
255
+ queryParamValues = values ;
256
+ return `<html><body>${ values } </body></html>` ;
257
+ }
258
+
259
+ @Get ( '/photos-query-param-date-array' )
260
+ getPhotosWithMultipleDateValuesRequired (
261
+ @QueryParam ( 'multipleDateValues' , { required : true , type : Date , isArray : true } ) values : Date [ ]
262
+ ) : string {
263
+ queryParamValues = values ;
264
+ return `<html><body>${ values } </body></html>` ;
265
+ }
266
+
242
267
@Get ( '/photos-with-json' )
243
268
getPhotosWithJsonParam (
244
269
@QueryParam ( 'filter' , { parse : true } ) filter : { keyword : string ; limit : number }
@@ -621,6 +646,60 @@ describe(``, () => {
621
646
expect ( queryParamShowAll ) . toEqual ( true ) ;
622
647
} ) ;
623
648
649
+ it ( '@QueryParam should give an array of string with only one query parameter' , async ( ) => {
650
+ expect . assertions ( 3 ) ;
651
+ const response = await axios . get ( '/photos-query-param-string-array?multipleStringValues=a' ) ;
652
+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
653
+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
654
+ expect ( queryParamValues ) . toEqual ( [ 'a' ] ) ;
655
+ } ) ;
656
+
657
+ it ( '@QueryParam should give an array of string with multiple query parameters' , async ( ) => {
658
+ expect . assertions ( 3 ) ;
659
+ const response = await axios . get (
660
+ '/photos-query-param-string-array?multipleStringValues=a&multipleStringValues=b&multipleStringValues=b'
661
+ ) ;
662
+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
663
+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
664
+ expect ( queryParamValues ) . toEqual ( [ 'a' , 'b' , 'b' ] ) ;
665
+ } ) ;
666
+
667
+ it ( '@QueryParam should give an array of number with only one query parameter' , async ( ) => {
668
+ expect . assertions ( 3 ) ;
669
+ const response = await axios . get ( '/photos-query-param-number-array?multipleNumberValues=1' ) ;
670
+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
671
+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
672
+ expect ( queryParamValues ) . toEqual ( [ 1 ] ) ;
673
+ } ) ;
674
+
675
+ it ( '@QueryParam should give an array of number with multiple query parameters' , async ( ) => {
676
+ expect . assertions ( 3 ) ;
677
+ const response = await axios . get (
678
+ '/photos-query-param-number-array?multipleNumberValues=1&multipleNumberValues=2&multipleNumberValues=2'
679
+ ) ;
680
+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
681
+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
682
+ expect ( queryParamValues ) . toEqual ( [ 1 , 2 , 2 ] ) ;
683
+ } ) ;
684
+
685
+ it ( '@QueryParam should give an array of date with only one query parameter' , async ( ) => {
686
+ expect . assertions ( 3 ) ;
687
+ const response = await axios . get ( '/photos-query-param-date-array?multipleDateValues=2021-01-01' ) ;
688
+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
689
+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
690
+ expect ( queryParamValues ) . toEqual ( [ new Date ( '2021-01-01' ) ] ) ;
691
+ } ) ;
692
+
693
+ it ( '@QueryParam should give an array of date with multiple query parameters' , async ( ) => {
694
+ expect . assertions ( 3 ) ;
695
+ const response = await axios . get (
696
+ '/photos-query-param-date-array?multipleDateValues=2021-01-01&multipleDateValues=2020-01-01&multipleDateValues=2021-05-01'
697
+ ) ;
698
+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
699
+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
700
+ expect ( queryParamValues ) . toEqual ( [ new Date ( '2021-01-01' ) , new Date ( '2020-01-01' ) , new Date ( '2021-05-01' ) ] ) ;
701
+ } ) ;
702
+
624
703
it ( '@QueryParam when required params must be provided and they should not be empty' , async ( ) => {
625
704
expect . assertions ( 6 ) ;
626
705
let response = await axios . get ( '/photos-with-required?limit=0' ) ;
0 commit comments