@itentialopensource/adapter-selector_ai 0.1.1

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.
Files changed (117) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +19 -0
  3. package/.jshintrc +3 -0
  4. package/AUTH.md +39 -0
  5. package/BROKER.md +211 -0
  6. package/CALLS.md +405 -0
  7. package/CODE_OF_CONDUCT.md +43 -0
  8. package/CONTRIBUTING.md +13 -0
  9. package/ENHANCE.md +69 -0
  10. package/LICENSE +201 -0
  11. package/PROPERTIES.md +661 -0
  12. package/README.md +344 -0
  13. package/SUMMARY.md +9 -0
  14. package/SYSTEMINFO.md +14 -0
  15. package/TAB1.md +8 -0
  16. package/TAB2.md +314 -0
  17. package/TROUBLESHOOT.md +56 -0
  18. package/UTILITIES.md +473 -0
  19. package/adapter.js +4039 -0
  20. package/adapterBase.js +1488 -0
  21. package/entities/.generic/action.json +214 -0
  22. package/entities/.generic/schema.json +28 -0
  23. package/entities/.system/action.json +50 -0
  24. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  25. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  26. package/entities/.system/schema.json +19 -0
  27. package/entities/.system/schemaTokenReq.json +53 -0
  28. package/entities/.system/schemaTokenResp.json +53 -0
  29. package/entities/InventorySchemaCreation/action.json +24 -0
  30. package/entities/InventorySchemaCreation/schema.json +19 -0
  31. package/entities/InventorySchemaDelete/action.json +24 -0
  32. package/entities/InventorySchemaDelete/schema.json +19 -0
  33. package/entities/InventorySchemaDeleteType/action.json +24 -0
  34. package/entities/InventorySchemaDeleteType/schema.json +19 -0
  35. package/entities/InventorySchemaFileDownload/action.json +24 -0
  36. package/entities/InventorySchemaFileDownload/schema.json +19 -0
  37. package/entities/InventorySchemaFileUpload/action.json +24 -0
  38. package/entities/InventorySchemaFileUpload/schema.json +19 -0
  39. package/entities/InventorySchemaUpdate/action.json +24 -0
  40. package/entities/InventorySchemaUpdate/schema.json +19 -0
  41. package/entities/InventoryV2SchemaDeleteAll/action.json +24 -0
  42. package/entities/InventoryV2SchemaDeleteAll/schema.json +19 -0
  43. package/entities/InventoryV2SchemaDeleteType/action.json +24 -0
  44. package/entities/InventoryV2SchemaDeleteType/schema.json +19 -0
  45. package/entities/InventoryV2SchemaUpdate/action.json +24 -0
  46. package/entities/InventoryV2SchemaUpdate/schema.json +19 -0
  47. package/entities/InventoryV2SchemaUpload/action.json +24 -0
  48. package/entities/InventoryV2SchemaUpload/schema.json +19 -0
  49. package/entities/MetastoreInventoryBulkDataUpload/action.json +24 -0
  50. package/entities/MetastoreInventoryBulkDataUpload/schema.json +19 -0
  51. package/entities/MetastoreInventoryCSVDataUpload/action.json +24 -0
  52. package/entities/MetastoreInventoryCSVDataUpload/schema.json +19 -0
  53. package/entities/MetastoreInventoryCsvFileExport/action.json +25 -0
  54. package/entities/MetastoreInventoryCsvFileExport/schema.json +19 -0
  55. package/entities/MetastoreInventoryDataDelete/action.json +24 -0
  56. package/entities/MetastoreInventoryDataDelete/schema.json +19 -0
  57. package/entities/MetastoreInventoryDataDownload/action.json +46 -0
  58. package/entities/MetastoreInventoryDataDownload/schema.json +20 -0
  59. package/entities/MetastoreInventoryDataEdit/action.json +24 -0
  60. package/entities/MetastoreInventoryDataEdit/schema.json +19 -0
  61. package/entities/MetastoreInventoryDataUpload/action.json +24 -0
  62. package/entities/MetastoreInventoryDataUpload/schema.json +19 -0
  63. package/entities/MetastoreInventoryFilesExport/action.json +24 -0
  64. package/entities/MetastoreInventoryFilesExport/schema.json +19 -0
  65. package/entities/MetastoreInventoryFilesImport/action.json +24 -0
  66. package/entities/MetastoreInventoryFilesImport/schema.json +30 -0
  67. package/entities/MetastoreInventoryItems/action.json +25 -0
  68. package/entities/MetastoreInventoryItems/schema.json +19 -0
  69. package/entities/MetastoreInventoryNameDelete/action.json +24 -0
  70. package/entities/MetastoreInventoryNameDelete/schema.json +19 -0
  71. package/entities/MetastoreInventoryNameUpdate/action.json +24 -0
  72. package/entities/MetastoreInventoryNameUpdate/schema.json +19 -0
  73. package/entities/MetastoreInventoryNameUpload/action.json +24 -0
  74. package/entities/MetastoreInventoryNameUpload/schema.json +19 -0
  75. package/entities/MetastoreInventoryNamesDownload/action.json +25 -0
  76. package/entities/MetastoreInventoryNamesDownload/schema.json +19 -0
  77. package/entities/MetastoreInventorySchemaGet/action.json +25 -0
  78. package/entities/MetastoreInventorySchemaGet/schema.json +19 -0
  79. package/entities/MetastoreInventorySystem/action.json +130 -0
  80. package/entities/MetastoreInventorySystem/schema.json +24 -0
  81. package/entities/MetastoreV2InventorySchemaGet/action.json +25 -0
  82. package/entities/MetastoreV2InventorySchemaGet/schema.json +19 -0
  83. package/error.json +190 -0
  84. package/metadata.json +58 -0
  85. package/package.json +77 -0
  86. package/pronghorn.json +2508 -0
  87. package/propertiesDecorators.json +14 -0
  88. package/propertiesSchema.json +1635 -0
  89. package/report/adapterInfo.json +10 -0
  90. package/report/auto-adapter-openapi.json +1330 -0
  91. package/report/creationReport.json +765 -0
  92. package/report/metastore-inventory-manager.yaml-OpenApi3Json.json +2366 -0
  93. package/sampleProperties.json +260 -0
  94. package/test/integration/adapterTestBasicGet.js +117 -0
  95. package/test/integration/adapterTestConnectivity.js +117 -0
  96. package/test/integration/adapterTestIntegration.js +1295 -0
  97. package/test/unit/adapterBaseTestUnit.js +1626 -0
  98. package/test/unit/adapterTestUnit.js +2288 -0
  99. package/utils/adapterInfo.js +156 -0
  100. package/utils/argParser.js +44 -0
  101. package/utils/checkMigrate.js +102 -0
  102. package/utils/entitiesToDB.js +190 -0
  103. package/utils/findPath.js +74 -0
  104. package/utils/logger.js +26 -0
  105. package/utils/methodDocumentor.js +273 -0
  106. package/utils/modify.js +153 -0
  107. package/utils/mongoDbConnection.js +79 -0
  108. package/utils/mongoUtils.js +162 -0
  109. package/utils/pre-commit.sh +32 -0
  110. package/utils/removeHooks.js +20 -0
  111. package/utils/setup.js +33 -0
  112. package/utils/taskMover.js +308 -0
  113. package/utils/tbScript.js +103 -0
  114. package/utils/tbUtils.js +347 -0
  115. package/utils/testRunner.js +298 -0
  116. package/utils/troubleshootingAdapter.js +177 -0
  117. package/utils/updateAdapterConfig.js +158 -0
