Skip to content

Commit fce6748

Browse files
authored
Added the test scenarios for nested array
1 parent ab42f48 commit fce6748

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import applicableActions from "../src/applicableActions";
2+
3+
const DISPLAY_MESSAGE_SIMPLE = {
4+
type: "message",
5+
params: { validationMessage: "Get the employees working in microsoft and status in active or paid-leave" },
6+
};
7+
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+
}];
19+
20+
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'] }
24+
expect(applicableActions(rulesSimple, factsSimple)).toEqual([]);
25+
});
26+
27+
const DISPLAY_MESSAGE_NESTED_SIMPLE = {
28+
type: "message",
29+
params: { validationMessage: "Get the employees working in microsoft and status in active or paid-leave" },
30+
};
31+
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+
}];
44+
45+
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'] }
51+
expect(applicableActions(rulesNestedSimple, factsNestedSimple)).toEqual([]);
52+
});
53+
54+
const DISPLAY_MESSAGE_NESTED_ARRAY = {
55+
type: "message",
56+
params: { validationMessage: "Get the employees working in microsoft and status in active or paid-leave" },
57+
};
58+
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+
}];
78+
79+
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'] }
83+
expect(applicableActions(rulesNestedArray, factsNestedArray)).toEqual([]);
84+
});
85+
86+
const DISPLAY_MESSAGE_COMPLEX_NESTED_ARRAY = {
87+
type: "message",
88+
params: { validationMessage: "Get the employees working in microsoft and status in active or paid-leave" },
89+
};
90+
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+
}];
113+
114+
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([]);
128+
});

0 commit comments

Comments
 (0)