@izara_project/izara-testing-shared 1.0.3 → 1.0.5

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 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
- const testingLib = require('./src/TestingLib')
20
+ import testingLib from './src/TestingLib.js';
21
21
 
22
- module.exports = {
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",
3
+ "version": "1.0.5",
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,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  'use strict';
19
19
 
20
- const isEqual = require('lodash.isequal');
20
+ import isEqual from 'lodash.isequal';
21
21
  const MAX_RECURSION_LEVEL = 20;
22
22
 
23
23
  /**
@@ -30,14 +30,14 @@ const MAX_RECURSION_LEVEL = 20;
30
30
  *
31
31
  * @returns {object[]} propertyNotPass - Array of properties that failed testing
32
32
  */
33
- module.exports.checkOutputEventOneLevel = (
33
+ function checkOutputEventOneLevel(
34
34
  _izContext,
35
35
  testEventConfigOneLevel,
36
36
  eventForTestingOneLevel,
37
37
  level,
38
38
  notPassPrefix,
39
39
  propertyNotPass = []
40
- ) => {
40
+ ) {
41
41
  _izContext.logger.debug("Lib checkOutputEventOneLevel:", {
42
42
  testEventConfigOneLevel,
43
43
  eventForTestingOneLevel,
@@ -59,39 +59,17 @@ module.exports.checkOutputEventOneLevel = (
59
59
 
60
60
  if (testEventConfigOneLevel.hasOwnProperty('eventValue')) {
61
61
  _izContext.logger.debug('Case eventValue');
62
- if (!testEventConfigOneLevel.hasOwnProperty('testValueMatches') || testEventConfigOneLevel.testValueMatches != false) {
63
- if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === false) {
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);
83
-
62
+ if (!testEventConfigOneLevel.hasOwnProperty('testValueMatches') || testEventConfigOneLevel.testValueMatches !== false) {
63
+ if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === true) {
84
64
  if (isEqual(eventForTestingOneLevel, testEventConfigOneLevel.eventValue) == false) {
85
65
  _izContext.logger.debug('test isEqual failed');
86
66
  propertyNotPass.push({
87
67
  prefix: notPassPrefix,
88
68
  expectedValue: testEventConfigOneLevel.eventValue,
89
- receivedValue: eventForTestingOneLevel,
90
- // propertyName: propertyName,
91
- // propertyConfig: propertyConfig
92
- })
93
- }
94
- }
69
+ receivedValue: eventForTestingOneLevel
70
+ });
71
+ };
72
+ };
95
73
  } else {
96
74
  // continue to next property if property(ex.requestParams) has set testValueMatches: false.
97
75
  _izContext.logger.debug(`eventValue set to not test (testValueMatches is false).`);
@@ -109,9 +87,10 @@ module.exports.checkOutputEventOneLevel = (
109
87
  _izContext.logger.debug('match eventForTestingOneLevel[propertyName]', eventForTestingOneLevel[propertyName])
110
88
 
111
89
  if (eventForTestingOneLevel[propertyName]) {
90
+
112
91
  // validate testValueMatches
113
92
  // continue to test property if set testValueMatches to false
114
- if ((!propertyConfig.hasOwnProperty('testValueMatches') || propertyConfig.testValueMatches != false)
93
+ if ((!propertyConfig.hasOwnProperty('testValueMatches') || propertyConfig.testValueMatches !== false)
115
94
  || (propertyConfig.hasOwnProperty('forStageMatching') && propertyConfig.forStageMatching === true)) {
116
95
 
117
96
  _izContext.logger.debug("forStageMatching is true", propertyConfig);
@@ -177,23 +156,53 @@ module.exports.checkOutputEventOneLevel = (
177
156
  propertyConfig: propertyConfig
178
157
  })
179
158
  // propertyNotPass.push(notPassPrefix + `(NO VALUE SET IN CONFIG) ${propertyName}: ${JSON.stringify(propertyConfig)}`)
159
+ } else {
160
+ // suport empty Object
161
+ if (isObject(eventForTestingOneLevel[propertyName]) && isObject(propertyConfig.value)) {
162
+ _izContext.logger.debug("check Object")
163
+ if (Object.keys(eventForTestingOneLevel[propertyName]).length > 0 && Object.keys(propertyConfig.value).length > 0) {
164
+ // console.log("invalid object should be set propertise inside for recuresive value in object");
165
+ propertyNotPass.push({
166
+ prefix: notPassPrefix,
167
+ expectedValue: `invalid check object much be set 'propertise' inside for recuresive value in object(${propertyConfig.value})`,
168
+ receivedValue: eventForTestingOneLevel[propertyName],
169
+ propertyName: propertyName,
170
+ propertyConfig: propertyConfig
171
+ })
172
+
173
+ } else {
174
+ _izContext.logger.debug("object is empty");
175
+ };
176
+ } else {
177
+ if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
178
+ console.log("misMatch data::::", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
179
+ propertyNotPass.push({
180
+ prefix: notPassPrefix,
181
+ expectedValue: propertyConfig.value,
182
+ receivedValue: eventForTestingOneLevel[propertyName],
183
+ propertyName: propertyName,
184
+ propertyConfig: propertyConfig
185
+ })
186
+ }
187
+ }
188
+
180
189
  }
181
190
  // do the standard test
182
191
 
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
- }
192
+ // if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
193
+ // _izContext.logger.debug("mismatch value::", {
194
+ // expectedValue: propertyConfig.value,
195
+ // receivedValue: eventForTestingOneLevel[propertyName]
196
+ // });
197
+ // // propertyNotPass.push(notPassPrefix + `${propertyName}: ${JSON.stringify(propertyConfig)}`)
198
+ // propertyNotPass.push({
199
+ // prefix: notPassPrefix,
200
+ // expectedValue: propertyConfig.value,
201
+ // receivedValue: eventForTestingOneLevel[propertyName],
202
+ // propertyName: propertyName,
203
+ // propertyConfig: propertyConfig
204
+ // })
205
+ // }
197
206
  }
198
207
  } else {
199
208
  // continue to next property if property(ex.requestParams) has set testValueMatches: false.
@@ -201,8 +210,18 @@ module.exports.checkOutputEventOneLevel = (
201
210
  _izContext.logger.debug(`propertyName: ${propertyName} not test testValueMatches.`);
202
211
  continue
203
212
  }
204
- };
213
+ } else {
214
+ // // mismatch eventForTestingOneLevel
215
+ propertyNotPass.push({
216
+ prefix: notPassPrefix,
217
+ error: `message event is not mach test config`,
218
+ receivedValue: eventForTestingOneLevel,
219
+ expectedValue: testEventConfigOneLevel
220
+ })
221
+
205
222
 
223
+
224
+ };
206
225
  }// end for loop check test
