11import bodyParser from 'body-parser' ;
2- import { IsBoolean , IsString , MaxLength , Min , ValidateNested } from 'class-validator' ;
2+ import { IsBoolean , IsString , MaxLength , Min , ValidateNested , IsArray , IsNumber , IsDate } from 'class-validator' ;
33import express from 'express' ;
44import FormData from 'form-data' ;
55import fs from 'fs' ;
@@ -29,6 +29,7 @@ import { createExpressServer, getMetadataArgsStorage } from '../../src/index';
2929import { SessionMiddleware } from '../fakes/global-options/SessionMiddleware' ;
3030import { axios } from '../utilities/axios' ;
3131import DoneCallback = jest . DoneCallback ;
32+ import { Type } from 'class-transformer' ;
3233
3334describe ( `` , ( ) => {
3435 let expressServer : HttpServer ;
@@ -116,6 +117,20 @@ describe(``, () => {
116117
117118 @ValidateNested ( )
118119 myObject : NestedQueryClass ;
120+
121+ @IsArray ( )
122+ @IsString ( { each : true } )
123+ multipleStringValues ?: string [ ] ;
124+
125+ @IsArray ( )
126+ @IsNumber ( undefined , { each : true } )
127+ @Type ( ( ) => Number )
128+ multipleNumberValues ?: number [ ] ;
129+
130+ @IsArray ( )
131+ @IsDate ( { each : true } )
132+ @Type ( ( ) => Date )
133+ multipleDateValues ?: Date [ ] ;
119134 }
120135
121136 @Controller ( )
@@ -493,20 +508,71 @@ describe(``, () => {
493508 */
494509
495510 it ( "@QueryParams should give a proper values from request's query parameters" , async ( ) => {
496- expect . assertions ( 6 ) ;
497- const response = await axios . get ( '/photos-params?sortBy=name&count=2&limit=10&showAll' ) ;
511+ expect . assertions ( 9 ) ;
512+ const response = await axios . get (
513+ '/photos-params?' +
514+ 'sortBy=name&' +
515+ 'count=2&' +
516+ 'limit=10&' +
517+ 'showAll&' +
518+ 'multipleStringValues=a&' +
519+ 'multipleStringValues=b&' +
520+ 'multipleNumberValues=1&' +
521+ 'multipleNumberValues=2.3&' +
522+ 'multipleDateValues=2017-02-01T00:00:00Z&' +
523+ 'multipleDateValues=2017-03-01T00:00:00Z'
524+ ) ;
498525 expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
499526 expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
500527 expect ( queryParams1 . sortBy ) . toEqual ( 'name' ) ;
501528 expect ( queryParams1 . count ) . toEqual ( '2' ) ;
502529 expect ( queryParams1 . limit ) . toEqual ( 10 ) ;
503530 expect ( queryParams1 . showAll ) . toEqual ( true ) ;
531+ expect ( queryParams1 . multipleStringValues ) . toEqual ( [ 'a' , 'b' ] ) ;
532+ expect ( queryParams1 . multipleNumberValues ) . toEqual ( [ 1 , 2.3 ] ) ;
533+ expect ( queryParams1 . multipleDateValues ) . toEqual ( [
534+ new Date ( '2017-02-01T00:00:00Z' ) ,
535+ new Date ( '2017-03-01T00:00:00Z' ) ,
536+ ] ) ;
504537 } ) ;
505538
506- it ( "@QueryParams should give a proper values from request's query parameters with nested json " , async ( ) => {
539+ it ( "@QueryParams should give a proper values from request's query parameters and one multiple value " , async ( ) => {
507540 expect . assertions ( 9 ) ;
508541 const response = await axios . get (
509- '/photos-params?sortBy=name&count=2&limit=10&showAll&myObject=%7B%22num%22%3A%205,%20%22str%22%3A%20%22five%22,%20%22isFive%22%3A%20true%7D'
542+ '/photos-params?' +
543+ 'sortBy=name&' +
544+ 'count=2&' +
545+ 'limit=10&' +
546+ 'showAll&' +
547+ 'multipleStringValues=a&' +
548+ 'multipleNumberValues=1&' +
549+ 'multipleDateValues=2017-02-01T01:00:00Z'
550+ ) ;
551+ expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
552+ expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
553+ expect ( queryParams1 . sortBy ) . toEqual ( 'name' ) ;
554+ expect ( queryParams1 . count ) . toEqual ( '2' ) ;
555+ expect ( queryParams1 . limit ) . toEqual ( 10 ) ;
556+ expect ( queryParams1 . showAll ) . toEqual ( true ) ;
557+ expect ( queryParams1 . multipleStringValues ) . toEqual ( [ 'a' ] ) ;
558+ expect ( queryParams1 . multipleNumberValues ) . toEqual ( [ 1 ] ) ;
559+ expect ( queryParams1 . multipleDateValues ) . toEqual ( [ new Date ( '2017-02-01T01:00:00Z' ) ] ) ;
560+ } ) ;
561+
562+ it ( "@QueryParams should give a proper values from request's query parameters with nested json" , async ( ) => {
563+ expect . assertions ( 12 ) ;
564+ const response = await axios . get (
565+ '/photos-params?' +
566+ 'sortBy=name&' +
567+ 'count=2&' +
568+ 'limit=10&' +
569+ 'showAll&' +
570+ 'myObject=%7B%22num%22%3A%205,%20%22str%22%3A%20%22five%22,%20%22isFive%22%3A%20true%7D&' +
571+ 'multipleStringValues=a&' +
572+ 'multipleStringValues=b&' +
573+ 'multipleNumberValues=1&' +
574+ 'multipleNumberValues=2.3&' +
575+ 'multipleDateValues=2017-02-01T00:00:00Z'
510576 ) ;
511577 expect ( response . status ) . toEqual ( HttpStatusCodes . OK ) ;
512578 expect ( response . headers [ 'content-type' ] ) . toEqual ( 'text/html; charset=utf-8' ) ;
@@ -517,6 +583,9 @@ describe(``, () => {
517583 expect ( queryParams1 . myObject . num ) . toEqual ( 5 ) ;
518584 expect ( queryParams1 . myObject . str ) . toEqual ( 'five' ) ;
519585 expect ( queryParams1 . myObject . isFive ) . toEqual ( true ) ;
586+ expect ( queryParams1 . multipleStringValues ) . toEqual ( [ 'a' , 'b' ] ) ;
587+ expect ( queryParams1 . multipleNumberValues ) . toEqual ( [ 1 , 2.3 ] ) ;
588+ expect ( queryParams1 . multipleDateValues ) . toEqual ( [ new Date ( '2017-02-01T00:00:00Z' ) ] ) ;
520589 } ) ;
521590
522591 it ( "@QueryParams should not validate request query parameters when it's turned off in validator options" , async ( ) => {
0 commit comments