@@ -190,6 +190,17 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
190
190
var result = customAttributeEvaluator . evaluate ( exactNumberCondition , { } ) ;
191
191
assert . isNull ( result ) ;
192
192
} ) ;
193
+
194
+ it ( 'should return null if the condition value is not finite' , function ( ) {
195
+ var invalidValueCondition = {
196
+ match : 'exact' ,
197
+ name : 'lasers_count' ,
198
+ type : 'custom_attribute' ,
199
+ value : Infinity ,
200
+ } ;
201
+ var result = customAttributeEvaluator . evaluate ( invalidValueCondition , { lasers_count : 9000 } ) ;
202
+ assert . isNull ( result ) ;
203
+ } ) ;
193
204
} ) ;
194
205
195
206
describe ( 'with a boolean condition value' , function ( ) {
@@ -279,22 +290,43 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
279
290
assert . isFalse ( result ) ;
280
291
} ) ;
281
292
282
- it ( 'should return null if the user-provided value is not a number' , function ( ) {
293
+ it ( 'should return null if the user-provided value is not a finite number' , function ( ) {
283
294
var result = customAttributeEvaluator . evaluate ( gtCondition , {
284
295
meters_travelled : 'a long way' ,
285
296
} ) ;
286
297
assert . isNull ( result ) ;
287
298
288
- var result = customAttributeEvaluator . evaluate ( gtCondition , {
299
+ result = customAttributeEvaluator . evaluate ( gtCondition , {
289
300
meters_travelled : '1000' ,
290
301
} ) ;
291
302
assert . isNull ( result ) ;
303
+
304
+ result = customAttributeEvaluator . evaluate ( gtCondition , {
305
+ meters_travelled : Infinity ,
306
+ } ) ;
307
+ assert . isNull ( result ) ;
292
308
} ) ;
293
309
294
310
it ( 'should return null if there is no user-provided value' , function ( ) {
295
311
var result = customAttributeEvaluator . evaluate ( gtCondition , { } ) ;
296
312
assert . isNull ( result ) ;
297
313
} ) ;
314
+
315
+ it ( 'should return null if the condition value is not a finite number' , function ( ) {
316
+ var userAttributes = { meters_travelled : 58.4 } ;
317
+ var invalidValueCondition = {
318
+ match : 'gt' ,
319
+ name : 'meters_travelled' ,
320
+ type : 'custom_attribute' ,
321
+ value : Infinity ,
322
+ } ;
323
+ var result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
324
+ assert . isNull ( result ) ;
325
+
326
+ invalidValueCondition . value = null ;
327
+ result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
328
+ assert . isNull ( result ) ;
329
+ } ) ;
298
330
} ) ;
299
331
300
332
describe ( 'less than match type' , function ( ) {
@@ -319,21 +351,42 @@ describe('lib/core/custom_attribute_condition_evaluator', function() {
319
351
assert . isFalse ( result ) ;
320
352
} ) ;
321
353
322
- it ( 'should return null if the user-provided value is not a number' , function ( ) {
354
+ it ( 'should return null if the user-provided value is not a finite number' , function ( ) {
323
355
var result = customAttributeEvaluator . evaluate ( ltCondition , {
324
356
meters_travelled : true ,
325
357
} ) ;
326
358
assert . isNull ( result ) ;
327
359
328
- var result = customAttributeEvaluator . evaluate ( ltCondition , {
360
+ result = customAttributeEvaluator . evaluate ( ltCondition , {
329
361
meters_travelled : '48.2' ,
330
362
} ) ;
331
363
assert . isNull ( result ) ;
364
+
365
+ result = customAttributeEvaluator . evaluate ( ltCondition , {
366
+ meters_travelled : Infinity ,
367
+ } ) ;
368
+ assert . isNull ( result ) ;
332
369
} ) ;
333
370
334
371
it ( 'should return null if there is no user-provided value' , function ( ) {
335
372
var result = customAttributeEvaluator . evaluate ( ltCondition , { } ) ;
336
373
assert . isNull ( result ) ;
337
374
} ) ;
375
+
376
+ it ( 'should return null if the condition value is not a finite number' , function ( ) {
377
+ var userAttributes = { meters_travelled : 10 } ;
378
+ var invalidValueCondition = {
379
+ match : 'lt' ,
380
+ name : 'meters_travelled' ,
381
+ type : 'custom_attribute' ,
382
+ value : Infinity ,
383
+ } ;
384
+ var result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
385
+ assert . isNull ( result ) ;
386
+
387
+ invalidValueCondition . value = { } ;
388
+ result = customAttributeEvaluator . evaluate ( invalidValueCondition , userAttributes ) ;
389
+ assert . isNull ( result ) ;
390
+ } ) ;
338
391
} ) ;
339
392
} ) ;
0 commit comments