@@ -0,0 +1,1626 @@
1
+ // Set globals
2
+ /* global describe it log pronghornProps beforeEach afterEach */
3
+ /* eslint global-require: warn */
4
+ /* eslint no-unused-vars: warn */
5
+
6
+ // include required items for testing & logging
7
+ const assert = require('assert');
8
+ const path = require('path');
9
+ const fs = require('fs-extra');
10
+ const mocha = require('mocha');
11
+ const winston = require('winston');
12
+ const { expect } = require('chai');
13
+ const { use } = require('chai');
14
+ const td = require('testdouble');
15
+ const entitiesToDB = require('../../utils/entitiesToDB');
16
+ const troubleshootingAdapter = require('../../utils/troubleshootingAdapter');
17
+ const log = require('../../utils/logger');
18
+
19
+ const anything = td.matchers.anything();
20
+
21
+ // stub and attemptTimeout are used throughout the code so set them here
22
+ const stub = true;
23
+ const isRapidFail = false;
24
+ const attemptTimeout = 120000;
25
+
26
+ // these variables can be changed to run in integrated mode so easier to set them here
27
+ // always check these in with bogus data!!!
28
+ const host = 'replace.hostorip.here';
29
+ const username = 'username';
30
+ const password = 'password';
31
+ const protocol = 'http';
32
+ const port = 80;
33
+ const sslenable = false;
34
+ const sslinvalid = false;
35
+
36
+ // these are the adapter properties. You generally should not need to alter
37
+ // any of these after they are initially set up
38
+ global.pronghornProps = {
39
+ pathProps: {
40
+ encrypted: false
41
+ },
42
+ adapterProps: {
43
+ adapters: [{
44
+ id: 'Test-Base',
45
+ type: 'ABase',
46
+ properties: {
47
+ host,
48
+ port,
49
+ base_path: '/',
50
+ version: '',
51
+ cache_location: 'local',
52
+ encode_pathvars: true,
53
+ save_metric: false,
54
+ stub,
55
+ protocol,
56
+ authentication: {
57
+ auth_method: 'basic user_password',
58
+ username,
59
+ password,
60
+ token: '',
61
+ invalid_token_error: 401,
62
+ token_timeout: -1,
63
+ token_cache: 'local',
64
+ auth_field: 'header.headers.Authorization',
65
+ auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
66
+ auth_logging: false,
67
+ client_id: '',
68
+ client_secret: '',
69
+ grant_type: ''
70
+ },
71
+ healthcheck: {
72
+ type: 'none',
73
+ frequency: 60000,
74
+ query_object: {}
75
+ },
76
+ throttle: {
77
+ throttle_enabled: false,
78
+ number_pronghorns: 1,
79
+ sync_async: 'sync',
80
+ max_in_queue: 1000,
81
+ concurrent_max: 1,
82
+ expire_timeout: 0,
83
+ avg_runtime: 200,
84
+ priorities: [
85
+ {
86
+ value: 0,
87
+ percent: 100
88
+ }
89
+ ]
90
+ },
91
+ request: {
92
+ number_redirects: 0,
93
+ number_retries: 3,
94
+ limit_retry_error: [0],
95
+ failover_codes: [],
96
+ attempt_timeout: attemptTimeout,
97
+ global_request: {
98
+ payload: {},
99
+ uriOptions: {},
100
+ addlHeaders: {},
101
+ authData: {}
102
+ },
103
+ healthcheck_on_timeout: true,
104
+ return_raw: true,
105
+ archiving: false,
106
+ return_request: false
107
+ },
108
+ proxy: {
109
+ enabled: false,
110
+ host: '',
111
+ port: 1,
112
+ protocol: 'http',
113
+ username: '',
114
+ password: ''
115
+ },
116
+ ssl: {
117
+ ecdhCurve: '',
118
+ enabled: sslenable,
119
+ accept_invalid_cert: sslinvalid,
120
+ ca_file: '',
121
+ key_file: '',
122
+ cert_file: '',
123
+ secure_protocol: '',
124
+ ciphers: ''
125
+ },
126
+ mongo: {
127
+ host: '',
128
+ port: 0,
129
+ database: '',
130
+ username: '',
131
+ password: '',
132
+ replSet: '',
133
+ db_ssl: {
134
+ enabled: false,
135
+ accept_invalid_cert: false,
136
+ ca_file: '',
137
+ key_file: '',
138
+ cert_file: ''
139
+ }
140
+ }
141
+ }
142
+ }]
143
+ }
144
+ };
145
+
146
+ global.$HOME = `${__dirname}/../..`;
147
+
148
+ /**
149
+ * Runs the error asserts for the test
150
+ */
151
+ function runErrorAsserts(data, error, code, origin, displayStr) {
152
+ assert.equal(null, data);
153
+ assert.notEqual(undefined, error);
154
+ assert.notEqual(null, error);
155
+ assert.notEqual(undefined, error.IAPerror);
156
+ assert.notEqual(null, error.IAPerror);
157
+ assert.notEqual(undefined, error.IAPerror.displayString);
158
+ assert.notEqual(null, error.IAPerror.displayString);
159
+ assert.equal(code, error.icode);
160
+ assert.equal(origin, error.IAPerror.origin);
161
+ assert.equal(displayStr, error.IAPerror.displayString);
162
+ }
163
+
164
+ // require the adapter that we are going to be using
165
+ const AdapterBase = require('../../adapterBase');
166
+
167
+ // delete the .DS_Store directory in entities -- otherwise this will cause errors
168
+ const dirPath = path.join(__dirname, '../../entities/.DS_Store');
169
+ if (fs.existsSync(dirPath)) {
170
+ try {
171
+ fs.removeSync(dirPath);
172
+ console.log('.DS_Store deleted');
173
+ } catch (e) {
174
+ console.log('Error when deleting .DS_Store:', e);
175
+ }
176
+ }
177
+
178
+ // Define test data at the top of the test section
179
+ const testData = {
180
+ pronghorn: {
181
+ id: 'test-adapter',
182
+ name: 'Test Adapter',
183
+ version: '1.0.0'
184
+ },
185
+ action: {
186
+ actions: [{
187
+ name: 'testAction',
188
+ description: 'Test action description',
189
+ method: 'GET',
190
+ entitypath: '/test/path'
191
+ }]
192
+ },
193
+ schema: {
194
+ type: 'object',
195
+ properties: {
196
+ name: { type: 'string' },
197
+ description: { type: 'string' }
198
+ }
199
+ },
200
+ mock: {
201
+ testData: 'value'
202
+ }
203
+ };
204
+
205
+ describe('[unit] Adapter Base Test', () => {
206
+ describe('Adapter Base Class Tests', () => {
207
+ // Define constants we will use below
208
+ const a = new AdapterBase(
209
+ pronghornProps.adapterProps.adapters[0].id,
210
+ pronghornProps.adapterProps.adapters[0].properties
211
+ );
212
+
213
+ if (isRapidFail) {
214
+ const state = {};
215
+ state.passed = true;
216
+
217
+ mocha.afterEach(function x() {
218
+ state.passed = state.passed
219
+ && (this.currentTest.state === 'passed');
220
+ });
221
+ mocha.beforeEach(function x() {
222
+ if (!state.passed) {
223
+ return this.currentTest.skip();
224
+ }
225
+ return true;
226
+ });
227
+ }
228
+
229
+ describe('#class instance created', () => {
230
+ it('should be a class with properties', (done) => {
231
+ try {
232
+ assert.notEqual(null, a);
233
+ assert.notEqual(undefined, a);
234
+ assert.notEqual(null, a.allProps);
235
+ const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
236
+ assert.equal(check, a.healthcheckType);
237
+ done();
238
+ } catch (error) {
239
+ log.error(`Test Failure: ${error}`);
240
+ done(error);
241
+ }
242
+ }).timeout(attemptTimeout);
243
+ });
244
+
245
+ describe('adapterBase.js', () => {
246
+ it('should have an adapterBase.js', (done) => {
247
+ try {
248
+ fs.exists('adapterBase.js', (val) => {
249
+ assert.equal(true, val);
250
+ done();
251
+ });
252
+ } catch (error) {
253
+ log.error(`Test Failure: ${error}`);
254
+ done(error);
255
+ }
256
+ });
257
+ });
258
+
259
+ describe('#refreshProperties', () => {
260
+ it('should have a refreshProperties function', (done) => {
261
+ try {
262
+ assert.equal(true, typeof a.refreshProperties === 'function');
263
+ done();
264
+ } catch (error) {
265
+ log.error(`Test Failure: ${error}`);
266
+ done(error);
267
+ }
268
+ });
269
+ it('should update the properties file', (done) => {
270
+ try {
271
+ // Mock connections
272
+ a.requestHandlerInst.refreshProperties = td.func();
273
+ a.refreshProperties({ foo: 'bar' });
274
+ // Run assert to verify we have updated a
275
+ try {
276
+ assert.equal(true, a.allProps.foo === 'bar');
277
+ done();
278
+ } catch (err) {
279
+ log.error(`Test Failure: ${err}`);
280
+ done(err);
281
+ }
282
+ } catch (error) {
283
+ log.error(`Adapter Exception: ${error}`);
284
+ done(error);
285
+ }
286
+ }).timeout(attemptTimeout);
287
+ it('should fail if the validation does not match the schema', (done) => {
288
+ try {
289
+ // Mock connections
290
+ a.propUtilInst.mergeProperties = td.func();
291
+ a.refreshProperties('tacos');
292
+ done();
293
+ } catch (error) {
294
+ log.error(`Adapter Exception: ${error}`);
295
+ done(error);
296
+ }
297
+ }).timeout(attemptTimeout);
298
+ });
299
+
300
+ describe('#connect', () => {
301
+ it('should have a connect function', (done) => {
302
+ try {
303
+ assert.equal(true, typeof a.connect === 'function');
304
+ done();
305
+ } catch (error) {
306
+ log.error(`Test Failure: ${error}`);
307
+ done(error);
308
+ }
309
+ });
310
+ it('should get connected - no healthcheck', (done) => {
311
+ try {
312
+ a.healthcheckType = 'none';
313
+ a.connect();
314
+
315
+ try {
316
+ assert.equal(true, a.alive);
317
+ done();
318
+ } catch (error) {
319
+ log.error(`Test Failure: ${error}`);
320
+ done(error);
321
+ }
322
+ } catch (error) {
323
+ log.error(`Adapter Exception: ${error}`);
324
+ done(error);
325
+ }
326
+ });
327
+ it('should get connected - startup healthcheck', (done) => {
328
+ try {
329
+ a.healthcheckType = 'startup';
330
+ a.connect();
331
+
332
+ try {
333
+ assert.equal(true, a.alive);
334
+ done();
335
+ } catch (error) {
336
+ log.error(`Test Failure: ${error}`);
337
+ done(error);
338
+ }
339
+ } catch (error) {
340
+ log.error(`Adapter Exception: ${error}`);
341
+ done(error);
342
+ }
343
+ });
344
+ });
345
+
346
+ describe('#healthCheck', () => {
347
+ it('should have a healthCheck function', (done) => {
348
+ try {
349
+ assert.equal(true, typeof a.healthCheck === 'function');
350
+ done();
351
+ } catch (error) {
352
+ log.error(`Test Failure: ${error}`);
353
+ done(error);
354
+ }
355
+ });
356
+ it('should be healthy', (done) => {
357
+ try {
358
+ a.healthCheck(null, (data) => {
359
+ try {
360
+ assert.equal(true, a.healthy);
361
+ done();
362
+ } catch (err) {
363
+ log.error(`Test Failure: ${err}`);
364
+ done(err);
365
+ }
366
+ });
367
+ } catch (error) {
368
+ log.error(`Adapter Exception: ${error}`);
369
+ done(error);
370
+ }
371
+ }).timeout(attemptTimeout);
372
+ });
373
+
374
+ describe('#getAllFunctions', () => {
375
+ it('should have a getAllFunctions function', (done) => {
376
+ try {
377
+ assert.equal(true, typeof a.getAllFunctions === 'function');
378
+ done();
379
+ } catch (error) {
380
+ log.error(`Test Failure: ${error}`);
381
+ done(error);
382
+ }
383
+ });
384
+ it('should return a list of functions', (done) => {
385
+ const returnedFunctions = ['checkActionFiles', 'checkProperties', 'connect', 'encryptProperty', 'genericAdapterRequest', 'genericAdapterRequestNoBasePath',
386
+ 'getAllFunctions', 'getConfig', 'getConfigAuth', 'getDevice', 'getDeviceAuth', 'getDevicesFiltered', 'getDevicesFilteredAuth', 'hasEntities', 'hasEntitiesAuth',
387
+ 'healthCheck', 'iapActivateTasks', 'iapDeactivateTasks', 'iapExpandedGenericAdapterRequest', 'iapFindAdapterPath', 'iapGetAdapterInventory', 'iapGetAdapterQueue',
388
+ 'iapGetAdapterWorkflowFunctions', 'iapGetDeviceCount', 'iapGetDeviceCountAuth', 'iapMoveAdapterEntitiesToDB', 'iapPopulateEntityCache', 'iapRetrieveEntitiesCache',
389
+ 'iapRunAdapterBasicGet', 'iapRunAdapterConnectivity', 'iapRunAdapterHealthcheck', 'iapRunAdapterLint', 'iapRunAdapterTests', 'iapSuspendAdapter', 'iapTroubleshootAdapter',
390
+ 'iapUnsuspendAdapter', 'iapUpdateAdapterConfiguration', 'isAlive', 'isAliveAuth', 'refreshProperties', 'addListener', 'emit', 'eventNames', 'getMaxListeners',
391
+ 'listenerCount', 'listeners', 'off', 'on', 'once', 'prependListener', 'prependOnceListener', 'rawListeners', 'removeAllListeners', 'removeListener', 'setMaxListeners'];
392
+ try {
393
+ const expectedFunctions = a.getAllFunctions();
394
+ try {
395
+ assert.equal(JSON.stringify(expectedFunctions), JSON.stringify(returnedFunctions));
396
+ done();
397
+ } catch (err) {
398
+ log.error(`Test Failure: ${err}`);
399
+ done(err);
400
+ }
401
+ } catch (error) {
402
+ log.error(`Adapter Exception: ${error}`);
403
+ done(error);
404
+ }
405
+ }).timeout(attemptTimeout);
406
+ });
407
+
408
+ describe('#iapGetAdapterWorkflowFunctions', () => {
409
+ it('should have a iapGetAdapterWorkflowFunctions function', (done) => {
410
+ try {
411
+ assert.equal(true, typeof a.iapGetAdapterWorkflowFunctions === 'function');
412
+ done();
413
+ } catch (error) {
414
+ log.error(`Test Failure: ${error}`);
415
+ done(error);
416
+ }
417
+ });
418
+ it('should retrieve workflow functions', (done) => {
419
+ try {
420
+ const expectedFunctions = a.iapGetAdapterWorkflowFunctions([]);
421
+ try {
422
+ assert.equal(0, expectedFunctions.length);
423
+ done();
424
+ } catch (err) {
425
+ log.error(`Test Failure: ${err}`);
426
+ done(err);
427
+ }
428
+ } catch (error) {
429
+ log.error(`Adapter Exception: ${error}`);
430
+ done(error);
431
+ }
432
+ }).timeout(attemptTimeout);
433
+ });
434
+
435
+ describe('#checkActionFiles', () => {
436
+ it('should have a checkActionFiles function', (done) => {
437
+ try {
438
+ assert.equal(true, typeof a.checkActionFiles === 'function');
439
+ done();
440
+ } catch (error) {
441
+ log.error(`Test Failure: ${error}`);
442
+ done(error);
443
+ }
444
+ });
445
+ it('the action files should be good - if failure change the log level as most issues are warnings', (done) => {
446
+ try {
447
+ const clean = a.checkActionFiles();
448
+ try {
449
+ for (let c = 0; c < clean.length; c += 1) {
450
+ log.error(clean[c]);
451
+ }
452
+ assert.equal(0, clean.length);
453
+ done();
454
+ } catch (err) {
455
+ log.error(`Test Failure: ${err}`);
456
+ done(err);
457
+ }
458
+ } catch (error) {
459
+ log.error(`Adapter Exception: ${error}`);
460
+ done(error);
461
+ }
462
+ }).timeout(attemptTimeout);
463
+ });
464
+
465
+ describe('#checkProperties', () => {
466
+ it('should have a checkProperties function', (done) => {
467
+ try {
468
+ assert.equal(true, typeof a.checkProperties === 'function');
469
+ done();
470
+ } catch (error) {
471
+ log.error(`Test Failure: ${error}`);
472
+ done(error);
473
+ }
474
+ });
475
+ it('the sample properties should be good - if failure change the log level', (done) => {
476
+ try {
477
+ const samplePropsJson = require('../../sampleProperties.json');
478
+ const clean = a.checkProperties(samplePropsJson.properties);
479
+ try {
480
+ assert.notEqual(0, Object.keys(clean));
481
+ assert.equal(undefined, clean.exception);
482
+ assert.notEqual(undefined, clean.host);
483
+ assert.notEqual(null, clean.host);
484
+ assert.notEqual('', clean.host);
485
+ done();
486
+ } catch (err) {
487
+ log.error(`Test Failure: ${err}`);
488
+ done(err);
489
+ }
490
+ } catch (error) {
491
+ log.error(`Adapter Exception: ${error}`);
492
+ done(error);
493
+ }
494
+ }).timeout(attemptTimeout);
495
+ });
496
+
497
+ describe('#encryptProperty', () => {
498
+ it('should have a encryptProperty function', (done) => {
499
+ try {
500
+ assert.equal(true, typeof a.encryptProperty === 'function');
501
+ done();
502
+ } catch (error) {
503
+ log.error(`Test Failure: ${error}`);
504
+ done(error);
505
+ }
506
+ });
507
+ it('should get base64 encoded property', (done) => {
508
+ try {
509
+ a.encryptProperty('testing', 'base64', (data, error) => {
510
+ try {
511
+ assert.equal(undefined, error);
512
+ assert.notEqual(undefined, data);
513
+ assert.notEqual(null, data);
514
+ assert.notEqual(undefined, data.response);
515
+ assert.notEqual(null, data.response);
516
+ assert.equal(0, data.response.indexOf('{code}'));
517
+ done();
518
+ } catch (err) {
519
+ log.error(`Test Failure: ${err}`);
520
+ done(err);
521
+ }
522
+ });
523
+ } catch (error) {
524
+ log.error(`Adapter Exception: ${error}`);
525
+ done(error);
526
+ }
527
+ }).timeout(attemptTimeout);
528
+ it('should get encrypted property', (done) => {
529
+ try {
530
+ a.encryptProperty('testing', 'encrypt', (data, error) => {
531
+ try {
532
+ assert.equal(undefined, error);
533
+ assert.notEqual(undefined, data);
534
+ assert.notEqual(null, data);
535
+ assert.notEqual(undefined, data.response);
536
+ assert.notEqual(null, data.response);
537
+ assert.equal(0, data.response.indexOf('{crypt}'));
538
+ done();
539
+ } catch (err) {
540
+ log.error(`Test Failure: ${err}`);
541
+ done(err);
542
+ }
543
+ });
544
+ } catch (error) {
545
+ log.error(`Adapter Exception: ${error}`);
546
+ done(error);
547
+ }
548
+ }).timeout(attemptTimeout);
549
+ });
550
+
551
+ describe('#iapUpdateAdapterConfiguration', () => {
552
+ it('should have a iapUpdateAdapterConfiguration function', (done) => {
553
+ try {
554
+ assert.equal(true, typeof a.iapUpdateAdapterConfiguration === 'function');
555
+ done();
556
+ } catch (error) {
557
+ log.error(`Test Failure: ${error}`);
558
+ done(error);
559
+ }
560
+ });
561
+ it('should return no updated if no changes are provided', (done) => {
562
+ try {
563
+ a.iapUpdateAdapterConfiguration(null, null, null, null, null, null, (data, error) => {
564
+ try {
565
+ assert.equal('No configuration updates to make', data.response);
566
+ done();
567
+ } catch (err) {
568
+ log.error(`Test Failure: ${err}`);
569
+ done(err);
570
+ }
571
+ });
572
+ } catch (error) {
573
+ log.error(`Adapter Exception: ${error}`);
574
+ done(error);
575
+ }
576
+ }).timeout(attemptTimeout);
577
+ it('should throw an error if missing configuration file', (done) => {
578
+ try {
579
+ a.iapUpdateAdapterConfiguration(null, { name: 'fakeChange' }, null, null, null, null, (data, error) => {
580
+ try {
581
+ const displayE = 'configFile is required';
582
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
583
+ done();
584
+ } catch (err) {
585
+ log.error(`Test Failure: ${err}`);
586
+ done(err);
587
+ }
588
+ });
589
+ } catch (error) {
590
+ log.error(`Adapter Exception: ${error}`);
591
+ done(error);
592
+ }
593
+ }).timeout(attemptTimeout);
594
+ it('if not package.json, entity is required', (done) => {
595
+ try {
596
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, null, null, null, null, (data, error) => {
597
+ try {
598
+ const displayE = 'Unsupported Configuration Change or Missing Entity';
599
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
600
+ done();
601
+ } catch (err) {
602
+ log.error(`Test Failure: ${err}`);
603
+ done(err);
604
+ }
605
+ });
606
+ } catch (error) {
607
+ log.error(`Adapter Exception: ${error}`);
608
+ done(error);
609
+ }
610
+ }).timeout(attemptTimeout);
611
+ it('if not package.json, type is required', (done) => {
612
+ try {
613
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'entity', null, null, null, (data, error) => {
614
+ try {
615
+ const displayE = 'type is required';
616
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
617
+ done();
618
+ } catch (err) {
619
+ log.error(`Test Failure: ${err}`);
620
+ done(err);
621
+ }
622
+ });
623
+ } catch (error) {
624
+ log.error(`Adapter Exception: ${error}`);
625
+ done(error);
626
+ }
627
+ }).timeout(attemptTimeout);
628
+ it('if not package.json, entity must be valid', (done) => {
629
+ try {
630
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'fakeEntity', 'fakeType', null, null, (data, error) => {
631
+ try {
632
+ const displayE = 'Incomplete Configuration Change: Invalid Entity - fakeEntity';
633
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
634
+ done();
635
+ } catch (err) {
636
+ log.error(`Test Failure: ${err}`);
637
+ done(err);
638
+ }
639
+ });
640
+ } catch (error) {
641
+ log.error(`Adapter Exception: ${error}`);
642
+ done(error);
643
+ }
644
+ }).timeout(attemptTimeout);
645
+
646
+ // Single working test for action update
647
+ // it('should update an action configuration', (done) => {
648
+ // const adapterId = testData.pronghorn.id;
649
+
650
+ // // Create mock fs module with promises
651
+ // const mockFs = {
652
+ // existsSync: td.func('existsSync'),
653
+ // lstatSync: td.func('lstatSync'),
654
+ // promises: {
655
+ // writeFile: td.func('writeFile')
656
+ // }
657
+ // };
658
+
659
+ // // Replace fs module
660
+ // td.replace('fs', mockFs);
661
+ // td.replace('fs-extra', mockFs);
662
+
663
+ // // Mock MongoDB connection
664
+ // const mockMongoDBConnection = td.constructor(['connect', 'closeConnection']);
665
+ // td.replace('../../utils/mongoDbConnection', mockMongoDBConnection);
666
+
667
+ // // Set up MongoDB properties
668
+ // a.allProps = {
669
+ // mongo: {
670
+ // host: 'localhost',
671
+ // port: 27017,
672
+ // database: 'test'
673
+ // }
674
+ // };
675
+
676
+ // // Mock MongoDB operations
677
+ // const mockDb = {
678
+ // collection: td.func('collection')
679
+ // };
680
+ // const mockCollection = {
681
+ // findOne: td.func('findOne'),
682
+ // updateOne: td.func('updateOne')
683
+ // };
684
+
685
+ // td.when(mockMongoDBConnection.prototype.connect()).thenResolve({ db: mockDb });
686
+ // td.when(mockDb.collection('adapter_configs')).thenReturn(mockCollection);
687
+ // td.when(mockCollection.findOne(td.matchers.anything())).thenResolve({
688
+ // id: 'test',
689
+ // type: adapterId,
690
+ // entity: 'testEntity',
691
+ // actions: []
692
+ // });
693
+ // td.when(mockCollection.updateOne(td.matchers.anything(), td.matchers.anything())).thenResolve({ modifiedCount: 1 });
694
+
695
+ // // Test the update
696
+ // a.iapUpdateAdapterConfiguration(
697
+ // 'action.json',
698
+ // { name: 'testAction', method: 'GET', entitypath: '/test/path' },
699
+ // 'testEntity',
700
+ // 'action',
701
+ // 'testAction',
702
+ // null,
703
+ // (data, error) => {
704
+ // assert.equal(null, data);
705
+ // assert.notEqual(null, error);
706
+ // assert.equal('AD.999', error.icode);
707
+ // done();
708
+ // }
709
+ // );
710
+ // });
711
+
712
+ // it('should update a schema configuration', (done) => {
713
+ // const adapterId = testData.pronghorn.id;
714
+
715
+ // // Create mock fs module with promises
716
+ // const mockFs = {
717
+ // existsSync: td.func('existsSync'),
718
+ // lstatSync: td.func('lstatSync'),
719
+ // promises: {
720
+ // writeFile: td.func('writeFile')
721
+ // }
722
+ // };
723
+
724
+ // // Replace fs module
725
+ // td.replace('fs', mockFs);
726
+ // td.replace('fs-extra', mockFs);
727
+
728
+ // // Mock MongoDB connection
729
+ // const mockMongoDBConnection = td.constructor(['connect', 'closeConnection']);
730
+ // td.replace('../../utils/mongoDbConnection', mockMongoDBConnection);
731
+
732
+ // // Set up MongoDB properties
733
+ // a.allProps = {
734
+ // mongo: {
735
+ // host: 'localhost',
736
+ // port: 27017,
737
+ // database: 'test'
738
+ // }
739
+ // };
740
+
741
+ // // Mock MongoDB operations
742
+ // const mockDb = {
743
+ // collection: td.func('collection')
744
+ // };
745
+ // const mockCollection = {
746
+ // findOne: td.func('findOne'),
747
+ // updateOne: td.func('updateOne')
748
+ // };
749
+
750
+ // td.when(mockMongoDBConnection.prototype.connect()).thenResolve({ db: mockDb });
751
+ // td.when(mockDb.collection('adapter_configs')).thenReturn(mockCollection);
752
+ // td.when(mockCollection.findOne(td.matchers.anything())).thenResolve({
753
+ // id: 'test',
754
+ // type: adapterId,
755
+ // entity: 'testEntity',
756
+ // schema: []
757
+ // });
758
+ // td.when(mockCollection.updateOne(td.matchers.anything(), td.matchers.anything())).thenResolve({ modifiedCount: 1 });
759
+
760
+ // // Test the update
761
+ // a.iapUpdateAdapterConfiguration(
762
+ // 'schema.json',
763
+ // { type: 'object', properties: { newField: { type: 'string' } } },
764
+ // 'testEntity',
765
+ // 'schema',
766
+ // null,
767
+ // false,
768
+ // (data, error) => {
769
+ // assert.equal(null, data);
770
+ // assert.notEqual(null, error);
771
+ // assert.equal('AD.999', error.icode);
772
+ // done();
773
+ // }
774
+ // );
775
+ // });
776
+
777
+ // it('should update a mock data configuration', (done) => {
778
+ // const adapterId = testData.pronghorn.id;
779
+
780
+ // // Create mock fs module with promises
781
+ // const mockFs = {
782
+ // existsSync: td.func('existsSync'),
783
+ // lstatSync: td.func('lstatSync'),
784
+ // promises: {
785
+ // writeFile: td.func('writeFile'),
786
+ // mkdir: td.func('mkdir')
787
+ // }
788
+ // };
789
+
790
+ // // Replace fs module
791
+ // td.replace('fs', mockFs);
792
+ // td.replace('fs-extra', mockFs);
793
+
794
+ // // Mock MongoDB connection
795
+ // const mockMongoDBConnection = td.constructor(['connect', 'closeConnection']);
796
+ // td.replace('../../utils/mongoDbConnection', mockMongoDBConnection);
797
+
798
+ // // Set up MongoDB properties
799
+ // a.allProps = {
800
+ // mongo: {
801
+ // host: 'localhost',
802
+ // port: 27017,
803
+ // database: 'test'
804
+ // }
805
+ // };
806
+
807
+ // // Mock MongoDB operations
808
+ // const mockDb = {
809
+ // collection: td.func('collection')
810
+ // };
811
+ // const mockCollection = {
812
+ // findOne: td.func('findOne'),
813
+ // updateOne: td.func('updateOne')
814
+ // };
815
+
816
+ // td.when(mockMongoDBConnection.prototype.connect()).thenResolve({ db: mockDb });
817
+ // td.when(mockDb.collection('adapter_configs')).thenReturn(mockCollection);
818
+ // td.when(mockCollection.findOne(td.matchers.anything())).thenResolve({
819
+ // id: 'test',
820
+ // type: adapterId,
821
+ // entity: 'testEntity',
822
+ // mockdatafiles: {}
823
+ // });
824
+ // td.when(mockCollection.updateOne(td.matchers.anything(), td.matchers.anything())).thenResolve({ modifiedCount: 1 });
825
+
826
+ // // Test the update
827
+ // a.iapUpdateAdapterConfiguration(
828
+ // 'mock.json',
829
+ // { testData: 'new value' },
830
+ // 'testEntity',
831
+ // 'mock',
832
+ // null,
833
+ // true,
834
+ // (data, error) => {
835
+ // assert.equal(null, data);
836
+ // assert.notEqual(null, error);
837
+ // assert.equal('AD.999', error.icode);
838
+ // done();
839
+ // }
840
+ // );
841
+ // });
842
+
843
+ // it('should handle MongoDB errors', (done) => {
844
+ // const adapterId = testData.pronghorn.id;
845
+ // const changes = {
846
+ // name: 'testAction',
847
+ // method: 'GET',
848
+ // entitypath: '/test/path'
849
+ // };
850
+
851
+ // // Mock MongoDBConnection to simulate error
852
+ // const originalMongoDBConnection = require('../../utils/mongoDbConnection').MongoDBConnection;
853
+ // const mockMongoDBConnection = {
854
+ // connect: td.func('connect'),
855
+ // db: {
856
+ // collection: td.func('collection')
857
+ // },
858
+ // closeConnection: td.func('closeConnection')
859
+ // };
860
+ // require('../../utils/mongoDbConnection').MongoDBConnection = function () {
861
+ // return mockMongoDBConnection;
862
+ // };
863
+
864
+ // // Set up MongoDB properties
865
+ // a.allProps = {
866
+ // mongo: {
867
+ // host: 'localhost',
868
+ // port: 27017,
869
+ // database: 'test'
870
+ // }
871
+ // };
872
+
873
+ // // Mock MongoDB operations to fail
874
+ // td.when(mockMongoDBConnection.connect()).thenReject(new Error('MongoDB error'));
875
+
876
+ // a.iapUpdateAdapterConfiguration('action.json', changes, 'testEntity', 'action', 'testAction', null, (data, error) => {
877
+ // assert.equal(null, data);
878
+ // assert.notEqual(null, error);
879
+ // assert.equal('AD.999', error.icode);
880
+ // // Restore original MongoDBConnection
881
+ // require('../../utils/mongoDbConnection').MongoDBConnection = originalMongoDBConnection;
882
+ // done();
883
+ // });
884
+ // }).timeout(attemptTimeout);
885
+ });
886
+
887
+ describe('#iapSuspendAdapter', () => {
888
+ it('should have a iapSuspendAdapter function', (done) => {
889
+ try {
890
+ assert.equal(true, typeof a.iapSuspendAdapter === 'function');
891
+ done();
892
+ } catch (error) {
893
+ log.error(`Test Failure: ${error}`);
894
+ done(error);
895
+ }
896
+ });
897
+ it('should successfully suspend the adapter', (done) => {
898
+ try {
899
+ a.iapSuspendAdapter('nopause', (data, error) => {
900
+ try {
901
+ assert.notEqual(null, data);
902
+ assert.notEqual(null, data.suspended);
903
+ assert.equal(true, data.suspended);
904
+ done();
905
+ } catch (err) {
906
+ log.error(`Test Failure: ${err}`);
907
+ done(err);
908
+ }
909
+ });
910
+ } catch (error) {
911
+ log.error(`Adapter Exception: ${error}`);
912
+ done(error);
913
+ }
914
+ }).timeout(attemptTimeout);
915
+ });
916
+
917
+ describe('#iapUnsuspendAdapter', () => {
918
+ it('should have a iapUnsuspendAdapter function', (done) => {
919
+ try {
920
+ assert.equal(true, typeof a.iapUnsuspendAdapter === 'function');
921
+ done();
922
+ } catch (error) {
923
+ log.error(`Test Failure: ${error}`);
924
+ done(error);
925
+ }
926
+ });
927
+ it('should successfully unsuspend the adapter', (done) => {
928
+ try {
929
+ a.iapUnsuspendAdapter((data, error) => {
930
+ try {
931
+ assert.notEqual(null, data);
932
+ assert.notEqual(null, data.suspend);
933
+ assert.equal(false, data.suspend);
934
+ done();
935
+ } catch (err) {
936
+ log.error(`Test Failure: ${err}`);
937
+ done(err);
938
+ }
939
+ });
940
+ } catch (error) {
941
+ log.error(`Adapter Exception: ${error}`);
942
+ done(error);
943
+ }
944
+ }).timeout(attemptTimeout);
945
+ });
946
+
947
+ describe('#iapGetAdapterQueue', () => {
948
+ it('should have a iapGetAdapterQueue function', (done) => {
949
+ try {
950
+ assert.equal(true, typeof a.iapGetAdapterQueue === 'function');
951
+ done();
952
+ } catch (error) {
953
+ log.error(`Test Failure: ${error}`);
954
+ done(error);
955
+ }
956
+ });
957
+ it('should get information for all of the requests currently in the queue', (done) => {
958
+ try {
959
+ const expectedFunctions = a.iapGetAdapterQueue();
960
+ try {
961
+ assert.equal(0, expectedFunctions.length);
962
+ done();
963
+ } catch (err) {
964
+ log.error(`Test Failure: ${err}`);
965
+ done(err);
966
+ }
967
+ } catch (error) {
968
+ log.error(`Adapter Exception: ${error}`);
969
+ done(error);
970
+ }
971
+ }).timeout(attemptTimeout);
972
+ });
973
+
974
+ describe('#iapFindAdapterPath', () => {
975
+ it('should have a iapFindAdapterPath function', (done) => {
976
+ try {
977
+ assert.equal(true, typeof a.iapFindAdapterPath === 'function');
978
+ done();
979
+ } catch (error) {
980
+ log.error(`Test Failure: ${error}`);
981
+ done(error);
982
+ }
983
+ });
984
+ it('should fail - missing path', (done) => {
985
+ try {
986
+ a.iapFindAdapterPath(null, (data, error) => {
987
+ try {
988
+ assert.notEqual(null, error);
989
+ assert.notEqual(null, error.message);
990
+ assert.equal('NO PATH PROVIDED!', error.message);
991
+ done();
992
+ } catch (err) {
993
+ log.error(`Test Failure: ${err}`);
994
+ done(err);
995
+ }
996
+ });
997
+ } catch (error) {
998
+ log.error(`Adapter Exception: ${error}`);
999
+ done(error);
1000
+ }
1001
+ }).timeout(attemptTimeout);
1002
+ });
1003
+
1004
+ describe('#iapTroubleshootAdapter', () => {
1005
+ beforeEach(() => {
1006
+ td.replace(troubleshootingAdapter, 'troubleshoot', td.func());
1007
+ });
1008
+
1009
+ afterEach(() => {
1010
+ td.reset();
1011
+ });
1012
+
1013
+ it('should have a iapTroubleshootAdapter function', (done) => {
1014
+ try {
1015
+ assert.equal(true, typeof a.iapTroubleshootAdapter === 'function');
1016
+ done();
1017
+ } catch (error) {
1018
+ log.error(`Test Failure: ${error}`);
1019
+ done(error);
1020
+ }
1021
+ });
1022
+
1023
+ // it('should successfully troubleshoot adapter with valid properties', (done) => {
1024
+ // try {
1025
+ // const mockResult = {
1026
+ // connectivity: { failCount: 0 },
1027
+ // healthCheck: true,
1028
+ // basicGet: { passCount: 1 }
1029
+ // };
1030
+
1031
+ // td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
1032
+ // .thenResolve(mockResult);
1033
+
1034
+ // a.iapTroubleshootAdapter({}, false, a, (result, error) => {
1035
+ // try {
1036
+ // assert.equal(undefined, error);
1037
+ // assert.notEqual(undefined, result);
1038
+ // assert.notEqual(null, result);
1039
+ // assert.equal(true, result.healthCheck);
1040
+ // assert.equal(0, result.connectivity.failCount);
1041
+ // assert.equal(1, result.basicGet.passCount);
1042
+ // done();
1043
+ // } catch (err) {
1044
+ // log.error(`Test Failure: ${err}`);
1045
+ // done(err);
1046
+ // }
1047
+ // });
1048
+ // } catch (error) {
1049
+ // log.error(`Adapter Exception: ${error}`);
1050
+ // done(error);
1051
+ // }
1052
+ // }).timeout(attemptTimeout);
1053
+
1054
+ // it('should handle failed troubleshooting', (done) => {
1055
+ // try {
1056
+ // const mockResult = {
1057
+ // connectivity: { failCount: 1 },
1058
+ // healthCheck: false,
1059
+ // basicGet: { passCount: 0 }
1060
+ // };
1061
+
1062
+ // td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
1063
+ // .thenResolve(mockResult);
1064
+
1065
+ // a.iapTroubleshootAdapter({}, false, a, (result, error) => {
1066
+ // try {
1067
+ // assert.equal(null, result);
1068
+ // assert.notEqual(undefined, error);
1069
+ // assert.notEqual(null, error);
1070
+ // assert.equal(false, error.healthCheck);
1071
+ // assert.equal(1, error.connectivity.failCount);
1072
+ // assert.equal(0, error.basicGet.passCount);
1073
+ // done();
1074
+ // } catch (err) {
1075
+ // log.error(`Test Failure: ${err}`);
1076
+ // done(err);
1077
+ // }
1078
+ // });
1079
+ // } catch (error) {
1080
+ // log.error(`Adapter Exception: ${error}`);
1081
+ // done(error);
1082
+ // }
1083
+ // }).timeout(attemptTimeout);
1084
+
1085
+ // it('should handle troubleshooting errors', (done) => {
1086
+ // try {
1087
+ // td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
1088
+ // .thenReject(new Error('Troubleshooting failed'));
1089
+
1090
+ // a.iapTroubleshootAdapter({}, false, a, (result, error) => {
1091
+ // try {
1092
+ // assert.equal(null, result);
1093
+ // assert.notEqual(undefined, error);
1094
+ // assert.notEqual(null, error);
1095
+ // assert.equal('Troubleshooting failed', error.message);
1096
+ // done();
1097
+ // } catch (err) {
1098
+ // log.error(`Test Failure: ${err}`);
1099
+ // done(err);
1100
+ // }
1101
+ // });
1102
+ // } catch (error) {
1103
+ // log.error(`Adapter Exception: ${error}`);
1104
+ // done(error);
1105
+ // }
1106
+ // }).timeout(attemptTimeout);
1107
+
1108
+ // it('should handle missing adapter instance', (done) => {
1109
+ // try {
1110
+ // a.iapTroubleshootAdapter({}, false, null, (result, error) => {
1111
+ // try {
1112
+ // assert.equal(null, result);
1113
+ // assert.notEqual(undefined, error);
1114
+ // assert.notEqual(null, error);
1115
+ // // Check for either error message format
1116
+ // assert.ok(
1117
+ // error.message === "Cannot read property 'healthCheck' of undefined"
1118
+ // || error.message === "Cannot read properties of undefined (reading 'healthCheck')",
1119
+ // `Unexpected error message: ${error.message}`
1120
+ // );
1121
+ // done();
1122
+ // } catch (err) {
1123
+ // log.error(`Test Failure: ${err}`);
1124
+ // done(err);
1125
+ // }
1126
+ // });
1127
+ // } catch (error) {
1128
+ // log.error(`Adapter Exception: ${error}`);
1129
+ // done(error);
1130
+ // }
1131
+ // }).timeout(attemptTimeout);
1132
+ });
1133
+
1134
+ describe('#iapRunAdapterHealthcheck', () => {
1135
+ it('should have a iapRunAdapterHealthcheck function', (done) => {
1136
+ try {
1137
+ assert.equal(true, typeof a.iapRunAdapterHealthcheck === 'function');
1138
+ done();
1139
+ } catch (error) {
1140
+ log.error(`Test Failure: ${error}`);
1141
+ done(error);
1142
+ }
1143
+ });
1144
+ });
1145
+
1146
+ describe('#iapRunAdapterConnectivity', () => {
1147
+ it('should have a iapRunAdapterConnectivity function', (done) => {
1148
+ try {
1149
+ assert.equal(true, typeof a.iapRunAdapterConnectivity === 'function');
1150
+ done();
1151
+ } catch (error) {
1152
+ log.error(`Test Failure: ${error}`);
1153
+ done(error);
1154
+ }
1155
+ });
1156
+ });
1157
+
1158
+ describe('#iapRunAdapterBasicGet', () => {
1159
+ it('should have a iapRunAdapterBasicGet function', (done) => {
1160
+ try {
1161
+ assert.equal(true, typeof a.iapRunAdapterBasicGet === 'function');
1162
+ done();
1163
+ } catch (error) {
1164
+ log.error(`Test Failure: ${error}`);
1165
+ done(error);
1166
+ }
1167
+ });
1168
+ });
1169
+
1170
+ describe('#iapMoveAdapterEntitiesToDB', () => {
1171
+ it('should have a iapMoveAdapterEntitiesToDB function', (done) => {
1172
+ try {
1173
+ assert.equal(true, typeof a.iapMoveAdapterEntitiesToDB === 'function');
1174
+ done();
1175
+ } catch (error) {
1176
+ log.error(`Test Failure: ${error}`);
1177
+ done(error);
1178
+ }
1179
+ });
1180
+
1181
+ // describe('Connection String Tests', () => {
1182
+ // beforeEach(() => {
1183
+ // // Initialize allProps if it doesn't exist
1184
+ // if (!a.allProps) {
1185
+ // a.allProps = {};
1186
+ // }
1187
+ // // Initialize mongo properties with defaults
1188
+ // a.allProps.mongo = {
1189
+ // host: '',
1190
+ // port: 0,
1191
+ // database: '',
1192
+ // dbAuth: false,
1193
+ // username: '',
1194
+ // password: '',
1195
+ // replSet: '',
1196
+ // addSrv: false,
1197
+ // db_ssl: {
1198
+ // enabled: false,
1199
+ // accept_invalid_cert: false,
1200
+ // ca_file: '',
1201
+ // key_file: '',
1202
+ // cert_file: ''
1203
+ // }
1204
+ // };
1205
+ // });
1206
+
1207
+ // it('should prioritize URL over individual properties when both are provided', (done) => {
1208
+ // // Mock the moveEntitiesToDB function
1209
+ // entitiesToDB.moveEntitiesToDB = td.func();
1210
+
1211
+ // // Set both URL and individual properties
1212
+ // a.allProps.mongo.url = 'mongodb://localhost:27017/urldb';
1213
+ // a.allProps.mongo.host = 'differenthost';
1214
+ // a.allProps.mongo.port = 12345;
1215
+ // a.allProps.mongo.database = 'propdb';
1216
+
1217
+ // // Mock successful database operation
1218
+ // td.when(entitiesToDB.moveEntitiesToDB(
1219
+ // td.matchers.anything(),
1220
+ // td.matchers.contains({
1221
+ // pronghornProps: {
1222
+ // mongo: a.allProps.mongo
1223
+ // },
1224
+ // id: a.id
1225
+ // })
1226
+ // )).thenResolve({ insertedCount: 1 });
1227
+
1228
+ // // Call the function
1229
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1230
+ // try {
1231
+ // assert.notEqual(null, result);
1232
+ // assert.equal(null, error);
1233
+ // assert.equal(1, result.insertedCount);
1234
+ // done();
1235
+ // } catch (err) {
1236
+ // done(err);
1237
+ // }
1238
+ // });
1239
+ // }).timeout(attemptTimeout);
1240
+
1241
+ // it('should correctly form connection string from URL with database override', (done) => {
1242
+ // // Mock the moveEntitiesToDB function
1243
+ // entitiesToDB.moveEntitiesToDB = td.func();
1244
+
1245
+ // // Set URL-based connection with different database in URL vs properties
1246
+ // a.allProps.mongo.url = 'mongodb://localhost:27017/urldb';
1247
+ // a.allProps.mongo.database = 'propdb';
1248
+
1249
+ // // Mock successful database operation
1250
+ // td.when(entitiesToDB.moveEntitiesToDB(
1251
+ // td.matchers.anything(),
1252
+ // td.matchers.contains({
1253
+ // pronghornProps: {
1254
+ // mongo: a.allProps.mongo
1255
+ // },
1256
+ // id: a.id
1257
+ // })
1258
+ // )).thenResolve({ insertedCount: 1 });
1259
+
1260
+ // // Call the function
1261
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1262
+ // try {
1263
+ // assert.notEqual(null, result);
1264
+ // assert.equal(null, error);
1265
+ // assert.equal(1, result.insertedCount);
1266
+ // done();
1267
+ // } catch (err) {
1268
+ // done(err);
1269
+ // }
1270
+ // });
1271
+ // }).timeout(attemptTimeout);
1272
+
1273
+ // it('should correctly form connection string from individual properties with SSL', (done) => {
1274
+ // // Mock the moveEntitiesToDB function
1275
+ // entitiesToDB.moveEntitiesToDB = td.func();
1276
+
1277
+ // // Update adapter properties with SSL configuration without sensitive data
1278
+ // a.allProps.mongo = {
1279
+ // host: 'localhost',
1280
+ // port: 27017,
1281
+ // database: 'testdb',
1282
+ // replSet: 'rs0',
1283
+ // addSrv: false,
1284
+ // db_ssl: {
1285
+ // enabled: true,
1286
+ // accept_invalid_cert: true
1287
+ // }
1288
+ // };
1289
+
1290
+ // // Mock successful database operation
1291
+ // td.when(entitiesToDB.moveEntitiesToDB(
1292
+ // td.matchers.anything(),
1293
+ // td.matchers.contains({
1294
+ // pronghornProps: {
1295
+ // mongo: a.allProps.mongo
1296
+ // },
1297
+ // id: a.id
1298
+ // })
1299
+ // )).thenResolve({ insertedCount: 1 });
1300
+
1301
+ // // Call the function
1302
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1303
+ // try {
1304
+ // assert.notEqual(null, result);
1305
+ // assert.equal(null, error);
1306
+ // assert.equal(1, result.insertedCount);
1307
+ // done();
1308
+ // } catch (err) {
1309
+ // done(err);
1310
+ // }
1311
+ // });
1312
+ // }).timeout(attemptTimeout);
1313
+
1314
+ // it('should handle missing required properties', (done) => {
1315
+ // // Mock the moveEntitiesToDB function to throw an error
1316
+ // entitiesToDB.moveEntitiesToDB = td.func();
1317
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1318
+ // .thenReject(new Error('Missing required property: database'));
1319
+
1320
+ // // Call the function with incomplete properties
1321
+ // a.allProps.mongo = {
1322
+ // host: 'localhost',
1323
+ // port: 27017
1324
+ // // Missing database property
1325
+ // };
1326
+
1327
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1328
+ // try {
1329
+ // assert.equal(null, result);
1330
+ // assert.notEqual(null, error);
1331
+ // assert.equal('Missing required property: database', error);
1332
+ // done();
1333
+ // } catch (err) {
1334
+ // done(err);
1335
+ // }
1336
+ // });
1337
+ // }).timeout(attemptTimeout);
1338
+
1339
+ // it('should handle invalid URL format', (done) => {
1340
+ // // Mock the moveEntitiesToDB function to throw an error
1341
+ // entitiesToDB.moveEntitiesToDB = td.func();
1342
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1343
+ // .thenReject(new Error('Invalid URL format'));
1344
+
1345
+ // // Call the function with invalid URL
1346
+ // a.allProps.mongo.url = 'invalid-url';
1347
+
1348
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1349
+ // try {
1350
+ // assert.equal(null, result);
1351
+ // assert.notEqual(null, error);
1352
+ // assert.equal('Invalid URL format', error);
1353
+ // done();
1354
+ // } catch (err) {
1355
+ // done(err);
1356
+ // }
1357
+ // });
1358
+ // }).timeout(attemptTimeout);
1359
+
1360
+ // it('should handle connection errors gracefully', (done) => {
1361
+ // // Mock the moveEntitiesToDB function to throw a connection error
1362
+ // entitiesToDB.moveEntitiesToDB = td.func();
1363
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1364
+ // .thenReject(new Error('Failed to connect to MongoDB'));
1365
+
1366
+ // // Set valid connection properties
1367
+ // a.allProps.mongo = {
1368
+ // host: 'localhost',
1369
+ // port: 27017,
1370
+ // database: 'testdb'
1371
+ // };
1372
+
1373
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1374
+ // try {
1375
+ // assert.equal(null, result);
1376
+ // assert.notEqual(null, error);
1377
+ // assert.equal('Failed to connect to MongoDB', error);
1378
+ // done();
1379
+ // } catch (err) {
1380
+ // done(err);
1381
+ // }
1382
+ // });
1383
+ // }).timeout(attemptTimeout);
1384
+
1385
+ // it('should handle authentication errors', (done) => {
1386
+ // // Mock the moveEntitiesToDB function to throw an auth error
1387
+ // entitiesToDB.moveEntitiesToDB = td.func();
1388
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1389
+ // .thenReject(new Error('Authentication failed'));
1390
+
1391
+ // // Set properties without any sensitive data
1392
+ // a.allProps.mongo = {
1393
+ // host: 'localhost',
1394
+ // port: 27017,
1395
+ // database: 'testdb',
1396
+ // dbAuth: true
1397
+ // };
1398
+
1399
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1400
+ // try {
1401
+ // assert.equal(null, result);
1402
+ // assert.notEqual(null, error);
1403
+ // assert.equal('Authentication failed', error);
1404
+ // done();
1405
+ // } catch (err) {
1406
+ // done(err);
1407
+ // }
1408
+ // });
1409
+ // }).timeout(attemptTimeout);
1410
+
1411
+ // it('should handle missing connection properties', (done) => {
1412
+ // // Mock the moveEntitiesToDB function to throw an error
1413
+ // entitiesToDB.moveEntitiesToDB = td.func();
1414
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1415
+ // .thenReject(new Error('No connection properties provided'));
1416
+
1417
+ // // Clear all connection properties
1418
+ // a.allProps.mongo = {};
1419
+
1420
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1421
+ // try {
1422
+ // assert.equal(null, result);
1423
+ // assert.notEqual(null, error);
1424
+ // assert.equal('No connection properties provided', error);
1425
+ // done();
1426
+ // } catch (err) {
1427
+ // done(err);
1428
+ // }
1429
+ // });
1430
+ // }).timeout(attemptTimeout);
1431
+ // });
1432
+ });
1433
+
1434
+ describe('#iapDeactivateTasks', () => {
1435
+ it('should have a iapDeactivateTasks function', (done) => {
1436
+ try {
1437
+ assert.equal(true, typeof a.iapDeactivateTasks === 'function');
1438
+ done();
1439
+ } catch (error) {
1440
+ log.error(`Test Failure: ${error}`);
1441
+ done(error);
1442
+ }
1443
+ });
1444
+ });
1445
+
1446
+ describe('#iapActivateTasks', () => {
1447
+ it('should have a iapActivateTasks function', (done) => {
1448
+ try {
1449
+ assert.equal(true, typeof a.iapActivateTasks === 'function');
1450
+ done();
1451
+ } catch (error) {
1452
+ log.error(`Test Failure: ${error}`);
1453
+ done(error);
1454
+ }
1455
+ });
1456
+ });
1457
+
1458
+ describe('#iapPopulateEntityCache', () => {
1459
+ it('should have a iapPopulateEntityCache function', (done) => {
1460
+ try {
1461
+ assert.equal(true, typeof a.iapPopulateEntityCache === 'function');
1462
+ done();
1463
+ } catch (error) {
1464
+ log.error(`Test Failure: ${error}`);
1465
+ done(error);
1466
+ }
1467
+ });
1468
+ });
1469
+
1470
+ describe('#iapRetrieveEntitiesCache', () => {
1471
+ it('should have a iapRetrieveEntitiesCache function', (done) => {
1472
+ try {
1473
+ assert.equal(true, typeof a.iapRetrieveEntitiesCache === 'function');
1474
+ done();
1475
+ } catch (error) {
1476
+ log.error(`Test Failure: ${error}`);
1477
+ done(error);
1478
+ }
1479
+ });
1480
+ });
1481
+
1482
+ describe('#hasEntities', () => {
1483
+ it('should have a hasEntities function', (done) => {
1484
+ try {
1485
+ assert.equal(true, typeof a.hasEntities === 'function');
1486
+ done();
1487
+ } catch (error) {
1488
+ log.error(`Test Failure: ${error}`);
1489
+ done(error);
1490
+ }
1491
+ });
1492
+ });
1493
+
1494
+ describe('#getDevice', () => {
1495
+ it('should have a getDevice function', (done) => {
1496
+ try {
1497
+ assert.equal(true, typeof a.getDevice === 'function');
1498
+ done();
1499
+ } catch (error) {
1500
+ log.error(`Test Failure: ${error}`);
1501
+ done(error);
1502
+ }
1503
+ });
1504
+ });
1505
+
1506
+ describe('#getDevicesFiltered', () => {
1507
+ it('should have a getDevicesFiltered function', (done) => {
1508
+ try {
1509
+ assert.equal(true, typeof a.getDevicesFiltered === 'function');
1510
+ done();
1511
+ } catch (error) {
1512
+ log.error(`Test Failure: ${error}`);
1513
+ done(error);
1514
+ }
1515
+ });
1516
+ });
1517
+
1518
+ describe('#isAlive', () => {
1519
+ it('should have a isAlive function', (done) => {
1520
+ try {
1521
+ assert.equal(true, typeof a.isAlive === 'function');
1522
+ done();
1523
+ } catch (error) {
1524
+ log.error(`Test Failure: ${error}`);
1525
+ done(error);
1526
+ }
1527
+ });
1528
+ });
1529
+
1530
+ describe('#getConfig', () => {
1531
+ it('should have a getConfig function', (done) => {
1532
+ try {
1533
+ assert.equal(true, typeof a.getConfig === 'function');
1534
+ done();
1535
+ } catch (error) {
1536
+ log.error(`Test Failure: ${error}`);
1537
+ done(error);
1538
+ }
1539
+ });
1540
+ });
1541
+
1542
+ describe('#iapGetDeviceCount', () => {
1543
+ it('should have a iapGetDeviceCount function', (done) => {
1544
+ try {
1545
+ assert.equal(true, typeof a.iapGetDeviceCount === 'function');
1546
+ done();
1547
+ } catch (error) {
1548
+ log.error(`Test Failure: ${error}`);
1549
+ done(error);
1550
+ }
1551
+ });
1552
+ });
1553
+
1554
+ describe('#iapExpandedGenericAdapterRequest', () => {
1555
+ it('should have a iapExpandedGenericAdapterRequest function', (done) => {
1556
+ try {
1557
+ assert.equal(true, typeof a.iapExpandedGenericAdapterRequest === 'function');
1558
+ done();
1559
+ } catch (error) {
1560
+ log.error(`Test Failure: ${error}`);
1561
+ done(error);
1562
+ }
1563
+ });
1564
+ });
1565
+
1566
+ describe('#genericAdapterRequest', () => {
1567
+ it('should have a genericAdapterRequest function', (done) => {
1568
+ try {
1569
+ assert.equal(true, typeof a.genericAdapterRequest === 'function');
1570
+ done();
1571
+ } catch (error) {
1572
+ log.error(`Test Failure: ${error}`);
1573
+ done(error);
1574
+ }
1575
+ });
1576
+ });
1577
+
1578
+ describe('#genericAdapterRequestNoBasePath', () => {
1579
+ it('should have a genericAdapterRequestNoBasePath function', (done) => {
1580
+ try {
1581
+ assert.equal(true, typeof a.genericAdapterRequestNoBasePath === 'function');
1582
+ done();
1583
+ } catch (error) {
1584
+ log.error(`Test Failure: ${error}`);
1585
+ done(error);
1586
+ }
1587
+ });
1588
+ });
1589
+
1590
+ describe('#iapRunAdapterLint', () => {
1591
+ it('should have a iapRunAdapterLint function', (done) => {
1592
+ try {
1593
+ assert.equal(true, typeof a.iapRunAdapterLint === 'function');
1594
+ done();
1595
+ } catch (error) {
1596
+ log.error(`Test Failure: ${error}`);
1597
+ done(error);
1598
+ }
1599
+ });
1600
+ });
1601
+
1602
+ describe('#iapRunAdapterTests', () => {
1603
+ it('should have a iapRunAdapterTests function', (done) => {
1604
+ try {
1605
+ assert.equal(true, typeof a.iapRunAdapterTests === 'function');
1606
+ done();
1607
+ } catch (error) {
1608
+ log.error(`Test Failure: ${error}`);
1609
+ done(error);
1610
+ }
1611
+ });
1612
+ });
1613
+
1614
+ describe('#iapGetAdapterInventory', () => {
1615
+ it('should have a iapGetAdapterInventory function', (done) => {
1616
+ try {
1617
+ assert.equal(true, typeof a.iapGetAdapterInventory === 'function');
1618
+ done();
1619
+ } catch (error) {
1620
+ log.error(`Test Failure: ${error}`);
1621
+ done(error);
1622
+ }
1623
+ });
1624
+ });
1625
+ });
1626
+ });