207
226
  }
208
227
  return propertyNotPass
@@ -222,12 +241,12 @@ module.exports.checkOutputEventOneLevel = (
222
241
  *
223
242
  * @returns {boolean} true/false - Returning true if matching
224
243
  */
225
- module.exports.matchingEventOneLevel = (
244
+ function matchingEventOneLevel(
226
245
  _izContext,
227
246
  testEventConfigOneLevel,
228
247
  eventForTestingOneLevel,
229
248
  level
230
- ) => {
249
+ ) {
231
250
  _izContext.logger.debug("Lib matchingEventOneLevel:", {
232
251
  testEventConfigOneLevel,
233
252
  eventForTestingOneLevel,
@@ -245,23 +264,37 @@ module.exports.matchingEventOneLevel = (
245
264
  }
246
265
 
247
266
  if (testEventConfigOneLevel.hasOwnProperty('eventValue')) {
248
- _izContext.logger.debug('case eventValue');
249
267
  if (testEventConfigOneLevel.hasOwnProperty('forStageMatching') && testEventConfigOneLevel.forStageMatching === true) {
250
- if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === false) {
251
- if (eventForTestingOneLevel != testEventConfigOneLevel.eventValue) { // true not equal "true"
252
- return false;
253
- }
254
- } else { // use isEqual by default is true
255
- _izContext.logger.debug('config has useIsEqual(default is true)');
268
+ if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === true) {
269
+ _izContext.logger.debug("Check array")// index in array is isEqual.
256
270
  if (isEqual(eventForTestingOneLevel, testEventConfigOneLevel.eventValue) == false) {
257
- _izContext.logger.debug('test isEqual failed');
271
+ _izContext.logger.debug('test array isEqual failed');
258
272
  return false;
273
+ } else {
274
+ _izContext.logger.debug('test array isEqual true');
275
+
259
276
  }
260
277
  }
261
278
  } else {
262
279
  // continue to next property if property(ex.requestParams) has set forStageMatching: false.
263
- _izContext.logger.debug(`forStageMatching set not mtachinf or default is false.`);
280
+ _izContext.logger.debug(`forStageMatching set not mtaching or default is false.`);
264
281
  }
282
+ // if (testEventConfigOneLevel.hasOwnProperty('forStageMatching') && testEventConfigOneLevel.forStageMatching === true) {
283
+ // if (testEventConfigOneLevel.hasOwnProperty('useIsEqual') && testEventConfigOneLevel.useIsEqual === false) {
284
+ // if (eventForTestingOneLevel !== testEventConfigOneLevel.eventValue) { // true not equal "true"
285
+ // return false;
286
+ // }
287
+ // } else { // use isEqual by default is true
288
+ // _izContext.logger.debug('config has useIsEqual(default is true)');
289
+ // if (isEqual(eventForTestingOneLevel, testEventConfigOneLevel.eventValue) == false) {
290
+ // _izContext.logger.debug('test isEqual failed');
291
+ // return false;
292
+ // }
293
+ // }
294
+ // } else {
295
+ // // continue to next property if property(ex.requestParams) has set forStageMatching: false.
296
+ // _izContext.logger.debug(`forStageMatching set not mtaching or default is false.`);
297
+ // }
265
298
 
266
299
  } else { // check if have properties
267
300
 
@@ -280,14 +313,15 @@ module.exports.matchingEventOneLevel = (
280
313
  }
281
314
 
282
315
  for (const [propertyName, propertyConfig] of Object.entries(testEventConfigOneLevel.properties)) {
283
- _izContext.logger.debug("[matchingEventOneLevel]Iterate testEventConfigOneLevel.properties:", { propertyName, propertyConfig });
316
+ _izContext.logger.debug("[matching]Iterate testEventConfigOneLevel.properties:", { propertyName, propertyConfig });
284
317
  _izContext.logger.debug('eventForTestingOneLevel[propertyName]', eventForTestingOneLevel[propertyName])
285
318
 
286
319
  // continue to test property if set forStageMatching to false
287
320
  if (propertyConfig.hasOwnProperty('forStageMatching') && propertyConfig.forStageMatching === true) {
288
- _izContext.logger.debug("[forStageMatching true]", {
321
+
322
+ _izContext.logger.debug("[matching] forStageMatching is true compare value", {
289
323
  "eventForTestingOneLevel[propertyName]": eventForTestingOneLevel[propertyName],
290
- propertyConfig
324
+ propertyConfig: propertyConfig
291
325
  });
292
326
 
293
327
  if (propertyConfig.stringified) {
@@ -318,11 +352,31 @@ module.exports.matchingEventOneLevel = (
318
352
  if (checkMatched == false) {
319
353
  return false;
320
354
  }
321
- } else if (eventForTestingOneLevel[propertyName] != propertyConfig.value) {
322
- console.log("misMatch", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
323
-
324
- return false;
325
355
  }
356
+ //old----------------
357
+ // else if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
358
+ // console.log("misMatch", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
359
+
360
+ // return false;
361
+ // }// is not check empty Object
362
+
363
+ else { // new ------------------------
364
+ // suport empty Object
365
+ if (isObject(eventForTestingOneLevel[propertyName]) && isObject(propertyConfig.value)) {
366
+ _izContext.logger.debug("check Object")
367
+ if (Object.keys(eventForTestingOneLevel[propertyName]).length > 0 && Object.keys(propertyConfig.value).length > 0) {
368
+ console.log("invalid object should be set propertise inside for recuresive value in object");
369
+ return false
370
+ } else {
371
+ _izContext.logger.debug("0000 is Empty object");
372
+ }
373
+ } else {
374
+ if (eventForTestingOneLevel[propertyName] !== propertyConfig.value) {
375
+ console.log("misMatch data::::", { valueEvent: eventForTestingOneLevel[propertyName], valueConfig: propertyConfig.value });
376
+ return false;
377
+ }
378
+ }
379
+ };
326
380
 
327
381
  } else {
328
382
  // continue to next property if property(ex.requestParams) has set forStageMatching: false.
@@ -333,4 +387,20 @@ module.exports.matchingEventOneLevel = (
333
387
  }
334
388
  }
335
389
  return true;
336
- }; // end recursive function
390
+ };
391
+ // end recursive function
392
+
393
+
394
+ function isObject(object) {
395
+
396
+ if (typeof object === 'object' && !Array.isArray(object)) {
397
+ return true;
398
+ };
399
+ return false
400
+ };
401
+
402
+
403
+ export default {
404
+ checkOutputEventOneLevel,
405
+ matchingEventOneLevel
406
+ }