@natlibfi/melinda-rest-api-commons 4.2.3 → 4.2.4-alpha.11

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 (47) hide show
  1. package/.github/workflows/melinda-node-tests.yml +1 -1
  2. package/dist/amqp.js +2 -2
  3. package/dist/amqp.js.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/mongo.js +158 -80
  7. package/dist/mongo.js.map +1 -1
  8. package/dist/mongoLog.js +1 -4
  9. package/dist/mongoLog.js.map +1 -1
  10. package/package.json +26 -24
  11. package/{dist → tests}/amqp.health.spec.js +17 -10
  12. package/tests/amqp.tests.spec.js +301 -0
  13. package/tests/helpers/conversion.spec.js +95 -0
  14. package/tests/helpers/fix.spec.js +41 -0
  15. package/tests/helpers/validation.spec.js +58 -0
  16. package/tests/mongo-add-blob-size.spec.js +100 -0
  17. package/tests/mongo-check-and-check-state.spec.js +112 -0
  18. package/tests/mongo-check-and-set-import-job-state.spec.js +112 -0
  19. package/tests/mongo-check-timeout.spec.js +111 -0
  20. package/tests/mongo-create-bulk.spec.js +100 -0
  21. package/tests/mongo-create-prio.spec.js +98 -0
  22. package/tests/mongo-get-one.spec.js +103 -0
  23. package/tests/mongo-get-stream.spec.js +120 -0
  24. package/tests/mongo-push-ids.spec.js +101 -0
  25. package/tests/mongo-push-messages.spec.js +99 -0
  26. package/tests/mongo-query-by-id.spec.js +112 -0
  27. package/tests/mongo-query.spec.js +108 -0
  28. package/tests/mongo-read-content.spec.js +123 -0
  29. package/tests/mongo-remove.spec.js +115 -0
  30. package/tests/mongo-set-blob-size.spec.js +99 -0
  31. package/tests/mongo-set-import-job-state.spec.js +102 -0
  32. package/tests/mongo-set-operation.spec.js +102 -0
  33. package/tests/mongo-set-operations.spec.js +101 -0
  34. package/tests/mongo-set-state.spec.js +102 -0
  35. package/{dist → tests}/mongoLog.spec.js +22 -22
  36. package/tests/testUtils.js +94 -0
  37. package/dist/amqp.health.spec.js.map +0 -1
  38. package/dist/amqp.tests.spec.js +0 -310
  39. package/dist/amqp.tests.spec.js.map +0 -1
  40. package/dist/helpers/conversion.spec.js +0 -88
  41. package/dist/helpers/conversion.spec.js.map +0 -1
  42. package/dist/helpers/fix.spec.js +0 -46
  43. package/dist/helpers/fix.spec.js.map +0 -1
  44. package/dist/helpers/validation.spec.js +0 -47
  45. package/dist/helpers/validation.spec.js.map +0 -1
  46. package/dist/mongo.spec.js.draft +0 -54
  47. package/dist/mongoLog.spec.js.map +0 -1
