@itentialopensource/adapter-meraki 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +12 -12
  3. package/CHANGELOG.md +32 -0
  4. package/README.md +270 -68
  5. package/adapter.js +2786 -24
  6. package/adapterBase.js +544 -17
  7. package/entities/.generic/action.json +109 -0
  8. package/entities/.generic/schema.json +23 -0
  9. package/entities/.system/action.json +1 -1
  10. package/entities/CameraQualityRetentionProfiles/action.json +3 -0
  11. package/entities/ConnectivityMonitoringDestinations/action.json +1 -0
  12. package/entities/DashboardBrandingPolicies/action.json +4 -0
  13. package/entities/Floorplans/action.json +3 -0
  14. package/entities/Licenses/action.json +5 -0
  15. package/entities/LinkAggregations/action.json +3 -0
  16. package/entities/MGConnectivityMonitoringDestinations/action.json +1 -0
  17. package/entities/MGDHCPSettings/action.json +1 -0
  18. package/entities/MGLANSettings/action.json +1 -0
  19. package/entities/MGPortforwardingRules/action.json +1 -0
  20. package/entities/MGSubnetPoolSettings/action.json +1 -0
  21. package/entities/MGUplinkSettings/action.json +1 -0
  22. package/entities/MXVLANPorts/action.json +1 -0
  23. package/entities/MXWarmSpareSettings/action.json +2 -0
  24. package/entities/NetFlowSettings/action.json +1 -0
  25. package/entities/Switch settings/action.json +9 -0
  26. package/entities/SwitchACLs/action.json +1 -0
  27. package/entities/SwitchPortsSchedules/action.json +3 -0
  28. package/entities/TrafficAnalysisSettings/action.json +1 -0
  29. package/entities/WirelessSettings/action.json +1 -0
  30. package/error.json +6 -0
  31. package/package.json +45 -23
  32. package/pronghorn.json +586 -16
  33. package/propertiesSchema.json +84 -11
  34. package/refs?service=git-upload-pack +0 -0
  35. package/report/meraki-newcalls-OpenApi3Json.json +5460 -0
  36. package/report/updateReport1594225126093.json +95 -0
  37. package/report/updateReport1615384306128.json +95 -0
  38. package/report/updateReport1642739939352.json +95 -0
  39. package/sampleProperties.json +20 -5
  40. package/test/integration/adapterTestBasicGet.js +85 -0
  41. package/test/integration/adapterTestConnectivity.js +93 -0
  42. package/test/integration/adapterTestIntegration.js +30 -11
  43. package/test/unit/adapterBaseTestUnit.js +944 -0
  44. package/test/unit/adapterTestUnit.js +638 -12
  45. package/utils/addAuth.js +94 -0
  46. package/utils/artifactize.js +9 -14
  47. package/utils/basicGet.js +50 -0
  48. package/utils/checkMigrate.js +63 -0
  49. package/utils/entitiesToDB.js +224 -0
  50. package/utils/findPath.js +74 -0
  51. package/utils/modify.js +154 -0
  52. package/utils/packModificationScript.js +1 -1
  53. package/utils/patches2bundledDeps.js +90 -0
  54. package/utils/pre-commit.sh +1 -1
  55. package/utils/removeHooks.js +20 -0
  56. package/utils/tbScript.js +169 -0
  57. package/utils/tbUtils.js +451 -0
  58. package/utils/troubleshootingAdapter.js +190 -0
  59. package/gl-code-quality-report.json +0 -1
