@@ -5,7 +5,7 @@ import { createApp } from './common/app';
5
5
6
6
import { date , dateTime } from '../src/framework/base.serdes' ;
7
7
8
- const apiSpecPath = path . join ( 'test' , '699.yaml' ) ;
8
+ const apiSpecPath = path . join ( 'test' , 'resources' , ' 699.yaml') ;
9
9
10
10
class ObjectID {
11
11
id : string ;
@@ -62,6 +62,7 @@ describe('699', () => {
62
62
id : req . params . id ,
63
63
creationDateTime : date ,
64
64
creationDate : date ,
65
+ shortOrLong : 'a' ,
65
66
history : [ {
66
67
modificationDate : date
67
68
} ] ,
@@ -80,7 +81,6 @@ describe('699', () => {
80
81
res . json ( req . body ) ;
81
82
} ) ;
82
83
app . use ( ( err , req , res , next ) => {
83
- console . error ( err )
84
84
res . status ( err . status ?? 500 ) . json ( {
85
85
message : err . message ,
86
86
code : err . status ?? 500 ,
@@ -101,7 +101,7 @@ describe('699', () => {
101
101
. get ( `${ app . basePath } /users/1234` )
102
102
. expect ( 400 )
103
103
. then ( ( r ) => {
104
- expect ( r . body . message ) . to . equal ( 'request. params. id should match pattern "^[0-9a-fA-F]{24}$"' ) ;
104
+ expect ( r . body . message ) . to . equal ( 'request/ params/ id must match pattern "^[0-9a-fA-F]{24}$"' ) ;
105
105
} ) ) ;
106
106
107
107
it ( 'should control GOOD id format and get a response in expected format' , async ( ) =>
@@ -121,7 +121,8 @@ describe('699', () => {
121
121
. send ( {
122
122
id : '5fdefd13a6640bb5fb5fa925' ,
123
123
creationDateTime : '2020-12-20T07:28:19.213Z' ,
124
- creationDate : '2020-12-20'
124
+ creationDate : '2020-12-20' ,
125
+ shortOrLong : 'ab' ,
125
126
} )
126
127
. set ( 'Content-Type' , 'application/json' )
127
128
. expect ( 200 )
@@ -137,12 +138,13 @@ describe('699', () => {
137
138
. send ( {
138
139
id : '5fdefd13a6640bb5fb5fa' ,
139
140
creationDateTime : '2020-12-20T07:28:19.213Z' ,
140
- creationDate : '2020-12-20'
141
+ creationDate : '2020-12-20' ,
142
+ shortOrLong : 'abcd' ,
141
143
} )
142
144
. set ( 'Content-Type' , 'application/json' )
143
145
. expect ( 400 )
144
146
. then ( ( r ) => {
145
- expect ( r . body . message ) . to . equal ( 'request. body. id should match pattern "^[0-9a-fA-F]{24}$"' ) ;
147
+ expect ( r . body . message ) . to . equal ( 'request/ body/ id must match pattern "^[0-9a-fA-F]{24}$"' ) ;
146
148
} ) ) ;
147
149
148
150
it ( 'should POST throw error on invalid schema Date' , async ( ) =>
@@ -156,9 +158,29 @@ describe('699', () => {
156
158
. set ( 'Content-Type' , 'application/json' )
157
159
. expect ( 400 )
158
160
. then ( ( r ) => {
159
- expect ( r . body . message ) . to . equal ( 'request. body. creationDate should match format "date"' ) ;
161
+ expect ( r . body . message ) . to . equal ( 'request/ body/ creationDate must match format "date"' ) ;
160
162
} ) ) ;
161
163
164
+ it ( 'should enforce anyOf validations' , async ( ) =>
165
+ request ( app )
166
+ . post ( `${ app . basePath } /users` )
167
+ . send ( {
168
+ id : '5fdefd13a6640bb5fb5fa925' ,
169
+ creationDateTime : '2020-12-20T07:28:19.213Z' ,
170
+ creationDate : '2020-12-20' ,
171
+ shortOrLong : 'abc' ,
172
+ } )
173
+ . set ( 'Content-Type' , 'application/json' )
174
+ . expect ( 400 )
175
+ . then ( ( r ) => {
176
+ expect ( r . body . message ) . to . equal (
177
+ [
178
+ 'request/body/shortOrLong must NOT have more than 2 characters' ,
179
+ 'request/body/shortOrLong must NOT have fewer than 4 characters' ,
180
+ 'request/body/shortOrLong must match a schema in anyOf' ,
181
+ ] . join ( ', ' ) ,
182
+ ) ;
183
+ } ) ) ;
162
184
} ) ;
163
185
164
186
@@ -198,6 +220,7 @@ describe('699 serialize response components only', () => {
198
220
id : new ObjectID ( req . params . id ) ,
199
221
creationDateTime : date ,
200
222
creationDate : undefined ,
223
+ shortOrLong : 'a' ,
201
224
history : [ {
202
225
modificationDate : date ,
203
226
} ] ,
@@ -229,7 +252,6 @@ describe('699 serialize response components only', () => {
229
252
res . json ( req . body ) ;
230
253
} ) ;
231
254
app . use ( ( err , req , res , next ) => {
232
- console . error ( err )
233
255
res . status ( err . status ?? 500 ) . json ( {
234
256
message : err . message ,
235
257
code : err . status ?? 500 ,
@@ -250,7 +272,7 @@ describe('699 serialize response components only', () => {
250
272
. get ( `${ app . basePath } /users/1234` )
251
273
. expect ( 400 )
252
274
. then ( ( r ) => {
253
- expect ( r . body . message ) . to . equal ( 'request. params. id should match pattern "^[0-9a-fA-F]{24}$"' ) ;
275
+ expect ( r . body . message ) . to . equal ( 'request/ params/ id must match pattern "^[0-9a-fA-F]{24}$"' ) ;
254
276
} ) ) ;
255
277
256
278
it ( 'should control GOOD id format and get a response in expected format' , async ( ) =>
@@ -291,7 +313,7 @@ describe('699 serialize response components only', () => {
291
313
. set ( 'Content-Type' , 'application/json' )
292
314
. expect ( 400 )
293
315
. then ( ( r ) => {
294
- expect ( r . body . message ) . to . equal ( 'request. body. id should match pattern "^[0-9a-fA-F]{24}$"' ) ;
316
+ expect ( r . body . message ) . to . equal ( 'request/ body/ id must match pattern "^[0-9a-fA-F]{24}$"' ) ;
295
317
} ) ) ;
296
318
297
319
it ( 'should POST throw error on invalid schema Date' , async ( ) =>
@@ -305,7 +327,7 @@ describe('699 serialize response components only', () => {
305
327
. set ( 'Content-Type' , 'application/json' )
306
328
. expect ( 400 )
307
329
. then ( ( r ) => {
308
- expect ( r . body . message ) . to . equal ( 'request. body. creationDate should match format "date"' ) ;
330
+ expect ( r . body . message ) . to . equal ( 'request/ body/ creationDate must match format "date"' ) ;
309
331
} ) ) ;
310
332
311
333
it ( 'should throw error 500 on invalid object type instead of Date expected' , async ( ) =>
@@ -314,8 +336,30 @@ describe('699 serialize response components only', () => {
314
336
. query ( { baddateresponse : 'functionNotExists' } )
315
337
. expect ( 500 )
316
338
. then ( ( r ) => {
317
- console . log ( r ) ;
318
- expect ( r . body . message ) . to . equal ( '.response.creationDate format is invalid' ) ;
339
+ expect ( r . body . message ) . to . equal (
340
+ '/response/creationDate format is invalid' ,
341
+ ) ;
342
+ } ) ) ;
343
+
344
+ it ( 'should enforce anyOf validations' , async ( ) =>
345
+ request ( app )
346
+ . post ( `${ app . basePath } /users` )
347
+ . send ( {
348
+ id : '5fdefd13a6640bb5fb5fa925' ,
349
+ creationDateTime : '2020-12-20T07:28:19.213Z' ,
350
+ creationDate : '2020-12-20' ,
351
+ shortOrLong : 'abc' ,
352
+ } )
353
+ . set ( 'Content-Type' , 'application/json' )
354
+ . expect ( 400 )
355
+ . then ( ( r ) => {
356
+ expect ( r . body . message ) . to . equal (
357
+ [
358
+ 'request/body/shortOrLong must NOT have more than 2 characters' ,
359
+ 'request/body/shortOrLong must NOT have fewer than 4 characters' ,
360
+ 'request/body/shortOrLong must match a schema in anyOf' ,
361
+ ] . join ( ', ' ) ,
362
+ ) ;
319
363
} ) ) ;
320
364
321
365
/*
@@ -327,15 +371,14 @@ describe('699 serialize response components only', () => {
327
371
.query({baddateresponse : 'functionBadFormat'})
328
372
.expect(200)
329
373
.then((r) => {
330
- console.log(r.body);
331
374
expect(r.body.message).to.equal('Something saying that date is not date-time format');
332
375
}));
333
376
334
377
*/
335
378
336
379
} ) ;
337
380
338
- describe ( '699 with jsonType array type string-list' , ( ) => {
381
+ describe ( '699 with array type string-list' , ( ) => {
339
382
let app = null ;
340
383
341
384
before ( async ( ) => {
@@ -359,7 +402,6 @@ describe('699 with jsonType array type string-list', () => {
359
402
} ,
360
403
{
361
404
format : 'string-list' ,
362
- jsonType : 'array' ,
363
405
deserialize : ( s ) : string [ ] => s . split ( ',' ) . map ( s => s . trim ( ) ) ,
364
406
serialize : ( o ) : string => ( o as string [ ] ) . join ( ',' ) ,
365
407
} ,
@@ -398,7 +440,6 @@ describe('699 with jsonType array type string-list', () => {
398
440
res . json ( req . body ) ;
399
441
} ) ;
400
442
app . use ( ( err , req , res , next ) => {
401
- console . error ( err )
402
443
res . status ( err . status ?? 500 ) . json ( {
403
444
message : err . message ,
404
445
code : err . status ?? 500 ,
@@ -419,7 +460,7 @@ describe('699 with jsonType array type string-list', () => {
419
460
. get ( `${ app . basePath } /users/1234` )
420
461
. expect ( 400 )
421
462
. then ( ( r ) => {
422
- expect ( r . body . message ) . to . equal ( 'request. params. id should match pattern "^[0-9a-fA-F]{24}$"' ) ;
463
+ expect ( r . body . message ) . to . equal ( 'request/ params/ id must match pattern "^[0-9a-fA-F]{24}$"' ) ;
423
464
} ) ) ;
424
465
425
466
it ( 'should control GOOD id format and get a response in expected format' , async ( ) => {
@@ -443,7 +484,8 @@ describe('699 with jsonType array type string-list', () => {
443
484
id : '5fdefd13a6640bb5fb5fa925' ,
444
485
tags : 'aa,bb,cc' ,
445
486
creationDateTime : '2020-12-20T07:28:19.213Z' ,
446
- creationDate : '2020-12-20'
487
+ creationDate : '2020-12-20' ,
488
+ shortOrLong : 'abcdef' ,
447
489
} )
448
490
. set ( 'Content-Type' , 'application/json' )
449
491
. expect ( 200 )
@@ -466,7 +508,7 @@ describe('699 with jsonType array type string-list', () => {
466
508
. set ( 'Content-Type' , 'application/json' )
467
509
. expect ( 400 )
468
510
. then ( ( r ) => {
469
- expect ( r . body . message ) . to . equal ( 'request. body. id should match pattern "^[0-9a-fA-F]{24}$"' ) ;
511
+ expect ( r . body . message ) . to . equal ( 'request/ body/ id must match pattern "^[0-9a-fA-F]{24}$"' ) ;
470
512
} ) ) ;
471
513
472
514
it ( 'should POST throw error on invalid schema Date' , async ( ) =>
@@ -481,7 +523,7 @@ describe('699 with jsonType array type string-list', () => {
481
523
. set ( 'Content-Type' , 'application/json' )
482
524
. expect ( 400 )
483
525
. then ( ( r ) => {
484
- expect ( r . body . message ) . to . equal ( 'request. body. creationDate should match format "date"' ) ;
526
+ expect ( r . body . message ) . to . equal ( 'request/ body/ creationDate must match format "date"' ) ;
485
527
} ) ) ;
486
528
487
529
it ( 'should POST throw error for deserialize on request of non-string format' , async ( ) =>
@@ -496,9 +538,29 @@ describe('699 with jsonType array type string-list', () => {
496
538
. set ( 'Content-Type' , 'application/json' )
497
539
. expect ( 400 )
498
540
. then ( ( r ) => {
499
- expect ( r . body . message ) . to . equal ( 'request. body. tags must be a string' ) ;
541
+ expect ( r . body . message ) . to . equal ( 'request/ body/ tags must be string' ) ;
500
542
} ) ) ;
501
543
544
+ it ( 'should enforce anyOf validations' , async ( ) =>
545
+ request ( app )
546
+ . post ( `${ app . basePath } /users` )
547
+ . send ( {
548
+ id : '5fdefd13a6640bb5fb5fa925' ,
549
+ creationDateTime : '2020-12-20T07:28:19.213Z' ,
550
+ creationDate : '2020-12-20' ,
551
+ shortOrLong : 'abc' ,
552
+ } )
553
+ . set ( 'Content-Type' , 'application/json' )
554
+ . expect ( 400 )
555
+ . then ( ( r ) => {
556
+ expect ( r . body . message ) . to . equal (
557
+ [
558
+ 'request/body/shortOrLong must NOT have more than 2 characters' ,
559
+ 'request/body/shortOrLong must NOT have fewer than 4 characters' ,
560
+ 'request/body/shortOrLong must match a schema in anyOf' ,
561
+ ] . join ( ', ' ) ,
562
+ ) ;
563
+ } ) ) ;
502
564
} ) ;
503
565
504
566
0 commit comments