@natlibfi/melinda-rest-api-commons 6.0.1 → 6.2.0-alpha.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.
- package/.github/workflows/melinda-node-tests-and-publish.yml +4 -2
- package/README.md +82 -0
- package/dist/amqp.d.ts +41 -0
- package/dist/amqp.d.ts.map +1 -0
- package/dist/amqp.js +242 -218
- package/dist/amqp.js.map +1 -7
- package/dist/constants.d.ts +49 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +38 -38
- package/dist/constants.js.map +1 -7
- package/dist/helpers/conversion.d.ts +8 -0
- package/dist/helpers/conversion.d.ts.map +1 -0
- package/dist/helpers/conversion.js +70 -65
- package/dist/helpers/conversion.js.map +1 -7
- package/dist/helpers/fix-constants.d.ts +76 -0
- package/dist/helpers/fix-constants.d.ts.map +1 -0
- package/dist/helpers/fix-constants.js +41 -41
- package/dist/helpers/fix-constants.js.map +1 -7
- package/dist/helpers/fix-handle-tempurns.d.ts +3 -0
- package/dist/helpers/fix-handle-tempurns.d.ts.map +1 -0
- package/dist/helpers/fix-handle-tempurns.js +73 -71
- package/dist/helpers/fix-handle-tempurns.js.map +1 -7
- package/dist/helpers/fix-strip-f884s.d.ts +10 -0
- package/dist/helpers/fix-strip-f884s.d.ts.map +1 -0
- package/dist/helpers/fix-strip-f884s.js +163 -151
- package/dist/helpers/fix-strip-f884s.js.map +1 -7
- package/dist/helpers/fix.d.ts +6 -0
- package/dist/helpers/fix.d.ts.map +1 -0
- package/dist/helpers/fix.js +133 -117
- package/dist/helpers/fix.js.map +1 -7
- package/dist/helpers/validation.d.ts +9 -0
- package/dist/helpers/validation.d.ts.map +1 -0
- package/dist/helpers/validation.js +14 -16
- package/dist/helpers/validation.js.map +1 -7
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -7
- package/dist/mongo.d.ts +165 -0
- package/dist/mongo.d.ts.map +1 -0
- package/dist/mongo.js +603 -464
- package/dist/mongo.js.map +1 -7
- package/dist/mongoError.d.ts +2 -0
- package/dist/mongoError.d.ts.map +1 -0
- package/dist/mongoError.js +19 -0
- package/dist/mongoError.js.map +1 -0
- package/dist/mongoLog.d.ts +50 -0
- package/dist/mongoLog.d.ts.map +1 -0
- package/dist/mongoLog.js +282 -172
- package/dist/mongoLog.js.map +1 -7
- package/dist/utils.d.ts +36 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +118 -87
- package/dist/utils.js.map +1 -7
- package/eslint.config.ts +66 -0
- package/package.json +23 -25
- package/test/amqp-error-branches.test.ts +551 -0
- package/{tests/amqp.healthtest.js → test/amqp.healthtest.ts} +19 -7
- package/{tests/amqp.tests.localtest.js → test/amqp.tests.localtest.ts} +66 -52
- package/{tests/helpers/conversion.test.js → test/helpers/conversion.test.ts} +39 -11
- package/test/helpers/fix-edge.test.ts +201 -0
- package/test/helpers/fix.test.ts +65 -0
- package/{tests/helpers/validation.test.js → test/helpers/validation.test.ts} +13 -8
- package/{tests/mongo-add-blob-size.test.js → test/mongo-add-blob-size.test.ts} +14 -15
- package/{tests/mongo-check-and-check-state.test.js → test/mongo-check-and-check-state.test.ts} +9 -9
- package/{tests/mongo-check-and-set-import-job-state.test.js → test/mongo-check-and-set-import-job-state.test.ts} +9 -10
- package/{tests/mongo-check-timeout.test.js → test/mongo-check-timeout.test.ts} +6 -9
- package/{tests/mongo-create-bulk.test.js → test/mongo-create-bulk.test.ts} +6 -7
- package/{tests/mongo-create-prio.test.js → test/mongo-create-prio.test.ts} +6 -6
- package/test/mongo-error-branches.test.ts +883 -0
- package/{tests/mongo-get-one.test.js → test/mongo-get-one.test.ts} +6 -6
- package/{tests/mongo-get-stream.test.js → test/mongo-get-stream.test.ts} +10 -9
- package/{tests/mongo-push-ids.test.js → test/mongo-push-ids.test.ts} +6 -6
- package/{tests/mongo-push-messages.test.js → test/mongo-push-messages.test.ts} +6 -6
- package/{tests/mongo-query-by-id.test.js → test/mongo-query-by-id.test.ts} +6 -9
- package/{tests/mongo-query.test.js → test/mongo-query.test.ts} +6 -7
- package/{tests/mongo-read-content.test.js → test/mongo-read-content.test.ts} +16 -9
- package/{tests/mongo-remove.test.js → test/mongo-remove.test.ts} +6 -8
- package/{tests/mongo-set-blob-size.test.js → test/mongo-set-blob-size.test.ts} +6 -6
- package/{tests/mongo-set-import-job-state.test.js → test/mongo-set-import-job-state.test.ts} +6 -6
- package/{tests/mongo-set-operation.test.js → test/mongo-set-operation.test.ts} +6 -6
- package/{tests/mongo-set-operations.test.js → test/mongo-set-operations.test.ts} +6 -6
- package/{tests/mongo-set-state.test.js → test/mongo-set-state.test.ts} +6 -6
- package/test/mongoLog-protect.test.ts +182 -0
- package/test/mongoLog.test.ts +191 -0
- package/{tests/testUtils.js → test/testUtils.ts} +49 -15
- package/test/utils.test.ts +360 -0
- package/tsconfig.json +62 -0
- package/tsconfig.test.json +17 -0
- package/dist/helpers/fix-utils.js +0 -39
- package/dist/helpers/fix-utils.js.map +0 -7
- package/eslint.config.js +0 -53
- package/tests/helpers/fix.test.js +0 -41
- package/tests/mongoLog.test.js +0 -84
|
@@ -2,7 +2,9 @@ import assert from 'node:assert';
|
|
|
2
2
|
import {describe, it} from 'node:test';
|
|
3
3
|
import fixtureFactory, {READERS} from '@natlibfi/fixura';
|
|
4
4
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
5
|
-
import
|
|
5
|
+
import type {MarcRecordObject} from '@natlibfi/marc-record';
|
|
6
|
+
|
|
7
|
+
import createValidator from '../../src/helpers/validation.ts';
|
|
6
8
|
|
|
7
9
|
describe('services/validate', () => {
|
|
8
10
|
const FIXTURES_PATH = [
|
|
@@ -22,16 +24,18 @@ describe('services/validate', () => {
|
|
|
22
24
|
'in',
|
|
23
25
|
'f003-fi-melinda.json'
|
|
24
26
|
]
|
|
25
|
-
}));
|
|
27
|
+
}) as MarcRecordObject);
|
|
26
28
|
const result = await validator(record.toObject());
|
|
27
29
|
const {record: expectedRecord, ...rest} = getFixture({
|
|
28
30
|
components: [
|
|
29
31
|
'out',
|
|
30
32
|
'f003-fi-melinda.json'
|
|
31
33
|
]
|
|
32
|
-
})
|
|
34
|
+
}) as Record<string, any>;
|
|
33
35
|
const {_validationOptions, ...expectedRecordData} = expectedRecord;
|
|
34
|
-
|
|
36
|
+
const {record: actualRecord, ...actualRest} = result;
|
|
37
|
+
assert.deepStrictEqual(actualRest, rest);
|
|
38
|
+
assert.deepStrictEqual(actualRecord.toObject(), new MarcRecord(expectedRecordData, _validationOptions).toObject());
|
|
35
39
|
assert.equal(result.failed, false);
|
|
36
40
|
});
|
|
37
41
|
});
|
|
@@ -44,18 +48,19 @@ describe('services/validate', () => {
|
|
|
44
48
|
'in',
|
|
45
49
|
'f003-not-fi-melinda.json'
|
|
46
50
|
]
|
|
47
|
-
}));
|
|
51
|
+
}) as MarcRecordObject);
|
|
48
52
|
const result = await validator(record.toObject());
|
|
49
53
|
const {record: expectedRecord, ...rest} = getFixture({
|
|
50
54
|
components: [
|
|
51
55
|
'out',
|
|
52
56
|
'f003-not-fi-melinda.json'
|
|
53
57
|
]
|
|
54
|
-
})
|
|
58
|
+
}) as Record<string, any>;
|
|
55
59
|
const {_validationOptions, ...expectedRecordData} = expectedRecord;
|
|
56
|
-
|
|
60
|
+
const {record: actualRecord, ...actualRest} = result;
|
|
61
|
+
assert.deepStrictEqual(actualRest, rest);
|
|
62
|
+
assert.deepStrictEqual(actualRecord.toObject(), new MarcRecord(expectedRecordData, _validationOptions).toObject());
|
|
57
63
|
assert.equal(result.failed, true);
|
|
58
64
|
});
|
|
59
65
|
});
|
|
60
66
|
});
|
|
61
|
-
|
|
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
|
4
4
|
import generateTests from '@natlibfi/fixugen';
|
|
5
5
|
import createDebugLogger from 'debug';
|
|
6
6
|
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
let mongoFixtures;
|
|
10
|
+
let mongoFixtures: any;
|
|
11
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:add-blob-size:test');
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
@@ -41,32 +41,31 @@ generateTests({
|
|
|
41
41
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
|
-
recurse: false,
|
|
45
44
|
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'add-blob-size'],
|
|
46
45
|
gridFS: {bucketName: 'foobar'},
|
|
47
46
|
useObjectId: true
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
async function callback(callbackParams: Record<string, any>) {
|
|
51
|
+
const {
|
|
52
|
+
getFixture,
|
|
53
|
+
functionName,
|
|
54
|
+
params,
|
|
55
|
+
expectModificationTime = false,
|
|
56
|
+
preFillDb = false,
|
|
57
|
+
expectedToThrow = false,
|
|
58
|
+
expectedErrorMessage = '',
|
|
59
|
+
expectedErrorStatus = ''
|
|
61
60
|
|
|
62
|
-
}
|
|
61
|
+
} = callbackParams;
|
|
63
62
|
|
|
64
63
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
65
64
|
const expectedResult = await getFixture('expectedResult.json');
|
|
66
65
|
|
|
67
66
|
await doPreFillDb(preFillDb);
|
|
68
67
|
|
|
69
|
-
async function doPreFillDb(preFillDb) {
|
|
68
|
+
async function doPreFillDb(preFillDb: boolean) {
|
|
70
69
|
if (preFillDb) {
|
|
71
70
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
72
71
|
return;
|
package/{tests/mongo-check-and-check-state.test.js → test/mongo-check-and-check-state.test.ts}
RENAMED
|
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
|
4
4
|
import generateTests from '@natlibfi/fixugen';
|
|
5
5
|
import createDebugLogger from 'debug';
|
|
6
6
|
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
let mongoFixtures;
|
|
10
|
+
let mongoFixtures: any;
|
|
11
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
@@ -41,14 +41,14 @@ generateTests({
|
|
|
41
41
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
|
-
recurse: false,
|
|
45
44
|
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'check-and-set-state'],
|
|
46
45
|
gridFS: {bucketName: 'foobar'},
|
|
47
46
|
useObjectId: true
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
async function callback({
|
|
50
|
+
async function callback(callbackParams: Record<string, any>) {
|
|
51
|
+
const {
|
|
52
52
|
getFixture,
|
|
53
53
|
functionName,
|
|
54
54
|
params,
|
|
@@ -59,14 +59,14 @@ async function callback({
|
|
|
59
59
|
expectedErrorStatus = '',
|
|
60
60
|
expectedOpResult = undefined,
|
|
61
61
|
updateStateBeforeTest = undefined
|
|
62
|
-
}
|
|
62
|
+
} = callbackParams;
|
|
63
63
|
|
|
64
64
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
65
65
|
const expectedResult = await getFixture('expectedResult.json');
|
|
66
66
|
|
|
67
67
|
await doPreFillDb(preFillDb);
|
|
68
68
|
|
|
69
|
-
async function doPreFillDb(preFillDb) {
|
|
69
|
+
async function doPreFillDb(preFillDb: boolean) {
|
|
70
70
|
if (preFillDb) {
|
|
71
71
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
72
72
|
return;
|
|
@@ -81,7 +81,6 @@ async function callback({
|
|
|
81
81
|
//{correlationId, state, errorMessage = undefined, errorStatus = undefined})
|
|
82
82
|
// timeout
|
|
83
83
|
|
|
84
|
-
// eslint-disable-next-line functional/no-conditional-statements
|
|
85
84
|
if (updateStateBeforeTest && params.correlationId) {
|
|
86
85
|
debug(`setState to reset modificationTime`);
|
|
87
86
|
await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
|
|
@@ -89,9 +88,10 @@ async function callback({
|
|
|
89
88
|
const opResult = await mongoOperator.checkAndSetState(params);
|
|
90
89
|
debug(`checkAndSetState result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
91
90
|
|
|
92
|
-
//
|
|
91
|
+
// checkAndSetState now returns a discriminated result
|
|
92
|
+
// {status: 'updated' | 'timeout' | 'unchanged', queueItem} - compare status
|
|
93
93
|
if (expectedOpResult !== undefined) {
|
|
94
|
-
assert.deepStrictEqual(opResult, expectedOpResult);
|
|
94
|
+
assert.deepStrictEqual(opResult.status, expectedOpResult);
|
|
95
95
|
}
|
|
96
96
|
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
97
97
|
|
|
@@ -4,9 +4,9 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
|
4
4
|
import generateTests from '@natlibfi/fixugen';
|
|
5
5
|
import createDebugLogger from 'debug';
|
|
6
6
|
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
|
-
let mongoFixtures;
|
|
9
|
+
let mongoFixtures: any;
|
|
10
10
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:check-and-set-import-job-state-test');
|
|
11
11
|
|
|
12
12
|
generateTests({
|
|
@@ -40,15 +40,14 @@ generateTests({
|
|
|
40
40
|
|
|
41
41
|
async function initMongofixtures() {
|
|
42
42
|
mongoFixtures = await mongoFixturesFactory({
|
|
43
|
-
recurse: false,
|
|
44
43
|
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'check-and-set-import-job-state'],
|
|
45
44
|
gridFS: {bucketName: 'foobar'},
|
|
46
45
|
useObjectId: true
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
async function callback(callbackParams: Record<string, any>) {
|
|
50
|
+
const {
|
|
52
51
|
getFixture,
|
|
53
52
|
functionName,
|
|
54
53
|
params,
|
|
@@ -59,14 +58,14 @@ async function callback({
|
|
|
59
58
|
expectedErrorStatus = '',
|
|
60
59
|
expectedOpResult = undefined,
|
|
61
60
|
updateStateBeforeTest = undefined
|
|
62
|
-
}
|
|
61
|
+
} = callbackParams;
|
|
63
62
|
|
|
64
63
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
65
64
|
const expectedResult = await getFixture('expectedResult.json');
|
|
66
65
|
|
|
67
66
|
await doPreFillDb(preFillDb);
|
|
68
67
|
|
|
69
|
-
async function doPreFillDb(preFillDb) {
|
|
68
|
+
async function doPreFillDb(preFillDb: boolean) {
|
|
70
69
|
if (preFillDb) {
|
|
71
70
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
72
71
|
return;
|
|
@@ -81,7 +80,6 @@ async function callback({
|
|
|
81
80
|
//{correlationId, operation, importJobState, errorMessage = '', errorStatus = ''}
|
|
82
81
|
// timeout
|
|
83
82
|
|
|
84
|
-
// eslint-disable-next-line functional/no-conditional-statements
|
|
85
83
|
if (updateStateBeforeTest && params.correlationId) {
|
|
86
84
|
debug(`setState to reset modificationTime`);
|
|
87
85
|
await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
|
|
@@ -89,9 +87,10 @@ async function callback({
|
|
|
89
87
|
const opResult = await mongoOperator.checkAndSetImportJobState(params);
|
|
90
88
|
debug(`checkAndSetImportJobState result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
91
89
|
|
|
92
|
-
//
|
|
90
|
+
// checkAndSetImportJobState now returns a discriminated result
|
|
91
|
+
// {status: 'updated' | 'timeout' | 'unchanged', queueItem} - compare status
|
|
93
92
|
if (expectedOpResult !== undefined) {
|
|
94
|
-
assert.deepStrictEqual(opResult, expectedOpResult);
|
|
93
|
+
assert.deepStrictEqual(opResult.status, expectedOpResult);
|
|
95
94
|
}
|
|
96
95
|
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
97
96
|
} catch (error) {
|
|
@@ -4,10 +4,10 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
|
4
4
|
import generateTests from '@natlibfi/fixugen';
|
|
5
5
|
import createDebugLogger from 'debug';
|
|
6
6
|
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
let mongoFixtures;
|
|
10
|
+
let mongoFixtures: any;
|
|
11
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:check-timeout:test');
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
@@ -41,15 +41,14 @@ generateTests({
|
|
|
41
41
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
|
-
recurse: false,
|
|
45
44
|
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'check-timeout'],
|
|
46
45
|
gridFS: {bucketName: 'foobar'},
|
|
47
46
|
useObjectId: true
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
async function callback(callbackParams: Record<string, any>) {
|
|
51
|
+
const {
|
|
53
52
|
getFixture,
|
|
54
53
|
functionName,
|
|
55
54
|
params,
|
|
@@ -60,14 +59,14 @@ async function callback({
|
|
|
60
59
|
expectedErrorStatus = '',
|
|
61
60
|
expectedOpResult = undefined,
|
|
62
61
|
updateStateBeforeTest = undefined
|
|
63
|
-
}
|
|
62
|
+
} = callbackParams;
|
|
64
63
|
|
|
65
64
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
66
65
|
const expectedResult = await getFixture('expectedResult.json');
|
|
67
66
|
|
|
68
67
|
await doPreFillDb(preFillDb);
|
|
69
68
|
|
|
70
|
-
async function doPreFillDb(preFillDb) {
|
|
69
|
+
async function doPreFillDb(preFillDb: boolean) {
|
|
71
70
|
if (preFillDb) {
|
|
72
71
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
73
72
|
return;
|
|
@@ -81,7 +80,6 @@ async function callback({
|
|
|
81
80
|
debug(JSON.stringify(params));
|
|
82
81
|
//{correlationId}
|
|
83
82
|
// timeout
|
|
84
|
-
// eslint-disable-next-line functional/no-conditional-statements
|
|
85
83
|
if (updateStateBeforeTest && params.correlationId) {
|
|
86
84
|
debug(`setState to reset modificationTime`);
|
|
87
85
|
await mongoOperator.setState({correlationId: params.correlationId, state: updateStateBeforeTest});
|
|
@@ -89,7 +87,6 @@ async function callback({
|
|
|
89
87
|
const opResult = await mongoOperator.checkTimeOut(params);
|
|
90
88
|
debug(`checkTimeOut result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
91
89
|
|
|
92
|
-
// eslint-disable-next-line functional/no-conditional-statements
|
|
93
90
|
if (expectedOpResult !== undefined) {
|
|
94
91
|
assert.deepStrictEqual(opResult, expectedOpResult);
|
|
95
92
|
}
|
|
@@ -3,9 +3,9 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
|
3
3
|
import generateTests from '@natlibfi/fixugen';
|
|
4
4
|
import createDebugLogger from 'debug';
|
|
5
5
|
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
6
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
6
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
7
7
|
|
|
8
|
-
let mongoFixtures;
|
|
8
|
+
let mongoFixtures: any;
|
|
9
9
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test:create-bulk');
|
|
10
10
|
|
|
11
11
|
generateTests({
|
|
@@ -39,15 +39,14 @@ generateTests({
|
|
|
39
39
|
|
|
40
40
|
async function initMongofixtures() {
|
|
41
41
|
mongoFixtures = await mongoFixturesFactory({
|
|
42
|
-
recurse: false,
|
|
43
42
|
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'create-bulk'],
|
|
44
43
|
gridFS: {bucketName: 'foobar'},
|
|
45
44
|
useObjectId: true
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
async function callback(callbackParams: Record<string, any>) {
|
|
49
|
+
const {
|
|
51
50
|
getFixture,
|
|
52
51
|
functionName,
|
|
53
52
|
params,
|
|
@@ -57,14 +56,14 @@ async function callback({
|
|
|
57
56
|
expectedErrorStatus = '',
|
|
58
57
|
contentStream = false,
|
|
59
58
|
expectedFileCount = undefined
|
|
60
|
-
}
|
|
59
|
+
} = callbackParams;
|
|
61
60
|
|
|
62
61
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
63
62
|
const expectedResult = await getFixture('expectedResult.json');
|
|
64
63
|
|
|
65
64
|
await doPreFillDb(preFillDb);
|
|
66
65
|
|
|
67
|
-
async function doPreFillDb(preFillDb) {
|
|
66
|
+
async function doPreFillDb(preFillDb: boolean) {
|
|
68
67
|
if (preFillDb) {
|
|
69
68
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
70
69
|
return;
|
|
@@ -3,10 +3,10 @@ import {READERS} from '@natlibfi/fixura';
|
|
|
3
3
|
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
4
4
|
import generateTests from '@natlibfi/fixugen';
|
|
5
5
|
import createDebugLogger from 'debug';
|
|
6
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
6
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
7
7
|
// import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
8
8
|
|
|
9
|
-
let mongoFixtures;
|
|
9
|
+
let mongoFixtures: any;
|
|
10
10
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:create-prio-test');
|
|
11
11
|
|
|
12
12
|
generateTests({
|
|
@@ -40,14 +40,14 @@ generateTests({
|
|
|
40
40
|
|
|
41
41
|
async function initMongofixtures() {
|
|
42
42
|
mongoFixtures = await mongoFixturesFactory({
|
|
43
|
-
recurse: false,
|
|
44
43
|
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'create-prio'],
|
|
45
44
|
gridFS: {bucketName: 'foobar'},
|
|
46
45
|
useObjectId: true
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
async function callback({
|
|
49
|
+
async function callback(callbackParams: Record<string, any>) {
|
|
50
|
+
const {
|
|
51
51
|
getFixture,
|
|
52
52
|
functionName,
|
|
53
53
|
params,
|
|
@@ -55,14 +55,14 @@ async function callback({
|
|
|
55
55
|
expectedToThrow = false,
|
|
56
56
|
expectedErrorMessage = '',
|
|
57
57
|
expectedErrorStatus = ''
|
|
58
|
-
}
|
|
58
|
+
} = callbackParams;
|
|
59
59
|
|
|
60
60
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
61
61
|
const expectedResult = await getFixture('expectedResult.json');
|
|
62
62
|
|
|
63
63
|
await doPreFillDb(preFillDb);
|
|
64
64
|
|
|
65
|
-
async function doPreFillDb(preFillDb) {
|
|
65
|
+
async function doPreFillDb(preFillDb: boolean) {
|
|
66
66
|
if (preFillDb) {
|
|
67
67
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
68
68
|
return;
|