@@ -0,0 +1,944 @@
1
+ // Set globals
2
+ /* global describe it log pronghornProps */
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 fs = require('fs-extra');
9
+ const mocha = require('mocha');
10
+ const path = require('path');
11
+ const winston = require('winston');
12
+ const { expect } = require('chai');
13
+ const { use } = require('chai');
14
+ const td = require('testdouble');
15
+
16
+ const anything = td.matchers.anything();
17
+
18
+ // stub and attemptTimeout are used throughout the code so set them here
19
+ let logLevel = 'none';
20
+ const stub = true;
21
+ const isRapidFail = false;
22
+ const attemptTimeout = 120000;
23
+
24
+ // these variables can be changed to run in integrated mode so easier to set them here
25
+ // always check these in with bogus data!!!
26
+ const host = 'replace.hostorip.here';
27
+ const username = 'username';
28
+ const password = 'password';
29
+ const protocol = 'http';
30
+ const port = 80;
31
+ const sslenable = false;
32
+ const sslinvalid = false;
33
+
34
+ // these are the adapter properties. You generally should not need to alter
35
+ // any of these after they are initially set up
36
+ global.pronghornProps = {
37
+ pathProps: {
38
+ encrypted: false
39
+ },
40
+ adapterProps: {
41
+ adapters: [{
42
+ id: 'Test-Base',
43
+ type: 'ABase',
44
+ properties: {
45
+ host,
46
+ port,
47
+ base_path: '/',
48
+ version: '',
49
+ cache_location: 'local',
50
+ encode_pathvars: true,
51
+ save_metric: false,
52
+ stub,
53
+ protocol,
54
+ authentication: {
55
+ auth_method: 'basic user_password',
56
+ username,
57
+ password,
58
+ token: '',
59
+ invalid_token_error: 401,
60
+ token_timeout: -1,
61
+ token_cache: 'local',
62
+ auth_field: 'header.headers.Authorization',
63
+ auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
64
+ auth_logging: false,
65
+ client_id: '',
66
+ client_secret: '',
67
+ grant_type: ''
68
+ },
69
+ healthcheck: {
70
+ type: 'none',
71
+ frequency: 60000,
72
+ query_object: {}
73
+ },
74
+ throttle: {
75
+ throttle_enabled: false,
76
+ number_pronghorns: 1,
77
+ sync_async: 'sync',
78
+ max_in_queue: 1000,
79
+ concurrent_max: 1,
80
+ expire_timeout: 0,
81
+ avg_runtime: 200,
82
+ priorities: [
83
+ {
84
+ value: 0,
85
+ percent: 100
86
+ }
87
+ ]
88
+ },
89
+ request: {
90
+ number_redirects: 0,
91
+ number_retries: 3,
92
+ limit_retry_error: [0],
93
+ failover_codes: [],
94
+ attempt_timeout: attemptTimeout,
95
+ global_request: {
96
+ payload: {},
97
+ uriOptions: {},
98
+ addlHeaders: {},
99
+ authData: {}
100
+ },
101
+ healthcheck_on_timeout: true,
102
+ return_raw: true,
103
+ archiving: false,
104
+ return_request: false
105
+ },
106
+ proxy: {
107
+ enabled: false,
108
+ host: '',
109
+ port: 1,
110
+ protocol: 'http',
111
+ username: '',
112
+ password: ''
113
+ },
114
+ ssl: {
115
+ ecdhCurve: '',
116
+ enabled: sslenable,
117
+ accept_invalid_cert: sslinvalid,
118
+ ca_file: '',
119
+ key_file: '',
120
+ cert_file: '',
121
+ secure_protocol: '',
122
+ ciphers: ''
123
+ },
124
+ mongo: {
125
+ host: '',
126
+ port: 0,
127
+ database: '',
128
+ username: '',
129
+ password: '',
130
+ replSet: '',
131
+ db_ssl: {
132
+ enabled: false,
133
+ accept_invalid_cert: false,
134
+ ca_file: '',
135
+ key_file: '',
136
+ cert_file: ''
137
+ }
138
+ }
139
+ }
140
+ }]
141
+ }
142
+ };
143
+
144
+ global.$HOME = `${__dirname}/../..`;
145
+
146
+ // set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
147
+ // this you may error on log.trace calls.
148
+ const myCustomLevels = {
149
+ levels: {
150
+ spam: 6,
151
+ trace: 5,
152
+ debug: 4,
153
+ info: 3,
154
+ warn: 2,
155
+ error: 1,
156
+ none: 0
157
+ }
158
+ };
159
+
160
+ // need to see if there is a log level passed in
161
+ process.argv.forEach((val) => {
162
+ // is there a log level defined to be passed in?
163
+ if (val.indexOf('--LOG') === 0) {
164
+ // get the desired log level
165
+ const inputVal = val.split('=')[1];
166
+
167
+ // validate the log level is supported, if so set it
168
+ if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
169
+ logLevel = inputVal;
170
+ }
171
+ }
172
+ });
173
+
174
+ // need to set global logging
175
+ global.log = winston.createLogger({
176
+ level: logLevel,
177
+ levels: myCustomLevels.levels,
178
+ transports: [
179
+ new winston.transports.Console()
180
+ ]
181
+ });
182
+
183
+ /**
184
+ * Runs the error asserts for the test
185
+ */
186
+ function runErrorAsserts(data, error, code, origin, displayStr) {
187
+ assert.equal(null, data);
188
+ assert.notEqual(undefined, error);
189
+ assert.notEqual(null, error);
190
+ assert.notEqual(undefined, error.IAPerror);
191
+ assert.notEqual(null, error.IAPerror);
192
+ assert.notEqual(undefined, error.IAPerror.displayString);
193
+ assert.notEqual(null, error.IAPerror.displayString);
194
+ assert.equal(code, error.icode);
195
+ assert.equal(origin, error.IAPerror.origin);
196
+ assert.equal(displayStr, error.IAPerror.displayString);
197
+ }
198
+
199
+ // require the adapter that we are going to be using
200
+ const AdapterBase = require('../../adapterBase');
201
+
202
+ // delete the .DS_Store directory in entities -- otherwise this will cause errors
203
+ const dirPath = path.join(__dirname, '../../entities/.DS_Store');
204
+ if (fs.existsSync(dirPath)) {
205
+ try {
206
+ fs.removeSync(dirPath);
207
+ console.log('.DS_Store deleted');
208
+ } catch (e) {
209
+ console.log('Error when deleting .DS_Store:', e);
210
+ }
211
+ }
212
+
213
+ describe('[unit] Adapter Base Test', () => {
214
+ describe('Adapter Base Class Tests', () => {
215
+ // Define constants we will use below
216
+ const a = new AdapterBase(
217
+ pronghornProps.adapterProps.adapters[0].id,
218
+ pronghornProps.adapterProps.adapters[0].properties
219
+ );
220
+
221
+ if (isRapidFail) {
222
+ const state = {};
223
+ state.passed = true;
224
+
225
+ mocha.afterEach(function x() {
226
+ state.passed = state.passed
227
+ && (this.currentTest.state === 'passed');
228
+ });
229
+ mocha.beforeEach(function x() {
230
+ if (!state.passed) {
231
+ return this.currentTest.skip();
232
+ }
233
+ return true;
234
+ });
235
+ }
236
+
237
+ describe('#class instance created', () => {
238
+ it('should be a class with properties', (done) => {
239
+ try {
240
+ assert.notEqual(null, a);
241
+ assert.notEqual(undefined, a);
242
+ assert.notEqual(null, a.allProps);
243
+ const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
244
+ assert.equal(check, a.healthcheckType);
245
+ done();
246
+ } catch (error) {
247
+ log.error(`Test Failure: ${error}`);
248
+ done(error);
249
+ }
250
+ }).timeout(attemptTimeout);
251
+ });
252
+
253
+ describe('adapterBase.js', () => {
254
+ it('should have an adapterBase.js', (done) => {
255
+ try {
256
+ fs.exists('adapterBase.js', (val) => {
257
+ assert.equal(true, val);
258
+ done();
259
+ });
260
+ } catch (error) {
261
+ log.error(`Test Failure: ${error}`);
262
+ done(error);
263
+ }
264
+ });
265
+ });
266
+
267
+ describe('#refreshProperties', () => {
268
+ it('should have a refreshProperties function', (done) => {
269
+ try {
270
+ assert.equal(true, typeof a.refreshProperties === 'function');
271
+ done();
272
+ } catch (error) {
273
+ log.error(`Test Failure: ${error}`);
274
+ done(error);
275
+ }
276
+ });
277
+ it('should update the properties file', (done) => {
278
+ try {
279
+ // Mock connections
280
+ a.requestHandlerInst.refreshProperties = td.func();
281
+ a.refreshProperties({ foo: 'bar' });
282
+ // Run assert to verify we have updated a
283
+ try {
284
+ assert.equal(true, a.allProps.foo === 'bar');
285
+ done();
286
+ } catch (err) {
287
+ log.error(`Test Failure: ${err}`);
288
+ done(err);
289
+ }
290
+ } catch (error) {
291
+ log.error(`Adapter Exception: ${error}`);
292
+ done(error);
293
+ }
294
+ }).timeout(attemptTimeout);
295
+ it('should fail if the validation does not match the schema', (done) => {
296
+ try {
297
+ // Mock connections
298
+ a.propUtilInst.mergeProperties = td.func();
299
+ a.refreshProperties('tacos');
300
+ done();
301
+ } catch (error) {
302
+ log.error(`Adapter Exception: ${error}`);
303
+ done(error);
304
+ }
305
+ }).timeout(attemptTimeout);
306
+ });
307
+
308
+ describe('#getAllFunctions', () => {
309
+ it('should have a getAllFunctions function', (done) => {
310
+ try {
311
+ assert.equal(true, typeof a.getAllFunctions === 'function');
312
+ done();
313
+ } catch (error) {
314
+ log.error(`Test Failure: ${error}`);
315
+ done(error);
316
+ }
317
+ });
318
+ it('should return a list of functions', (done) => {
319
+ const returnedFunctions = ['addEntityCache', 'capabilityResults', 'checkActionFiles', 'checkProperties', 'connect', 'encryptProperty',
320
+ 'entityInList', 'findPath', 'getAllCapabilities', 'getAllFunctions', 'getQueue', 'getWorkflowFunctions', 'healthCheck', 'moveEntitiesToDB',
321
+ 'refreshProperties', 'runBasicGet', 'runConnectivity', 'runHealthcheck', 'suspend', 'troubleshoot', 'unsuspend', 'updateAdapterConfiguration', 'addListener',
322
+ 'emit', 'eventNames', 'getMaxListeners', 'listenerCount', 'listeners', 'off', 'on', 'once', 'prependListener',
323
+ 'prependOnceListener', 'rawListeners', 'removeAllListeners', 'removeListener', 'setMaxListeners'];
324
+ try {
325
+ const expectedFunctions = a.getAllFunctions();
326
+ try {
327
+ assert.equal(JSON.stringify(expectedFunctions), JSON.stringify(returnedFunctions));
328
+ done();
329
+ } catch (err) {
330
+ log.error(`Test Failure: ${err}`);
331
+ done(err);
332
+ }
333
+ } catch (error) {
334
+ log.error(`Adapter Exception: ${error}`);
335
+ done(error);
336
+ }
337
+ }).timeout(attemptTimeout);
338
+ });
339
+
340
+ describe('#getWorkflowFunctions', () => {
341
+ it('should have a getWorkflowFunctions function', (done) => {
342
+ try {
343
+ assert.equal(true, typeof a.getWorkflowFunctions === 'function');
344
+ done();
345
+ } catch (error) {
346
+ log.error(`Test Failure: ${error}`);
347
+ done(error);
348
+ }
349
+ });
350
+ it('should retrieve workflow functions', (done) => {
351
+ try {
352
+ const expectedFunctions = a.getWorkflowFunctions([]);
353
+ try {
354
+ assert.equal(0, expectedFunctions.length);
355
+ done();
356
+ } catch (err) {
357
+ log.error(`Test Failure: ${err}`);
358
+ done(err);
359
+ }
360
+ } catch (error) {
361
+ log.error(`Adapter Exception: ${error}`);
362
+ done(error);
363
+ }
364
+ }).timeout(attemptTimeout);
365
+ });
366
+
367
+ describe('#checkProperties', () => {
368
+ it('should have a checkProperties function', (done) => {
369
+ try {
370
+ assert.equal(true, typeof a.checkProperties === 'function');
371
+ done();
372
+ } catch (error) {
373
+ log.error(`Test Failure: ${error}`);
374
+ done(error);
375
+ }
376
+ });
377
+ it('the sample properties should be good - if failure change the log level', (done) => {
378
+ try {
379
+ const samplePropsJson = require('../../sampleProperties.json');
380
+ const clean = a.checkProperties(samplePropsJson.properties);
381
+ try {
382
+ assert.notEqual(0, Object.keys(clean));
383
+ assert.equal(undefined, clean.exception);
384
+ assert.notEqual(undefined, clean.host);
385
+ assert.notEqual(null, clean.host);
386
+ assert.notEqual('', clean.host);
387
+ done();
388
+ } catch (err) {
389
+ log.error(`Test Failure: ${err}`);
390
+ done(err);
391
+ }
392
+ } catch (error) {
393
+ log.error(`Adapter Exception: ${error}`);
394
+ done(error);
395
+ }
396
+ }).timeout(attemptTimeout);
397
+ });
398
+
399
+ describe('#checkActionFiles', () => {
400
+ it('should have a checkActionFiles function', (done) => {
401
+ try {
402
+ assert.equal(true, typeof a.checkActionFiles === 'function');
403
+ done();
404
+ } catch (error) {
405
+ log.error(`Test Failure: ${error}`);
406
+ done(error);
407
+ }
408
+ });
409
+ it('the action files should be good - if failure change the log level as most issues are warnings', (done) => {
410
+ try {
411
+ const clean = a.checkActionFiles();
412
+ try {
413
+ for (let c = 0; c < clean.length; c += 1) {
414
+ log.error(clean[c]);
415
+ }
416
+ assert.equal(0, clean.length);
417
+ done();
418
+ } catch (err) {
419
+ log.error(`Test Failure: ${err}`);
420
+ done(err);
421
+ }
422
+ } catch (error) {
423
+ log.error(`Adapter Exception: ${error}`);
424
+ done(error);
425
+ }
426
+ }).timeout(attemptTimeout);
427
+ });
428
+
429
+ describe('#getQueue', () => {
430
+ it('should have a getQueue function', (done) => {
431
+ try {
432
+ assert.equal(true, typeof a.getQueue === 'function');
433
+ done();
434
+ } catch (error) {
435
+ log.error(`Test Failure: ${error}`);
436
+ done(error);
437
+ }
438
+ });
439
+ it('should get information for all of the requests currently in the queue', (done) => {
440
+ try {
441
+ const expectedFunctions = a.getQueue();
442
+ try {
443
+ assert.equal(0, expectedFunctions.length);
444
+ done();
445
+ } catch (err) {
446
+ log.error(`Test Failure: ${err}`);
447
+ done(err);
448
+ }
449
+ } catch (error) {
450
+ log.error(`Adapter Exception: ${error}`);
451
+ done(error);
452
+ }
453
+ }).timeout(attemptTimeout);
454
+ });
455
+
456
+ describe('#connect', () => {
457
+ it('should have a connect function', (done) => {
458
+ try {
459
+ assert.equal(true, typeof a.connect === 'function');
460
+ done();
461
+ } catch (error) {
462
+ log.error(`Test Failure: ${error}`);
463
+ done(error);
464
+ }
465
+ });
466
+ it('should get connected - no healthcheck', (done) => {
467
+ try {
468
+ a.healthcheckType = 'none';
469
+ a.connect();
470
+
471
+ try {
472
+ assert.equal(true, a.alive);
473
+ done();
474
+ } catch (error) {
475
+ log.error(`Test Failure: ${error}`);
476
+ done(error);
477
+ }
478
+ } catch (error) {
479
+ log.error(`Adapter Exception: ${error}`);
480
+ done(error);
481
+ }
482
+ });
483
+ it('should get connected - startup healthcheck', (done) => {
484
+ try {
485
+ a.healthcheckType = 'startup';
486
+ a.connect();
487
+
488
+ try {
489
+ assert.equal(true, a.alive);
490
+ done();
491
+ } catch (error) {
492
+ log.error(`Test Failure: ${error}`);
493
+ done(error);
494
+ }
495
+ } catch (error) {
496
+ log.error(`Adapter Exception: ${error}`);
497
+ done(error);
498
+ }
499
+ });
500
+ });
501
+
502
+ describe('#healthCheck', () => {
503
+ it('should have a healthCheck function', (done) => {
504
+ try {
505
+ assert.equal(true, typeof a.healthCheck === 'function');
506
+ done();
507
+ } catch (error) {
508
+ log.error(`Test Failure: ${error}`);
509
+ done(error);
510
+ }
511
+ });
512
+ it('should be healthy', (done) => {
513
+ try {
514
+ a.healthCheck(null, (data) => {
515
+ try {
516
+ assert.equal(true, a.healthy);
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
+ });
529
+
530
+ describe('#encryptProperty', () => {
531
+ it('should have a encryptProperty function', (done) => {
532
+ try {
533
+ assert.equal(true, typeof a.encryptProperty === 'function');
534
+ done();
535
+ } catch (error) {
536
+ log.error(`Test Failure: ${error}`);
537
+ done(error);
538
+ }
539
+ });
540
+ it('should get base64 encoded property', (done) => {
541
+ try {
542
+ a.encryptProperty('testing', 'base64', (data, error) => {
543
+ try {
544
+ assert.equal(undefined, error);
545
+ assert.notEqual(undefined, data);
546
+ assert.notEqual(null, data);
547
+ assert.notEqual(undefined, data.response);
548
+ assert.notEqual(null, data.response);
549
+ assert.equal(0, data.response.indexOf('{code}'));
550
+ done();
551
+ } catch (err) {
552
+ log.error(`Test Failure: ${err}`);
553
+ done(err);
554
+ }
555
+ });
556
+ } catch (error) {
557
+ log.error(`Adapter Exception: ${error}`);
558
+ done(error);
559
+ }
560
+ }).timeout(attemptTimeout);
561
+ it('should get encrypted property', (done) => {
562
+ try {
563
+ a.encryptProperty('testing', 'encrypt', (data, error) => {
564
+ try {
565
+ assert.equal(undefined, error);
566
+ assert.notEqual(undefined, data);
567
+ assert.notEqual(null, data);
568
+ assert.notEqual(undefined, data.response);
569
+ assert.notEqual(null, data.response);
570
+ assert.equal(0, data.response.indexOf('{crypt}'));
571
+ done();
572
+ } catch (err) {
573
+ log.error(`Test Failure: ${err}`);
574
+ done(err);
575
+ }
576
+ });
577
+ } catch (error) {
578
+ log.error(`Adapter Exception: ${error}`);
579
+ done(error);
580
+ }
581
+ }).timeout(attemptTimeout);
582
+ });
583
+
584
+ const entityType = 'mockType';
585
+ const entities = {
586
+ response: [
587
+ {
588
+ name: 'Godric Gryffindor'
589
+ }, {
590
+ name: 'Salazar Slytherin'
591
+ }
592
+ ]
593
+ };
594
+ const key = 'name';
595
+ describe('#addEntityCache', () => {
596
+ it('should have a addEntityCache function', (done) => {
597
+ try {
598
+ assert.equal(true, typeof a.addEntityCache === 'function');
599
+ done();
600
+ } catch (error) {
601
+ log.error(`Test Failure: ${error}`);
602
+ done(error);
603
+ }
604
+ });
605
+ it('should take the entities and add them to the cache', (done) => {
606
+ // Run the promise and verify the results match what we were expecting.
607
+ try {
608
+ a.addEntityCache(entityType, entities, key, (data, error) => {
609
+ try {
610
+ assert.equal(true, data);
611
+ done();
612
+ } catch (err) {
613
+ log.error(`Test Failure: ${err}`);
614
+ done(err);
615
+ }
616
+ });
617
+ } catch (error) {
618
+ log.error(`Adapter Exception: ${error}`);
619
+ done(error);
620
+ }
621
+ }).timeout(attemptTimeout);
622
+ });
623
+
624
+ const cache = [
625
+ 'Godric Gryffindor',
626
+ 'Salazar Slytherin'
627
+ ];
628
+ describe('#entityInList', () => {
629
+ it('should have a entityInList function', (done) => {
630
+ try {
631
+ assert.equal(true, typeof a.entityInList === 'function');
632
+ done();
633
+ } catch (error) {
634
+ log.error(`Test Failure: ${error}`);
635
+ done(error);
636
+ }
637
+ });
638
+ it('should return true if the entity is in the list of entities for this adapter', (done) => {
639
+ try {
640
+ const entityExist = a.entityInList('Godric Gryffindor', cache);
641
+ try {
642
+ assert.equal(true, entityExist[0]);
643
+ done();
644
+ } catch (err) {
645
+ log.error(`Test Failure: ${err}`);
646
+ done(err);
647
+ }
648
+ } catch (error) {
649
+ log.error(`Adapter Exception: ${error}`);
650
+ done(error);
651
+ }
652
+ }).timeout(attemptTimeout);
653
+ it('should return false if the entity is not in the list of entities for this adapter', (done) => {
654
+ try {
655
+ const entityExist = a.entityInList('XXXX', cache);
656
+ try {
657
+ assert.equal(false, entityExist[0]);
658
+ done();
659
+ } catch (err) {
660
+ log.error(`Test Failure: ${err}`);
661
+ done(err);
662
+ }
663
+ } catch (error) {
664
+ log.error(`Adapter Exception: ${error}`);
665
+ done(error);
666
+ }
667
+ }).timeout(attemptTimeout);
668
+ it('should return status of each item if an array is passed', (done) => {
669
+ try {
670
+ const entityExist = a.entityInList(['Godric Gryffindor', 'XXXX'], cache);
671
+ try {
672
+ assert.equal(true, entityExist[0]);
673
+ assert.equal(false, entityExist[1]);
674
+ done();
675
+ } catch (err) {
676
+ log.error(`Test Failure: ${err}`);
677
+ done(err);
678
+ }
679
+ } catch (error) {
680
+ log.error(`Adapter Exception: ${error}`);
681
+ done(error);
682
+ }
683
+ }).timeout(attemptTimeout);
684
+ });
685
+
686
+ describe('#capabilityResults', () => {
687
+ it('should have a capabilityResults function', (done) => {
688
+ try {
689
+ assert.equal(true, typeof a.capabilityResults === 'function');
690
+ done();
691
+ } catch (error) {
692
+ log.error(`Test Failure: ${error}`);
693
+ done(error);
694
+ }
695
+ });
696
+ it('should throw an error if needupdate is passed into the function', (done) => {
697
+ try {
698
+ const results = ['needupdate'];
699
+ a.capabilityResults(results, (data, error) => {
700
+ try {
701
+ const displayE = 'Could not load entity: unknown, into cache';
702
+ runErrorAsserts(data, error, 'AD.320', 'Test-Base-adapterBase-capabilityResults', displayE);
703
+ done();
704
+ } catch (err) {
705
+ log.error(`Test Failure: ${err}`);
706
+ done(err);
707
+ }
708
+ });
709
+ } catch (error) {
710
+ log.error(`Adapter Exception: ${error}`);
711
+ done(error);
712
+ }
713
+ }).timeout(attemptTimeout);
714
+ it('should throw an error if error is passed into the function', (done) => {
715
+ try {
716
+ const results = ['error'];
717
+ a.capabilityResults(results, (data, error) => {
718
+ try {
719
+ const displayE = 'Could not verify entity in cache';
720
+ runErrorAsserts(data, error, 'AD.321', 'Test-Base-adapterBase-capabilityResults', displayE);
721
+ done();
722
+ } catch (err) {
723
+ log.error(`Test Failure: ${err}`);
724
+ done(err);
725
+ }
726
+ });
727
+ } catch (error) {
728
+ log.error(`Adapter Exception: ${error}`);
729
+ done(error);
730
+ }
731
+ }).timeout(attemptTimeout);
732
+ it('should return null if nothing passed in', (done) => {
733
+ try {
734
+ const results = null;
735
+ a.capabilityResults(results, (data, error) => {
736
+ try {
737
+ assert.equal(null, data);
738
+ done();
739
+ } catch (err) {
740
+ log.error(`Test Failure: ${err}`);
741
+ done(err);
742
+ }
743
+ });
744
+ } catch (error) {
745
+ log.error(`Adapter Exception: ${error}`);
746
+ done(error);
747
+ }
748
+ }).timeout(attemptTimeout);
749
+ it('should return true if results is not an array and is "found"', (done) => {
750
+ try {
751
+ const results = 'found';
752
+ a.capabilityResults(results, (data, error) => {
753
+ try {
754
+ assert.equal(true, data[0]);
755
+ done();
756
+ } catch (err) {
757
+ log.error(`Test Failure: ${err}`);
758
+ done(err);
759
+ }
760
+ });
761
+ } catch (error) {
762
+ log.error(`Adapter Exception: ${error}`);
763
+ done(error);
764
+ }
765
+ }).timeout(attemptTimeout);
766
+ it('should return false if results is not an array and is not "found"', (done) => {
767
+ try {
768
+ const results = 'notfound';
769
+ a.capabilityResults(results, (data, error) => {
770
+ try {
771
+ assert.equal(false, data[0]);
772
+ done();
773
+ } catch (err) {
774
+ log.error(`Test Failure: ${err}`);
775
+ done(err);
776
+ }
777
+ });
778
+ } catch (error) {
779
+ log.error(`Adapter Exception: ${error}`);
780
+ done(error);
781
+ }
782
+ }).timeout(attemptTimeout);
783
+ it('should process an incoming array and return an array of values', (done) => {
784
+ try {
785
+ const results = ['found', 'notFound', 'found'];
786
+ a.capabilityResults(results, (data, error) => {
787
+ try {
788
+ assert.equal(true, data[0]);
789
+ assert.equal(false, data[1]);
790
+ assert.equal(true, data[2]);
791
+ done();
792
+ } catch (err) {
793
+ log.error(`Test Failure: ${err}`);
794
+ done(err);
795
+ }
796
+ });
797
+ } catch (error) {
798
+ log.error(`Adapter Exception: ${error}`);
799
+ done(error);
800
+ }
801
+ }).timeout(attemptTimeout);
802
+ });
803
+
804
+ describe('#getAllCapabilities', () => {
805
+ it('should have a getAllCapabilities function', (done) => {
806
+ try {
807
+ assert.equal(true, typeof a.getAllCapabilities === 'function');
808
+ done();
809
+ } catch (error) {
810
+ log.error(`Test Failure: ${error}`);
811
+ done(error);
812
+ }
813
+ });
814
+ it('should have capabilities returned', (done) => {
815
+ try {
816
+ const expectedCapabilities = a.getAllCapabilities();
817
+ try {
818
+ assert.notEqual(0, expectedCapabilities.length);
819
+ assert.equal('.generic', expectedCapabilities[0].entity);
820
+ assert.equal(5, expectedCapabilities[0].actions.length);
821
+ assert.equal('getGenerics', expectedCapabilities[0].actions[0]);
822
+ assert.equal('createGeneric', expectedCapabilities[0].actions[1]);
823
+ assert.equal('updateGeneric', expectedCapabilities[0].actions[2]);
824
+ assert.equal('patchGeneric', expectedCapabilities[0].actions[3]);
825
+ assert.equal('deleteGeneric', expectedCapabilities[0].actions[4]);
826
+ assert.equal('.system', expectedCapabilities[1].entity);
827
+ assert.equal(2, expectedCapabilities[1].actions.length);
828
+ assert.equal('getToken', expectedCapabilities[1].actions[0]);
829
+ assert.equal('healthcheck', expectedCapabilities[1].actions[1]);
830
+ for (let e = 1; e < expectedCapabilities.length; e += 1) {
831
+ assert.notEqual('', expectedCapabilities[e].entity);
832
+ assert.notEqual(null, expectedCapabilities[e].actions);
833
+ }
834
+ done();
835
+ } catch (err) {
836
+ log.error(`Test Failure: ${err}`);
837
+ done(err);
838
+ }
839
+ } catch (error) {
840
+ log.error(`Adapter Exception: ${error}`);
841
+ done(error);
842
+ }
843
+ }).timeout(attemptTimeout);
844
+ });
845
+
846
+ // const returnedFunctions = ['updateAdapterConfiguration'];
847
+
848
+ describe('#updateAdapterConfiguration', () => {
849
+ it('should have a updateAdapterConfiguration function', (done) => {
850
+ try {
851
+ assert.equal(true, typeof a.updateAdapterConfiguration === 'function');
852
+ done();
853
+ } catch (error) {
854
+ log.error(`Test Failure: ${error}`);
855
+ done(error);
856
+ }
857
+ });
858
+ it('should return no updated if no changes are provided', (done) => {
859
+ try {
860
+ a.updateAdapterConfiguration(null, null, null, null, null, (data, error) => {
861
+ try {
862
+ assert.equal('No configuration updates to make', data.response);
863
+ done();
864
+ } catch (err) {
865
+ log.error(`Test Failure: ${err}`);
866
+ done(err);
867
+ }
868
+ });
869
+ } catch (error) {
870
+ log.error(`Adapter Exception: ${error}`);
871
+ done(error);
872
+ }
873
+ }).timeout(attemptTimeout);
874
+ it('should throw an error if missing configuration file', (done) => {
875
+ try {
876
+ a.updateAdapterConfiguration(null, { name: 'fakeChange' }, null, null, null, (data, error) => {
877
+ try {
878
+ const displayE = 'configFile is required';
879
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
880
+ done();
881
+ } catch (err) {
882
+ log.error(`Test Failure: ${err}`);
883
+ done(err);
884
+ }
885
+ });
886
+ } catch (error) {
887
+ log.error(`Adapter Exception: ${error}`);
888
+ done(error);
889
+ }
890
+ }).timeout(attemptTimeout);
891
+ it('if not package.json, entity is required', (done) => {
892
+ try {
893
+ a.updateAdapterConfiguration('notPackage', { name: 'fakeChange' }, null, null, null, (data, error) => {
894
+ try {
895
+ const displayE = 'Unsupported Configuration Change or Missing Entity';
896
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
897
+ done();
898
+ } catch (err) {
899
+ log.error(`Test Failure: ${err}`);
900
+ done(err);
901
+ }
902
+ });
903
+ } catch (error) {
904
+ log.error(`Adapter Exception: ${error}`);
905
+ done(error);
906
+ }
907
+ }).timeout(attemptTimeout);
908
+ it('if not package.json, type is required', (done) => {
909
+ try {
910
+ a.updateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'entity', null, null, (data, error) => {
911
+ try {
912
+ const displayE = 'type is required';
913
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
914
+ done();
915
+ } catch (err) {
916
+ log.error(`Test Failure: ${err}`);
917
+ done(err);
918
+ }
919
+ });
920
+ } catch (error) {
921
+ log.error(`Adapter Exception: ${error}`);
922
+ done(error);
923
+ }
924
+ }).timeout(attemptTimeout);
925
+ it('if not package.json, entity must be valid', (done) => {
926
+ try {
927
+ a.updateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'fakeEntity', 'fakeType', null, (data, error) => {
928
+ try {
929
+ const displayE = 'Incomplete Configuration Change: Invalid Entity - fakeEntity';
930
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-updateAdapterConfiguration', displayE);
931
+ done();
932
+ } catch (err) {
933
+ log.error(`Test Failure: ${err}`);
934
+ done(err);
935
+ }
936
+ });
937
+ } catch (error) {
938
+ log.error(`Adapter Exception: ${error}`);
939
+ done(error);
940
+ }
941
+ }).timeout(attemptTimeout);
942
+ });
943
+ });
944
+ });