@@ -62,7 +62,7 @@ describe(packageJson.name, () => {
62
62
app . server . close ( ) ;
63
63
} ) ;
64
64
65
- it ( 'should not allow read only properties in requests' , async ( ) =>
65
+ it ( 'should remove read only properties in requests' , async ( ) =>
66
66
request ( app )
67
67
. post ( `${ app . basePath } /products` )
68
68
. set ( 'content-type' , 'application/json' )
@@ -72,11 +72,11 @@ describe(packageJson.name, () => {
72
72
price : 10.99 ,
73
73
created_at : new Date ( ) . toISOString ( ) ,
74
74
} )
75
- . expect ( 400 )
75
+ . expect ( 200 )
76
76
. then ( ( r ) => {
77
77
const body = r . body ;
78
- // id is a readonly property and should not be allowed in the request
79
- expect ( body . message ) . to . contain ( 'id' ) ;
78
+ // id is a readonly property and should be allowed in the request but should be deleted before entering in route
79
+ expect ( body . id ) . to . be . undefined ;
80
80
} ) ) ;
81
81
82
82
it ( 'should allow read only properties in responses' , async ( ) =>
@@ -87,7 +87,7 @@ describe(packageJson.name, () => {
87
87
expect ( r . body ) . to . be . an ( 'array' ) . with . length ( 1 ) ;
88
88
} ) ) ;
89
89
90
- it ( 'should not allow read only inlined properties in requests' , async ( ) =>
90
+ it ( 'should remove read only inlined properties in requests' , async ( ) =>
91
91
request ( app )
92
92
. post ( `${ app . basePath } /products/inlined` )
93
93
. set ( 'content-type' , 'application/json' )
@@ -97,14 +97,13 @@ describe(packageJson.name, () => {
97
97
price : 10.99 ,
98
98
created_at : new Date ( ) . toUTCString ( ) ,
99
99
} )
100
- . expect ( 400 )
101
100
. then ( ( r ) => {
102
101
const body = r . body ;
103
102
// id is a readonly property and should not be allowed in the request
104
- expect ( body . message ) . to . contain ( 'id' ) ;
103
+ expect ( body . id ) . to . be . undefined ;
105
104
} ) ) ;
106
105
107
- it ( 'should not allow read only properties in requests (nested schema $refs)' , async ( ) =>
106
+ it ( 'should remove read only properties in requests (nested schema $refs)' , async ( ) =>
108
107
request ( app )
109
108
. post ( `${ app . basePath } /products/nested` )
110
109
. set ( 'content-type' , 'application/json' )
@@ -113,19 +112,19 @@ describe(packageJson.name, () => {
113
112
name : 'some name' ,
114
113
price : 10.99 ,
115
114
created_at : new Date ( ) . toISOString ( ) ,
116
- reviews : {
117
- id : 'review_id' ,
115
+ reviews : [ {
116
+ id : 2 ,
118
117
rating : 5 ,
119
- } ,
118
+ } ] ,
120
119
} )
121
- . expect ( 400 )
120
+ . expect ( 200 )
122
121
. then ( ( r ) => {
123
122
const body = r . body ;
124
- // id is a readonly property and should not be allowed in the request
125
- expect ( body . message ) . to . contain ( 'id ') ;
123
+ // id is a readonly property and should be removed from the request
124
+ expect ( body . id ) . to . be . equal ( 'test ') ;
126
125
} ) ) ;
127
126
128
- it ( 'should not allow read only properties in requests (deep nested schema $refs)' , async ( ) =>
127
+ it ( 'should remove read only properties in requests (deep nested schema $refs)' , async ( ) =>
129
128
request ( app )
130
129
. post ( `${ app . basePath } /products/nested` )
131
130
. set ( 'content-type' , 'application/json' )
@@ -139,11 +138,11 @@ describe(packageJson.name, () => {
139
138
} ,
140
139
] ,
141
140
} )
142
- . expect ( 400 )
141
+ . expect ( 200 )
143
142
. then ( ( r ) => {
144
143
const body = r . body ;
145
144
// id is a readonly property and should not be allowed in the request
146
- expect ( body . message ) . to . contain ( 'request/body/ reviews/0/id' ) ;
145
+ expect ( body . reviews [ 0 ] . id ) . to . be . undefined ;
147
146
} ) ) ;
148
147
149
148
it ( 'should pass validation if required read only properties to be missing from request ($ref)' , async ( ) =>
0 commit comments