@@ -2,6 +2,164 @@ import ComparisonOperators from '../../src/rules-engine/operators/comparison'
2
2
3
3
describe ( 'Comparison Operators' , ( ) => {
4
4
describe ( 'Equal Operator' , ( ) => {
5
- test . todo ( 'Should pass given two equal values' )
5
+ test ( 'Should pass given two equal strings' , ( ) => {
6
+ const result = ComparisonOperators . equal ( 'Switch' , 'Switch' )
7
+ expect ( result ) . toBeTruthy ( )
8
+ } )
9
+
10
+ test ( 'Should fail given two different strings' , ( ) => {
11
+ const result = ComparisonOperators . equal ( 'PS5' , 'Xbox Series X' )
12
+ expect ( result ) . toBeFalsy ( )
13
+ } )
14
+ test ( 'Should pass given two different numbers' , ( ) => {
15
+ const result = ComparisonOperators . equal ( 360 , 360 )
16
+ expect ( result ) . toBeTruthy ( )
17
+ } )
18
+ test ( 'Should fail given two different numbers' , ( ) => {
19
+ const result = ComparisonOperators . equal ( 360 , 90 )
20
+ expect ( result ) . toBeFalsy ( )
21
+ } )
22
+ test ( 'Should pass given two equal values with different types' , ( ) => {
23
+ const result = ComparisonOperators . equal ( 180 , '180' )
24
+ expect ( result ) . toBeTruthy ( )
25
+ } )
26
+ } )
27
+
28
+ describe ( 'NotEqual Operator' , ( ) => {
29
+ test ( 'Should fail given two equal strings' , ( ) => {
30
+ const result = ComparisonOperators . notEqual ( 'Switch' , 'Switch' )
31
+ expect ( result ) . toBeFalsy ( )
32
+ } )
33
+
34
+ test ( 'Should pass given two different strings' , ( ) => {
35
+ const result = ComparisonOperators . notEqual ( 'PS5' , 'Xbox Series X' )
36
+ expect ( result ) . toBeTruthy ( )
37
+ } )
38
+ test ( 'Should fail given two different numbers' , ( ) => {
39
+ const result = ComparisonOperators . notEqual ( 360 , 360 )
40
+ expect ( result ) . toBeFalsy ( )
41
+ } )
42
+ test ( 'Should pass given two different numbers' , ( ) => {
43
+ const result = ComparisonOperators . notEqual ( 360 , 90 )
44
+ expect ( result ) . toBeTruthy ( )
45
+ } )
46
+ test ( 'Should pass given two equal values with different types' , ( ) => {
47
+ const result = ComparisonOperators . notEqual ( 180 , '180' )
48
+ expect ( result ) . toBeTruthy ( )
49
+ } )
50
+ } )
51
+
52
+ describe ( 'LessThan and LessThanInclusive Operator' , ( ) => {
53
+ test ( 'Should fail if the first string is less than the second one' , ( ) => {
54
+ const result = ComparisonOperators . lessThan ( 'X' , 'A' )
55
+ expect ( result ) . toBeFalsy ( )
56
+ } )
57
+
58
+ test ( 'Should fail comparing the same string' , ( ) => {
59
+ const result = ComparisonOperators . lessThan ( 'A' , 'A' )
60
+ expect ( result ) . toBeFalsy ( )
61
+ } )
62
+
63
+ test ( 'Should pass if the first string is greater than the second one' , ( ) => {
64
+ const result = ComparisonOperators . lessThan ( 'A' , 'X' )
65
+ expect ( result ) . toBeTruthy ( )
66
+ } )
67
+
68
+ test ( 'Should pass if the first number is less than the second one' , ( ) => {
69
+ const result = ComparisonOperators . lessThan ( 10 , 100 )
70
+ expect ( result ) . toBeTruthy ( )
71
+ } )
72
+
73
+ test ( 'Should fail comparing the same number' , ( ) => {
74
+ const result = ComparisonOperators . lessThan ( 10 , 10 )
75
+ expect ( result ) . toBeFalsy ( )
76
+ } )
77
+
78
+ test ( 'Should fail if the first number is greater than the second one' , ( ) => {
79
+ const result = ComparisonOperators . lessThan ( 100 , 10 )
80
+ expect ( result ) . toBeFalsy ( )
81
+ } )
82
+
83
+ test ( 'Should pass if the first number is less or equal than the second one' , ( ) => {
84
+ expect ( ComparisonOperators . lessThanInclusive ( 1 , 10 ) ) . toBeTruthy ( )
85
+ expect ( ComparisonOperators . lessThanInclusive ( 10 , 10 ) ) . toBeTruthy ( )
86
+ } )
87
+
88
+ test ( 'Should pass if the first string is less or equal than the second one' , ( ) => {
89
+ expect ( ComparisonOperators . lessThanInclusive ( 'a' , 'x' ) ) . toBeTruthy ( )
90
+ expect ( ComparisonOperators . lessThanInclusive ( 'a' , 'a' ) ) . toBeTruthy ( )
91
+ } )
92
+
93
+ test ( 'Should pass if the first date is before than the second one' , ( ) => {
94
+ const result = ComparisonOperators . lessThan (
95
+ '2022-03-15T20:42:58.510Z' ,
96
+ new Date ( ) . toISOString ( )
97
+ )
98
+ expect ( result ) . toBeTruthy ( )
99
+ } )
100
+ test ( 'Should fail if the first date is after than the second one' , ( ) => {
101
+ const result = ComparisonOperators . lessThan (
102
+ new Date ( ) . toISOString ( ) ,
103
+ '2022-03-15T20:42:58.510Z'
104
+ )
105
+ expect ( result ) . toBeFalsy ( )
106
+ } )
107
+ } )
108
+
109
+ describe ( 'GreaterThan and GreaterThanInclusive Operator' , ( ) => {
110
+ test ( 'Should fail if the first string is greater than the second one' , ( ) => {
111
+ const result = ComparisonOperators . greaterThan ( 'A' , 'X' )
112
+ expect ( result ) . toBeFalsy ( )
113
+ } )
114
+
115
+ test ( 'Should fail comparing the same string' , ( ) => {
116
+ const result = ComparisonOperators . greaterThan ( 'A' , 'A' )
117
+ expect ( result ) . toBeFalsy ( )
118
+ } )
119
+
120
+ test ( 'Should pass if the first string is less than the second one' , ( ) => {
121
+ const result = ComparisonOperators . greaterThan ( 'X' , 'A' )
122
+ expect ( result ) . toBeTruthy ( )
123
+ } )
124
+
125
+ test ( 'Should pass if the first number is greater than the second one' , ( ) => {
126
+ const result = ComparisonOperators . greaterThan ( 100 , 10 )
127
+ expect ( result ) . toBeTruthy ( )
128
+ } )
129
+
130
+ test ( 'Should fail comparing the same number' , ( ) => {
131
+ const result = ComparisonOperators . greaterThan ( 10 , 10 )
132
+ expect ( result ) . toBeFalsy ( )
133
+ } )
134
+
135
+ test ( 'Should fail if the first number is less than the second one' , ( ) => {
136
+ const result = ComparisonOperators . greaterThan ( 10 , 100 )
137
+ expect ( result ) . toBeFalsy ( )
138
+ } )
139
+
140
+ test ( 'Should pass if the first number is greater or equal than the second one' , ( ) => {
141
+ expect ( ComparisonOperators . greaterThanInclusive ( 10 , 1 ) ) . toBeTruthy ( )
142
+ expect ( ComparisonOperators . greaterThanInclusive ( 10 , 10 ) ) . toBeTruthy ( )
143
+ } )
144
+
145
+ test ( 'Should pass if the first string is greater or equal than the second one' , ( ) => {
146
+ expect ( ComparisonOperators . greaterThanInclusive ( 'x' , 'a' ) ) . toBeTruthy ( )
147
+ expect ( ComparisonOperators . greaterThanInclusive ( 'a' , 'a' ) ) . toBeTruthy ( )
148
+ } )
149
+
150
+ test ( 'Should pass if the first date is after than the second one' , ( ) => {
151
+ const result = ComparisonOperators . greaterThan (
152
+ new Date ( ) . toISOString ( ) ,
153
+ '2022-03-15T20:42:58.510Z'
154
+ )
155
+ expect ( result ) . toBeTruthy ( )
156
+ } )
157
+ test ( 'Should fail if the first date is before than the second one' , ( ) => {
158
+ const result = ComparisonOperators . greaterThan (
159
+ '2022-03-15T20:42:58.510Z' ,
160
+ new Date ( ) . toISOString ( )
161
+ )
162
+ expect ( result ) . toBeFalsy ( )
163
+ } )
6
164
} )
7
165
} )
0 commit comments