@@ -0,0 +1,115 @@
1
+ //import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
3
+ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
+ import generateTests from '@natlibfi/fixugen';
5
+ import createMongoOperator from '../src/mongo';
6
+ import createDebugLogger from 'debug';
7
+ //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
8
+ import {handleError, compareToFirstDbEntry} from './testUtils';
9
+
10
+
11
+ let mongoFixtures; // eslint-disable-line functional/no-let
12
+ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:remove:test');
13
+
14
+ generateTests({
15
+ callback,
16
+ path: [__dirname, '..', 'test-fixtures', 'mongo', 'remove'],
17
+ recurse: false,
18
+ useMetadataFile: true,
19
+ fixura: {
20
+ failWhenNotFound: true,
21
+ reader: READERS.JSON
22
+ },
23
+ mocha: {
24
+ before: async () => {
25
+ //debug(`<< Before`);
26
+ await initMongofixtures();
27
+ },
28
+ beforeEach: async () => {
29
+ //debug(`<< BeforeEach`);
30
+ await mongoFixtures.clear();
31
+ },
32
+ afterEach: async () => {
33
+ //debug(`<< AfterEach`);
34
+ await mongoFixtures.clear();
35
+ },
36
+ after: async () => {
37
+ //debug(`<< After`);
38
+ await mongoFixtures.close();
39
+ }
40
+ }
41
+ });
42
+
43
+ async function initMongofixtures() {
44
+ mongoFixtures = await mongoFixturesFactory({
45
+ recurse: false,
46
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'remove'],
47
+ gridFS: {bucketName: 'foobar'},
48
+ useObjectId: true
49
+ });
50
+ }
51
+
52
+ // eslint-disable-next-line max-statements, complexity
53
+ async function callback({
54
+ getFixture,
55
+ functionName,
56
+ params,
57
+ expectModificationTime = false,
58
+ preFillDb = false,
59
+ expectedToThrow = false,
60
+ expectedErrorMessage = '',
61
+ expectedErrorStatus = '',
62
+ contentStream = false,
63
+ //expectedOpResult = undefined,
64
+ //updateStateBeforeTest = undefined,
65
+ //resultIndex = undefined,
66
+ createBulkParams = undefined,
67
+ expectedFileCount = undefined,
68
+ expectUndefined = undefined
69
+ }) {
70
+
71
+ const mongoUri = await mongoFixtures.getUri();
72
+ const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
73
+ const expectedResult = await getFixture('expectedResult.json');
74
+
75
+ await doPreFillDb(preFillDb);
76
+
77
+ async function doPreFillDb(preFillDb) {
78
+ if (preFillDb) {
79
+ await mongoFixtures.populate(getFixture('dbContents.json'));
80
+ return;
81
+ }
82
+ return;
83
+ }
84
+
85
+
86
+ if (functionName === 'remove') {
87
+
88
+ try {
89
+ debug(`remove`);
90
+ debug(JSON.stringify(params));
91
+ //params: {correlationId}
92
+
93
+ // eslint-disable-next-line functional/no-conditional-statements
94
+ if (createBulkParams) {
95
+ const stream = contentStream ? await getFixture({components: ['contentStream'], reader: READERS.STREAM}) : createBulkParams.stream;
96
+ //debug(stream);
97
+ const params2 = {...createBulkParams, stream};
98
+ const createBulkResult = await mongoOperator.createBulk(params2);
99
+ debug(`createBulkResult: ${JSON.stringify(createBulkResult)}`);
100
+ }
101
+
102
+ const opResult = await mongoOperator.remove(params);
103
+ debug(`remove result: ${JSON.stringify(opResult)}`);
104
+ debug(`expectUndefined: ${expectUndefined}`);
105
+
106
+ await compareToFirstDbEntry({mongoFixtures, expectedResult: expectUndefined ? undefined : expectedResult, expectModificationTime, formatDates: true, expectedFileCount});
107
+
108
+ } catch (error) {
109
+ handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
110
+ return;
111
+ }
112
+ return;
113
+ }
114
+ throw new Error(`Unknown functionName: ${functionName}`);
115
+ }
@@ -0,0 +1,99 @@
1
+ //import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
3
+ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
+ import generateTests from '@natlibfi/fixugen';
5
+ import createMongoOperator from '../src/mongo';
6
+ import createDebugLogger from 'debug';
7
+ //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
8
+ import {handleError, compareToFirstDbEntry} from './testUtils';
9
+
10
+ let mongoFixtures; // eslint-disable-line functional/no-let
11
+ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-blob-size:test');
12
+
13
+ generateTests({
14
+ callback,
15
+ path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-blob-size'],
16
+ recurse: false,
17
+ useMetadataFile: true,
18
+ fixura: {
19
+ failWhenNotFound: true,
20
+ reader: READERS.JSON
21
+ },
22
+ mocha: {
23
+ before: async () => {
24
+ //debug(`<< Before`);
25
+ await initMongofixtures();
26
+ },
27
+ beforeEach: async () => {
28
+ //debug(`<< BeforeEach`);
29
+ await mongoFixtures.clear();
30
+ },
31
+ afterEach: async () => {
32
+ //debug(`<< AfterEach`);
33
+ await mongoFixtures.clear();
34
+ },
35
+ after: async () => {
36
+ //debug(`<< After`);
37
+ await mongoFixtures.close();
38
+ }
39
+ }
40
+ });
41
+
42
+ async function initMongofixtures() {
43
+ mongoFixtures = await mongoFixturesFactory({
44
+ recurse: false,
45
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-blob-size'],
46
+ gridFS: {bucketName: 'foobar'},
47
+ useObjectId: true
48
+ });
49
+ }
50
+
51
+ // eslint-disable-next-line max-statements, complexity
52
+ async function callback({
53
+ getFixture,
54
+ functionName,
55
+ params,
56
+ expectModificationTime = false,
57
+ preFillDb = false,
58
+ expectedToThrow = false,
59
+ expectedErrorMessage = '',
60
+ expectedErrorStatus = ''
61
+ // contentStream = false,
62
+ // expectedOpResult = undefined,
63
+ // updateStateBeforeTest = undefined,
64
+ // resultIndex = undefined,
65
+ // createBulkParams = undefined,
66
+ // expectedFileCount = undefined,
67
+ // expectUndefined = undefined
68
+ }) {
69
+
70
+ const mongoUri = await mongoFixtures.getUri();
71
+ const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
72
+ const expectedResult = await getFixture('expectedResult.json');
73
+
74
+ await doPreFillDb(preFillDb);
75
+
76
+ async function doPreFillDb(preFillDb) {
77
+ if (preFillDb) {
78
+ await mongoFixtures.populate(getFixture('dbContents.json'));
79
+ return;
80
+ }
81
+ return;
82
+ }
83
+
84
+ if (functionName === 'setBlobSize') {
85
+ try {
86
+ debug(`setBlobSize`);
87
+ debug(JSON.stringify(params));
88
+ //{correlationId, blobSize}
89
+ const opResult = await mongoOperator.setBlobSize(params);
90
+ debug(`setBlobSize result: ${JSON.stringify(opResult)}`);
91
+ await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
92
+ } catch (error) {
93
+ handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
94
+ return;
95
+ }
96
+ return;
97
+ }
98
+ throw new Error(`Unknown functionName: ${functionName}`);
99
+ }
@@ -0,0 +1,102 @@
1
+ //import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
3
+ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
+ import generateTests from '@natlibfi/fixugen';
5
+ import createMongoOperator from '../src/mongo';
6
+ import createDebugLogger from 'debug';
7
+ //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
8
+ import {handleError, compareToFirstDbEntry} from './testUtils';
9
+
10
+
11
+ let mongoFixtures; // eslint-disable-line functional/no-let
12
+ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-import-job-state:test');
13
+
14
+ generateTests({
15
+ callback,
16
+ path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-import-job-state'],
17
+ recurse: false,
18
+ useMetadataFile: true,
19
+ fixura: {
20
+ failWhenNotFound: true,
21
+ reader: READERS.JSON
22
+ },
23
+ mocha: {
24
+ before: async () => {
25
+ //debug(`<< Before`);
26
+ await initMongofixtures();
27
+ },
28
+ beforeEach: async () => {
29
+ //debug(`<< BeforeEach`);
30
+ await mongoFixtures.clear();
31
+ },
32
+ afterEach: async () => {
33
+ //debug(`<< AfterEach`);
34
+ await mongoFixtures.clear();
35
+ },
36
+ after: async () => {
37
+ //debug(`<< After`);
38
+ await mongoFixtures.close();
39
+ }
40
+ }
41
+ });
42
+
43
+ async function initMongofixtures() {
44
+ mongoFixtures = await mongoFixturesFactory({
45
+ recurse: false,
46
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-import-job-state'],
47
+ gridFS: {bucketName: 'foobar'},
48
+ useObjectId: true
49
+ });
50
+ }
51
+
52
+ // eslint-disable-next-line max-statements, complexity
53
+ async function callback({
54
+ getFixture,
55
+ functionName,
56
+ params,
57
+ expectModificationTime = false,
58
+ preFillDb = false,
59
+ expectedToThrow = false,
60
+ expectedErrorMessage = '',
61
+ expectedErrorStatus = ''
62
+ // contentStream = false,
63
+ // expectedOpResult = undefined,
64
+ // updateStateBeforeTest = undefined,
65
+ // resultIndex = undefined,
66
+ // createBulkParams = undefined,
67
+ // expectedFileCount = undefined,
68
+ // expectUndefined = undefined
69
+ }) {
70
+
71
+ const mongoUri = await mongoFixtures.getUri();
72
+ const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
73
+ const expectedResult = await getFixture('expectedResult.json');
74
+
75
+ await doPreFillDb(preFillDb);
76
+
77
+ async function doPreFillDb(preFillDb) {
78
+ if (preFillDb) {
79
+ await mongoFixtures.populate(getFixture('dbContents.json'));
80
+ return;
81
+ }
82
+ return;
83
+ }
84
+
85
+
86
+ if (functionName === 'setImportJobState') {
87
+ try {
88
+ debug(`setImportJobState`);
89
+ debug(JSON.stringify(params));
90
+ //{correlationId, operation, importJobState}
91
+ const opResult = await mongoOperator.setImportJobState(params);
92
+ debug(`setImportJobState result: ${JSON.stringify(opResult)}`);
93
+ await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
94
+ } catch (error) {
95
+ handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
96
+ return;
97
+ }
98
+ return;
99
+ }
100
+ throw new Error(`Unknown functionName: ${functionName}`);
101
+ }
102
+
@@ -0,0 +1,102 @@
1
+ //import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
3
+ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
+ import generateTests from '@natlibfi/fixugen';
5
+ import createMongoOperator from '../src/mongo';
6
+ import createDebugLogger from 'debug';
7
+ //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
8
+ import {handleError, compareToFirstDbEntry} from './testUtils';
9
+
10
+ let mongoFixtures; // eslint-disable-line functional/no-let
11
+ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operation:test');
12
+
13
+ generateTests({
14
+ callback,
15
+ path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
16
+ recurse: false,
17
+ useMetadataFile: true,
18
+ fixura: {
19
+ failWhenNotFound: true,
20
+ reader: READERS.JSON
21
+ },
22
+ mocha: {
23
+ before: async () => {
24
+ //debug(`<< Before`);
25
+ await initMongofixtures();
26
+ },
27
+ beforeEach: async () => {
28
+ //debug(`<< BeforeEach`);
29
+ await mongoFixtures.clear();
30
+ },
31
+ afterEach: async () => {
32
+ //debug(`<< AfterEach`);
33
+ await mongoFixtures.clear();
34
+ },
35
+ after: async () => {
36
+ //debug(`<< After`);
37
+ await mongoFixtures.close();
38
+ }
39
+ }
40
+ });
41
+
42
+ async function initMongofixtures() {
43
+ mongoFixtures = await mongoFixturesFactory({
44
+ recurse: false,
45
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
46
+ gridFS: {bucketName: 'foobar'},
47
+ useObjectId: true
48
+ });
49
+ }
50
+
51
+ // eslint-disable-next-line max-statements, complexity
52
+ async function callback({
53
+ getFixture,
54
+ functionName,
55
+ params,
56
+ expectModificationTime = false,
57
+ preFillDb = false,
58
+ expectedToThrow = false,
59
+ expectedErrorMessage = '',
60
+ expectedErrorStatus = ''
61
+ // contentStream = false,
62
+ // expectedOpResult = undefined,
63
+ // updateStateBeforeTest = undefined,
64
+ // resultIndex = undefined,
65
+ // createBulkParams = undefined,
66
+ // expectedFileCount = undefined,
67
+ // expectUndefined = undefined
68
+ }) {
69
+
70
+ const mongoUri = await mongoFixtures.getUri();
71
+ const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
72
+ const expectedResult = await getFixture('expectedResult.json');
73
+
74
+ await doPreFillDb(preFillDb);
75
+
76
+ async function doPreFillDb(preFillDb) {
77
+ if (preFillDb) {
78
+ await mongoFixtures.populate(getFixture('dbContents.json'));
79
+ return;
80
+ }
81
+ return;
82
+ }
83
+
84
+ if (functionName === 'setOperation') {
85
+ try {
86
+ debug(`setOperation`);
87
+ debug(JSON.stringify(params));
88
+ //{correlationId, operation}
89
+ const opResult = await mongoOperator.setOperation(params);
90
+ debug(`setOperation result: ${JSON.stringify(opResult)}`);
91
+ await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
92
+
93
+ } catch (error) {
94
+ handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
95
+ return;
96
+ }
97
+ return;
98
+ }
99
+
100
+ throw new Error(`Unknown functionName: ${functionName}`);
101
+ }
102
+
@@ -0,0 +1,101 @@
1
+ //import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
3
+ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
+ import generateTests from '@natlibfi/fixugen';
5
+ import createMongoOperator from '../src/mongo';
6
+ import createDebugLogger from 'debug';
7
+ //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
8
+ import {handleError, compareToFirstDbEntry} from './testUtils';
9
+
10
+ let mongoFixtures; // eslint-disable-line functional/no-let
11
+ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operations:test');
12
+
13
+ generateTests({
14
+ callback,
15
+ path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
16
+ recurse: false,
17
+ useMetadataFile: true,
18
+ fixura: {
19
+ failWhenNotFound: true,
20
+ reader: READERS.JSON
21
+ },
22
+ mocha: {
23
+ before: async () => {
24
+ //debug(`<< Before`);
25
+ await initMongofixtures();
26
+ },
27
+ beforeEach: async () => {
28
+ //debug(`<< BeforeEach`);
29
+ await mongoFixtures.clear();
30
+ },
31
+ afterEach: async () => {
32
+ //debug(`<< AfterEach`);
33
+ await mongoFixtures.clear();
34
+ },
35
+ after: async () => {
36
+ //debug(`<< After`);
37
+ await mongoFixtures.close();
38
+ }
39
+ }
40
+ });
41
+
42
+ async function initMongofixtures() {
43
+ mongoFixtures = await mongoFixturesFactory({
44
+ recurse: false,
45
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
46
+ gridFS: {bucketName: 'foobar'},
47
+ useObjectId: true
48
+ });
49
+ }
50
+
51
+ // eslint-disable-next-line max-statements, complexity
52
+ async function callback({
53
+ getFixture,
54
+ functionName,
55
+ params,
56
+ expectModificationTime = false,
57
+ preFillDb = false,
58
+ expectedToThrow = false,
59
+ expectedErrorMessage = '',
60
+ expectedErrorStatus = ''
61
+ // contentStream = false,
62
+ // expectedOpResult = undefined,
63
+ // updateStateBeforeTest = undefined,
64
+ // resultIndex = undefined,
65
+ // createBulkParams = undefined,
66
+ // expectedFileCount = undefined,
67
+ // expectUndefined = undefined
68
+ }) {
69
+
70
+ const mongoUri = await mongoFixtures.getUri();
71
+ const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
72
+ const expectedResult = await getFixture('expectedResult.json');
73
+
74
+ await doPreFillDb(preFillDb);
75
+
76
+ async function doPreFillDb(preFillDb) {
77
+ if (preFillDb) {
78
+ await mongoFixtures.populate(getFixture('dbContents.json'));
79
+ return;
80
+ }
81
+ return;
82
+ }
83
+
84
+
85
+ if (functionName === 'setOperations') {
86
+ try {
87
+ debug(`setOperations`);
88
+ debug(JSON.stringify(params));
89
+ //{correlationId, addOperation, removeOperation = undefined}
90
+ const opResult = await mongoOperator.setOperations(params);
91
+ debug(`setOperations result: ${JSON.stringify(opResult)}`);
92
+ await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
93
+ } catch (error) {
94
+ handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
95
+ return;
96
+ }
97
+ return;
98
+ }
99
+ throw new Error(`Unknown functionName: ${functionName}`);
100
+ }
101
+
@@ -0,0 +1,102 @@
1
+ //import {expect} from 'chai';
2
+ import {READERS} from '@natlibfi/fixura';
3
+ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
4
+ import generateTests from '@natlibfi/fixugen';
5
+ import createMongoOperator from '../src/mongo';
6
+ import createDebugLogger from 'debug';
7
+ //import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
8
+ import {handleError, compareToFirstDbEntry} from './testUtils';
9
+
10
+
11
+ let mongoFixtures; // eslint-disable-line functional/no-let
12
+ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-state:test');
13
+
14
+ generateTests({
15
+ callback,
16
+ path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-state'],
17
+ recurse: false,
18
+ useMetadataFile: true,
19
+ fixura: {
20
+ failWhenNotFound: true,
21
+ reader: READERS.JSON
22
+ },
23
+ mocha: {
24
+ before: async () => {
25
+ //debug(`<< Before`);
26
+ await initMongofixtures();
27
+ },
28
+ beforeEach: async () => {
29
+ //debug(`<< BeforeEach`);
30
+ await mongoFixtures.clear();
31
+ },
32
+ afterEach: async () => {
33
+ //debug(`<< AfterEach`);
34
+ await mongoFixtures.clear();
35
+ },
36
+ after: async () => {
37
+ //debug(`<< After`);
38
+ await mongoFixtures.close();
39
+ }
40
+ }
41
+ });
42
+
43
+ async function initMongofixtures() {
44
+ mongoFixtures = await mongoFixturesFactory({
45
+ recurse: false,
46
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-state'],
47
+ gridFS: {bucketName: 'foobar'},
48
+ useObjectId: true
49
+ });
50
+ }
51
+
52
+ // eslint-disable-next-line max-statements, complexity
53
+ async function callback({
54
+ getFixture,
55
+ functionName,
56
+ params,
57
+ expectModificationTime = false,
58
+ preFillDb = false,
59
+ expectedToThrow = false,
60
+ expectedErrorMessage = '',
61
+ expectedErrorStatus = ''
62
+ // contentStream = false,
63
+ // expectedOpResult = undefined,
64
+ // updateStateBeforeTest = undefined,
65
+ // resultIndex = undefined,
66
+ // createBulkParams = undefined,
67
+ // expectedFileCount = undefined,
68
+ // expectUndefined = undefined
69
+ }) {
70
+
71
+ const mongoUri = await mongoFixtures.getUri();
72
+ const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
73
+ const expectedResult = await getFixture('expectedResult.json');
74
+
75
+ await doPreFillDb(preFillDb);
76
+
77
+ async function doPreFillDb(preFillDb) {
78
+ if (preFillDb) {
79
+ await mongoFixtures.populate(getFixture('dbContents.json'));
80
+ return;
81
+ }
82
+ return;
83
+ }
84
+
85
+
86
+ if (functionName === 'setState') {
87
+ try {
88
+ debug(`setState`);
89
+ debug(JSON.stringify(params));
90
+ //{correlationId, state, errorMessage = undefined, errorStatus = undefined}
91
+ const opResult = await mongoOperator.setState(params);
92
+ debug(`setState result: ${JSON.stringify(opResult)}`);
93
+ await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
94
+
95
+ } catch (error) {
96
+ handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
97
+ return;
98
+ }
99
+ return;
100
+ }
101
+ throw new Error(`Unknown functionName: ${functionName}`);
102
+ }