@itentialopensource/adapter-netbrain 1.3.7 → 1.4.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 (45) hide show
  1. package/.eslintrc.js +1 -0
  2. package/AUTH.md +4 -4
  3. package/BROKER.md +4 -4
  4. package/CALLS.md +9 -9
  5. package/ENHANCE.md +3 -3
  6. package/PROPERTIES.md +24 -9
  7. package/README.md +24 -23
  8. package/SUMMARY.md +2 -2
  9. package/SYSTEMINFO.md +1 -1
  10. package/TAB1.md +2 -2
  11. package/TAB2.md +9 -5
  12. package/TROUBLESHOOT.md +10 -1
  13. package/UTILITIES.md +473 -0
  14. package/adapter.js +5 -5
  15. package/adapterBase.js +52 -16
  16. package/package.json +24 -28
  17. package/pronghorn.json +49 -47
  18. package/propertiesSchema.json +68 -7
  19. package/report/adapterInfo.json +7 -7
  20. package/report/auto-adapter-openapi.json +1333 -0
  21. package/report/updateReport1748556272953.json +120 -0
  22. package/sampleProperties.json +4 -0
  23. package/test/integration/adapterTestBasicGet.js +88 -54
  24. package/test/integration/adapterTestConnectivity.js +15 -16
  25. package/test/integration/adapterTestIntegration.js +4 -41
  26. package/test/unit/adapterBaseTestUnit.js +651 -47
  27. package/test/unit/adapterTestUnit.js +17 -54
  28. package/utils/adapterInfo.js +114 -164
  29. package/utils/argParser.js +44 -0
  30. package/utils/checkMigrate.js +77 -38
  31. package/utils/entitiesToDB.js +53 -42
  32. package/utils/logger.js +26 -0
  33. package/utils/modify.js +56 -55
  34. package/utils/mongoDbConnection.js +79 -0
  35. package/utils/mongoUtils.js +162 -0
  36. package/utils/taskMover.js +31 -32
  37. package/utils/tbScript.js +36 -172
  38. package/utils/tbUtils.js +84 -226
  39. package/utils/troubleshootingAdapter.js +68 -84
  40. package/utils/updateAdapterConfig.js +158 -0
  41. package/utils/addAuth.js +0 -94
  42. package/utils/artifactize.js +0 -146
  43. package/utils/basicGet.js +0 -50
  44. package/utils/packModificationScript.js +0 -35
  45. package/utils/patches2bundledDeps.js +0 -90
@@ -1,5 +1,5 @@
1
1
  // Set globals
2
- /* global describe it log pronghornProps */
2
+ /* global describe it log pronghornProps beforeEach afterEach */
3
3
  /* eslint global-require: warn */
4
4
  /* eslint no-unused-vars: warn */
5
5
 
@@ -12,11 +12,13 @@ const winston = require('winston');
12
12
  const { expect } = require('chai');
13
13
  const { use } = require('chai');
14
14
  const td = require('testdouble');
15
+ const entitiesToDB = require('../../utils/entitiesToDB');
16
+ const troubleshootingAdapter = require('../../utils/troubleshootingAdapter');
17
+ const log = require('../../utils/logger');
15
18
 
16
19
  const anything = td.matchers.anything();
17
20
 
18
21
  // stub and attemptTimeout are used throughout the code so set them here
19
- let logLevel = 'none';
20
22
  const stub = true;
21
23
  const isRapidFail = false;
22
24
  const attemptTimeout = 120000;
@@ -143,43 +145,6 @@ global.pronghornProps = {
143
145
 
144
146
  global.$HOME = `${__dirname}/../..`;
145
147
 
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
148
  /**
184
149
  * Runs the error asserts for the test
185
150
  */
@@ -210,6 +175,33 @@ if (fs.existsSync(dirPath)) {
210
175
  }
211
176
  }
212
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
+
213
205
  describe('[unit] Adapter Base Test', () => {
214
206
  describe('Adapter Base Class Tests', () => {
215
207
  // Define constants we will use below
@@ -650,6 +642,246 @@ describe('[unit] Adapter Base Test', () => {
650
642
  done(error);
651
643
  }
652
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);
653
885
  });
654
886
 
655
887
  describe('#iapSuspendAdapter', () => {
@@ -724,14 +956,16 @@ describe('[unit] Adapter Base Test', () => {
724
956
  });
725
957
  it('should get information for all of the requests currently in the queue', (done) => {
726
958
  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
- }
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
+ });
735
969
  } catch (error) {
736
970
  log.error(`Adapter Exception: ${error}`);
737
971
  done(error);
@@ -770,6 +1004,14 @@ describe('[unit] Adapter Base Test', () => {
770
1004
  });
771
1005
 
772
1006
  describe('#iapTroubleshootAdapter', () => {
1007
+ beforeEach(() => {
1008
+ td.replace(troubleshootingAdapter, 'troubleshoot', td.func());
1009
+ });
1010
+
1011
+ afterEach(() => {
1012
+ td.reset();
1013
+ });
1014
+
773
1015
  it('should have a iapTroubleshootAdapter function', (done) => {
774
1016
  try {
775
1017
  assert.equal(true, typeof a.iapTroubleshootAdapter === 'function');
@@ -779,6 +1021,116 @@ describe('[unit] Adapter Base Test', () => {
779
1021
  done(error);
780
1022
  }
781
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);
782
1134
  });
783
1135
 
784
1136
  describe('#iapRunAdapterHealthcheck', () => {
@@ -827,6 +1179,258 @@ describe('[unit] Adapter Base Test', () => {
827
1179
  done(error);
828
1180
  }
829
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
+ // });
830
1434
  });
831
1435
 
832
1436
  describe('#iapDeactivateTasks', () => {