@itentialopensource/adapter-sendgrid 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 (182) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.jshintrc +3 -0
  4. package/AUTH.md +31 -0
  5. package/BROKER.md +211 -0
  6. package/CALLS.md +2211 -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 +646 -0
  12. package/README.md +343 -0
  13. package/SUMMARY.md +9 -0
  14. package/SYSTEMINFO.md +20 -0
  15. package/TAB1.md +11 -0
  16. package/TAB2.md +302 -0
  17. package/TROUBLESHOOT.md +47 -0
  18. package/adapter.js +38033 -0
  19. package/adapterBase.js +1452 -0
  20. package/entities/.generic/action.json +214 -0
  21. package/entities/.generic/schema.json +28 -0
  22. package/entities/.system/action.json +50 -0
  23. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  24. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  25. package/entities/.system/schema.json +19 -0
  26. package/entities/.system/schemaTokenReq.json +53 -0
  27. package/entities/.system/schemaTokenResp.json +53 -0
  28. package/entities/APIKeyPermissions/action.json +25 -0
  29. package/entities/APIKeyPermissions/schema.json +19 -0
  30. package/entities/APIKeys/action.json +126 -0
  31. package/entities/APIKeys/schema.json +35 -0
  32. package/entities/Alerts/action.json +106 -0
  33. package/entities/Alerts/schema.json +34 -0
  34. package/entities/BlocksAPI/action.json +86 -0
  35. package/entities/BlocksAPI/schema.json +44 -0
  36. package/entities/BouncesAPI/action.json +86 -0
  37. package/entities/BouncesAPI/schema.json +55 -0
  38. package/entities/CSVUIOnly/action.json +45 -0
  39. package/entities/CSVUIOnly/schema.json +31 -0
  40. package/entities/CampaignsAPI/action.json +227 -0
  41. package/entities/CampaignsAPI/schema.json +40 -0
  42. package/entities/CancelScheduledSends/action.json +147 -0
  43. package/entities/CancelScheduledSends/schema.json +36 -0
  44. package/entities/Categories/action.json +67 -0
  45. package/entities/Categories/schema.json +76 -0
  46. package/entities/Certificates/action.json +106 -0
  47. package/entities/Certificates/schema.json +45 -0
  48. package/entities/Contacts/action.json +270 -0
  49. package/entities/Contacts/schema.json +42 -0
  50. package/entities/ContactsAPICustomFields/action.json +107 -0
  51. package/entities/ContactsAPICustomFields/schema.json +34 -0
  52. package/entities/ContactsAPILists/action.json +207 -0
  53. package/entities/ContactsAPILists/schema.json +72 -0
  54. package/entities/ContactsAPIRecipients/action.json +251 -0
  55. package/entities/ContactsAPIRecipients/schema.json +63 -0
  56. package/entities/ContactsAPISegments/action.json +127 -0
  57. package/entities/ContactsAPISegments/schema.json +57 -0
  58. package/entities/CustomFields/action.json +85 -0
  59. package/entities/CustomFields/schema.json +33 -0
  60. package/entities/DesignsAPI/action.json +188 -0
  61. package/entities/DesignsAPI/schema.json +49 -0
  62. package/entities/DomainAuthentication/action.json +248 -0
  63. package/entities/DomainAuthentication/schema.json +52 -0
  64. package/entities/EmailAddressValidation/action.json +24 -0
  65. package/entities/EmailAddressValidation/schema.json +19 -0
  66. package/entities/EmailCNAMERecords/action.json +24 -0
  67. package/entities/EmailCNAMERecords/schema.json +19 -0
  68. package/entities/IPAccessManagement/action.json +127 -0
  69. package/entities/IPAccessManagement/schema.json +35 -0
  70. package/entities/IPAddresses/action.json +108 -0
  71. package/entities/IPAddresses/schema.json +56 -0
  72. package/entities/IPPools/action.json +146 -0
  73. package/entities/IPPools/schema.json +36 -0
  74. package/entities/IPWarmup/action.json +86 -0
  75. package/entities/IPWarmup/schema.json +33 -0
  76. package/entities/InvalidEmailsAPI/action.json +86 -0
  77. package/entities/InvalidEmailsAPI/schema.json +44 -0
  78. package/entities/LinkBranding/action.json +208 -0
  79. package/entities/LinkBranding/schema.json +39 -0
  80. package/entities/Lists/action.json +147 -0
  81. package/entities/Lists/schema.json +80 -0
  82. package/entities/MailSend/action.json +24 -0
  83. package/entities/MailSend/schema.json +19 -0
  84. package/entities/MarketingCampaignsStats/action.json +172 -0
  85. package/entities/MarketingCampaignsStats/schema.json +147 -0
  86. package/entities/Query/action.json +46 -0
  87. package/entities/Query/schema.json +31 -0
  88. package/entities/ReverseDNS/action.json +106 -0
  89. package/entities/ReverseDNS/schema.json +23 -0
  90. package/entities/SegmentingContacts/action.json +126 -0
  91. package/entities/SegmentingContacts/schema.json +68 -0
  92. package/entities/SegmentingContactsV2/action.json +86 -0
  93. package/entities/SegmentingContactsV2/schema.json +66 -0
  94. package/entities/SegmentingContactsV2Beta/action.json +24 -0
  95. package/entities/SegmentingContactsV2Beta/schema.json +30 -0
  96. package/entities/SendTestEmail/action.json +24 -0
  97. package/entities/SendTestEmail/schema.json +19 -0
  98. package/entities/SenderIdentitiesAPI/action.json +126 -0
  99. package/entities/SenderIdentitiesAPI/schema.json +35 -0
  100. package/entities/SenderVerification/action.json +168 -0
  101. package/entities/SenderVerification/schema.json +26 -0
  102. package/entities/Senders/action.json +24 -0
  103. package/entities/Senders/schema.json +19 -0
  104. package/entities/SettingsEnforcedTLS/action.json +45 -0
  105. package/entities/SettingsEnforcedTLS/schema.json +20 -0
  106. package/entities/SettingsInboundParse/action.json +85 -0
  107. package/entities/SettingsInboundParse/schema.json +22 -0
  108. package/entities/SettingsMail/action.json +271 -0
  109. package/entities/SettingsMail/schema.json +31 -0
  110. package/entities/SettingsPartner/action.json +66 -0
  111. package/entities/SettingsPartner/schema.json +21 -0
  112. package/entities/SettingsTracking/action.json +189 -0
  113. package/entities/SettingsTracking/schema.json +27 -0
  114. package/entities/SingleSends/action.json +227 -0
  115. package/entities/SingleSends/schema.json +51 -0
  116. package/entities/SingleSignOnSettings/action.json +106 -0
  117. package/entities/SingleSignOnSettings/schema.json +23 -0
  118. package/entities/SingleSignOnTeammates/action.json +44 -0
  119. package/entities/SingleSignOnTeammates/schema.json +20 -0
  120. package/entities/SpamReportsAPI/action.json +86 -0
  121. package/entities/SpamReportsAPI/schema.json +44 -0
  122. package/entities/Stats/action.json +151 -0
  123. package/entities/Stats/schema.json +80 -0
  124. package/entities/SubuserMonitorSettings/action.json +85 -0
  125. package/entities/SubuserMonitorSettings/schema.json +33 -0
  126. package/entities/SubuserStatistics/action.json +88 -0
  127. package/entities/SubuserStatistics/schema.json +88 -0
  128. package/entities/SubusersAPI/action.json +126 -0
  129. package/entities/SubusersAPI/schema.json +35 -0
  130. package/entities/SuppressionsGlobalSuppressions/action.json +86 -0
  131. package/entities/SuppressionsGlobalSuppressions/schema.json +44 -0
  132. package/entities/SuppressionsSuppressions/action.json +127 -0
  133. package/entities/SuppressionsSuppressions/schema.json +35 -0
  134. package/entities/SuppressionsUnsubscribeGroups/action.json +106 -0
  135. package/entities/SuppressionsUnsubscribeGroups/schema.json +34 -0
  136. package/entities/Teammates/action.json +228 -0
  137. package/entities/Teammates/schema.json +40 -0
  138. package/entities/TransactionalTemplates/action.json +126 -0
  139. package/entities/TransactionalTemplates/schema.json +57 -0
  140. package/entities/TransactionalTemplatesVersions/action.json +105 -0
  141. package/entities/TransactionalTemplatesVersions/schema.json +45 -0
  142. package/entities/UsersAPI/action.json +189 -0
  143. package/entities/UsersAPI/schema.json +27 -0
  144. package/entities/Webhooks/action.json +148 -0
  145. package/entities/Webhooks/schema.json +58 -0
  146. package/error.json +190 -0
  147. package/metadata.json +77 -0
  148. package/package.json +81 -0
  149. package/pronghorn.json +17316 -0
  150. package/propertiesDecorators.json +14 -0
  151. package/propertiesSchema.json +1574 -0
  152. package/report/adapter-openapi.json +59750 -0
  153. package/report/adapter-openapi.yaml +43964 -0
  154. package/report/adapterInfo.json +10 -0
  155. package/report/auto-adapter-openapi.json +14137 -0
  156. package/report/creationReport.json +2750 -0
  157. package/report/sendgrid.json +48136 -0
  158. package/sampleProperties.json +257 -0
  159. package/test/integration/adapterTestBasicGet.js +83 -0
  160. package/test/integration/adapterTestConnectivity.js +118 -0
  161. package/test/integration/adapterTestIntegration.js +9099 -0
  162. package/test/unit/adapterBaseTestUnit.js +1024 -0
  163. package/test/unit/adapterTestUnit.js +8691 -0
  164. package/utils/adapterInfo.js +206 -0
  165. package/utils/addAuth.js +94 -0
  166. package/utils/artifactize.js +146 -0
  167. package/utils/basicGet.js +50 -0
  168. package/utils/checkMigrate.js +63 -0
  169. package/utils/entitiesToDB.js +179 -0
  170. package/utils/findPath.js +74 -0
  171. package/utils/methodDocumentor.js +273 -0
  172. package/utils/modify.js +152 -0
  173. package/utils/packModificationScript.js +35 -0
  174. package/utils/patches2bundledDeps.js +90 -0
  175. package/utils/pre-commit.sh +32 -0
  176. package/utils/removeHooks.js +20 -0
  177. package/utils/setup.js +33 -0
  178. package/utils/taskMover.js +309 -0
  179. package/utils/tbScript.js +239 -0
  180. package/utils/tbUtils.js +489 -0
  181. package/utils/testRunner.js +298 -0
  182. package/utils/troubleshootingAdapter.js +193 -0
