@izara_project/izara-testing-shared 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -4
- package/package.json +2 -1
- package/src/TestingLib.js +302 -151
package/index.js
CHANGED
|
@@ -17,8 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
import testingLib from './src/TestingLib.js';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
testingLib: testingLib
|
|
24
|
-
};
|
|
22
|
+
export default { testingLib };
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-testing-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Libraries shared by both local and deployed test environments",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest"
|
|
8
8
|
},
|
|
9
|
+
"type": "module",
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
11
12
|
"url": "git+ssh://git@bitbucket.org/izara-core-testing/izara-core-testing-library-shared.git"
|
package/src/TestingLib.js
CHANGED
|
@@ -17,9 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
|
|
18
18
|
'use strict';
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
import isEqual from 'lodash.isequal';
|
|
21
21
|
const MAX_RECURSION_LEVEL = 20;
|
|
22
|
-
|
|
22
|
+
// import correlationIds from '@izara_project/izara-core-library-correlation-ids';
|
|
23
|
+
// import logger from "@izara_project/izara-core-library-logger"
|
|
24
|
+
// import integrationTestDetail from "@izara_project/izara-core-library-integration-tests"
|
|
25
|
+
// import resourceUse from "@izara_project/izara-core-library-resource-use";
|
|
26
|
+
// let _izContext = {
|
|
27
|
+
// correlationIds: correlationIds,
|
|
28
|
+
// logger: logger,
|
|
29
|
+
// integrationTestDetail: integrationTestDetail,
|
|
30
|
+
// resourceUse: resourceUse
|
|
31
|
+
// }
|
|
23
32
|
/**
|
|
24
33
|
* @param {object} _izContext - The CorrelationId and Logger instances
|
|
25
34
|
* @param {object} testEventConfigOneLevel - Event config for tesing
|
|
@@ -30,19 +39,19 @@ const MAX_RECURSION_LEVEL = 20;
|
|
|
30
39
|
*
|
|
31
40
|
* @returns {object[]} propertyNotPass - Array of properties that failed testing
|
|
32
41
|
*/
|
|
33
|
-
|
|
42
|
+
function checkOutputEventOneLevel(
|
|
34
43
|
_izContext,
|
|
35
44
|
testEventConfigOneLevel,
|
|
36
45
|
eventForTestingOneLevel,
|
|
37
46
|
level,
|
|
38
47
|
notPassPrefix,
|
|
39
48
|
propertyNotPass = []
|
|
40
|
-
)
|
|
49
|
+
) {
|
|
41
50
|
_izContext.logger.debug("Lib checkOutputEventOneLevel:", {
|
|
42
|
-
testEventConfigOneLevel,
|
|
43
|
-
eventForTestingOneLevel,
|
|
44
|
-
level,
|
|
45
|
-
notPassPrefix,
|
|
51
|
+
// testEventConfigOneLevel,
|
|
52
|
+
// eventForTestingOneLevel,
|
|
53
|
+
// level,
|
|
54
|
+
// notPassPrefix,
|
|
46
55
|
propertyNotPass
|
|
47
56
|
});
|
|
48
57
|
|
|
@@ -53,158 +62,208 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
53
62
|
};
|
|
54
63
|
//check response/outputEvent // recusive level 2 cannot find eventValue or eventParams
|
|
55
64
|
|
|
56
|
-
if (!testEventConfigOneLevel.hasOwnProperty('eventValue')
|
|
65
|
+
if (!testEventConfigOneLevel.hasOwnProperty('eventValue')
|
|
66
|
+
&& !testEventConfigOneLevel.hasOwnProperty('properties')
|
|
67
|
+
&& !testEventConfigOneLevel.hasOwnProperty('value')) {
|
|
57
68
|
throw new Error(`outputEvent not have eventValue and properties and value.`)
|
|
58
69
|
};
|
|
59
70
|
|
|
60
71
|
if (testEventConfigOneLevel.hasOwnProperty('eventValue')) {
|
|
61
72
|
_izContext.logger.debug('Case eventValue');
|
|
62
|
-
if (!testEventConfigOneLevel.hasOwnProperty('testValueMatches')
|
|
63
|
-
|
|
64
|
-
if (eventForTestingOneLevel !== testEventConfigOneLevel.eventValue) { // true not equal "true"
|
|
65
|
-
// propertyNotPass.push(notPassPrefix + JSON.stringify(testEventConfigOneLevel.eventValue))
|
|
66
|
-
propertyNotPass.push({
|
|
67
|
-
prefix: notPassPrefix,
|
|
68
|
-
expectedValue: testEventConfigOneLevel.eventValue,
|
|
69
|
-
receivedValue: eventForTestingOneLevel,
|
|
70
|
-
// propertyName: propertyName,
|
|
71
|
-
// propertyConfig: propertyConfig
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
_izContext.logger.debug('config has useIsEqual'); // for array/stringset
|
|
76
|
-
|
|
77
|
-
if (testEventConfigOneLevel.hasOwnProperty('isStringSet') && testEventConfigOneLevel.isStringSet == true) {
|
|
78
|
-
eventForTestingOneLevel = eventForTestingOneLevel.values
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
_izContext.logger.debug('eventForTestingOneLevel', eventForTestingOneLevel);
|
|
82
|
-
_izContext.logger.debug('testEventConfigOneLevel.eventValue', testEventConfigOneLevel.eventValue);
|
|
73
|
+
if (!testEventConfigOneLevel.hasOwnProperty('testValueMatches')
|
|
74
|
+
|| testEventConfigOneLevel.testValueMatches !== false) {
|
|
83
75
|
|
|
76
|
+
if (testEventConfigOneLevel.hasOwnProperty('useIsEqual')
|
|
77
|
+
&& testEventConfigOneLevel.useIsEqual === true) {
|
|
84
78
|
if (isEqual(eventForTestingOneLevel, testEventConfigOneLevel.eventValue) == false) {
|
|
85
79
|
_izContext.logger.debug('test isEqual failed');
|
|
86
80
|
propertyNotPass.push({
|
|
87
81
|
prefix: notPassPrefix,
|
|
88
82
|
expectedValue: testEventConfigOneLevel.eventValue,
|
|
89
|
-
receivedValue: eventForTestingOneLevel
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
83
|
+
receivedValue: eventForTestingOneLevel
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
};
|
|
95
87
|
} else {
|
|
96
88
|
// continue to next property if property(ex.requestParams) has set testValueMatches: false.
|
|
97
89
|
_izContext.logger.debug(`eventValue set to not test (testValueMatches is false).`);
|
|
98
90
|
return
|
|
99
91
|
}
|
|
100
92
|
|
|
101
|
-
} else if (testEventConfigOneLevel.hasOwnProperty('properties')
|
|
93
|
+
} else if (testEventConfigOneLevel.hasOwnProperty('properties')
|
|
94
|
+
&& typeof testEventConfigOneLevel === 'object') {
|
|
102
95
|
_izContext.logger.debug("Case: properties", {
|
|
103
96
|
"testEventConfigOneLevel.properties": testEventConfigOneLevel.properties,
|
|
104
97
|
"eventForTestingOneLevel": eventForTestingOneLevel
|
|
105
98
|
});
|
|
106
99
|
|
|
107
100
|
for (const [propertyName, propertyConfig] of Object.entries(testEventConfigOneLevel.properties)) {
|
|
108
|
-
_izContext.logger.debug('
|
|
109
|
-
_izContext.logger.debug('
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
eventForTestingOneLevel[propertyName]
|
|
120
|
-
|
|
101
|
+
_izContext.logger.debug('Loop testEventConfigOneLevel:', { propertyName, propertyConfig });
|
|
102
|
+
_izContext.logger.debug('find propertyName in eventForTestingOneLevel', eventForTestingOneLevel[propertyName]);
|
|
103
|
+
|
|
104
|
+
// 0 , false, == falsy
|
|
105
|
+
if (eventForTestingOneLevel[propertyName]
|
|
106
|
+
|| (typeof eventForTestingOneLevel[propertyName] == 'number' && eventForTestingOneLevel[propertyName] == 0)
|
|
107
|
+
|| (typeof eventForTestingOneLevel[propertyName] == 'boolean' && eventForTestingOneLevel[propertyName] == false)
|
|
108
|
+
|
|
109
|
+
)
|
|
110
|
+
if (eventForTestingOneLevel.hasOwnProperty(propertyName)) {
|
|
111
|
+
if (eventForTestingOneLevel[propertyName]
|
|
112
|
+
|| (typeof eventForTestingOneLevel[propertyName] == "boolean" || (typeof eventForTestingOneLevel[propertyName] == "number") || (typeof eventForTestingOneLevel[propertyName] == "undefined"))
|
|
113
|
+
) {
|
|
114
|
+
// validate testValueMatches
|
|
115
|
+
// continue to test property if set testValueMatches to false
|
|
116
|
+
if ((!propertyConfig.hasOwnProperty('testValueMatches')
|
|
117
|
+
|| propertyConfig.testValueMatches !== false)
|
|
118
|
+
|| (propertyConfig.hasOwnProperty('forStageMatching')
|
|
119
|
+
&& propertyConfig.forStageMatching === true)) {
|
|
120
|
+
|
|
121
|
+
_izContext.logger.debug("case forStageMatching is true", propertyConfig);
|
|
122
|
+
if (propertyConfig.stringified) {
|
|
123
|
+
_izContext.logger.debug('stringified::::', propertyConfig.stringified);
|
|
124
|
+
eventForTestingOneLevel[propertyName] = JSON.parse(eventForTestingOneLevel[propertyName]);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//== check config matching to massege.
|
|
128
|
+
if (!eventForTestingOneLevel.hasOwnProperty(propertyName)) {
|
|
129
|
+
_izContext.logger.debug("eventForTestingOneLevel not have propertyName:", propertyName);
|
|
130
|
+
|
|
131
|
+
// propertyNotPass.push(notPassPrefix + `${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
132
|
+
propertyNotPass.push({
|
|
133
|
+
prefix: notPassPrefix,
|
|
134
|
+
expectedValue: `(NO propertyName SET IN CONFIG)`,
|
|
135
|
+
receivedValue: eventForTestingOneLevel[propertyName],
|
|
136
|
+
propertyName: propertyName,
|
|
137
|
+
propertyConfig: propertyConfig
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
else if (propertyConfig.eventValue) {
|
|
141
|
+
_izContext.logger.debug('eventValue::::', propertyConfig.eventValue);
|
|
142
|
+
//calling recursive function again.
|
|
143
|
+
this.checkOutputEventOneLevel(
|
|
144
|
+
_izContext,
|
|
145
|
+
propertyConfig,
|
|
146
|
+
eventForTestingOneLevel[propertyName],
|
|
147
|
+
level + 1,
|
|
148
|
+
notPassPrefix,
|
|
149
|
+
propertyNotPass
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
else if (propertyConfig.properties) {
|
|
153
|
+
_izContext.logger.debug("properties::::", propertyConfig.properties);
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
(typeof (propertyConfig.properties.value) == 'object'
|
|
157
|
+
&& (Object.keys(propertyConfig.properties.value).length === 0))
|
|
158
|
+
&& (typeof (eventForTestingOneLevel[propertyName]) == 'object'
|
|
159
|
+
&& Object.keys(eventForTestingOneLevel[propertyName]).length === 0)
|
|
160
|
+
) {
|
|
161
|
+
// match empty object
|
|
162
|
+
_izContext.logger.debug("match empty object", propertyConfig.properties.value, eventForTestingOneLevel[propertyName])
|
|
163
|
+
} else {
|
|
164
|
+
//calling recursive function again.
|
|
165
|
+
this.checkOutputEventOneLevel(
|
|
166
|
+
_izContext,
|
|
167
|
+
propertyConfig,
|
|
168
|
+
eventForTestingOneLevel[propertyName],
|
|
169
|
+
level + 1,
|
|
170
|
+
notPassPrefix,
|
|
171
|
+
propertyNotPass
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
};
|
|
175
|
+
} else {
|
|
176
|
+
// if config not have value the test is not valid, test fails and note in the result
|
|
177
|
+
if (propertyConfig.hasOwnProperty("value")) {
|
|
178
|
+
// console.log("am value");
|
|
179
|
+
if (isObject(eventForTestingOneLevel[propertyName]) && isObject(propertyConfig.value)) {
|
|
180
|
+
_izContext.logger.debug("check Object")
|
|
181
|
+
if (Object.keys(eventForTestingOneLevel[propertyName]).length > 0 && Object.keys(propertyConfig.value).length > 0) {
|
|
182
|
+
// console.log("invalid object should be set propertise inside for recuresive value in object");
|
|
183
|
+
propertyNotPass.push({
|
|
184
|
+
prefix: notPassPrefix,
|
|
185
|
+
expectedValue: `invalid check object much be set 'propertise' inside for recuresive value in object(${propertyConfig.value})`,
|
|
186
|
+
receivedValue: eventForTestingOneLevel[propertyName],
|
|
187
|
+
propertyName: propertyName,
|
|
188
|
+
propertyConfig: propertyConfig
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
} else {
|
|
192
|
+
_izContext.logger.debug("object is empty");
|
|
193
|
+
};
|
|
194
|
+
} else {
|
|
195
|
+
if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
|
|
196
|
+
_izContext.logger.debug("miss match v",
|
|
197
|
+
{
|
|
198
|
+
eventForTestingOneLevel: eventForTestingOneLevel,
|
|
199
|
+
event: eventForTestingOneLevel[propertyName].value,
|
|
200
|
+
config: propertyConfig.value
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
propertyNotPass.push({
|
|
205
|
+
prefix: notPassPrefix,
|
|
206
|
+
expectedValue: propertyConfig.value,
|
|
207
|
+
receivedValue: eventForTestingOneLevel[propertyName],
|
|
208
|
+
propertyName: propertyName,
|
|
209
|
+
propertyConfig: propertyConfig
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} else if (propertyConfig.hasOwnProperty("Value")) {
|
|
214
|
+
// console.log("am Value");
|
|
215
|
+
if (eventForTestingOneLevel[propertyName].hasOwnProperty("Type")
|
|
216
|
+
&& eventForTestingOneLevel[propertyName].hasOwnProperty("Value")) {
|
|
217
|
+
|
|
218
|
+
if (eventForTestingOneLevel[propertyName].Value !== propertyConfig.Value) {
|
|
219
|
+
_izContext.logger.debug("miss match VV", {
|
|
220
|
+
event: eventForTestingOneLevel[propertyName].Value,
|
|
221
|
+
config: propertyConfig.Value
|
|
222
|
+
});
|
|
223
|
+
_izContext.logger.debug("Message attribute is miss match!");
|
|
224
|
+
propertyNotPass.push({
|
|
225
|
+
prefix: notPassPrefix,
|
|
226
|
+
expectedValue: propertyConfig.Value,
|
|
227
|
+
receivedValue: eventForTestingOneLevel[propertyName],
|
|
228
|
+
propertyName: propertyName,
|
|
229
|
+
propertyConfig: propertyConfig
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
};
|
|
234
|
+
} else {
|
|
235
|
+
_izContext.logger.debug("NO 'VALUE' SET IN CONFIG", { notPassPrefix, propertyConfig })
|
|
236
|
+
propertyNotPass.push({
|
|
237
|
+
prefix: notPassPrefix,
|
|
238
|
+
expectedValue: "(NO 'VALUE' SET IN CONFIG)",
|
|
239
|
+
receivedValue: eventForTestingOneLevel[propertyName],
|
|
240
|
+
propertyName: propertyName,
|
|
241
|
+
propertyConfig: propertyConfig
|
|
242
|
+
})
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
_izContext.logger.debug(`propertyName: ${propertyName} not test testValueMatches.`);
|
|
247
|
+
continue
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
121
250
|
|
|
122
|
-
|
|
123
|
-
if (!eventForTestingOneLevel.hasOwnProperty(propertyName)) {
|
|
124
|
-
// propertyNotPass.push(notPassPrefix + `${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
251
|
+
// // mismatch eventForTestingOneLevel
|
|
125
252
|
propertyNotPass.push({
|
|
126
253
|
prefix: notPassPrefix,
|
|
127
|
-
|
|
128
|
-
receivedValue: eventForTestingOneLevel
|
|
129
|
-
|
|
130
|
-
propertyConfig: propertyConfig
|
|
254
|
+
error: `message event is not mach test config`,
|
|
255
|
+
receivedValue: eventForTestingOneLevel,
|
|
256
|
+
expectedValue: testEventConfigOneLevel
|
|
131
257
|
})
|
|
132
|
-
}
|
|
133
|
-
else if (propertyConfig.eventValue) {
|
|
134
|
-
_izContext.logger.debug('propertyConfig.eventValue', propertyConfig.eventValue);
|
|
135
|
-
//calling recursive function again.
|
|
136
|
-
this.checkOutputEventOneLevel(
|
|
137
|
-
_izContext,
|
|
138
|
-
propertyConfig,
|
|
139
|
-
eventForTestingOneLevel[propertyName],
|
|
140
|
-
level + 1,
|
|
141
|
-
notPassPrefix,
|
|
142
|
-
propertyNotPass
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
else if (propertyConfig.properties) {
|
|
146
|
-
_izContext.logger.debug("[checkOutputEventOneLevel]propertyConfig.properties", propertyConfig.properties);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (
|
|
150
|
-
(typeof (propertyConfig.properties.value) == 'object'
|
|
151
|
-
&& (Object.keys(propertyConfig.properties.value).length === 0))
|
|
152
|
-
&& (typeof (eventForTestingOneLevel[propertyName]) == 'object'
|
|
153
|
-
&& Object.keys(eventForTestingOneLevel[propertyName]).length === 0)
|
|
154
|
-
) {
|
|
155
|
-
// match empty object
|
|
156
|
-
_izContext.logger.debug("match empty object", propertyConfig.properties.value, eventForTestingOneLevel[propertyName])
|
|
157
|
-
} else {
|
|
158
|
-
//calling recursive function again.
|
|
159
|
-
this.checkOutputEventOneLevel(
|
|
160
|
-
_izContext,
|
|
161
|
-
propertyConfig,
|
|
162
|
-
eventForTestingOneLevel[propertyName],
|
|
163
|
-
level + 1,
|
|
164
|
-
notPassPrefix,
|
|
165
|
-
propertyNotPass
|
|
166
|
-
)
|
|
167
258
|
|
|
168
|
-
|
|
169
|
-
} else {
|
|
170
|
-
// if config not have value the test is not valid, test fails and note in the result
|
|
171
|
-
if (!propertyConfig.hasOwnProperty('value')) {
|
|
172
|
-
propertyNotPass.push({
|
|
173
|
-
prefix: notPassPrefix,
|
|
174
|
-
expectedValue: "(NO VALUE SET IN CONFIG)",
|
|
175
|
-
receivedValue: eventForTestingOneLevel[propertyName],
|
|
176
|
-
propertyName: propertyName,
|
|
177
|
-
propertyConfig: propertyConfig
|
|
178
|
-
})
|
|
179
|
-
// propertyNotPass.push(notPassPrefix + `(NO VALUE SET IN CONFIG) ${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
180
|
-
}
|
|
181
|
-
// do the standard test
|
|
182
|
-
|
|
183
|
-
if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
|
|
184
|
-
_izContext.logger.debug("mismatch value::", {
|
|
185
|
-
expectedValue: propertyConfig.value,
|
|
186
|
-
receivedValue: eventForTestingOneLevel[propertyName]
|
|
187
|
-
});
|
|
188
|
-
// propertyNotPass.push(notPassPrefix + `${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
189
|
-
propertyNotPass.push({
|
|
190
|
-
prefix: notPassPrefix,
|
|
191
|
-
expectedValue: propertyConfig.value,
|
|
192
|
-
receivedValue: eventForTestingOneLevel[propertyName],
|
|
193
|
-
propertyName: propertyName,
|
|
194
|
-
propertyConfig: propertyConfig
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
// continue to next property if property(ex.requestParams) has set testValueMatches: false.
|
|
200
|
-
// _izContext.logger.debug(`propertyName: ${propertyName} set to not test (testValueMatches is false).`);
|
|
201
|
-
_izContext.logger.debug(`propertyName: ${propertyName} not test testValueMatches.`);
|
|
202
|
-
continue
|
|
259
|
+
};
|
|
203
260
|
}
|
|
204
|
-
};
|
|
205
261
|
|
|
206
262
|
}// end for loop check test
|
|
207
263
|
}
|
|
264
|
+
if (propertyNotPass.length == 0) {
|
|
265
|
+
_izContext.logger.debug("event is matching all is passed!")
|
|
266
|
+
}
|
|
208
267
|
return propertyNotPass
|
|
209
268
|
} catch (err) {
|
|
210
269
|
console.error('error in recursion checkOutputEventOneLevel: ', err);
|
|
@@ -222,12 +281,12 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
222
281
|
*
|
|
223
282
|
* @returns {boolean} true/false - Returning true if matching
|
|
224
283
|
*/
|
|
225
|
-
|
|
284
|
+
function matchingEventOneLevel(
|
|
226
285
|
_izContext,
|
|
227
286
|
testEventConfigOneLevel,
|
|
228
287
|
eventForTestingOneLevel,
|
|
229
288
|
level
|
|
230
|
-
)
|
|
289
|
+
) {
|
|
231
290
|
_izContext.logger.debug("Lib matchingEventOneLevel:", {
|
|
232
291
|
testEventConfigOneLevel,
|
|
233
292
|
eventForTestingOneLevel,
|
|
@@ -245,24 +304,21 @@ module.exports.matchingEventOneLevel = (
|
|
|
245
304
|
}
|
|
246
305
|
|
|
247
306
|
if (testEventConfigOneLevel.hasOwnProperty('eventValue')) {
|
|
248
|
-
_izContext.logger.debug('case eventValue');
|
|
249
307
|
if (testEventConfigOneLevel.hasOwnProperty('forStageMatching') && testEventConfigOneLevel.forStageMatching === true) {
|
|
250
|
-
if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual ===
|
|
251
|
-
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
} else { // use isEqual by default is true
|
|
255
|
-
_izContext.logger.debug('config has useIsEqual(default is true)');
|
|
308
|
+
if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === true) {
|
|
309
|
+
_izContext.logger.debug("Check array")// index in array is isEqual.
|
|
256
310
|
if (isEqual(eventForTestingOneLevel, testEventConfigOneLevel.eventValue) == false) {
|
|
257
|
-
_izContext.logger.debug('test isEqual failed');
|
|
311
|
+
_izContext.logger.debug('test array isEqual failed');
|
|
258
312
|
return false;
|
|
313
|
+
} else {
|
|
314
|
+
_izContext.logger.debug('test array isEqual true');
|
|
315
|
+
|
|
259
316
|
}
|
|
260
317
|
}
|
|
261
318
|
} else {
|
|
262
319
|
// continue to next property if property(ex.requestParams) has set forStageMatching: false.
|
|
263
|
-
_izContext.logger.debug(`forStageMatching set not
|
|
320
|
+
_izContext.logger.debug(`forStageMatching set not mtaching or default is false.`);
|
|
264
321
|
}
|
|
265
|
-
|
|
266
322
|
} else { // check if have properties
|
|
267
323
|
|
|
268
324
|
// check testEventConfigOneLevel is eventParams object output.
|
|
@@ -280,14 +336,15 @@ module.exports.matchingEventOneLevel = (
|
|
|
280
336
|
}
|
|
281
337
|
|
|
282
338
|
for (const [propertyName, propertyConfig] of Object.entries(testEventConfigOneLevel.properties)) {
|
|
283
|
-
_izContext.logger.debug("[
|
|
339
|
+
_izContext.logger.debug("[matching]Iterate testEventConfigOneLevel.properties:", { propertyName, propertyConfig });
|
|
284
340
|
_izContext.logger.debug('eventForTestingOneLevel[propertyName]', eventForTestingOneLevel[propertyName])
|
|
285
341
|
|
|
286
342
|
// continue to test property if set forStageMatching to false
|
|
287
343
|
if (propertyConfig.hasOwnProperty('forStageMatching') && propertyConfig.forStageMatching === true) {
|
|
288
|
-
|
|
344
|
+
|
|
345
|
+
_izContext.logger.debug("[matching] forStageMatching is true compare value", {
|
|
289
346
|
"eventForTestingOneLevel[propertyName]": eventForTestingOneLevel[propertyName],
|
|
290
|
-
propertyConfig
|
|
347
|
+
propertyConfig: propertyConfig
|
|
291
348
|
});
|
|
292
349
|
|
|
293
350
|
if (propertyConfig.stringified) {
|
|
@@ -306,7 +363,11 @@ module.exports.matchingEventOneLevel = (
|
|
|
306
363
|
_izContext.logger.debug('propertyConfig.eventValue', propertyConfig.eventValue);
|
|
307
364
|
//calling recursive function again.
|
|
308
365
|
// let checkMatched = checkOutputEventOneLevel(propertyConfig, eventForTestingOneLevel[propertyName], level + 1)
|
|
309
|
-
let checkMatched =
|
|
366
|
+
let checkMatched = matchingEventOneLevel(
|
|
367
|
+
_izContext,
|
|
368
|
+
propertyConfig,
|
|
369
|
+
eventForTestingOneLevel[propertyName],
|
|
370
|
+
level + 1)
|
|
310
371
|
if (checkMatched == false) {
|
|
311
372
|
return false;
|
|
312
373
|
}
|
|
@@ -314,15 +375,57 @@ module.exports.matchingEventOneLevel = (
|
|
|
314
375
|
else if (propertyConfig.hasOwnProperty("properties")) {
|
|
315
376
|
_izContext.logger.debug("[matchingEventOneLevel]propertyConfig.properties");
|
|
316
377
|
|
|
317
|
-
let checkMatched =
|
|
378
|
+
let checkMatched = matchingEventOneLevel(
|
|
379
|
+
_izContext,
|
|
380
|
+
propertyConfig,
|
|
381
|
+
eventForTestingOneLevel[propertyName],
|
|
382
|
+
level + 1
|
|
383
|
+
)
|
|
318
384
|
if (checkMatched == false) {
|
|
319
385
|
return false;
|
|
320
|
-
}
|
|
321
|
-
} else if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
|
|
322
|
-
console.log("misMatch", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
|
|
323
|
-
|
|
324
|
-
return false;
|
|
386
|
+
};
|
|
325
387
|
}
|
|
388
|
+
else { // new ------------------------
|
|
389
|
+
// suport empty Object
|
|
390
|
+
if (isObject(eventForTestingOneLevel[propertyName]) && isObject(propertyConfig.value)) {
|
|
391
|
+
_izContext.logger.debug("check Object")
|
|
392
|
+
if (Object.keys(eventForTestingOneLevel[propertyName]).length > 0 && Object.keys(propertyConfig.value).length > 0) {
|
|
393
|
+
console.log("invalid object should be set propertise inside for recuresive value in object");
|
|
394
|
+
return false
|
|
395
|
+
} else {
|
|
396
|
+
_izContext.logger.debug("0000 is Empty object");
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
// check value
|
|
400
|
+
if (propertyConfig.hasOwnProperty("value")) {
|
|
401
|
+
if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
|
|
402
|
+
_izContext.logger.debug("event is miss match!", { event: eventForTestingOneLevel[propertyName], testConfig: propertyConfig.value });
|
|
403
|
+
return false
|
|
404
|
+
};
|
|
405
|
+
} else if (propertyConfig.hasOwnProperty("Value")) {
|
|
406
|
+
_izContext.logger.debug("check Value of Attribute");
|
|
407
|
+
if (eventForTestingOneLevel[propertyName].hasOwnProperty("Type")
|
|
408
|
+
&& eventForTestingOneLevel[propertyName].hasOwnProperty("Value")) {
|
|
409
|
+
_izContext.logger.debug("messageAttTestConfig:", propertyConfig.Value);
|
|
410
|
+
_izContext.logger.debug("messageAttEvent:", eventForTestingOneLevel[propertyName].Value);
|
|
411
|
+
|
|
412
|
+
if (eventForTestingOneLevel[propertyName].Value !== propertyConfig.Value) {
|
|
413
|
+
_izContext.logger.debug("Message attribute is miss match!", {
|
|
414
|
+
event: eventForTestingOneLevel[propertyName].Value,
|
|
415
|
+
testConfig: propertyConfig.Value
|
|
416
|
+
});
|
|
417
|
+
return false
|
|
418
|
+
} else {
|
|
419
|
+
_izContext.logger.debug("Message attribute is match!");
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
// if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
|
|
424
|
+
// console.log("misMatch data::::", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
|
|
425
|
+
// return false;
|
|
426
|
+
// }
|
|
427
|
+
}
|
|
428
|
+
};
|
|
326
429
|
|
|
327
430
|
} else {
|
|
328
431
|
// continue to next property if property(ex.requestParams) has set forStageMatching: false.
|
|
@@ -333,4 +436,52 @@ module.exports.matchingEventOneLevel = (
|
|
|
333
436
|
}
|
|
334
437
|
}
|
|
335
438
|
return true;
|
|
336
|
-
};
|
|
439
|
+
};
|
|
440
|
+
// matchingEventOneLevel(
|
|
441
|
+
// _izContext,
|
|
442
|
+
// {
|
|
443
|
+
// properties: {
|
|
444
|
+
// callingFlow: {
|
|
445
|
+
// forStageMatching: true,
|
|
446
|
+
// Value: 'maxxCart2TestProcessValidateCart'
|
|
447
|
+
// },
|
|
448
|
+
// 'x-correlation-base-user-id': {
|
|
449
|
+
// forStageMatching: true,
|
|
450
|
+
// Value: 'maxx'
|
|
451
|
+
|
|
452
|
+
// }
|
|
453
|
+
// }
|
|
454
|
+
// },
|
|
455
|
+
// {
|
|
456
|
+
// callingFlow: { Type: 'String', Value: 'maxxCart2TestProcessValidateCart' },
|
|
457
|
+
// 'x-correlation-intTest-time': { Type: 'String', Value: '1766387880112' },
|
|
458
|
+
// 'x-correlation-intTest-serviceTag': { Type: 'String', Value: 'IntTesting' },
|
|
459
|
+
// 'x-correlation-call-chain-length': { Type: 'String', Value: '1' },
|
|
460
|
+
// 'x-correlation-intTest-tag': {
|
|
461
|
+
// Type: 'String',
|
|
462
|
+
// Value: 'validateCart_cartValidationStatus_valid_CaseCombineWinIsTrueAndFalse_ESmodule_003_Complete'
|
|
463
|
+
// },
|
|
464
|
+
// serviceTag: { Type: 'String', Value: 'IntTesting' },
|
|
465
|
+
// 'x-correlation-id': { Type: 'String', Value: 'b0e7188c-32c0-428a-8202-c15642445e63' },
|
|
466
|
+
// 'x-correlation-debug-log-enabled': { Type: 'String', Value: 'false' },
|
|
467
|
+
// 'x-correlation-base-user-id': { Type: 'String', Value: 'maxx' }
|
|
468
|
+
// },
|
|
469
|
+
// 1
|
|
470
|
+
|
|
471
|
+
// )
|
|
472
|
+
|
|
473
|
+
// end recursive function
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
function isObject(object) {
|
|
477
|
+
|
|
478
|
+
if (typeof object === 'object' && !Array.isArray(object)) {
|
|
479
|
+
return true;
|
|
480
|
+
};
|
|
481
|
+
return false
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
export default {
|
|
485
|
+
checkOutputEventOneLevel,
|
|
486
|
+
matchingEventOneLevel
|
|
487
|
+
}
|