@@ -55,6 +55,27 @@ describe('findMatchingRule', () => {
55
55
it ( 'returns null if attributes do not match any rules' , ( ) => {
56
56
const rules = [ numericRule ] ;
57
57
expect ( findMatchingRule ( { totalSales : 101 } , rules , false ) ) . toEqual ( null ) ;
58
+
59
+ // input subject attribute is a string which is not a valid semver nor numeric
60
+ // verify that is not parsed to a semver nor a numeric.
61
+ expect (
62
+ findMatchingRule (
63
+ { version : '1.2.03' } ,
64
+ [
65
+ {
66
+ allocationKey : 'test' ,
67
+ conditions : [
68
+ {
69
+ operator : OperatorType . GTE ,
70
+ attribute : 'version' ,
71
+ value : '1.2.0' ,
72
+ } ,
73
+ ] ,
74
+ } ,
75
+ ] ,
76
+ false ,
77
+ ) ,
78
+ ) . toEqual ( null ) ;
58
79
} ) ;
59
80
60
81
it ( 'returns the rule if attributes match AND conditions' , ( ) => {
@@ -79,10 +100,10 @@ describe('findMatchingRule', () => {
79
100
expect ( findMatchingRule ( { totalSales : 101 } , rules , false ) ) . toEqual ( ruleWithEmptyConditions ) ;
80
101
} ) ;
81
102
82
- it ( 'returns null if using numeric operator with string' , ( ) => {
103
+ it ( 'allows for a mix of numeric and string values ' , ( ) => {
83
104
const rules = [ numericRule , ruleWithMatchesCondition ] ;
84
105
expect ( findMatchingRule ( { totalSales : 'stringValue' } , rules , false ) ) . toEqual ( null ) ;
85
- expect ( findMatchingRule ( { totalSales : '20' } , rules , false ) ) . toEqual ( null ) ;
106
+ expect ( findMatchingRule ( { totalSales : '20' } , rules , false ) ) . toEqual ( numericRule ) ;
86
107
} ) ;
87
108
88
109
it ( 'handles rule with matches operator' , ( ) => {
0 commit comments