@@ -0,0 +1,1024 @@
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 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
+
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('#connect', () => {
309
+ it('should have a connect function', (done) => {
310
+ try {
311
+ assert.equal(true, typeof a.connect === 'function');
312
+ done();
313
+ } catch (error) {
314
+ log.error(`Test Failure: ${error}`);
315
+ done(error);
316
+ }
317
+ });
318
+ it('should get connected - no healthcheck', (done) => {
319
+ try {
320
+ a.healthcheckType = 'none';
321
+ a.connect();
322
+
323
+ try {
324
+ assert.equal(true, a.alive);
325
+ done();
326
+ } catch (error) {
327
+ log.error(`Test Failure: ${error}`);
328
+ done(error);
329
+ }
330
+ } catch (error) {
331
+ log.error(`Adapter Exception: ${error}`);
332
+ done(error);
333
+ }
334
+ });
335
+ it('should get connected - startup healthcheck', (done) => {
336
+ try {
337
+ a.healthcheckType = 'startup';
338
+ a.connect();
339
+
340
+ try {
341
+ assert.equal(true, a.alive);
342
+ done();
343
+ } catch (error) {
344
+ log.error(`Test Failure: ${error}`);
345
+ done(error);
346
+ }
347
+ } catch (error) {
348
+ log.error(`Adapter Exception: ${error}`);
349
+ done(error);
350
+ }
351
+ });
352
+ });
353
+
354
+ describe('#healthCheck', () => {
355
+ it('should have a healthCheck function', (done) => {
356
+ try {
357
+ assert.equal(true, typeof a.healthCheck === 'function');
358
+ done();
359
+ } catch (error) {
360
+ log.error(`Test Failure: ${error}`);
361
+ done(error);
362
+ }
363
+ });
364
+ it('should be healthy', (done) => {
365
+ try {
366
+ a.healthCheck(null, (data) => {
367
+ try {
368
+ assert.equal(true, a.healthy);
369
+ done();
370
+ } catch (err) {
371
+ log.error(`Test Failure: ${err}`);
372
+ done(err);
373
+ }
374
+ });
375
+ } catch (error) {
376
+ log.error(`Adapter Exception: ${error}`);
377
+ done(error);
378
+ }
379
+ }).timeout(attemptTimeout);
380
+ });
381
+
382
+ describe('#getAllFunctions', () => {
383
+ it('should have a getAllFunctions function', (done) => {
384
+ try {
385
+ assert.equal(true, typeof a.getAllFunctions === 'function');
386
+ done();
387
+ } catch (error) {
388
+ log.error(`Test Failure: ${error}`);
389
+ done(error);
390
+ }
391
+ });
392
+ it('should return a list of functions', (done) => {
393
+ const returnedFunctions = ['checkActionFiles', 'checkProperties', 'connect', 'encryptProperty', 'genericAdapterRequest', 'genericAdapterRequestNoBasePath',
394
+ 'getAllFunctions', 'getConfig', 'getConfigAuth', 'getDevice', 'getDeviceAuth', 'getDevicesFiltered', 'getDevicesFilteredAuth', 'hasEntities', 'hasEntitiesAuth',
395
+ 'healthCheck', 'iapActivateTasks', 'iapDeactivateTasks', 'iapExpandedGenericAdapterRequest', 'iapFindAdapterPath', 'iapGetAdapterInventory', 'iapGetAdapterQueue',
396
+ 'iapGetAdapterWorkflowFunctions', 'iapGetDeviceCount', 'iapGetDeviceCountAuth', 'iapMoveAdapterEntitiesToDB', 'iapPopulateEntityCache', 'iapRetrieveEntitiesCache',
397
+ 'iapRunAdapterBasicGet', 'iapRunAdapterConnectivity', 'iapRunAdapterHealthcheck', 'iapRunAdapterLint', 'iapRunAdapterTests', 'iapSuspendAdapter', 'iapTroubleshootAdapter',
398
+ 'iapUnsuspendAdapter', 'iapUpdateAdapterConfiguration', 'isAlive', 'isAliveAuth', 'refreshProperties', 'addListener', 'emit', 'eventNames', 'getMaxListeners',
399
+ 'listenerCount', 'listeners', 'off', 'on', 'once', 'prependListener', 'prependOnceListener', 'rawListeners', 'removeAllListeners', 'removeListener', 'setMaxListeners'];
400
+ try {
401
+ const expectedFunctions = a.getAllFunctions();
402
+ try {
403
+ assert.equal(JSON.stringify(expectedFunctions), JSON.stringify(returnedFunctions));
404
+ done();
405
+ } catch (err) {
406
+ log.error(`Test Failure: ${err}`);
407
+ done(err);
408
+ }
409
+ } catch (error) {
410
+ log.error(`Adapter Exception: ${error}`);
411
+ done(error);
412
+ }
413
+ }).timeout(attemptTimeout);
414
+ });
415
+
416
+ describe('#iapGetAdapterWorkflowFunctions', () => {
417
+ it('should have a iapGetAdapterWorkflowFunctions function', (done) => {
418
+ try {
419
+ assert.equal(true, typeof a.iapGetAdapterWorkflowFunctions === 'function');
420
+ done();
421
+ } catch (error) {
422
+ log.error(`Test Failure: ${error}`);
423
+ done(error);
424
+ }
425
+ });
426
+ it('should retrieve workflow functions', (done) => {
427
+ try {
428
+ const expectedFunctions = a.iapGetAdapterWorkflowFunctions([]);
429
+ try {
430
+ assert.equal(0, expectedFunctions.length);
431
+ done();
432
+ } catch (err) {
433
+ log.error(`Test Failure: ${err}`);
434
+ done(err);
435
+ }
436
+ } catch (error) {
437
+ log.error(`Adapter Exception: ${error}`);
438
+ done(error);
439
+ }
440
+ }).timeout(attemptTimeout);
441
+ });
442
+
443
+ describe('#checkActionFiles', () => {
444
+ it('should have a checkActionFiles function', (done) => {
445
+ try {
446
+ assert.equal(true, typeof a.checkActionFiles === 'function');
447
+ done();
448
+ } catch (error) {
449
+ log.error(`Test Failure: ${error}`);
450
+ done(error);
451
+ }
452
+ });
453
+ it('the action files should be good - if failure change the log level as most issues are warnings', (done) => {
454
+ try {
455
+ const clean = a.checkActionFiles();
456
+ try {
457
+ for (let c = 0; c < clean.length; c += 1) {
458
+ log.error(clean[c]);
459
+ }
460
+ assert.equal(0, clean.length);
461
+ done();
462
+ } catch (err) {
463
+ log.error(`Test Failure: ${err}`);
464
+ done(err);
465
+ }
466
+ } catch (error) {
467
+ log.error(`Adapter Exception: ${error}`);
468
+ done(error);
469
+ }
470
+ }).timeout(attemptTimeout);
471
+ });
472
+
473
+ describe('#checkProperties', () => {
474
+ it('should have a checkProperties function', (done) => {
475
+ try {
476
+ assert.equal(true, typeof a.checkProperties === 'function');
477
+ done();
478
+ } catch (error) {
479
+ log.error(`Test Failure: ${error}`);
480
+ done(error);
481
+ }
482
+ });
483
+ it('the sample properties should be good - if failure change the log level', (done) => {
484
+ try {
485
+ const samplePropsJson = require('../../sampleProperties.json');
486
+ const clean = a.checkProperties(samplePropsJson.properties);
487
+ try {
488
+ assert.notEqual(0, Object.keys(clean));
489
+ assert.equal(undefined, clean.exception);
490
+ assert.notEqual(undefined, clean.host);
491
+ assert.notEqual(null, clean.host);
492
+ assert.notEqual('', clean.host);
493
+ done();
494
+ } catch (err) {
495
+ log.error(`Test Failure: ${err}`);
496
+ done(err);
497
+ }
498
+ } catch (error) {
499
+ log.error(`Adapter Exception: ${error}`);
500
+ done(error);
501
+ }
502
+ }).timeout(attemptTimeout);
503
+ });
504
+
505
+ describe('#encryptProperty', () => {
506
+ it('should have a encryptProperty function', (done) => {
507
+ try {
508
+ assert.equal(true, typeof a.encryptProperty === 'function');
509
+ done();
510
+ } catch (error) {
511
+ log.error(`Test Failure: ${error}`);
512
+ done(error);
513
+ }
514
+ });
515
+ it('should get base64 encoded property', (done) => {
516
+ try {
517
+ a.encryptProperty('testing', 'base64', (data, error) => {
518
+ try {
519
+ assert.equal(undefined, error);
520
+ assert.notEqual(undefined, data);
521
+ assert.notEqual(null, data);
522
+ assert.notEqual(undefined, data.response);
523
+ assert.notEqual(null, data.response);
524
+ assert.equal(0, data.response.indexOf('{code}'));
525
+ done();
526
+ } catch (err) {
527
+ log.error(`Test Failure: ${err}`);
528
+ done(err);
529
+ }
530
+ });
531
+ } catch (error) {
532
+ log.error(`Adapter Exception: ${error}`);
533
+ done(error);
534
+ }
535
+ }).timeout(attemptTimeout);
536
+ it('should get encrypted property', (done) => {
537
+ try {
538
+ a.encryptProperty('testing', 'encrypt', (data, error) => {
539
+ try {
540
+ assert.equal(undefined, error);
541
+ assert.notEqual(undefined, data);
542
+ assert.notEqual(null, data);
543
+ assert.notEqual(undefined, data.response);
544
+ assert.notEqual(null, data.response);
545
+ assert.equal(0, data.response.indexOf('{crypt}'));
546
+ done();
547
+ } catch (err) {
548
+ log.error(`Test Failure: ${err}`);
549
+ done(err);
550
+ }
551
+ });
552
+ } catch (error) {
553
+ log.error(`Adapter Exception: ${error}`);
554
+ done(error);
555
+ }
556
+ }).timeout(attemptTimeout);
557
+ });
558
+
559
+ describe('#iapUpdateAdapterConfiguration', () => {
560
+ it('should have a iapUpdateAdapterConfiguration function', (done) => {
561
+ try {
562
+ assert.equal(true, typeof a.iapUpdateAdapterConfiguration === 'function');
563
+ done();
564
+ } catch (error) {
565
+ log.error(`Test Failure: ${error}`);
566
+ done(error);
567
+ }
568
+ });
569
+ it('should return no updated if no changes are provided', (done) => {
570
+ try {
571
+ a.iapUpdateAdapterConfiguration(null, null, null, null, null, null, (data, error) => {
572
+ try {
573
+ assert.equal('No configuration updates to make', data.response);
574
+ done();
575
+ } catch (err) {
576
+ log.error(`Test Failure: ${err}`);
577
+ done(err);
578
+ }
579
+ });
580
+ } catch (error) {
581
+ log.error(`Adapter Exception: ${error}`);
582
+ done(error);
583
+ }
584
+ }).timeout(attemptTimeout);
585
+ it('should throw an error if missing configuration file', (done) => {
586
+ try {
587
+ a.iapUpdateAdapterConfiguration(null, { name: 'fakeChange' }, null, null, null, null, (data, error) => {
588
+ try {
589
+ const displayE = 'configFile is required';
590
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
591
+ done();
592
+ } catch (err) {
593
+ log.error(`Test Failure: ${err}`);
594
+ done(err);
595
+ }
596
+ });
597
+ } catch (error) {
598
+ log.error(`Adapter Exception: ${error}`);
599
+ done(error);
600
+ }
601
+ }).timeout(attemptTimeout);
602
+ it('if not package.json, entity is required', (done) => {
603
+ try {
604
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, null, null, null, null, (data, error) => {
605
+ try {
606
+ const displayE = 'Unsupported Configuration Change or Missing Entity';
607
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
608
+ done();
609
+ } catch (err) {
610
+ log.error(`Test Failure: ${err}`);
611
+ done(err);
612
+ }
613
+ });
614
+ } catch (error) {
615
+ log.error(`Adapter Exception: ${error}`);
616
+ done(error);
617
+ }
618
+ }).timeout(attemptTimeout);
619
+ it('if not package.json, type is required', (done) => {
620
+ try {
621
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'entity', null, null, null, (data, error) => {
622
+ try {
623
+ const displayE = 'type is required';
624
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
625
+ done();
626
+ } catch (err) {
627
+ log.error(`Test Failure: ${err}`);
628
+ done(err);
629
+ }
630
+ });
631
+ } catch (error) {
632
+ log.error(`Adapter Exception: ${error}`);
633
+ done(error);
634
+ }
635
+ }).timeout(attemptTimeout);
636
+ it('if not package.json, entity must be valid', (done) => {
637
+ try {
638
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'fakeEntity', 'fakeType', null, null, (data, error) => {
639
+ try {
640
+ const displayE = 'Incomplete Configuration Change: Invalid Entity - fakeEntity';
641
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
642
+ done();
643
+ } catch (err) {
644
+ log.error(`Test Failure: ${err}`);
645
+ done(err);
646
+ }
647
+ });
648
+ } catch (error) {
649
+ log.error(`Adapter Exception: ${error}`);
650
+ done(error);
651
+ }
652
+ }).timeout(attemptTimeout);
653
+ });
654
+
655
+ describe('#iapSuspendAdapter', () => {
656
+ it('should have a iapSuspendAdapter function', (done) => {
657
+ try {
658
+ assert.equal(true, typeof a.iapSuspendAdapter === 'function');
659
+ done();
660
+ } catch (error) {
661
+ log.error(`Test Failure: ${error}`);
662
+ done(error);
663
+ }
664
+ });
665
+ it('should successfully suspend the adapter', (done) => {
666
+ try {
667
+ a.iapSuspendAdapter('nopause', (data, error) => {
668
+ try {
669
+ assert.notEqual(null, data);
670
+ assert.notEqual(null, data.suspended);
671
+ assert.equal(true, data.suspended);
672
+ done();
673
+ } catch (err) {
674
+ log.error(`Test Failure: ${err}`);
675
+ done(err);
676
+ }
677
+ });
678
+ } catch (error) {
679
+ log.error(`Adapter Exception: ${error}`);
680
+ done(error);
681
+ }
682
+ }).timeout(attemptTimeout);
683
+ });
684
+
685
+ describe('#iapUnsuspendAdapter', () => {
686
+ it('should have a iapUnsuspendAdapter function', (done) => {
687
+ try {
688
+ assert.equal(true, typeof a.iapUnsuspendAdapter === 'function');
689
+ done();
690
+ } catch (error) {
691
+ log.error(`Test Failure: ${error}`);
692
+ done(error);
693
+ }
694
+ });
695
+ it('should successfully unsuspend the adapter', (done) => {
696
+ try {
697
+ a.iapUnsuspendAdapter((data, error) => {
698
+ try {
699
+ assert.notEqual(null, data);
700
+ assert.notEqual(null, data.suspend);
701
+ assert.equal(false, data.suspend);
702
+ done();
703
+ } catch (err) {
704
+ log.error(`Test Failure: ${err}`);
705
+ done(err);
706
+ }
707
+ });
708
+ } catch (error) {
709
+ log.error(`Adapter Exception: ${error}`);
710
+ done(error);
711
+ }
712
+ }).timeout(attemptTimeout);
713
+ });
714
+
715
+ describe('#iapGetAdapterQueue', () => {
716
+ it('should have a iapGetAdapterQueue function', (done) => {
717
+ try {
718
+ assert.equal(true, typeof a.iapGetAdapterQueue === 'function');
719
+ done();
720
+ } catch (error) {
721
+ log.error(`Test Failure: ${error}`);
722
+ done(error);
723
+ }
724
+ });
725
+ it('should get information for all of the requests currently in the queue', (done) => {
726
+ try {
727
+ const expectedFunctions = a.iapGetAdapterQueue();
728
+ try {
729
+ assert.equal(0, expectedFunctions.length);
730
+ done();
731
+ } catch (err) {
732
+ log.error(`Test Failure: ${err}`);
733
+ done(err);
734
+ }
735
+ } catch (error) {
736
+ log.error(`Adapter Exception: ${error}`);
737
+ done(error);
738
+ }
739
+ }).timeout(attemptTimeout);
740
+ });
741
+
742
+ describe('#iapFindAdapterPath', () => {
743
+ it('should have a iapFindAdapterPath function', (done) => {
744
+ try {
745
+ assert.equal(true, typeof a.iapFindAdapterPath === 'function');
746
+ done();
747
+ } catch (error) {
748
+ log.error(`Test Failure: ${error}`);
749
+ done(error);
750
+ }
751
+ });
752
+ it('should fail - missing path', (done) => {
753
+ try {
754
+ a.iapFindAdapterPath(null, (data, error) => {
755
+ try {
756
+ assert.notEqual(null, error);
757
+ assert.notEqual(null, error.message);
758
+ assert.equal('NO PATH PROVIDED!', error.message);
759
+ done();
760
+ } catch (err) {
761
+ log.error(`Test Failure: ${err}`);
762
+ done(err);
763
+ }
764
+ });
765
+ } catch (error) {
766
+ log.error(`Adapter Exception: ${error}`);
767
+ done(error);
768
+ }
769
+ }).timeout(attemptTimeout);
770
+ });
771
+
772
+ describe('#iapTroubleshootAdapter', () => {
773
+ it('should have a iapTroubleshootAdapter function', (done) => {
774
+ try {
775
+ assert.equal(true, typeof a.iapTroubleshootAdapter === 'function');
776
+ done();
777
+ } catch (error) {
778
+ log.error(`Test Failure: ${error}`);
779
+ done(error);
780
+ }
781
+ });
782
+ });
783
+
784
+ describe('#iapRunAdapterHealthcheck', () => {
785
+ it('should have a iapRunAdapterHealthcheck function', (done) => {
786
+ try {
787
+ assert.equal(true, typeof a.iapRunAdapterHealthcheck === 'function');
788
+ done();
789
+ } catch (error) {
790
+ log.error(`Test Failure: ${error}`);
791
+ done(error);
792
+ }
793
+ });
794
+ });
795
+
796
+ describe('#iapRunAdapterConnectivity', () => {
797
+ it('should have a iapRunAdapterConnectivity function', (done) => {
798
+ try {
799
+ assert.equal(true, typeof a.iapRunAdapterConnectivity === 'function');
800
+ done();
801
+ } catch (error) {
802
+ log.error(`Test Failure: ${error}`);
803
+ done(error);
804
+ }
805
+ });
806
+ });
807
+
808
+ describe('#iapRunAdapterBasicGet', () => {
809
+ it('should have a iapRunAdapterBasicGet function', (done) => {
810
+ try {
811
+ assert.equal(true, typeof a.iapRunAdapterBasicGet === 'function');
812
+ done();
813
+ } catch (error) {
814
+ log.error(`Test Failure: ${error}`);
815
+ done(error);
816
+ }
817
+ });
818
+ });
819
+
820
+ describe('#iapMoveAdapterEntitiesToDB', () => {
821
+ it('should have a iapMoveAdapterEntitiesToDB function', (done) => {
822
+ try {
823
+ assert.equal(true, typeof a.iapMoveAdapterEntitiesToDB === 'function');
824
+ done();
825
+ } catch (error) {
826
+ log.error(`Test Failure: ${error}`);
827
+ done(error);
828
+ }
829
+ });
830
+ });
831
+
832
+ describe('#iapDeactivateTasks', () => {
833
+ it('should have a iapDeactivateTasks function', (done) => {
834
+ try {
835
+ assert.equal(true, typeof a.iapDeactivateTasks === 'function');
836
+ done();
837
+ } catch (error) {
838
+ log.error(`Test Failure: ${error}`);
839
+ done(error);
840
+ }
841
+ });
842
+ });
843
+
844
+ describe('#iapActivateTasks', () => {
845
+ it('should have a iapActivateTasks function', (done) => {
846
+ try {
847
+ assert.equal(true, typeof a.iapActivateTasks === 'function');
848
+ done();
849
+ } catch (error) {
850
+ log.error(`Test Failure: ${error}`);
851
+ done(error);
852
+ }
853
+ });
854
+ });
855
+
856
+ describe('#iapPopulateEntityCache', () => {
857
+ it('should have a iapPopulateEntityCache function', (done) => {
858
+ try {
859
+ assert.equal(true, typeof a.iapPopulateEntityCache === 'function');
860
+ done();
861
+ } catch (error) {
862
+ log.error(`Test Failure: ${error}`);
863
+ done(error);
864
+ }
865
+ });
866
+ });
867
+
868
+ describe('#iapRetrieveEntitiesCache', () => {
869
+ it('should have a iapRetrieveEntitiesCache function', (done) => {
870
+ try {
871
+ assert.equal(true, typeof a.iapRetrieveEntitiesCache === 'function');
872
+ done();
873
+ } catch (error) {
874
+ log.error(`Test Failure: ${error}`);
875
+ done(error);
876
+ }
877
+ });
878
+ });
879
+
880
+ describe('#hasEntities', () => {
881
+ it('should have a hasEntities function', (done) => {
882
+ try {
883
+ assert.equal(true, typeof a.hasEntities === 'function');
884
+ done();
885
+ } catch (error) {
886
+ log.error(`Test Failure: ${error}`);
887
+ done(error);
888
+ }
889
+ });
890
+ });
891
+
892
+ describe('#getDevice', () => {
893
+ it('should have a getDevice function', (done) => {
894
+ try {
895
+ assert.equal(true, typeof a.getDevice === 'function');
896
+ done();
897
+ } catch (error) {
898
+ log.error(`Test Failure: ${error}`);
899
+ done(error);
900
+ }
901
+ });
902
+ });
903
+
904
+ describe('#getDevicesFiltered', () => {
905
+ it('should have a getDevicesFiltered function', (done) => {
906
+ try {
907
+ assert.equal(true, typeof a.getDevicesFiltered === 'function');
908
+ done();
909
+ } catch (error) {
910
+ log.error(`Test Failure: ${error}`);
911
+ done(error);
912
+ }
913
+ });
914
+ });
915
+
916
+ describe('#isAlive', () => {
917
+ it('should have a isAlive function', (done) => {
918
+ try {
919
+ assert.equal(true, typeof a.isAlive === 'function');
920
+ done();
921
+ } catch (error) {
922
+ log.error(`Test Failure: ${error}`);
923
+ done(error);
924
+ }
925
+ });
926
+ });
927
+
928
+ describe('#getConfig', () => {
929
+ it('should have a getConfig function', (done) => {
930
+ try {
931
+ assert.equal(true, typeof a.getConfig === 'function');
932
+ done();
933
+ } catch (error) {
934
+ log.error(`Test Failure: ${error}`);
935
+ done(error);
936
+ }
937
+ });
938
+ });
939
+
940
+ describe('#iapGetDeviceCount', () => {
941
+ it('should have a iapGetDeviceCount function', (done) => {
942
+ try {
943
+ assert.equal(true, typeof a.iapGetDeviceCount === 'function');
944
+ done();
945
+ } catch (error) {
946
+ log.error(`Test Failure: ${error}`);
947
+ done(error);
948
+ }
949
+ });
950
+ });
951
+
952
+ describe('#iapExpandedGenericAdapterRequest', () => {
953
+ it('should have a iapExpandedGenericAdapterRequest function', (done) => {
954
+ try {
955
+ assert.equal(true, typeof a.iapExpandedGenericAdapterRequest === 'function');
956
+ done();
957
+ } catch (error) {
958
+ log.error(`Test Failure: ${error}`);
959
+ done(error);
960
+ }
961
+ });
962
+ });
963
+
964
+ describe('#genericAdapterRequest', () => {
965
+ it('should have a genericAdapterRequest function', (done) => {
966
+ try {
967
+ assert.equal(true, typeof a.genericAdapterRequest === 'function');
968
+ done();
969
+ } catch (error) {
970
+ log.error(`Test Failure: ${error}`);
971
+ done(error);
972
+ }
973
+ });
974
+ });
975
+
976
+ describe('#genericAdapterRequestNoBasePath', () => {
977
+ it('should have a genericAdapterRequestNoBasePath function', (done) => {
978
+ try {
979
+ assert.equal(true, typeof a.genericAdapterRequestNoBasePath === 'function');
980
+ done();
981
+ } catch (error) {
982
+ log.error(`Test Failure: ${error}`);
983
+ done(error);
984
+ }
985
+ });
986
+ });
987
+
988
+ describe('#iapRunAdapterLint', () => {
989
+ it('should have a iapRunAdapterLint function', (done) => {
990
+ try {
991
+ assert.equal(true, typeof a.iapRunAdapterLint === 'function');
992
+ done();
993
+ } catch (error) {
994
+ log.error(`Test Failure: ${error}`);
995
+ done(error);
996
+ }
997
+ });
998
+ });
999
+
1000
+ describe('#iapRunAdapterTests', () => {
1001
+ it('should have a iapRunAdapterTests function', (done) => {
1002
+ try {
1003
+ assert.equal(true, typeof a.iapRunAdapterTests === 'function');
1004
+ done();
1005
+ } catch (error) {
1006
+ log.error(`Test Failure: ${error}`);
1007
+ done(error);
1008
+ }
1009
+ });
1010
+ });
1011
+
1012
+ describe('#iapGetAdapterInventory', () => {
1013
+ it('should have a iapGetAdapterInventory function', (done) => {
1014
+ try {
1015
+ assert.equal(true, typeof a.iapGetAdapterInventory === 'function');
1016
+ done();
1017
+ } catch (error) {
1018
+ log.error(`Test Failure: ${error}`);
1019
+ done(error);
1020
+ }
1021
+ });
1022
+ });
1023
+ });
1024
+ });