@@ -27,7 +27,7 @@ const validDog = {
2727 } ,
2828} ;
2929
30- describe ( 'validate properties' , ( ) => {
30+ describe ( 'validate properties based on discriminated schemas ' , ( ) => {
3131 let client : Client ;
3232 let app : ValidationApplication ;
3333
@@ -49,16 +49,11 @@ describe('validate properties', () => {
4949 await client . post ( '/pets' ) . send ( validDog ) . expect ( 200 ) ;
5050 } ) ;
5151
52- it ( 'should fail with error indicating the invalid barkVolume' , async ( ) => {
52+ it ( 'should fail with error indicating invalid barkVolume type ' , async ( ) => {
5353 const invalidDog = { ...validDog } ;
5454 invalidDog . animalProperties . barkVolume = 'loud' as unknown as number ;
5555 const response = await client . post ( '/pets' ) . send ( invalidDog ) . expect ( 422 ) ;
5656
57- /*
58- below expect statements pass after fixing the bug in function convertToJsonSchema()
59- loopback-next/packages/rest/src/validation/request-body.validator.ts#lines-87:99
60- a possible solution is indicated under //NOTE
61- */
6257 expect ( response . body . error . details . length ) . to . equal ( 1 ) ;
6358 expect ( response . body . error . details [ 0 ] . message ) . to . equal ( 'must be number' ) ;
6459 expect ( response . body . error . details ) . to . deepEqual ( [
@@ -72,4 +67,23 @@ describe('validate properties', () => {
7267 } ,
7368 ] ) ;
7469 } ) ;
70+
71+ it ( 'should fail with error indicating invalid whiskerLength type' , async ( ) => {
72+ const invalidCat = { ...validCat } ;
73+ invalidCat . animalProperties . whiskerLength = 'long' as unknown as number ;
74+ const response = await client . post ( '/pets' ) . send ( invalidCat ) . expect ( 422 ) ;
75+
76+ expect ( response . body . error . details . length ) . to . equal ( 1 ) ;
77+ expect ( response . body . error . details [ 0 ] . message ) . to . equal ( 'must be number' ) ;
78+ expect ( response . body . error . details ) . to . deepEqual ( [
79+ {
80+ code : 'type' ,
81+ info : {
82+ type : 'number' ,
83+ } ,
84+ message : 'must be number' ,
85+ path : '/animalProperties/whiskerLength' ,
86+ } ,
87+ ] ) ;
88+ } ) ;
7589} ) ;
0 commit comments