@natlibfi/melinda-rest-api-commons 4.2.4-alpha.8 → 4.2.5-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/melinda-node-tests.yml +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +28 -27
- 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 +0 -792
- package/dist/mongo.spec.js.map +0 -1
- package/dist/mongoLog.spec.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import fixtureFactory, {READERS} from '@natlibfi/fixura';
|
|
3
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
4
|
+
import createValidator from '../../src/helpers/validation';
|
|
5
|
+
|
|
6
|
+
describe('services/validate', () => {
|
|
7
|
+
const FIXTURES_PATH = [
|
|
8
|
+
__dirname,
|
|
9
|
+
'..',
|
|
10
|
+
'..',
|
|
11
|
+
'test-fixtures',
|
|
12
|
+
'validation'
|
|
13
|
+
];
|
|
14
|
+
const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});
|
|
15
|
+
|
|
16
|
+
describe('f003-fi-melinda', () => {
|
|
17
|
+
it('Should have failed: false', async () => {
|
|
18
|
+
const validator = await createValidator();
|
|
19
|
+
const record = new MarcRecord(getFixture({
|
|
20
|
+
components: [
|
|
21
|
+
'in',
|
|
22
|
+
'f003-fi-melinda.json'
|
|
23
|
+
]
|
|
24
|
+
}));
|
|
25
|
+
const result = await validator(record.toObject());
|
|
26
|
+
const expected = getFixture({
|
|
27
|
+
components: [
|
|
28
|
+
'out',
|
|
29
|
+
'f003-fi-melinda.json'
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
expect(result).to.eql(expected);
|
|
33
|
+
expect(result.failed).to.equal(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('f003-not-fi-melinda', () => {
|
|
38
|
+
it('Should have failed: true', async () => {
|
|
39
|
+
const validator = await createValidator();
|
|
40
|
+
const record = new MarcRecord(getFixture({
|
|
41
|
+
components: [
|
|
42
|
+
'in',
|
|
43
|
+
'f003-not-fi-melinda.json'
|
|
44
|
+
]
|
|
45
|
+
}));
|
|
46
|
+
const result = await validator(record.toObject());
|
|
47
|
+
const expected = getFixture({
|
|
48
|
+
components: [
|
|
49
|
+
'out',
|
|
50
|
+
'f003-not-fi-melinda.json'
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
expect(result).to.eql(expected);
|
|
54
|
+
expect(result.failed).to.equal(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
@@ -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:add-blob-size:test');
|
|
12
|
+
|
|
13
|
+
generateTests({
|
|
14
|
+
callback,
|
|
15
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'add-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', 'add-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
|
+
|
|
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
|
+
if (functionName === 'addBlobSize') {
|
|
78
|
+
try {
|
|
79
|
+
debug(`addBlobSize`);
|
|
80
|
+
debug(JSON.stringify(params));
|
|
81
|
+
//{correlationId}
|
|
82
|
+
const opResult = await mongoOperator.addBlobSize(params);
|
|
83
|
+
debug(`addBlobSize result: ${JSON.stringify(opResult)}`);
|
|
84
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
92
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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:test');
|
|
12
|
+
|
|
13
|
+
generateTests({
|
|
14
|
+
callback,
|
|
15
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'check-and-set-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', 'check-and-set-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
|
+
expectedOpResult = undefined,
|
|
61
|
+
updateStateBeforeTest = 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
|
+
if (functionName === 'checkAndSetState') {
|
|
78
|
+
try {
|
|
79
|
+
debug(`checkAndSetState`);
|
|
80
|
+
debug(JSON.stringify(params));
|
|
81
|
+
//{correlationId, state, errorMessage = undefined, errorStatus = undefined})
|
|
82
|
+
// timeout
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
85
|
+
if (updateStateBeforeTest && params.correlationId) {
|
|
86
|
+
debug(`setState to reset modificationTime`);
|
|
87
|
+
await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
|
|
88
|
+
}
|
|
89
|
+
const opResult = await mongoOperator.checkAndSetState(params);
|
|
90
|
+
debug(`checkAndSetState result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
93
|
+
if (expectedOpResult !== undefined) {
|
|
94
|
+
expect(opResult).to.eql(expectedOpResult);
|
|
95
|
+
}
|
|
96
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
97
|
+
|
|
98
|
+
} catch (error) {
|
|
99
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
105
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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:check-and-set-import-job-state-test');
|
|
11
|
+
|
|
12
|
+
generateTests({
|
|
13
|
+
callback,
|
|
14
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'check-and-set-import-job-state'],
|
|
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', 'check-and-set-import-job-state'],
|
|
45
|
+
gridFS: {bucketName: 'foobar'},
|
|
46
|
+
useObjectId: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line max-statements, complexity
|
|
51
|
+
async function callback({
|
|
52
|
+
getFixture,
|
|
53
|
+
functionName,
|
|
54
|
+
params,
|
|
55
|
+
expectModificationTime = false,
|
|
56
|
+
preFillDb = false,
|
|
57
|
+
expectedToThrow = false,
|
|
58
|
+
expectedErrorMessage = '',
|
|
59
|
+
expectedErrorStatus = '',
|
|
60
|
+
expectedOpResult = undefined,
|
|
61
|
+
updateStateBeforeTest = 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
|
+
if (functionName === 'checkAndSetImportJobState') {
|
|
78
|
+
try {
|
|
79
|
+
debug(`checkAndSetImportJobState`);
|
|
80
|
+
debug(JSON.stringify(params));
|
|
81
|
+
//{correlationId, operation, importJobState, errorMessage = '', errorStatus = ''}
|
|
82
|
+
// timeout
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
85
|
+
if (updateStateBeforeTest && params.correlationId) {
|
|
86
|
+
debug(`setState to reset modificationTime`);
|
|
87
|
+
await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
|
|
88
|
+
}
|
|
89
|
+
const opResult = await mongoOperator.checkAndSetImportJobState(params);
|
|
90
|
+
debug(`checkAndSetImportJobState result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
93
|
+
if (expectedOpResult !== undefined) {
|
|
94
|
+
expect(opResult).to.eql(expectedOpResult);
|
|
95
|
+
}
|
|
96
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
104
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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:check-timeout:test');
|
|
12
|
+
|
|
13
|
+
generateTests({
|
|
14
|
+
callback,
|
|
15
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'check-timeout'],
|
|
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', 'check-timeout'],
|
|
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
|
+
expectedOpResult = undefined,
|
|
62
|
+
updateStateBeforeTest = undefined
|
|
63
|
+
}) {
|
|
64
|
+
|
|
65
|
+
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
66
|
+
const expectedResult = await getFixture('expectedResult.json');
|
|
67
|
+
|
|
68
|
+
await doPreFillDb(preFillDb);
|
|
69
|
+
|
|
70
|
+
async function doPreFillDb(preFillDb) {
|
|
71
|
+
if (preFillDb) {
|
|
72
|
+
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (functionName === 'checkTimeOut') {
|
|
79
|
+
try {
|
|
80
|
+
debug(`checkTimeOut`);
|
|
81
|
+
debug(JSON.stringify(params));
|
|
82
|
+
//{correlationId}
|
|
83
|
+
// timeout
|
|
84
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
85
|
+
if (updateStateBeforeTest && params.correlationId) {
|
|
86
|
+
debug(`setState to reset modificationTime`);
|
|
87
|
+
await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
|
|
88
|
+
}
|
|
89
|
+
const opResult = await mongoOperator.checkTimeOut(params);
|
|
90
|
+
debug(`checkTimeOut result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line functional/no-conditional-statements
|
|
93
|
+
if (expectedOpResult !== undefined) {
|
|
94
|
+
expect(opResult).to.eql(expectedOpResult);
|
|
95
|
+
}
|
|
96
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
104
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {READERS} from '@natlibfi/fixura';
|
|
2
|
+
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
3
|
+
import generateTests from '@natlibfi/fixugen';
|
|
4
|
+
import createDebugLogger from 'debug';
|
|
5
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
6
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
7
|
+
|
|
8
|
+
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
9
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test:create-bulk');
|
|
10
|
+
|
|
11
|
+
generateTests({
|
|
12
|
+
callback,
|
|
13
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'create-bulk'],
|
|
14
|
+
recurse: false,
|
|
15
|
+
useMetadataFile: true,
|
|
16
|
+
fixura: {
|
|
17
|
+
failWhenNotFound: true,
|
|
18
|
+
reader: READERS.JSON
|
|
19
|
+
},
|
|
20
|
+
mocha: {
|
|
21
|
+
before: async () => {
|
|
22
|
+
//debug(`<< Before`);
|
|
23
|
+
await initMongofixtures();
|
|
24
|
+
},
|
|
25
|
+
beforeEach: async () => {
|
|
26
|
+
//debug(`<< BeforeEach`);
|
|
27
|
+
await mongoFixtures.clear();
|
|
28
|
+
},
|
|
29
|
+
afterEach: async () => {
|
|
30
|
+
//debug(`<< AfterEach`);
|
|
31
|
+
await mongoFixtures.clear();
|
|
32
|
+
},
|
|
33
|
+
after: async () => {
|
|
34
|
+
//debug(`<< After`);
|
|
35
|
+
await mongoFixtures.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
async function initMongofixtures() {
|
|
41
|
+
mongoFixtures = await mongoFixturesFactory({
|
|
42
|
+
recurse: false,
|
|
43
|
+
rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'create-bulk'],
|
|
44
|
+
gridFS: {bucketName: 'foobar'},
|
|
45
|
+
useObjectId: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line max-statements, complexity
|
|
50
|
+
async function callback({
|
|
51
|
+
getFixture,
|
|
52
|
+
functionName,
|
|
53
|
+
params,
|
|
54
|
+
preFillDb = false,
|
|
55
|
+
expectedToThrow = false,
|
|
56
|
+
expectedErrorMessage = '',
|
|
57
|
+
expectedErrorStatus = '',
|
|
58
|
+
contentStream = false,
|
|
59
|
+
expectedFileCount = undefined
|
|
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
|
+
if (functionName === 'createBulk') {
|
|
76
|
+
try {
|
|
77
|
+
debug(`CreateBulk`);
|
|
78
|
+
debug(JSON.stringify(params));
|
|
79
|
+
//{correlationId, cataloger, oCatalogerIn, operation, contentType, recordLoadParams, stream, operationSettings}
|
|
80
|
+
const stream = contentStream ? await getFixture({components: ['contentStream'], reader: READERS.STREAM}) : params.stream;
|
|
81
|
+
const params2 = {...params, stream};
|
|
82
|
+
const opResult = await mongoOperator.createBulk(params2);
|
|
83
|
+
debug(`createBulkResult: ${JSON.stringify(opResult)}`);
|
|
84
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, formatDates: true, expectedFileCount});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
93
|
+
}
|
|
@@ -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 {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
7
|
+
// import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
8
|
+
|
|
9
|
+
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:create-prio-test');
|
|
11
|
+
|
|
12
|
+
generateTests({
|
|
13
|
+
callback,
|
|
14
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'create-prio'],
|
|
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', 'create-prio'],
|
|
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
|
+
}) {
|
|
59
|
+
|
|
60
|
+
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
61
|
+
const expectedResult = await getFixture('expectedResult.json');
|
|
62
|
+
|
|
63
|
+
await doPreFillDb(preFillDb);
|
|
64
|
+
|
|
65
|
+
async function doPreFillDb(preFillDb) {
|
|
66
|
+
if (preFillDb) {
|
|
67
|
+
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (functionName === 'createPrio') {
|
|
74
|
+
try {
|
|
75
|
+
debug(`CreatePrio`);
|
|
76
|
+
debug(JSON.stringify(params));
|
|
77
|
+
const opResult = await mongoOperator.createPrio(params);
|
|
78
|
+
debug(`createPrio result: ${JSON.stringify(opResult)}`);
|
|
79
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, formatDates: true});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
88
|
+
}
|
|
89
|
+
|