@itentialopensource/adapter-microsoft_graph 1.4.7 → 1.5.0

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 +17 -11
  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 +15 -13
  18. package/propertiesSchema.json +68 -7
  19. package/report/adapterInfo.json +7 -7
  20. package/report/auto-adapter-openapi.json +8063 -0
  21. package/report/updateReport1748551976792.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 +1 -38
  26. package/test/unit/adapterBaseTestUnit.js +641 -39
  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', () => {
@@ -770,6 +1002,14 @@ describe('[unit] Adapter Base Test', () => {
770
1002
  });
771
1003
 
772
1004
  describe('#iapTroubleshootAdapter', () => {
1005
+ beforeEach(() => {
1006
+ td.replace(troubleshootingAdapter, 'troubleshoot', td.func());
1007
+ });
1008
+
1009
+ afterEach(() => {
1010
+ td.reset();
1011
+ });
1012
+
773
1013
  it('should have a iapTroubleshootAdapter function', (done) => {
774
1014
  try {
775
1015
  assert.equal(true, typeof a.iapTroubleshootAdapter === 'function');
@@ -779,6 +1019,116 @@ describe('[unit] Adapter Base Test', () => {
779
1019
  done(error);
780
1020
  }
781
1021
  });
1022
+
1023
+ // it('should successfully troubleshoot adapter with valid properties', (done) => {
1024
+ // try {
1025
+ // const mockResult = {
1026
+ // connectivity: { failCount: 0 },
1027
+ // healthCheck: true,
1028
+ // basicGet: { passCount: 1 }
1029
+ // };
1030
+
1031
+ // td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
1032
+ // .thenResolve(mockResult);
1033
+
1034
+ // a.iapTroubleshootAdapter({}, false, a, (result, error) => {
1035
+ // try {
1036
+ // assert.equal(undefined, error);
1037
+ // assert.notEqual(undefined, result);
1038
+ // assert.notEqual(null, result);
1039
+ // assert.equal(true, result.healthCheck);
1040
+ // assert.equal(0, result.connectivity.failCount);
1041
+ // assert.equal(1, result.basicGet.passCount);
1042
+ // done();
1043
+ // } catch (err) {
1044
+ // log.error(`Test Failure: ${err}`);
1045
+ // done(err);
1046
+ // }
1047
+ // });
1048
+ // } catch (error) {
1049
+ // log.error(`Adapter Exception: ${error}`);
1050
+ // done(error);
1051
+ // }
1052
+ // }).timeout(attemptTimeout);
1053
+
1054
+ // it('should handle failed troubleshooting', (done) => {
1055
+ // try {
1056
+ // const mockResult = {
1057
+ // connectivity: { failCount: 1 },
1058
+ // healthCheck: false,
1059
+ // basicGet: { passCount: 0 }
1060
+ // };
1061
+
1062
+ // td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
1063
+ // .thenResolve(mockResult);
1064
+
1065
+ // a.iapTroubleshootAdapter({}, false, a, (result, error) => {
1066
+ // try {
1067
+ // assert.equal(null, result);
1068
+ // assert.notEqual(undefined, error);
1069
+ // assert.notEqual(null, error);
1070
+ // assert.equal(false, error.healthCheck);
1071
+ // assert.equal(1, error.connectivity.failCount);
1072
+ // assert.equal(0, error.basicGet.passCount);
1073
+ // done();
1074
+ // } catch (err) {
1075
+ // log.error(`Test Failure: ${err}`);
1076
+ // done(err);
1077
+ // }
1078
+ // });
1079
+ // } catch (error) {
1080
+ // log.error(`Adapter Exception: ${error}`);
1081
+ // done(error);
1082
+ // }
1083
+ // }).timeout(attemptTimeout);
1084
+
1085
+ // it('should handle troubleshooting errors', (done) => {
1086
+ // try {
1087
+ // td.when(troubleshootingAdapter.troubleshoot(td.matchers.anything(), false, td.matchers.anything()))
1088
+ // .thenReject(new Error('Troubleshooting failed'));
1089
+
1090
+ // a.iapTroubleshootAdapter({}, false, a, (result, error) => {
1091
+ // try {
1092
+ // assert.equal(null, result);
1093
+ // assert.notEqual(undefined, error);
1094
+ // assert.notEqual(null, error);
1095
+ // assert.equal('Troubleshooting failed', error.message);
1096
+ // done();
1097
+ // } catch (err) {
1098
+ // log.error(`Test Failure: ${err}`);
1099
+ // done(err);
1100
+ // }
1101
+ // });
1102
+ // } catch (error) {
1103
+ // log.error(`Adapter Exception: ${error}`);
1104
+ // done(error);
1105
+ // }
1106
+ // }).timeout(attemptTimeout);
1107
+
1108
+ // it('should handle missing adapter instance', (done) => {
1109
+ // try {
1110
+ // a.iapTroubleshootAdapter({}, false, null, (result, error) => {
1111
+ // try {
1112
+ // assert.equal(null, result);
1113
+ // assert.notEqual(undefined, error);
1114
+ // assert.notEqual(null, error);
1115
+ // // Check for either error message format
1116
+ // assert.ok(
1117
+ // error.message === "Cannot read property 'healthCheck' of undefined"
1118
+ // || error.message === "Cannot read properties of undefined (reading 'healthCheck')",
1119
+ // `Unexpected error message: ${error.message}`
1120
+ // );
1121
+ // done();
1122
+ // } catch (err) {
1123
+ // log.error(`Test Failure: ${err}`);
1124
+ // done(err);
1125
+ // }
1126
+ // });
1127
+ // } catch (error) {
1128
+ // log.error(`Adapter Exception: ${error}`);
1129
+ // done(error);
1130
+ // }
1131
+ // }).timeout(attemptTimeout);
782
1132
  });
783
1133
 
784
1134
  describe('#iapRunAdapterHealthcheck', () => {
@@ -827,6 +1177,258 @@ describe('[unit] Adapter Base Test', () => {
827
1177
  done(error);
828
1178
  }
829
1179
  });
1180
+
1181
+ // describe('Connection String Tests', () => {
1182
+ // beforeEach(() => {
1183
+ // // Initialize allProps if it doesn't exist
1184
+ // if (!a.allProps) {
1185
+ // a.allProps = {};
1186
+ // }
1187
+ // // Initialize mongo properties with defaults
1188
+ // a.allProps.mongo = {
1189
+ // host: '',
1190
+ // port: 0,
1191
+ // database: '',
1192
+ // dbAuth: false,
1193
+ // username: '',
1194
+ // password: '',
1195
+ // replSet: '',
1196
+ // addSrv: false,
1197
+ // db_ssl: {
1198
+ // enabled: false,
1199
+ // accept_invalid_cert: false,
1200
+ // ca_file: '',
1201
+ // key_file: '',
1202
+ // cert_file: ''
1203
+ // }
1204
+ // };
1205
+ // });
1206
+
1207
+ // it('should prioritize URL over individual properties when both are provided', (done) => {
1208
+ // // Mock the moveEntitiesToDB function
1209
+ // entitiesToDB.moveEntitiesToDB = td.func();
1210
+
1211
+ // // Set both URL and individual properties
1212
+ // a.allProps.mongo.url = 'mongodb://localhost:27017/urldb';
1213
+ // a.allProps.mongo.host = 'differenthost';
1214
+ // a.allProps.mongo.port = 12345;
1215
+ // a.allProps.mongo.database = 'propdb';
1216
+
1217
+ // // Mock successful database operation
1218
+ // td.when(entitiesToDB.moveEntitiesToDB(
1219
+ // td.matchers.anything(),
1220
+ // td.matchers.contains({
1221
+ // pronghornProps: {
1222
+ // mongo: a.allProps.mongo
1223
+ // },
1224
+ // id: a.id
1225
+ // })
1226
+ // )).thenResolve({ insertedCount: 1 });
1227
+
1228
+ // // Call the function
1229
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1230
+ // try {
1231
+ // assert.notEqual(null, result);
1232
+ // assert.equal(null, error);
1233
+ // assert.equal(1, result.insertedCount);
1234
+ // done();
1235
+ // } catch (err) {
1236
+ // done(err);
1237
+ // }
1238
+ // });
1239
+ // }).timeout(attemptTimeout);
1240
+
1241
+ // it('should correctly form connection string from URL with database override', (done) => {
1242
+ // // Mock the moveEntitiesToDB function
1243
+ // entitiesToDB.moveEntitiesToDB = td.func();
1244
+
1245
+ // // Set URL-based connection with different database in URL vs properties
1246
+ // a.allProps.mongo.url = 'mongodb://localhost:27017/urldb';
1247
+ // a.allProps.mongo.database = 'propdb';
1248
+
1249
+ // // Mock successful database operation
1250
+ // td.when(entitiesToDB.moveEntitiesToDB(
1251
+ // td.matchers.anything(),
1252
+ // td.matchers.contains({
1253
+ // pronghornProps: {
1254
+ // mongo: a.allProps.mongo
1255
+ // },
1256
+ // id: a.id
1257
+ // })
1258
+ // )).thenResolve({ insertedCount: 1 });
1259
+
1260
+ // // Call the function
1261
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1262
+ // try {
1263
+ // assert.notEqual(null, result);
1264
+ // assert.equal(null, error);
1265
+ // assert.equal(1, result.insertedCount);
1266
+ // done();
1267
+ // } catch (err) {
1268
+ // done(err);
1269
+ // }
1270
+ // });
1271
+ // }).timeout(attemptTimeout);
1272
+
1273
+ // it('should correctly form connection string from individual properties with SSL', (done) => {
1274
+ // // Mock the moveEntitiesToDB function
1275
+ // entitiesToDB.moveEntitiesToDB = td.func();
1276
+
1277
+ // // Update adapter properties with SSL configuration without sensitive data
1278
+ // a.allProps.mongo = {
1279
+ // host: 'localhost',
1280
+ // port: 27017,
1281
+ // database: 'testdb',
1282
+ // replSet: 'rs0',
1283
+ // addSrv: false,
1284
+ // db_ssl: {
1285
+ // enabled: true,
1286
+ // accept_invalid_cert: true
1287
+ // }
1288
+ // };
1289
+
1290
+ // // Mock successful database operation
1291
+ // td.when(entitiesToDB.moveEntitiesToDB(
1292
+ // td.matchers.anything(),
1293
+ // td.matchers.contains({
1294
+ // pronghornProps: {
1295
+ // mongo: a.allProps.mongo
1296
+ // },
1297
+ // id: a.id
1298
+ // })
1299
+ // )).thenResolve({ insertedCount: 1 });
1300
+
1301
+ // // Call the function
1302
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1303
+ // try {
1304
+ // assert.notEqual(null, result);
1305
+ // assert.equal(null, error);
1306
+ // assert.equal(1, result.insertedCount);
1307
+ // done();
1308
+ // } catch (err) {
1309
+ // done(err);
1310
+ // }
1311
+ // });
1312
+ // }).timeout(attemptTimeout);
1313
+
1314
+ // it('should handle missing required properties', (done) => {
1315
+ // // Mock the moveEntitiesToDB function to throw an error
1316
+ // entitiesToDB.moveEntitiesToDB = td.func();
1317
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1318
+ // .thenReject(new Error('Missing required property: database'));
1319
+
1320
+ // // Call the function with incomplete properties
1321
+ // a.allProps.mongo = {
1322
+ // host: 'localhost',
1323
+ // port: 27017
1324
+ // // Missing database property
1325
+ // };
1326
+
1327
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1328
+ // try {
1329
+ // assert.equal(null, result);
1330
+ // assert.notEqual(null, error);
1331
+ // assert.equal('Missing required property: database', error);
1332
+ // done();
1333
+ // } catch (err) {
1334
+ // done(err);
1335
+ // }
1336
+ // });
1337
+ // }).timeout(attemptTimeout);
1338
+
1339
+ // it('should handle invalid URL format', (done) => {
1340
+ // // Mock the moveEntitiesToDB function to throw an error
1341
+ // entitiesToDB.moveEntitiesToDB = td.func();
1342
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1343
+ // .thenReject(new Error('Invalid URL format'));
1344
+
1345
+ // // Call the function with invalid URL
1346
+ // a.allProps.mongo.url = 'invalid-url';
1347
+
1348
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1349
+ // try {
1350
+ // assert.equal(null, result);
1351
+ // assert.notEqual(null, error);
1352
+ // assert.equal('Invalid URL format', error);
1353
+ // done();
1354
+ // } catch (err) {
1355
+ // done(err);
1356
+ // }
1357
+ // });
1358
+ // }).timeout(attemptTimeout);
1359
+
1360
+ // it('should handle connection errors gracefully', (done) => {
1361
+ // // Mock the moveEntitiesToDB function to throw a connection error
1362
+ // entitiesToDB.moveEntitiesToDB = td.func();
1363
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1364
+ // .thenReject(new Error('Failed to connect to MongoDB'));
1365
+
1366
+ // // Set valid connection properties
1367
+ // a.allProps.mongo = {
1368
+ // host: 'localhost',
1369
+ // port: 27017,
1370
+ // database: 'testdb'
1371
+ // };
1372
+
1373
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1374
+ // try {
1375
+ // assert.equal(null, result);
1376
+ // assert.notEqual(null, error);
1377
+ // assert.equal('Failed to connect to MongoDB', error);
1378
+ // done();
1379
+ // } catch (err) {
1380
+ // done(err);
1381
+ // }
1382
+ // });
1383
+ // }).timeout(attemptTimeout);
1384
+
1385
+ // it('should handle authentication errors', (done) => {
1386
+ // // Mock the moveEntitiesToDB function to throw an auth error
1387
+ // entitiesToDB.moveEntitiesToDB = td.func();
1388
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1389
+ // .thenReject(new Error('Authentication failed'));
1390
+
1391
+ // // Set properties without any sensitive data
1392
+ // a.allProps.mongo = {
1393
+ // host: 'localhost',
1394
+ // port: 27017,
1395
+ // database: 'testdb',
1396
+ // dbAuth: true
1397
+ // };
1398
+
1399
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1400
+ // try {
1401
+ // assert.equal(null, result);
1402
+ // assert.notEqual(null, error);
1403
+ // assert.equal('Authentication failed', error);
1404
+ // done();
1405
+ // } catch (err) {
1406
+ // done(err);
1407
+ // }
1408
+ // });
1409
+ // }).timeout(attemptTimeout);
1410
+
1411
+ // it('should handle missing connection properties', (done) => {
1412
+ // // Mock the moveEntitiesToDB function to throw an error
1413
+ // entitiesToDB.moveEntitiesToDB = td.func();
1414
+ // td.when(entitiesToDB.moveEntitiesToDB(td.matchers.anything(), td.matchers.anything()))
1415
+ // .thenReject(new Error('No connection properties provided'));
1416
+
1417
+ // // Clear all connection properties
1418
+ // a.allProps.mongo = {};
1419
+
1420
+ // a.iapMoveAdapterEntitiesToDB((result, error) => {
1421
+ // try {
1422
+ // assert.equal(null, result);
1423
+ // assert.notEqual(null, error);
1424
+ // assert.equal('No connection properties provided', error);
1425
+ // done();
1426
+ // } catch (err) {
1427
+ // done(err);
1428
+ // }
1429
+ // });
1430
+ // }).timeout(attemptTimeout);
1431
+ // });
830
1432
  });
831
1433
 
832
1434
  describe('#iapDeactivateTasks', () => {