@@ -2,127 +2,255 @@ import applicableActions from "../src/applicableActions";
2
2
3
3
const DISPLAY_MESSAGE_SIMPLE = {
4
4
type : "message" ,
5
- params : { validationMessage : "Get the employees working in microsoft and status in active or paid-leave" } ,
5
+ params : {
6
+ validationMessage :
7
+ "Get the employees working in microsoft and status in active or paid-leave" ,
8
+ } ,
6
9
} ;
7
10
8
- let rulesSimple = [
9
- {
10
- conditions : {
11
- and : [
12
- { and : [ { company : { is : 'microsoft' } } ,
13
- { or : [ { 'status' : { equal : 'paid-leave' } } , { 'status' : { equal : 'active' } } ]
14
- } ] }
15
- ] ,
16
- } ,
17
- event : DISPLAY_MESSAGE_SIMPLE
18
- } ] ;
11
+ let rulesSimple = [
12
+ {
13
+ conditions : {
14
+ and : [
15
+ {
16
+ and : [
17
+ { company : { is : "microsoft" } } ,
18
+ {
19
+ or : [
20
+ { status : { equal : "paid-leave" } } ,
21
+ { status : { equal : "active" } } ,
22
+ ] ,
23
+ } ,
24
+ ] ,
25
+ } ,
26
+ ] ,
27
+ } ,
28
+ event : DISPLAY_MESSAGE_SIMPLE ,
29
+ } ,
30
+ ] ;
19
31
20
32
test ( "check simple json work" , function ( ) {
21
- let factsSimple = { accountId : 'Lincoln' , company : 'microsoft' , status : 'paid-leave' , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
22
- expect ( applicableActions ( rulesSimple , factsSimple ) ) . toEqual ( [ DISPLAY_MESSAGE_SIMPLE ] ) ;
23
- factsSimple = { accountId : 'Lincoln' , company : 'ibm' , status : 'paid-leave' , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
33
+ let factsSimple = {
34
+ accountId : "Lincoln" ,
35
+ company : "microsoft" ,
36
+ status : "paid-leave" ,
37
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
38
+ } ;
39
+ expect ( applicableActions ( rulesSimple , factsSimple ) ) . toEqual ( [
40
+ DISPLAY_MESSAGE_SIMPLE ,
41
+ ] ) ;
42
+ factsSimple = {
43
+ accountId : "Lincoln" ,
44
+ company : "ibm" ,
45
+ status : "paid-leave" ,
46
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
47
+ } ;
24
48
expect ( applicableActions ( rulesSimple , factsSimple ) ) . toEqual ( [ ] ) ;
25
49
} ) ;
26
50
27
51
const DISPLAY_MESSAGE_NESTED_SIMPLE = {
28
52
type : "message" ,
29
- params : { validationMessage : "Get the employees working in microsoft and status in active or paid-leave" } ,
53
+ params : {
54
+ validationMessage :
55
+ "Get the employees working in microsoft and status in active or paid-leave" ,
56
+ } ,
30
57
} ;
31
58
32
- let rulesNestedSimple = [
33
- {
34
- conditions : {
35
- and : [
36
- { accountId : { is : 'Lincoln' } } ,
37
- { and : [ { company : { is : 'microsoft' } } ,
38
- { or : [ { 'status.code.description' : { equal : 'paid-leave' } } , { 'status.code.description' : { equal : 'active' } } ]
39
- } ] }
40
- ] ,
41
- } ,
42
- event : DISPLAY_MESSAGE_NESTED_SIMPLE
43
- } ] ;
59
+ let rulesNestedSimple = [
60
+ {
61
+ conditions : {
62
+ and : [
63
+ { accountId : { is : "Lincoln" } } ,
64
+ {
65
+ and : [
66
+ { company : { is : "microsoft" } } ,
67
+ {
68
+ or : [
69
+ { "status.code.description" : { equal : "paid-leave" } } ,
70
+ { "status.code.description" : { equal : "active" } } ,
71
+ ] ,
72
+ } ,
73
+ ] ,
74
+ } ,
75
+ ] ,
76
+ } ,
77
+ event : DISPLAY_MESSAGE_NESTED_SIMPLE ,
78
+ } ,
79
+ ] ;
44
80
45
81
test ( "check simple nested json work" , function ( ) {
46
- let factsNestedSimple = { accountId : 'Lincoln' , company : 'microsoft' , status : { code : { 'description' : 'paid-leave' } } , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
47
- expect ( applicableActions ( rulesNestedSimple , factsNestedSimple ) ) . toEqual ( [ DISPLAY_MESSAGE_NESTED_SIMPLE ] ) ;
48
- factsNestedSimple = { accountId : 'Lincoln' , company : 'microsoft' , status : { code : { 'description' : 'active' } } , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
49
- expect ( applicableActions ( rulesNestedSimple , factsNestedSimple ) ) . toEqual ( [ DISPLAY_MESSAGE_NESTED_SIMPLE ] ) ;
50
- factsNestedSimple = { accountId : 'Lincoln' , company : 'microsoft' , status : { code : { 'description' : 'off' } } , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
82
+ let factsNestedSimple = {
83
+ accountId : "Lincoln" ,
84
+ company : "microsoft" ,
85
+ status : { code : { description : "paid-leave" } } ,
86
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
87
+ } ;
88
+ expect ( applicableActions ( rulesNestedSimple , factsNestedSimple ) ) . toEqual ( [
89
+ DISPLAY_MESSAGE_NESTED_SIMPLE ,
90
+ ] ) ;
91
+ factsNestedSimple = {
92
+ accountId : "Lincoln" ,
93
+ company : "microsoft" ,
94
+ status : { code : { description : "active" } } ,
95
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
96
+ } ;
97
+ expect ( applicableActions ( rulesNestedSimple , factsNestedSimple ) ) . toEqual ( [
98
+ DISPLAY_MESSAGE_NESTED_SIMPLE ,
99
+ ] ) ;
100
+ factsNestedSimple = {
101
+ accountId : "Lincoln" ,
102
+ company : "microsoft" ,
103
+ status : { code : { description : "off" } } ,
104
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
105
+ } ;
51
106
expect ( applicableActions ( rulesNestedSimple , factsNestedSimple ) ) . toEqual ( [ ] ) ;
52
107
} ) ;
53
108
54
109
const DISPLAY_MESSAGE_NESTED_ARRAY = {
55
110
type : "message" ,
56
- params : { validationMessage : "Get the employees working in microsoft and status in active or paid-leave" } ,
111
+ params : {
112
+ validationMessage :
113
+ "Get the employees working in microsoft and status in active or paid-leave" ,
114
+ } ,
57
115
} ;
58
116
59
- let rulesNestedArray = [
60
- {
61
- conditions : {
62
- and : [
63
- { accountId : { is : 'Lincoln' } } ,
64
- { and : [
65
- { company : { is : 'microsoft' } } ,
66
- {
67
- status :
68
- {
69
- or : [ { 'code' : { equal : 'paid-leave' } } , { 'code' : { equal : 'active' } } ]
70
- }
71
- }
72
- ]
73
- }
74
- ] ,
75
- } ,
76
- event : DISPLAY_MESSAGE_NESTED_ARRAY
77
- } ] ;
117
+ let rulesNestedArray = [
118
+ {
119
+ conditions : {
120
+ and : [
121
+ { accountId : { is : "Lincoln" } } ,
122
+ {
123
+ and : [
124
+ { company : { is : "microsoft" } } ,
125
+ {
126
+ status : {
127
+ or : [
128
+ { code : { equal : "paid-leave" } } ,
129
+ { code : { equal : "active" } } ,
130
+ ] ,
131
+ } ,
132
+ } ,
133
+ ] ,
134
+ } ,
135
+ ] ,
136
+ } ,
137
+ event : DISPLAY_MESSAGE_NESTED_ARRAY ,
138
+ } ,
139
+ ] ;
78
140
79
141
test ( "check simple nested array work" , function ( ) {
80
- let factsNestedArray = { accountId : 'Lincoln' , company : 'microsoft' , status : [ { code : 'paid-leave' } , { code : 'active' } ] , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
81
- expect ( applicableActions ( rulesNestedArray , factsNestedArray ) ) . toEqual ( [ DISPLAY_MESSAGE_NESTED_ARRAY ] ) ;
82
- factsNestedArray = { accountId : 'Jeferryson' , company : 'microsoft' , status : [ { code : 'paid-leave' } , { code : 'active' } ] , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] }
142
+ let factsNestedArray = {
143
+ accountId : "Lincoln" ,
144
+ company : "microsoft" ,
145
+ status : [ { code : "paid-leave" } , { code : "active" } ] ,
146
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
147
+ } ;
148
+ expect ( applicableActions ( rulesNestedArray , factsNestedArray ) ) . toEqual ( [
149
+ DISPLAY_MESSAGE_NESTED_ARRAY ,
150
+ ] ) ;
151
+ factsNestedArray = {
152
+ accountId : "Jeferryson" ,
153
+ company : "microsoft" ,
154
+ status : [ { code : "paid-leave" } , { code : "active" } ] ,
155
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
156
+ } ;
83
157
expect ( applicableActions ( rulesNestedArray , factsNestedArray ) ) . toEqual ( [ ] ) ;
84
158
} ) ;
85
159
86
160
const DISPLAY_MESSAGE_COMPLEX_NESTED_ARRAY = {
87
161
type : "message" ,
88
- params : { validationMessage : "Get the employees working in microsoft and status in active or paid-leave" } ,
162
+ params : {
163
+ validationMessage :
164
+ "Get the employees working in microsoft and status in active or paid-leave" ,
165
+ } ,
89
166
} ;
90
167
91
- let rulesComplexNestedArray = [
92
- {
93
- conditions : {
94
- Accounts : {
95
- and : [
96
- { accountId : { is : 'Lincoln' } } ,
97
- { and : [ { company : { is : 'microsoft' } } ,
98
- {
99
- status :
100
- {
101
- code : {
102
- or : [ { 'description' : { equal : 'paid-leave' } } , { 'description' : { equal : 'active' } } ]
103
- }
104
- }
105
- }
106
- ]
107
- }
108
- ] ,
109
- }
110
- } ,
111
- event : DISPLAY_MESSAGE_COMPLEX_NESTED_ARRAY
112
- } ] ;
168
+ let rulesComplexNestedArray = [
169
+ {
170
+ conditions : {
171
+ Accounts : {
172
+ and : [
173
+ { accountId : { is : "Lincoln" } } ,
174
+ {
175
+ and : [
176
+ { company : { is : "microsoft" } } ,
177
+ {
178
+ status : {
179
+ code : {
180
+ or : [
181
+ { description : { equal : "paid-leave" } } ,
182
+ { description : { equal : "active" } } ,
183
+ ] ,
184
+ } ,
185
+ } ,
186
+ } ,
187
+ ] ,
188
+ } ,
189
+ ] ,
190
+ } ,
191
+ } ,
192
+ event : DISPLAY_MESSAGE_COMPLEX_NESTED_ARRAY ,
193
+ } ,
194
+ ] ;
113
195
114
196
test ( "check nested complex array work" , function ( ) {
115
- let factsArrayComplexNestedArray = {
116
- Accounts :
117
- [ { accountId : 'Jefferson' , company : 'microsoft' , status : [ { code : [ { description : 'paid-leave' } , { description : 'half-day' } ] } , { code : [ { description : 'full-day' } , { description : 'Lop' } ] } ] , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] } ,
118
- { accountId : 'Lincoln' , company : 'microsoft' , status : [ { code : [ { description : 'paid-leave' } , { description : 'full-day' } ] } , { code : [ { description : 'Lop' } , { description : 'active' } ] } ] , ptoDaysTaken : [ '2016-12-25' , '2016-12-21' ] } ]
119
- }
120
- expect ( applicableActions ( rulesComplexNestedArray , factsArrayComplexNestedArray ) ) . toEqual ( [ DISPLAY_MESSAGE_COMPLEX_NESTED_ARRAY ] ) ;
121
-
122
- factsArrayComplexNestedArray = {
123
- Accounts :
124
- [ { accountId : 'Dunken' , company : 'microsoft' , status : [ { code : [ { description : 'paid-leave' } , { description : 'half-day' } ] } , { code : [ { description : 'full-day' } , { description : 'Lop' } ] } ] , ptoDaysTaken : [ '2016-12-25' , '2016-12-28' ] } ,
125
- { accountId : 'Steve' , company : 'microsoft' , status : [ { code : [ { description : 'paid-leave' } , { description : 'full-day' } ] } , { code : [ { description : 'Lop' } , { description : 'Sick Leave' } ] } ] , ptoDaysTaken : [ '2016-12-25' , '2016-12-21' ] } ]
126
- }
127
- expect ( applicableActions ( rulesComplexNestedArray , factsArrayComplexNestedArray ) ) . toEqual ( [ ] ) ;
197
+ let factsArrayComplexNestedArray = {
198
+ Accounts : [
199
+ {
200
+ accountId : "Jefferson" ,
201
+ company : "microsoft" ,
202
+ status : [
203
+ {
204
+ code : [ { description : "paid-leave" } , { description : "half-day" } ] ,
205
+ } ,
206
+ { code : [ { description : "full-day" } , { description : "Lop" } ] } ,
207
+ ] ,
208
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
209
+ } ,
210
+ {
211
+ accountId : "Lincoln" ,
212
+ company : "microsoft" ,
213
+ status : [
214
+ {
215
+ code : [ { description : "paid-leave" } , { description : "full-day" } ] ,
216
+ } ,
217
+ { code : [ { description : "Lop" } , { description : "active" } ] } ,
218
+ ] ,
219
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-21" ] ,
220
+ } ,
221
+ ] ,
222
+ } ;
223
+ expect (
224
+ applicableActions ( rulesComplexNestedArray , factsArrayComplexNestedArray )
225
+ ) . toEqual ( [ DISPLAY_MESSAGE_COMPLEX_NESTED_ARRAY ] ) ;
226
+
227
+ factsArrayComplexNestedArray = {
228
+ Accounts : [
229
+ {
230
+ accountId : "Dunken" ,
231
+ company : "microsoft" ,
232
+ status : [
233
+ {
234
+ code : [ { description : "paid-leave" } , { description : "half-day" } ] ,
235
+ } ,
236
+ { code : [ { description : "full-day" } , { description : "Lop" } ] } ,
237
+ ] ,
238
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-28" ] ,
239
+ } ,
240
+ {
241
+ accountId : "Steve" ,
242
+ company : "microsoft" ,
243
+ status : [
244
+ {
245
+ code : [ { description : "paid-leave" } , { description : "full-day" } ] ,
246
+ } ,
247
+ { code : [ { description : "Lop" } , { description : "Sick Leave" } ] } ,
248
+ ] ,
249
+ ptoDaysTaken : [ "2016-12-25" , "2016-12-21" ] ,
250
+ } ,
251
+ ] ,
252
+ } ;
253
+ expect (
254
+ applicableActions ( rulesComplexNestedArray , factsArrayComplexNestedArray )
255
+ ) . toEqual ( [ ] ) ;
128
256
} ) ;
0 commit comments