@izara_project/izara-testing-shared 1.0.1 → 1.0.3
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/package.json +2 -2
- package/src/TestingLib.js +122 -63
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-testing-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Libraries shared by both local and deployed test environments",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"lodash.isequal": "^4.5.0"
|
|
24
24
|
}
|
|
25
|
-
}
|
|
25
|
+
}
|
package/src/TestingLib.js
CHANGED
|
@@ -21,9 +21,9 @@ const isEqual = require('lodash.isequal');
|
|
|
21
21
|
const MAX_RECURSION_LEVEL = 20;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @param {object} _izContext - The CorrelationId and Logger instances
|
|
25
|
-
* @param {object} testEventConfigOneLevel - Event config for tesing
|
|
26
|
-
* @param {object} eventForTestingOneLevel - Event response
|
|
24
|
+
* @param {object} _izContext - The CorrelationId and Logger instances
|
|
25
|
+
* @param {object} testEventConfigOneLevel - Event config for tesing
|
|
26
|
+
* @param {object} eventForTestingOneLevel - Event response
|
|
27
27
|
* @param {number} level - The level of loop recursion maximun = 20
|
|
28
28
|
* @param {string} notPassPrefix - The prefix name of testing
|
|
29
29
|
* @param {object[]} propertyNotPass - Array of properties that failed testing and send back to recursion again and again
|
|
@@ -38,20 +38,27 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
38
38
|
notPassPrefix,
|
|
39
39
|
propertyNotPass = []
|
|
40
40
|
) => {
|
|
41
|
+
_izContext.logger.debug("Lib checkOutputEventOneLevel:", {
|
|
42
|
+
testEventConfigOneLevel,
|
|
43
|
+
eventForTestingOneLevel,
|
|
44
|
+
level,
|
|
45
|
+
notPassPrefix,
|
|
46
|
+
propertyNotPass
|
|
47
|
+
});
|
|
48
|
+
|
|
41
49
|
try {
|
|
42
50
|
// stop recursive function if level > MAX_RECURSION_LEVEL
|
|
43
51
|
if (level > MAX_RECURSION_LEVEL) {
|
|
44
52
|
throw new Error(`exceeded maximum recursion level for property checks: ` + MAX_RECURSION_LEVEL)
|
|
45
|
-
}
|
|
46
|
-
//check response/outputEvent // recusive level 2 cannot find eventValue or eventParams
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
53
|
+
};
|
|
54
|
+
//check response/outputEvent // recusive level 2 cannot find eventValue or eventParams
|
|
55
|
+
|
|
56
|
+
if (!testEventConfigOneLevel.hasOwnProperty('eventValue') && !testEventConfigOneLevel.hasOwnProperty('properties') && !testEventConfigOneLevel.hasOwnProperty('value')) {
|
|
57
|
+
throw new Error(`outputEvent not have eventValue and properties and value.`)
|
|
58
|
+
};
|
|
52
59
|
|
|
53
60
|
if (testEventConfigOneLevel.hasOwnProperty('eventValue')) {
|
|
54
|
-
_izContext.logger.debug('
|
|
61
|
+
_izContext.logger.debug('Case eventValue');
|
|
55
62
|
if (!testEventConfigOneLevel.hasOwnProperty('testValueMatches') || testEventConfigOneLevel.testValueMatches != false) {
|
|
56
63
|
if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === false) {
|
|
57
64
|
if (eventForTestingOneLevel != testEventConfigOneLevel.eventValue) { // true not equal "true"
|
|
@@ -65,7 +72,7 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
65
72
|
})
|
|
66
73
|
}
|
|
67
74
|
} else {
|
|
68
|
-
_izContext.logger.debug('config has useIsEqual'); // for array/stringset
|
|
75
|
+
_izContext.logger.debug('config has useIsEqual'); // for array/stringset
|
|
69
76
|
|
|
70
77
|
if (testEventConfigOneLevel.hasOwnProperty('isStringSet') && testEventConfigOneLevel.isStringSet == true) {
|
|
71
78
|
eventForTestingOneLevel = eventForTestingOneLevel.values
|
|
@@ -73,10 +80,9 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
73
80
|
|
|
74
81
|
_izContext.logger.debug('eventForTestingOneLevel', eventForTestingOneLevel);
|
|
75
82
|
_izContext.logger.debug('testEventConfigOneLevel.eventValue', testEventConfigOneLevel.eventValue);
|
|
76
|
-
|
|
83
|
+
|
|
77
84
|
if (isEqual(eventForTestingOneLevel, testEventConfigOneLevel.eventValue) == false) {
|
|
78
85
|
_izContext.logger.debug('test isEqual failed');
|
|
79
|
-
// propertyNotPass.push(notPassPrefix + JSON.stringify(testEventConfigOneLevel.eventValue))
|
|
80
86
|
propertyNotPass.push({
|
|
81
87
|
prefix: notPassPrefix,
|
|
82
88
|
expectedValue: testEventConfigOneLevel.eventValue,
|
|
@@ -89,31 +95,31 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
89
95
|
} else {
|
|
90
96
|
// continue to next property if property(ex.requestParams) has set testValueMatches: false.
|
|
91
97
|
_izContext.logger.debug(`eventValue set to not test (testValueMatches is false).`);
|
|
92
|
-
// continue
|
|
93
98
|
return
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
} else {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
_izContext.logger.debug('eventForTestingOneLevel', eventForTestingOneLevel);
|
|
101
|
+
} else if (testEventConfigOneLevel.hasOwnProperty('properties') && typeof testEventConfigOneLevel === 'object') {
|
|
102
|
+
_izContext.logger.debug("Case: properties", {
|
|
103
|
+
"testEventConfigOneLevel.properties": testEventConfigOneLevel.properties,
|
|
104
|
+
"eventForTestingOneLevel": eventForTestingOneLevel
|
|
105
|
+
});
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
_izContext.logger.debug('eventForTestingOneLevel[propertyName]', eventForTestingOneLevel[propertyName])
|
|
107
|
+
for (const [propertyName, propertyConfig] of Object.entries(testEventConfigOneLevel.properties)) {
|
|
108
|
+
_izContext.logger.debug('Iterate testEventConfigOneLevel.properties:', { propertyName, propertyConfig });
|
|
109
|
+
_izContext.logger.debug('match eventForTestingOneLevel[propertyName]', eventForTestingOneLevel[propertyName])
|
|
107
110
|
|
|
111
|
+
if (eventForTestingOneLevel[propertyName]) {
|
|
112
|
+
// validate testValueMatches
|
|
108
113
|
// continue to test property if set testValueMatches to false
|
|
109
|
-
if (!propertyConfig.hasOwnProperty('testValueMatches') || propertyConfig.testValueMatches != false)
|
|
114
|
+
if ((!propertyConfig.hasOwnProperty('testValueMatches') || propertyConfig.testValueMatches != false)
|
|
115
|
+
|| (propertyConfig.hasOwnProperty('forStageMatching') && propertyConfig.forStageMatching === true)) {
|
|
116
|
+
|
|
117
|
+
_izContext.logger.debug("forStageMatching is true", propertyConfig);
|
|
110
118
|
if (propertyConfig.stringified) {
|
|
111
119
|
eventForTestingOneLevel[propertyName] = JSON.parse(eventForTestingOneLevel[propertyName]);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
//== check config matching to massege.
|
|
120
|
+
};
|
|
115
121
|
|
|
116
|
-
|
|
122
|
+
//== check config matching to massege.
|
|
117
123
|
if (!eventForTestingOneLevel.hasOwnProperty(propertyName)) {
|
|
118
124
|
// propertyNotPass.push(notPassPrefix + `${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
119
125
|
propertyNotPass.push({
|
|
@@ -124,17 +130,43 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
124
130
|
propertyConfig: propertyConfig
|
|
125
131
|
})
|
|
126
132
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// causes problems too.. might have to return to using isObject
|
|
130
|
-
// else if (propertyConfig.isObject) {
|
|
131
|
-
else if (propertyConfig.isObject || propertyConfig.eventValue) {
|
|
132
|
-
_izContext.logger.debug('propertyConfig.properties', propertyConfig.properties);
|
|
133
|
+
else if (propertyConfig.eventValue) {
|
|
134
|
+
_izContext.logger.debug('propertyConfig.eventValue', propertyConfig.eventValue);
|
|
133
135
|
//calling recursive function again.
|
|
134
|
-
this.checkOutputEventOneLevel(
|
|
136
|
+
this.checkOutputEventOneLevel(
|
|
137
|
+
_izContext,
|
|
138
|
+
propertyConfig,
|
|
139
|
+
eventForTestingOneLevel[propertyName],
|
|
140
|
+
level + 1,
|
|
141
|
+
notPassPrefix,
|
|
142
|
+
propertyNotPass
|
|
143
|
+
)
|
|
135
144
|
}
|
|
136
|
-
|
|
137
|
-
|
|
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
|
+
|
|
168
|
+
};
|
|
169
|
+
} else {
|
|
138
170
|
// if config not have value the test is not valid, test fails and note in the result
|
|
139
171
|
if (!propertyConfig.hasOwnProperty('value')) {
|
|
140
172
|
propertyNotPass.push({
|
|
@@ -147,7 +179,12 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
147
179
|
// propertyNotPass.push(notPassPrefix + `(NO VALUE SET IN CONFIG) ${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
148
180
|
}
|
|
149
181
|
// do the standard test
|
|
182
|
+
|
|
150
183
|
if (eventForTestingOneLevel[propertyName] != propertyConfig.value) {
|
|
184
|
+
_izContext.logger.debug("mismatch value::", {
|
|
185
|
+
expectedValue: propertyConfig.value,
|
|
186
|
+
receivedValue: eventForTestingOneLevel[propertyName]
|
|
187
|
+
});
|
|
151
188
|
// propertyNotPass.push(notPassPrefix + `${propertyName}: ${JSON.stringify(propertyConfig)}`)
|
|
152
189
|
propertyNotPass.push({
|
|
153
190
|
prefix: notPassPrefix,
|
|
@@ -160,30 +197,30 @@ module.exports.checkOutputEventOneLevel = (
|
|
|
160
197
|
}
|
|
161
198
|
} else {
|
|
162
199
|
// continue to next property if property(ex.requestParams) has set testValueMatches: false.
|
|
163
|
-
_izContext.logger.debug(`propertyName: ${propertyName} set to not test (testValueMatches is false).`);
|
|
200
|
+
// _izContext.logger.debug(`propertyName: ${propertyName} set to not test (testValueMatches is false).`);
|
|
201
|
+
_izContext.logger.debug(`propertyName: ${propertyName} not test testValueMatches.`);
|
|
164
202
|
continue
|
|
165
203
|
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
204
|
+
};
|
|
169
205
|
|
|
206
|
+
}// end for loop check test
|
|
207
|
+
}
|
|
170
208
|
return propertyNotPass
|
|
171
209
|
} catch (err) {
|
|
172
210
|
console.error('error in recursion checkOutputEventOneLevel: ', err);
|
|
173
211
|
throw (err)
|
|
174
212
|
}
|
|
175
213
|
|
|
176
|
-
}
|
|
177
|
-
|
|
214
|
+
}
|
|
178
215
|
|
|
179
216
|
|
|
180
217
|
/**
|
|
181
|
-
* @param {object} _izContext - The CorrelationId and Logger instances
|
|
182
|
-
* @param {object} testEventConfigOneLevel - Event config for tesing
|
|
183
|
-
* @param {object} eventForTestingOneLevel - Event response
|
|
218
|
+
* @param {object} _izContext - The CorrelationId and Logger instances
|
|
219
|
+
* @param {object} testEventConfigOneLevel - Event config for tesing
|
|
220
|
+
* @param {object} eventForTestingOneLevel - Event response
|
|
184
221
|
* @param {number} level - The level of loop recursion maximun = 20
|
|
185
222
|
*
|
|
186
|
-
* @returns {boolean} true/false - Returning true if matching
|
|
223
|
+
* @returns {boolean} true/false - Returning true if matching
|
|
187
224
|
*/
|
|
188
225
|
module.exports.matchingEventOneLevel = (
|
|
189
226
|
_izContext,
|
|
@@ -191,21 +228,24 @@ module.exports.matchingEventOneLevel = (
|
|
|
191
228
|
eventForTestingOneLevel,
|
|
192
229
|
level
|
|
193
230
|
) => {
|
|
231
|
+
_izContext.logger.debug("Lib matchingEventOneLevel:", {
|
|
232
|
+
testEventConfigOneLevel,
|
|
233
|
+
eventForTestingOneLevel,
|
|
234
|
+
level
|
|
235
|
+
});
|
|
194
236
|
|
|
195
237
|
// stop recursive function if level > MAX_RECURSION_LEVEL
|
|
196
238
|
if (level > MAX_RECURSION_LEVEL) {
|
|
197
239
|
throw new Error(`exceeded maximum recursion level for property checks: ` + MAX_RECURSION_LEVEL)
|
|
198
240
|
}
|
|
199
|
-
//check response/outputEvent // recusive level 2 cannot find eventValue or eventParams
|
|
200
|
-
_izContext.logger.debug('testEventConfigOneLevel matchingEventOneLevel', testEventConfigOneLevel);
|
|
201
|
-
_izContext.logger.debug('eventForTestingOneLevel matchingEventOneLevel', eventForTestingOneLevel);
|
|
241
|
+
//check response/outputEvent // recusive level 2 cannot find eventValue or eventParams
|
|
202
242
|
|
|
203
243
|
if (!testEventConfigOneLevel.hasOwnProperty('eventValue') && !testEventConfigOneLevel.hasOwnProperty('properties')) {
|
|
204
244
|
throw new Error(`outputEvent not have eventValue and not have properties.`)
|
|
205
245
|
}
|
|
206
246
|
|
|
207
247
|
if (testEventConfigOneLevel.hasOwnProperty('eventValue')) {
|
|
208
|
-
_izContext.logger.debug('
|
|
248
|
+
_izContext.logger.debug('case eventValue');
|
|
209
249
|
if (testEventConfigOneLevel.hasOwnProperty('forStageMatching') && testEventConfigOneLevel.forStageMatching === true) {
|
|
210
250
|
if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === false) {
|
|
211
251
|
if (eventForTestingOneLevel != testEventConfigOneLevel.eventValue) { // true not equal "true"
|
|
@@ -225,9 +265,14 @@ module.exports.matchingEventOneLevel = (
|
|
|
225
265
|
|
|
226
266
|
} else { // check if have properties
|
|
227
267
|
|
|
228
|
-
// check testEventConfigOneLevel is eventParams object output.
|
|
268
|
+
// check testEventConfigOneLevel is eventParams object output.
|
|
229
269
|
if (testEventConfigOneLevel.hasOwnProperty('properties') && typeof testEventConfigOneLevel.properties === 'object') {
|
|
230
|
-
_izContext.logger.debug(
|
|
270
|
+
_izContext.logger.debug("Case Object",
|
|
271
|
+
{
|
|
272
|
+
"testEventConfigOneLevel.properties": testEventConfigOneLevel.properties,
|
|
273
|
+
"eventForTestingOneLevel": eventForTestingOneLevel
|
|
274
|
+
}
|
|
275
|
+
);
|
|
231
276
|
|
|
232
277
|
if (typeof eventForTestingOneLevel !== 'object') {
|
|
233
278
|
_izContext.logger.debug(`${eventForTestingOneLevel} config set properties but eventForTestingOneLevel is not an object.`);
|
|
@@ -235,26 +280,30 @@ module.exports.matchingEventOneLevel = (
|
|
|
235
280
|
}
|
|
236
281
|
|
|
237
282
|
for (const [propertyName, propertyConfig] of Object.entries(testEventConfigOneLevel.properties)) {
|
|
238
|
-
_izContext.logger.debug(
|
|
239
|
-
_izContext.logger.debug('propertyConfig', propertyConfig)
|
|
283
|
+
_izContext.logger.debug("[matchingEventOneLevel]Iterate testEventConfigOneLevel.properties:", { propertyName, propertyConfig });
|
|
240
284
|
_izContext.logger.debug('eventForTestingOneLevel[propertyName]', eventForTestingOneLevel[propertyName])
|
|
241
285
|
|
|
242
286
|
// continue to test property if set forStageMatching to false
|
|
243
287
|
if (propertyConfig.hasOwnProperty('forStageMatching') && propertyConfig.forStageMatching === true) {
|
|
288
|
+
_izContext.logger.debug("[forStageMatching true]", {
|
|
289
|
+
"eventForTestingOneLevel[propertyName]": eventForTestingOneLevel[propertyName],
|
|
290
|
+
propertyConfig
|
|
291
|
+
});
|
|
292
|
+
|
|
244
293
|
if (propertyConfig.stringified) {
|
|
245
294
|
eventForTestingOneLevel[propertyName] = JSON.parse(eventForTestingOneLevel[propertyName]);
|
|
246
295
|
}
|
|
247
|
-
//== check config matching to massege.
|
|
296
|
+
//== check config matching to massege.
|
|
248
297
|
|
|
249
298
|
if (!eventForTestingOneLevel.hasOwnProperty(propertyName)) {
|
|
250
299
|
_izContext.logger.debug(`${eventForTestingOneLevel} not have properties: ${propertyName} for matching.`);
|
|
251
300
|
return false;
|
|
252
301
|
}
|
|
253
|
-
// NOT SURE - was setting all eventValue properties to also set isObject: true, try this to see if works so not need to add isObject, but seem to remember this
|
|
302
|
+
// NOT SURE - was setting all eventValue properties to also set isObject: true, try this to see if works so not need to add isObject, but seem to remember this
|
|
254
303
|
// causes problems too.. might have to return to using isObject
|
|
255
304
|
// else if (propertyConfig.isObject) { // send to recursion again if set isObject both properties and eventValue
|
|
256
|
-
else if (propertyConfig.
|
|
257
|
-
_izContext.logger.debug('propertyConfig.
|
|
305
|
+
else if (propertyConfig.eventValue) { // send to recursion again if set isObject both properties and eventValue
|
|
306
|
+
_izContext.logger.debug('propertyConfig.eventValue', propertyConfig.eventValue);
|
|
258
307
|
//calling recursive function again.
|
|
259
308
|
// let checkMatched = checkOutputEventOneLevel(propertyConfig, eventForTestingOneLevel[propertyName], level + 1)
|
|
260
309
|
let checkMatched = this.matchingEventOneLevel(_izContext, propertyConfig, eventForTestingOneLevel[propertyName], level + 1)
|
|
@@ -262,9 +311,19 @@ module.exports.matchingEventOneLevel = (
|
|
|
262
311
|
return false;
|
|
263
312
|
}
|
|
264
313
|
}
|
|
265
|
-
else if (
|
|
314
|
+
else if (propertyConfig.hasOwnProperty("properties")) {
|
|
315
|
+
_izContext.logger.debug("[matchingEventOneLevel]propertyConfig.properties");
|
|
316
|
+
|
|
317
|
+
let checkMatched = this.matchingEventOneLevel(_izContext, propertyConfig, eventForTestingOneLevel[propertyName], level + 1)
|
|
318
|
+
if (checkMatched == false) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
} else if (eventForTestingOneLevel[propertyName] != propertyConfig.value) {
|
|
322
|
+
console.log("misMatch", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
|
|
323
|
+
|
|
266
324
|
return false;
|
|
267
325
|
}
|
|
326
|
+
|
|
268
327
|
} else {
|
|
269
328
|
// continue to next property if property(ex.requestParams) has set forStageMatching: false.
|
|
270
329
|
_izContext.logger.debug(`propertyName: ${propertyName} set to not matching (forStageMatching default is false).`);
|
|
@@ -274,4 +333,4 @@ module.exports.matchingEventOneLevel = (
|
|
|
274
333
|
}
|
|
275
334
|
}
|
|
276
335
|
return true;
|
|
277
|
-
}; // end recursive function
|
|
336
|
+
}; // end recursive function
|