@itentialopensource/adapter-bluecat_ipam 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.
- package/.eslintignore +5 -0
- package/.eslintrc.js +19 -0
- package/.jshintrc +3 -0
- package/AUTH.md +39 -0
- package/BROKER.md +211 -0
- package/CALLS.md +3069 -0
- package/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +43 -0
- package/CONTRIBUTING.md +13 -0
- package/ENHANCE.md +69 -0
- package/LICENSE +201 -0
- package/PROPERTIES.md +681 -0
- package/README.md +344 -0
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +25 -0
- package/TAB1.md +15 -0
- package/TAB2.md +318 -0
- package/TROUBLESHOOT.md +56 -0
- package/UTILITIES.md +473 -0
- package/adapter.js +47832 -0
- package/adapterBase.js +1526 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/ACLResources/action.json +127 -0
- package/entities/ACLResources/schema.json +24 -0
- package/entities/AdminResources/action.json +1954 -0
- package/entities/AdminResources/schema.json +113 -0
- package/entities/ConfigurationResources/action.json +106 -0
- package/entities/ConfigurationResources/schema.json +23 -0
- package/entities/DHCPClientClassResources/action.json +250 -0
- package/entities/DHCPClientClassResources/schema.json +30 -0
- package/entities/DHCPZoneResources/action.json +250 -0
- package/entities/DHCPZoneResources/schema.json +30 -0
- package/entities/DNSSECResources/action.json +147 -0
- package/entities/DNSSECResources/schema.json +25 -0
- package/entities/DeploymentOptionResources/action.json +250 -0
- package/entities/DeploymentOptionResources/schema.json +30 -0
- package/entities/DeploymentRoleResources/action.json +169 -0
- package/entities/DeploymentRoleResources/schema.json +26 -0
- package/entities/DeviceResources/action.json +352 -0
- package/entities/DeviceResources/schema.json +35 -0
- package/entities/FavoriteResources/action.json +65 -0
- package/entities/FavoriteResources/schema.json +21 -0
- package/entities/IPv4AndIPv6Resources/action.json +1964 -0
- package/entities/IPv4AndIPv6Resources/schema.json +113 -0
- package/entities/KerberosResources/action.json +393 -0
- package/entities/KerberosResources/schema.json +37 -0
- package/entities/LocationResources/action.json +209 -0
- package/entities/LocationResources/schema.json +28 -0
- package/entities/MACAddressAndClientIdentifierResources/action.json +395 -0
- package/entities/MACAddressAndClientIdentifierResources/schema.json +37 -0
- package/entities/NamingPolicyResources/action.json +476 -0
- package/entities/NamingPolicyResources/schema.json +41 -0
- package/entities/ResourceRecordResources/action.json +377 -0
- package/entities/ResourceRecordResources/schema.json +36 -0
- package/entities/ServerResources/action.json +784 -0
- package/entities/ServerResources/schema.json +56 -0
- package/entities/TFTPResources/action.json +250 -0
- package/entities/TFTPResources/schema.json +30 -0
- package/entities/TagResources/action.json +495 -0
- package/entities/TagResources/schema.json +42 -0
- package/entities/TaskResources/action.json +106 -0
- package/entities/TaskResources/schema.json +23 -0
- package/entities/VendorProfileResources/action.json +106 -0
- package/entities/VendorProfileResources/schema.json +23 -0
- package/entities/ViewAndZoneResources/action.json +660 -0
- package/entities/ViewAndZoneResources/schema.json +50 -0
- package/error.json +190 -0
- package/metadata.json +84 -0
- package/package.json +75 -0
- package/pronghorn.json +34480 -0
- package/propertiesDecorators.json +18 -0
- package/propertiesSchema.json +1777 -0
- package/report/Bluecat IPAM 9.5 v2 API.yml-OpenApi3Json.json +114720 -0
- package/report/adapterInfo.json +10 -0
- package/report/auto-adapter-openapi.json +28663 -0
- package/report/creationReport.json +2910 -0
- package/sampleProperties.json +264 -0
- package/test/integration/adapterTestBasicGet.js +117 -0
- package/test/integration/adapterTestConnectivity.js +117 -0
- package/test/integration/adapterTestIntegration.js +12568 -0
- package/test/unit/adapterBaseTestUnit.js +1628 -0
- package/test/unit/adapterTestUnit.js +16058 -0
- package/utils/adapterInfo.js +156 -0
- package/utils/argParser.js +44 -0
- package/utils/checkMigrate.js +102 -0
- package/utils/entitiesToDB.js +190 -0
- package/utils/findPath.js +74 -0
- package/utils/logger.js +26 -0
- package/utils/methodDocumentor.js +298 -0
- package/utils/modify.js +153 -0
- package/utils/mongoDbConnection.js +79 -0
- package/utils/mongoUtils.js +162 -0
- package/utils/pre-commit.sh +32 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/taskMover.js +308 -0
- package/utils/tbScript.js +103 -0
- package/utils/tbUtils.js +347 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +177 -0
- package/utils/updateAdapterConfig.js +158 -0
|
@@ -0,0 +1,1628 @@
|
|
|
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', 'parseIapMetadata', '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
|
+
a.iapGetAdapterQueue((data, error) => {
|
|
960
|
+
try {
|
|
961
|
+
assert.notEqual(null, data);
|
|
962
|
+
assert.equal(0, data.length);
|
|
963
|
+
done();
|
|
964
|
+
} catch (err) {
|
|
965
|
+
log.error(`Test Failure: ${err}`);
|
|
966
|
+
done(err);
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
} catch (error) {
|
|
970
|
+
log.error(`Adapter Exception: ${error}`);
|
|
971
|
+
done(error);
|
|
972
|
+
}
|
|
973
|
+
}).timeout(attemptTimeout);
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
describe('#iapFindAdapterPath', () => {
|
|
977
|
+
it('should have a iapFindAdapterPath function', (done) => {
|
|
978
|
+
try {
|
|
979
|
+
assert.equal(true, typeof a.iapFindAdapterPath === 'function');
|
|
980
|
+
done();
|
|
981
|
+
} catch (error) {
|
|
982
|
+
log.error(`Test Failure: ${error}`);
|
|
983
|
+
done(error);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
it('should fail - missing path', (done) => {
|
|
987
|
+
try {
|
|
988
|
+
a.iapFindAdapterPath(null, (data, error) => {
|
|
989
|
+
try {
|
|
990
|
+
assert.notEqual(null, error);
|
|
991
|
+
assert.notEqual(null, error.message);
|
|
992
|
+
assert.equal('NO PATH PROVIDED!', error.message);
|
|
993
|
+
done();
|
|
994
|
+
} catch (err) {
|
|
995
|
+
log.error(`Test Failure: ${err}`);
|
|
996
|
+
done(err);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
} catch (error) {
|
|
1000
|
+
log.error(`Adapter Exception: ${error}`);
|
|
1001
|
+
done(error);
|
|
1002
|
+
}
|
|
1003
|
+
}).timeout(attemptTimeout);
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
describe('#iapTroubleshootAdapter', () => {
|
|
1007
|
+
beforeEach(() => {
|
|
1008
|
+
td.replace(troubleshootingAdapter, 'troubleshoot', td.func());
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
afterEach(() => {
|
|
1012
|
+
td.reset();
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
it('should have a iapTroubleshootAdapter function', (done) => {
|
|
1016
|
+
try {
|
|
1017
|
+
assert.equal(true, typeof a.iapTroubleshootAdapter === 'function');
|
|
1018
|
+
done();
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
log.error(`Test Failure: ${error}`);
|
|
1021
|
+
done(error);
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
// it('should successfully troubleshoot adapter with valid properties', (done) => {
|
|
1026
|
+
// try {
|
|
1027
|
+
// const mockResult = {
|
|
1028
|
+
// connectivity: { failCount: 0 },
|
|
1029
|
+
// healthCheck: true,
|
|
1030
|
+
// basicGet: { passCount: 1 }
|
|
1031
|
+
// };
|
|
1032
|
+
|
|
1033
|
+
// td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
|
|
1034
|
+
// .thenResolve(mockResult);
|
|
1035
|
+
|
|
1036
|
+
// a.iapTroubleshootAdapter({}, false, a, (result, error) => {
|
|
1037
|
+
// try {
|
|
1038
|
+
// assert.equal(undefined, error);
|
|
1039
|
+
// assert.notEqual(undefined, result);
|
|
1040
|
+
// assert.notEqual(null, result);
|
|
1041
|
+
// assert.equal(true, result.healthCheck);
|
|
1042
|
+
// assert.equal(0, result.connectivity.failCount);
|
|
1043
|
+
// assert.equal(1, result.basicGet.passCount);
|
|
1044
|
+
// done();
|
|
1045
|
+
// } catch (err) {
|
|
1046
|
+
// log.error(`Test Failure: ${err}`);
|
|
1047
|
+
// done(err);
|
|
1048
|
+
// }
|
|
1049
|
+
// });
|
|
1050
|
+
// } catch (error) {
|
|
1051
|
+
// log.error(`Adapter Exception: ${error}`);
|
|
1052
|
+
// done(error);
|
|
1053
|
+
// }
|
|
1054
|
+
// }).timeout(attemptTimeout);
|
|
1055
|
+
|
|
1056
|
+
// it('should handle failed troubleshooting', (done) => {
|
|
1057
|
+
// try {
|
|
1058
|
+
// const mockResult = {
|
|
1059
|
+
// connectivity: { failCount: 1 },
|
|
1060
|
+
// healthCheck: false,
|
|
1061
|
+
// basicGet: { passCount: 0 }
|
|
1062
|
+
// };
|
|
1063
|
+
|
|
1064
|
+
// td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
|
|
1065
|
+
// .thenResolve(mockResult);
|
|
1066
|
+
|
|
1067
|
+
// a.iapTroubleshootAdapter({}, false, a, (result, error) => {
|
|
1068
|
+
// try {
|
|
1069
|
+
// assert.equal(null, result);
|
|
1070
|
+
// assert.notEqual(undefined, error);
|
|
1071
|
+
// assert.notEqual(null, error);
|
|
1072
|
+
// assert.equal(false, error.healthCheck);
|
|
1073
|
+
// assert.equal(1, error.connectivity.failCount);
|
|
1074
|
+
// assert.equal(0, error.basicGet.passCount);
|
|
1075
|
+
// done();
|
|
1076
|
+
// } catch (err) {
|
|
1077
|
+
// log.error(`Test Failure: ${err}`);
|
|
1078
|
+
// done(err);
|
|
1079
|
+
// }
|
|
1080
|
+
// });
|
|
1081
|
+
// } catch (error) {
|
|
1082
|
+
// log.error(`Adapter Exception: ${error}`);
|
|
1083
|
+
// done(error);
|
|
1084
|
+
// }
|
|
1085
|
+
// }).timeout(attemptTimeout);
|
|
1086
|
+
|
|
1087
|
+
// it('should handle troubleshooting errors', (done) => {
|
|
1088
|
+
// try {
|
|
1089
|
+
// td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
|
|
1090
|
+
// .thenReject(new Error('Troubleshooting failed'));
|
|
1091
|
+
|
|
1092
|
+
// a.iapTroubleshootAdapter({}, false, a, (result, error) => {
|
|
1093
|
+
// try {
|
|
1094
|
+
// assert.equal(null, result);
|
|
1095
|
+
// assert.notEqual(undefined, error);
|
|
1096
|
+
// assert.notEqual(null, error);
|
|
1097
|
+
// assert.equal('Troubleshooting failed', error.message);
|
|
1098
|
+
// done();
|
|
1099
|
+
// } catch (err) {
|
|
1100
|
+
// log.error(`Test Failure: ${err}`);
|
|
1101
|
+
// done(err);
|
|
1102
|
+
// }
|
|
1103
|
+
// });
|
|
1104
|
+
// } catch (error) {
|
|
1105
|
+
// log.error(`Adapter Exception: ${error}`);
|
|
1106
|
+
// done(error);
|
|
1107
|
+
// }
|
|
1108
|
+
// }).timeout(attemptTimeout);
|
|
1109
|
+
|
|
1110
|
+
// it('should handle missing adapter instance', (done) => {
|
|
1111
|
+
// try {
|
|
1112
|
+
// a.iapTroubleshootAdapter({}, false, null, (result, error) => {
|
|
1113
|
+
// try {
|
|
1114
|
+
// assert.equal(null, result);
|
|
1115
|
+
// assert.notEqual(undefined, error);
|
|
1116
|
+
// assert.notEqual(null, error);
|
|
1117
|
+
// // Check for either error message format
|
|
1118
|
+
// assert.ok(
|
|
1119
|
+
// error.message === "Cannot read property 'healthCheck' of undefined"
|
|
1120
|
+
// || error.message === "Cannot read properties of undefined (reading 'healthCheck')",
|
|
1121
|
+
// `Unexpected error message: ${error.message}`
|
|
1122
|
+
// );
|
|
1123
|
+
// done();
|
|
1124
|
+
// } catch (err) {
|
|
1125
|
+
// log.error(`Test Failure: ${err}`);
|
|
1126
|
+
// done(err);
|
|
1127
|
+
// }
|
|
1128
|
+
// });
|
|
1129
|
+
// } catch (error) {
|
|
1130
|
+
// log.error(`Adapter Exception: ${error}`);
|
|
1131
|
+
// done(error);
|
|
1132
|
+
// }
|
|
1133
|
+
// }).timeout(attemptTimeout);
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
describe('#iapRunAdapterHealthcheck', () => {
|
|
1137
|
+
it('should have a iapRunAdapterHealthcheck function', (done) => {
|
|
1138
|
+
try {
|
|
1139
|
+
assert.equal(true, typeof a.iapRunAdapterHealthcheck === 'function');
|
|
1140
|
+
done();
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
log.error(`Test Failure: ${error}`);
|
|
1143
|
+
done(error);
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
describe('#iapRunAdapterConnectivity', () => {
|
|
1149
|
+
it('should have a iapRunAdapterConnectivity function', (done) => {
|
|
1150
|
+
try {
|
|
1151
|
+
assert.equal(true, typeof a.iapRunAdapterConnectivity === 'function');
|
|
1152
|
+
done();
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
log.error(`Test Failure: ${error}`);
|
|
1155
|
+
done(error);
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
1159
|
+
|
|
1160
|
+
describe('#iapRunAdapterBasicGet', () => {
|
|
1161
|
+
it('should have a iapRunAdapterBasicGet function', (done) => {
|
|
1162
|
+
try {
|
|
1163
|
+
assert.equal(true, typeof a.iapRunAdapterBasicGet === 'function');
|
|
1164
|
+
done();
|
|
1165
|
+
} catch (error) {
|
|
1166
|
+
log.error(`Test Failure: ${error}`);
|
|
1167
|
+
done(error);
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
describe('#iapMoveAdapterEntitiesToDB', () => {
|
|
1173
|
+
it('should have a iapMoveAdapterEntitiesToDB function', (done) => {
|
|
1174
|
+
try {
|
|
1175
|
+
assert.equal(true, typeof a.iapMoveAdapterEntitiesToDB === 'function');
|
|
1176
|
+
done();
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
log.error(`Test Failure: ${error}`);
|
|
1179
|
+
done(error);
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
// describe('Connection String Tests', () => {
|
|
1184
|
+
// beforeEach(() => {
|
|
1185
|
+
// // Initialize allProps if it doesn't exist
|
|
1186
|
+
// if (!a.allProps) {
|
|
1187
|
+
// a.allProps = {};
|
|
1188
|
+
// }
|
|
1189
|
+
// // Initialize mongo properties with defaults
|
|
1190
|
+
// a.allProps.mongo = {
|
|
1191
|
+
// host: '',
|
|
1192
|
+
// port: 0,
|
|
1193
|
+
// database: '',
|
|
1194
|
+
// dbAuth: false,
|
|
1195
|
+
// username: '',
|
|
1196
|
+
// password: '',
|
|
1197
|
+
// replSet: '',
|
|
1198
|
+
// addSrv: false,
|
|
1199
|
+
// db_ssl: {
|
|
1200
|
+
// enabled: false,
|
|
1201
|
+
// accept_invalid_cert: false,
|
|
1202
|
+
// ca_file: '',
|
|
1203
|
+
// key_file: '',
|
|
1204
|
+
// cert_file: ''
|
|
1205
|
+
// }
|
|
1206
|
+
// };
|
|
1207
|
+
// });
|
|
1208
|
+
|
|
1209
|
+
// it('should prioritize URL over individual properties when both are provided', (done) => {
|
|
1210
|
+
// // Mock the moveEntitiesToDB function
|
|
1211
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1212
|
+
|
|
1213
|
+
// // Set both URL and individual properties
|
|
1214
|
+
// a.allProps.mongo.url = 'mongodb://localhost:27017/urldb';
|
|
1215
|
+
// a.allProps.mongo.host = 'differenthost';
|
|
1216
|
+
// a.allProps.mongo.port = 12345;
|
|
1217
|
+
// a.allProps.mongo.database = 'propdb';
|
|
1218
|
+
|
|
1219
|
+
// // Mock successful database operation
|
|
1220
|
+
// td.when(entitiesToDB.moveEntitiesToDB(
|
|
1221
|
+
// td.matchers.anything(),
|
|
1222
|
+
// td.matchers.contains({
|
|
1223
|
+
// pronghornProps: {
|
|
1224
|
+
// mongo: a.allProps.mongo
|
|
1225
|
+
// },
|
|
1226
|
+
// id: a.id
|
|
1227
|
+
// })
|
|
1228
|
+
// )).thenResolve({ insertedCount: 1 });
|
|
1229
|
+
|
|
1230
|
+
// // Call the function
|
|
1231
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1232
|
+
// try {
|
|
1233
|
+
// assert.notEqual(null, result);
|
|
1234
|
+
// assert.equal(null, error);
|
|
1235
|
+
// assert.equal(1, result.insertedCount);
|
|
1236
|
+
// done();
|
|
1237
|
+
// } catch (err) {
|
|
1238
|
+
// done(err);
|
|
1239
|
+
// }
|
|
1240
|
+
// });
|
|
1241
|
+
// }).timeout(attemptTimeout);
|
|
1242
|
+
|
|
1243
|
+
// it('should correctly form connection string from URL with database override', (done) => {
|
|
1244
|
+
// // Mock the moveEntitiesToDB function
|
|
1245
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1246
|
+
|
|
1247
|
+
// // Set URL-based connection with different database in URL vs properties
|
|
1248
|
+
// a.allProps.mongo.url = 'mongodb://localhost:27017/urldb';
|
|
1249
|
+
// a.allProps.mongo.database = 'propdb';
|
|
1250
|
+
|
|
1251
|
+
// // Mock successful database operation
|
|
1252
|
+
// td.when(entitiesToDB.moveEntitiesToDB(
|
|
1253
|
+
// td.matchers.anything(),
|
|
1254
|
+
// td.matchers.contains({
|
|
1255
|
+
// pronghornProps: {
|
|
1256
|
+
// mongo: a.allProps.mongo
|
|
1257
|
+
// },
|
|
1258
|
+
// id: a.id
|
|
1259
|
+
// })
|
|
1260
|
+
// )).thenResolve({ insertedCount: 1 });
|
|
1261
|
+
|
|
1262
|
+
// // Call the function
|
|
1263
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1264
|
+
// try {
|
|
1265
|
+
// assert.notEqual(null, result);
|
|
1266
|
+
// assert.equal(null, error);
|
|
1267
|
+
// assert.equal(1, result.insertedCount);
|
|
1268
|
+
// done();
|
|
1269
|
+
// } catch (err) {
|
|
1270
|
+
// done(err);
|
|
1271
|
+
// }
|
|
1272
|
+
// });
|
|
1273
|
+
// }).timeout(attemptTimeout);
|
|
1274
|
+
|
|
1275
|
+
// it('should correctly form connection string from individual properties with SSL', (done) => {
|
|
1276
|
+
// // Mock the moveEntitiesToDB function
|
|
1277
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1278
|
+
|
|
1279
|
+
// // Update adapter properties with SSL configuration without sensitive data
|
|
1280
|
+
// a.allProps.mongo = {
|
|
1281
|
+
// host: 'localhost',
|
|
1282
|
+
// port: 27017,
|
|
1283
|
+
// database: 'testdb',
|
|
1284
|
+
// replSet: 'rs0',
|
|
1285
|
+
// addSrv: false,
|
|
1286
|
+
// db_ssl: {
|
|
1287
|
+
// enabled: true,
|
|
1288
|
+
// accept_invalid_cert: true
|
|
1289
|
+
// }
|
|
1290
|
+
// };
|
|
1291
|
+
|
|
1292
|
+
// // Mock successful database operation
|
|
1293
|
+
// td.when(entitiesToDB.moveEntitiesToDB(
|
|
1294
|
+
// td.matchers.anything(),
|
|
1295
|
+
// td.matchers.contains({
|
|
1296
|
+
// pronghornProps: {
|
|
1297
|
+
// mongo: a.allProps.mongo
|
|
1298
|
+
// },
|
|
1299
|
+
// id: a.id
|
|
1300
|
+
// })
|
|
1301
|
+
// )).thenResolve({ insertedCount: 1 });
|
|
1302
|
+
|
|
1303
|
+
// // Call the function
|
|
1304
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1305
|
+
// try {
|
|
1306
|
+
// assert.notEqual(null, result);
|
|
1307
|
+
// assert.equal(null, error);
|
|
1308
|
+
// assert.equal(1, result.insertedCount);
|
|
1309
|
+
// done();
|
|
1310
|
+
// } catch (err) {
|
|
1311
|
+
// done(err);
|
|
1312
|
+
// }
|
|
1313
|
+
// });
|
|
1314
|
+
// }).timeout(attemptTimeout);
|
|
1315
|
+
|
|
1316
|
+
// it('should handle missing required properties', (done) => {
|
|
1317
|
+
// // Mock the moveEntitiesToDB function to throw an error
|
|
1318
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1319
|
+
// td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
|
|
1320
|
+
// .thenReject(new Error('Missing required property: database'));
|
|
1321
|
+
|
|
1322
|
+
// // Call the function with incomplete properties
|
|
1323
|
+
// a.allProps.mongo = {
|
|
1324
|
+
// host: 'localhost',
|
|
1325
|
+
// port: 27017
|
|
1326
|
+
// // Missing database property
|
|
1327
|
+
// };
|
|
1328
|
+
|
|
1329
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1330
|
+
// try {
|
|
1331
|
+
// assert.equal(null, result);
|
|
1332
|
+
// assert.notEqual(null, error);
|
|
1333
|
+
// assert.equal('Missing required property: database', error);
|
|
1334
|
+
// done();
|
|
1335
|
+
// } catch (err) {
|
|
1336
|
+
// done(err);
|
|
1337
|
+
// }
|
|
1338
|
+
// });
|
|
1339
|
+
// }).timeout(attemptTimeout);
|
|
1340
|
+
|
|
1341
|
+
// it('should handle invalid URL format', (done) => {
|
|
1342
|
+
// // Mock the moveEntitiesToDB function to throw an error
|
|
1343
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1344
|
+
// td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
|
|
1345
|
+
// .thenReject(new Error('Invalid URL format'));
|
|
1346
|
+
|
|
1347
|
+
// // Call the function with invalid URL
|
|
1348
|
+
// a.allProps.mongo.url = 'invalid-url';
|
|
1349
|
+
|
|
1350
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1351
|
+
// try {
|
|
1352
|
+
// assert.equal(null, result);
|
|
1353
|
+
// assert.notEqual(null, error);
|
|
1354
|
+
// assert.equal('Invalid URL format', error);
|
|
1355
|
+
// done();
|
|
1356
|
+
// } catch (err) {
|
|
1357
|
+
// done(err);
|
|
1358
|
+
// }
|
|
1359
|
+
// });
|
|
1360
|
+
// }).timeout(attemptTimeout);
|
|
1361
|
+
|
|
1362
|
+
// it('should handle connection errors gracefully', (done) => {
|
|
1363
|
+
// // Mock the moveEntitiesToDB function to throw a connection error
|
|
1364
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1365
|
+
// td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
|
|
1366
|
+
// .thenReject(new Error('Failed to connect to MongoDB'));
|
|
1367
|
+
|
|
1368
|
+
// // Set valid connection properties
|
|
1369
|
+
// a.allProps.mongo = {
|
|
1370
|
+
// host: 'localhost',
|
|
1371
|
+
// port: 27017,
|
|
1372
|
+
// database: 'testdb'
|
|
1373
|
+
// };
|
|
1374
|
+
|
|
1375
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1376
|
+
// try {
|
|
1377
|
+
// assert.equal(null, result);
|
|
1378
|
+
// assert.notEqual(null, error);
|
|
1379
|
+
// assert.equal('Failed to connect to MongoDB', error);
|
|
1380
|
+
// done();
|
|
1381
|
+
// } catch (err) {
|
|
1382
|
+
// done(err);
|
|
1383
|
+
// }
|
|
1384
|
+
// });
|
|
1385
|
+
// }).timeout(attemptTimeout);
|
|
1386
|
+
|
|
1387
|
+
// it('should handle authentication errors', (done) => {
|
|
1388
|
+
// // Mock the moveEntitiesToDB function to throw an auth error
|
|
1389
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1390
|
+
// td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
|
|
1391
|
+
// .thenReject(new Error('Authentication failed'));
|
|
1392
|
+
|
|
1393
|
+
// // Set properties without any sensitive data
|
|
1394
|
+
// a.allProps.mongo = {
|
|
1395
|
+
// host: 'localhost',
|
|
1396
|
+
// port: 27017,
|
|
1397
|
+
// database: 'testdb',
|
|
1398
|
+
// dbAuth: true
|
|
1399
|
+
// };
|
|
1400
|
+
|
|
1401
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1402
|
+
// try {
|
|
1403
|
+
// assert.equal(null, result);
|
|
1404
|
+
// assert.notEqual(null, error);
|
|
1405
|
+
// assert.equal('Authentication failed', error);
|
|
1406
|
+
// done();
|
|
1407
|
+
// } catch (err) {
|
|
1408
|
+
// done(err);
|
|
1409
|
+
// }
|
|
1410
|
+
// });
|
|
1411
|
+
// }).timeout(attemptTimeout);
|
|
1412
|
+
|
|
1413
|
+
// it('should handle missing connection properties', (done) => {
|
|
1414
|
+
// // Mock the moveEntitiesToDB function to throw an error
|
|
1415
|
+
// entitiesToDB.moveEntitiesToDB = td.func();
|
|
1416
|
+
// td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
|
|
1417
|
+
// .thenReject(new Error('No connection properties provided'));
|
|
1418
|
+
|
|
1419
|
+
// // Clear all connection properties
|
|
1420
|
+
// a.allProps.mongo = {};
|
|
1421
|
+
|
|
1422
|
+
// a.iapMoveAdapterEntitiesToDB((result, error) => {
|
|
1423
|
+
// try {
|
|
1424
|
+
// assert.equal(null, result);
|
|
1425
|
+
// assert.notEqual(null, error);
|
|
1426
|
+
// assert.equal('No connection properties provided', error);
|
|
1427
|
+
// done();
|
|
1428
|
+
// } catch (err) {
|
|
1429
|
+
// done(err);
|
|
1430
|
+
// }
|
|
1431
|
+
// });
|
|
1432
|
+
// }).timeout(attemptTimeout);
|
|
1433
|
+
// });
|
|
1434
|
+
});
|
|
1435
|
+
|
|
1436
|
+
describe('#iapDeactivateTasks', () => {
|
|
1437
|
+
it('should have a iapDeactivateTasks function', (done) => {
|
|
1438
|
+
try {
|
|
1439
|
+
assert.equal(true, typeof a.iapDeactivateTasks === 'function');
|
|
1440
|
+
done();
|
|
1441
|
+
} catch (error) {
|
|
1442
|
+
log.error(`Test Failure: ${error}`);
|
|
1443
|
+
done(error);
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
describe('#iapActivateTasks', () => {
|
|
1449
|
+
it('should have a iapActivateTasks function', (done) => {
|
|
1450
|
+
try {
|
|
1451
|
+
assert.equal(true, typeof a.iapActivateTasks === 'function');
|
|
1452
|
+
done();
|
|
1453
|
+
} catch (error) {
|
|
1454
|
+
log.error(`Test Failure: ${error}`);
|
|
1455
|
+
done(error);
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
describe('#iapPopulateEntityCache', () => {
|
|
1461
|
+
it('should have a iapPopulateEntityCache function', (done) => {
|
|
1462
|
+
try {
|
|
1463
|
+
assert.equal(true, typeof a.iapPopulateEntityCache === 'function');
|
|
1464
|
+
done();
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
log.error(`Test Failure: ${error}`);
|
|
1467
|
+
done(error);
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
});
|
|
1471
|
+
|
|
1472
|
+
describe('#iapRetrieveEntitiesCache', () => {
|
|
1473
|
+
it('should have a iapRetrieveEntitiesCache function', (done) => {
|
|
1474
|
+
try {
|
|
1475
|
+
assert.equal(true, typeof a.iapRetrieveEntitiesCache === 'function');
|
|
1476
|
+
done();
|
|
1477
|
+
} catch (error) {
|
|
1478
|
+
log.error(`Test Failure: ${error}`);
|
|
1479
|
+
done(error);
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
});
|
|
1483
|
+
|
|
1484
|
+
describe('#hasEntities', () => {
|
|
1485
|
+
it('should have a hasEntities function', (done) => {
|
|
1486
|
+
try {
|
|
1487
|
+
assert.equal(true, typeof a.hasEntities === 'function');
|
|
1488
|
+
done();
|
|
1489
|
+
} catch (error) {
|
|
1490
|
+
log.error(`Test Failure: ${error}`);
|
|
1491
|
+
done(error);
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
describe('#getDevice', () => {
|
|
1497
|
+
it('should have a getDevice function', (done) => {
|
|
1498
|
+
try {
|
|
1499
|
+
assert.equal(true, typeof a.getDevice === 'function');
|
|
1500
|
+
done();
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
log.error(`Test Failure: ${error}`);
|
|
1503
|
+
done(error);
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
});
|
|
1507
|
+
|
|
1508
|
+
describe('#getDevicesFiltered', () => {
|
|
1509
|
+
it('should have a getDevicesFiltered function', (done) => {
|
|
1510
|
+
try {
|
|
1511
|
+
assert.equal(true, typeof a.getDevicesFiltered === 'function');
|
|
1512
|
+
done();
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
log.error(`Test Failure: ${error}`);
|
|
1515
|
+
done(error);
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
describe('#isAlive', () => {
|
|
1521
|
+
it('should have a isAlive function', (done) => {
|
|
1522
|
+
try {
|
|
1523
|
+
assert.equal(true, typeof a.isAlive === 'function');
|
|
1524
|
+
done();
|
|
1525
|
+
} catch (error) {
|
|
1526
|
+
log.error(`Test Failure: ${error}`);
|
|
1527
|
+
done(error);
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
describe('#getConfig', () => {
|
|
1533
|
+
it('should have a getConfig function', (done) => {
|
|
1534
|
+
try {
|
|
1535
|
+
assert.equal(true, typeof a.getConfig === 'function');
|
|
1536
|
+
done();
|
|
1537
|
+
} catch (error) {
|
|
1538
|
+
log.error(`Test Failure: ${error}`);
|
|
1539
|
+
done(error);
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
describe('#iapGetDeviceCount', () => {
|
|
1545
|
+
it('should have a iapGetDeviceCount function', (done) => {
|
|
1546
|
+
try {
|
|
1547
|
+
assert.equal(true, typeof a.iapGetDeviceCount === 'function');
|
|
1548
|
+
done();
|
|
1549
|
+
} catch (error) {
|
|
1550
|
+
log.error(`Test Failure: ${error}`);
|
|
1551
|
+
done(error);
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
|
|
1556
|
+
describe('#iapExpandedGenericAdapterRequest', () => {
|
|
1557
|
+
it('should have a iapExpandedGenericAdapterRequest function', (done) => {
|
|
1558
|
+
try {
|
|
1559
|
+
assert.equal(true, typeof a.iapExpandedGenericAdapterRequest === 'function');
|
|
1560
|
+
done();
|
|
1561
|
+
} catch (error) {
|
|
1562
|
+
log.error(`Test Failure: ${error}`);
|
|
1563
|
+
done(error);
|
|
1564
|
+
}
|
|
1565
|
+
});
|
|
1566
|
+
});
|
|
1567
|
+
|
|
1568
|
+
describe('#genericAdapterRequest', () => {
|
|
1569
|
+
it('should have a genericAdapterRequest function', (done) => {
|
|
1570
|
+
try {
|
|
1571
|
+
assert.equal(true, typeof a.genericAdapterRequest === 'function');
|
|
1572
|
+
done();
|
|
1573
|
+
} catch (error) {
|
|
1574
|
+
log.error(`Test Failure: ${error}`);
|
|
1575
|
+
done(error);
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
});
|
|
1579
|
+
|
|
1580
|
+
describe('#genericAdapterRequestNoBasePath', () => {
|
|
1581
|
+
it('should have a genericAdapterRequestNoBasePath function', (done) => {
|
|
1582
|
+
try {
|
|
1583
|
+
assert.equal(true, typeof a.genericAdapterRequestNoBasePath === 'function');
|
|
1584
|
+
done();
|
|
1585
|
+
} catch (error) {
|
|
1586
|
+
log.error(`Test Failure: ${error}`);
|
|
1587
|
+
done(error);
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
describe('#iapRunAdapterLint', () => {
|
|
1593
|
+
it('should have a iapRunAdapterLint function', (done) => {
|
|
1594
|
+
try {
|
|
1595
|
+
assert.equal(true, typeof a.iapRunAdapterLint === 'function');
|
|
1596
|
+
done();
|
|
1597
|
+
} catch (error) {
|
|
1598
|
+
log.error(`Test Failure: ${error}`);
|
|
1599
|
+
done(error);
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
describe('#iapRunAdapterTests', () => {
|
|
1605
|
+
it('should have a iapRunAdapterTests function', (done) => {
|
|
1606
|
+
try {
|
|
1607
|
+
assert.equal(true, typeof a.iapRunAdapterTests === 'function');
|
|
1608
|
+
done();
|
|
1609
|
+
} catch (error) {
|
|
1610
|
+
log.error(`Test Failure: ${error}`);
|
|
1611
|
+
done(error);
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
describe('#iapGetAdapterInventory', () => {
|
|
1617
|
+
it('should have a iapGetAdapterInventory function', (done) => {
|
|
1618
|
+
try {
|
|
1619
|
+
assert.equal(true, typeof a.iapGetAdapterInventory === 'function');
|
|
1620
|
+
done();
|
|
1621
|
+
} catch (error) {
|
|
1622
|
+
log.error(`Test Failure: ${error}`);
|
|
1623
|
+
done(error);
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
});
|
|
1627
|
+
});
|
|
1628
|
+
});
|