@@ -80,6 +80,7 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
80
80
username : " luis" ,
81
81
password : " luis" ,
82
82
83
+ status : 1 ,
83
84
bogus : now (),
84
85
anotherBogus : now ()
85
86
},
@@ -146,6 +147,82 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
146
147
} );
147
148
} );
148
149
} );
150
+
151
+
152
+ story ( " I want to access error metadata in UDF and method validators" , function (){
153
+ given ( " invalid data" , function (){
154
+ then ( " it should allow access to custom udf metadata" , function (){
155
+ var e = this .request (
156
+ route = " /main/validateOnly" ,
157
+ params = {
158
+ username : " luis" ,
159
+
160
+ password : " luis"
161
+ },
162
+ method = " post"
163
+ );
164
+
165
+ var result = e .getPrivateValue ( " result" );
166
+
167
+ expect ( result .getErrors ().len () ).toBe ( 1 );
168
+ expect ( result .getErrors ()[ 1 ].getValidationType () ).toBe ( " UDF" );
169
+ expect ( result .getErrors ()[ 1 ].getErrorMetaData () ).toHaveKey ( " custom" );
170
+ } );
171
+ then ( " it should allow udf generated error messages based on metadata" , function (){
172
+ var e = this .request (
173
+ route = " /main/validateOnly" ,
174
+ params = {
175
+ username : " luis" ,
176
+
177
+ password : " luis"
178
+ },
179
+ method = " post"
180
+ );
181
+
182
+ var result = e .getPrivateValue ( " result" );
183
+ expect ( result .getErrors ()[ 1 ].getMessage () ).toBe (
184
+ " This is a custom error message from within the udf"
185
+ );
186
+ } );
187
+ then ( " it should allow access to custom method metadata" , function (){
188
+ var e = this .request (
189
+ route = " /main/validateOnly" ,
190
+ params = {
191
+ username : " luis" ,
192
+
193
+ password : " luis" ,
194
+ status : 1 ,
195
+ type : 4 // should not validate
196
+ },
197
+ method = " post"
198
+ );
199
+
200
+ var result = e .getPrivateValue ( " result" );
201
+
202
+ expect ( result .getErrors ().len () ).toBe ( 1 );
203
+ expect ( result .getErrors ()[ 1 ].getValidationType () ).toBe ( " method" );
204
+ expect ( result .getErrors ()[ 1 ].getErrorMetaData () ).toHaveKey ( " custom" );
205
+ } );
206
+ then ( " it should allow method generated error messages based on metadata" , function (){
207
+ var e = this .request (
208
+ route = " /main/validateOnly" ,
209
+ params = {
210
+ username : " luis" ,
211
+
212
+ password : " luis" ,
213
+ status : 1 ,
214
+ type : 4 // should not validate
215
+ },
216
+ method = " post"
217
+ );
218
+
219
+ var result = e .getPrivateValue ( " result" );
220
+ expect ( result .getErrors ()[ 1 ].getMessage () ).toBe (
221
+ " This is a custom error message from within the method"
222
+ );
223
+ } );
224
+ } );
225
+ } );
149
226
}
150
227
151
228
}
0 commit comments