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