@natlibfi/melinda-rest-api-commons 4.2.5-alpha.1 → 5.0.0-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 +9 -6
- package/dist/conversion.js +70 -0
- package/dist/conversion.js.map +7 -0
- package/dist/fix-constants.js +63 -0
- package/dist/fix-constants.js.map +7 -0
- package/dist/fix-handle-tempurns.js +83 -0
- package/dist/fix-handle-tempurns.js.map +7 -0
- package/dist/fix-strip-f884s.js +160 -0
- package/dist/fix-strip-f884s.js.map +7 -0
- package/dist/fix-utils.js +39 -0
- package/dist/fix-utils.js.map +7 -0
- package/dist/fix.js +142 -0
- package/dist/fix.js.map +7 -0
- package/dist/validation.js +19 -0
- package/dist/validation.js.map +7 -0
- package/eslint.config.js +53 -0
- package/package.json +23 -96
- package/tests/{amqp.health.spec.js → amqp.healthtest.js} +2 -2
- package/tests/{amqp.tests.spec.js → amqp.tests.localtest.js} +46 -46
- package/tests/helpers/{conversion.spec.js → conversion.test.js} +38 -25
- package/tests/helpers/{fix.spec.js → fix.test.js} +6 -6
- package/tests/helpers/{validation.spec.js → validation.test.js} +12 -9
- package/tests/{mongo-add-blob-size.spec.js → mongo-add-blob-size.test.js} +6 -6
- package/tests/{mongo-check-and-check-state.spec.js → mongo-check-and-check-state.test.js} +7 -7
- package/tests/{mongo-check-and-set-import-job-state.spec.js → mongo-check-and-set-import-job-state.test.js} +7 -7
- package/tests/{mongo-check-timeout.spec.js → mongo-check-timeout.test.js} +7 -7
- package/tests/{mongo-create-bulk.spec.js → mongo-create-bulk.test.js} +5 -5
- package/tests/{mongo-create-prio.spec.js → mongo-create-prio.test.js} +6 -6
- package/tests/{mongo-get-one.spec.js → mongo-get-one.test.js} +7 -7
- package/tests/{mongo-get-stream.spec.js → mongo-get-stream.test.js} +7 -7
- package/tests/{mongo-push-ids.spec.js → mongo-push-ids.test.js} +5 -5
- package/tests/{mongo-push-messages.spec.js → mongo-push-messages.test.js} +6 -6
- package/tests/{mongo-query-by-id.spec.js → mongo-query-by-id.test.js} +7 -7
- package/tests/{mongo-query.spec.js → mongo-query.test.js} +7 -7
- package/tests/{mongo-read-content.spec.js → mongo-read-content.test.js} +8 -8
- package/tests/{mongo-remove.spec.js → mongo-remove.test.js} +6 -6
- package/tests/{mongo-set-blob-size.spec.js → mongo-set-blob-size.test.js} +6 -6
- package/tests/{mongo-set-import-job-state.spec.js → mongo-set-import-job-state.test.js} +6 -6
- package/tests/{mongo-set-operation.spec.js → mongo-set-operation.test.js} +6 -6
- package/tests/{mongo-set-operations.spec.js → mongo-set-operations.test.js} +6 -6
- package/tests/{mongo-set-state.spec.js → mongo-set-state.test.js} +7 -7
- package/tests/{mongoLog.spec.js → mongoLog.test.js} +10 -11
- package/tests/testUtils.js +9 -8
- package/dist/amqp.js +0 -326
- package/dist/amqp.js.map +0 -1
- package/dist/constants.js +0 -60
- package/dist/constants.js.map +0 -1
- package/dist/helpers/conversion.js +0 -88
- package/dist/helpers/conversion.js.map +0 -1
- package/dist/helpers/fix-constants.js +0 -70
- package/dist/helpers/fix-constants.js.map +0 -1
- package/dist/helpers/fix-handle-tempurns.js +0 -133
- package/dist/helpers/fix-handle-tempurns.js.map +0 -1
- package/dist/helpers/fix-strip-f884s.js +0 -210
- package/dist/helpers/fix-strip-f884s.js.map +0 -1
- package/dist/helpers/fix-utils.js +0 -54
- package/dist/helpers/fix-utils.js.map +0 -1
- package/dist/helpers/fix.js +0 -202
- package/dist/helpers/fix.js.map +0 -1
- package/dist/helpers/validation.js +0 -37
- package/dist/helpers/validation.js.map +0 -1
- package/dist/index.js +0 -109
- package/dist/index.js.map +0 -1
- package/dist/mongo.js +0 -822
- package/dist/mongo.js.map +0 -1
- package/dist/mongoLog.js +0 -409
- package/dist/mongoLog.js.map +0 -1
- package/dist/utils.js +0 -211
- package/dist/utils.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, compareToDbEntry, formatQueueItem} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToDbEntry, formatQueueItem} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
@@ -12,14 +12,14 @@ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:query-
|
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
14
14
|
callback,
|
|
15
|
-
path: [
|
|
15
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'query-by-id'],
|
|
16
16
|
recurse: false,
|
|
17
17
|
useMetadataFile: true,
|
|
18
18
|
fixura: {
|
|
19
19
|
failWhenNotFound: true,
|
|
20
20
|
reader: READERS.JSON
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
hooks: {
|
|
23
23
|
before: async () => {
|
|
24
24
|
//debug(`<< Before`);
|
|
25
25
|
await initMongofixtures();
|
|
@@ -42,7 +42,7 @@ generateTests({
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
44
|
recurse: false,
|
|
45
|
-
rootPath: [
|
|
45
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'query-by-id'],
|
|
46
46
|
gridFS: {bucketName: 'foobar'},
|
|
47
47
|
useObjectId: true
|
|
48
48
|
});
|
|
@@ -91,7 +91,7 @@ async function callback({
|
|
|
91
91
|
debug(`queryById result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
92
92
|
// eslint-disable-next-line functional/no-conditional-statements
|
|
93
93
|
if (expectedOpResult !== undefined) {
|
|
94
|
-
|
|
94
|
+
assert.deepStrictEqual(formatQueueItem(opResult), formatQueueItem(expectedOpResult));
|
|
95
95
|
}
|
|
96
96
|
const compareResultIndex = resultIndex ? resultIndex : 0;
|
|
97
97
|
await compareToDbEntry({mongoFixtures, expectedResult, resultIndex: compareResultIndex, expectModificationTime, formatDates: true});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
10
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
|
|
11
11
|
|
|
12
12
|
generateTests({
|
|
13
13
|
callback,
|
|
14
|
-
path: [
|
|
14
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'query'],
|
|
15
15
|
recurse: false,
|
|
16
16
|
useMetadataFile: true,
|
|
17
17
|
fixura: {
|
|
18
18
|
failWhenNotFound: true,
|
|
19
19
|
reader: READERS.JSON
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
hooks: {
|
|
22
22
|
before: async () => {
|
|
23
23
|
//debug(`<< Before`);
|
|
24
24
|
await initMongofixtures();
|
|
@@ -41,7 +41,7 @@ generateTests({
|
|
|
41
41
|
async function initMongofixtures() {
|
|
42
42
|
mongoFixtures = await mongoFixturesFactory({
|
|
43
43
|
recurse: false,
|
|
44
|
-
rootPath: [
|
|
44
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'query'],
|
|
45
45
|
gridFS: {bucketName: 'foobar'},
|
|
46
46
|
useObjectId: true
|
|
47
47
|
});
|
|
@@ -85,7 +85,7 @@ async function callback({
|
|
|
85
85
|
debug(`query result: ${JSON.stringify(opResult)} (it should be: ${JSON.stringify(expectedOpResult)})}`);
|
|
86
86
|
// eslint-disable-next-line functional/no-conditional-statements
|
|
87
87
|
if (expectedOpResult !== undefined) {
|
|
88
|
-
|
|
88
|
+
assert.deepStrictEqual(opResult, expectedOpResult);
|
|
89
89
|
}
|
|
90
90
|
} catch (error) {
|
|
91
91
|
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, streamToString} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, streamToString} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
@@ -12,14 +12,14 @@ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:read-c
|
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
14
14
|
callback,
|
|
15
|
-
path: [
|
|
15
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'read-content'],
|
|
16
16
|
recurse: false,
|
|
17
17
|
useMetadataFile: true,
|
|
18
18
|
fixura: {
|
|
19
19
|
failWhenNotFound: true,
|
|
20
20
|
reader: READERS.JSON
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
hooks: {
|
|
23
23
|
before: async () => {
|
|
24
24
|
//debug(`<< Before`);
|
|
25
25
|
await initMongofixtures();
|
|
@@ -42,7 +42,7 @@ generateTests({
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
44
|
recurse: false,
|
|
45
|
-
rootPath: [
|
|
45
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'read-content'],
|
|
46
46
|
gridFS: {bucketName: 'foobar'},
|
|
47
47
|
useObjectId: true
|
|
48
48
|
});
|
|
@@ -95,13 +95,13 @@ async function callback({
|
|
|
95
95
|
|
|
96
96
|
// eslint-disable-next-line functional/no-conditional-statements
|
|
97
97
|
if (createBulkParams && createBulkParams.contentType) {
|
|
98
|
-
|
|
98
|
+
assert.equal(opResult.contentType, createBulkParams.contentType);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
if (contentStream) {
|
|
102
102
|
const contentStreamString = await getFixture({components: ['contentStream'], reader: READERS.TEXT});
|
|
103
103
|
//debug(contentStreamString);
|
|
104
|
-
|
|
104
|
+
assert.equal(opResultString, contentStreamString);
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//import
|
|
1
|
+
//import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
@@ -12,14 +12,14 @@ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:remove
|
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
14
14
|
callback,
|
|
15
|
-
path: [
|
|
15
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'remove'],
|
|
16
16
|
recurse: false,
|
|
17
17
|
useMetadataFile: true,
|
|
18
18
|
fixura: {
|
|
19
19
|
failWhenNotFound: true,
|
|
20
20
|
reader: READERS.JSON
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
hooks: {
|
|
23
23
|
before: async () => {
|
|
24
24
|
//debug(`<< Before`);
|
|
25
25
|
await initMongofixtures();
|
|
@@ -42,7 +42,7 @@ generateTests({
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
44
|
recurse: false,
|
|
45
|
-
rootPath: [
|
|
45
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'remove'],
|
|
46
46
|
gridFS: {bucketName: 'foobar'},
|
|
47
47
|
useObjectId: true
|
|
48
48
|
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
//import
|
|
1
|
+
//import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
10
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-blob-size:test');
|
|
11
11
|
|
|
12
12
|
generateTests({
|
|
13
13
|
callback,
|
|
14
|
-
path: [
|
|
14
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-blob-size'],
|
|
15
15
|
recurse: false,
|
|
16
16
|
useMetadataFile: true,
|
|
17
17
|
fixura: {
|
|
18
18
|
failWhenNotFound: true,
|
|
19
19
|
reader: READERS.JSON
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
hooks: {
|
|
22
22
|
before: async () => {
|
|
23
23
|
//debug(`<< Before`);
|
|
24
24
|
await initMongofixtures();
|
|
@@ -41,7 +41,7 @@ generateTests({
|
|
|
41
41
|
async function initMongofixtures() {
|
|
42
42
|
mongoFixtures = await mongoFixturesFactory({
|
|
43
43
|
recurse: false,
|
|
44
|
-
rootPath: [
|
|
44
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-blob-size'],
|
|
45
45
|
gridFS: {bucketName: 'foobar'},
|
|
46
46
|
useObjectId: true
|
|
47
47
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//import
|
|
1
|
+
//import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
@@ -12,14 +12,14 @@ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-im
|
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
14
14
|
callback,
|
|
15
|
-
path: [
|
|
15
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-import-job-state'],
|
|
16
16
|
recurse: false,
|
|
17
17
|
useMetadataFile: true,
|
|
18
18
|
fixura: {
|
|
19
19
|
failWhenNotFound: true,
|
|
20
20
|
reader: READERS.JSON
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
hooks: {
|
|
23
23
|
before: async () => {
|
|
24
24
|
//debug(`<< Before`);
|
|
25
25
|
await initMongofixtures();
|
|
@@ -42,7 +42,7 @@ generateTests({
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
44
|
recurse: false,
|
|
45
|
-
rootPath: [
|
|
45
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-import-job-state'],
|
|
46
46
|
gridFS: {bucketName: 'foobar'},
|
|
47
47
|
useObjectId: true
|
|
48
48
|
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
//import
|
|
1
|
+
//import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
10
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operation:test');
|
|
11
11
|
|
|
12
12
|
generateTests({
|
|
13
13
|
callback,
|
|
14
|
-
path: [
|
|
14
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
|
|
15
15
|
recurse: false,
|
|
16
16
|
useMetadataFile: true,
|
|
17
17
|
fixura: {
|
|
18
18
|
failWhenNotFound: true,
|
|
19
19
|
reader: READERS.JSON
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
hooks: {
|
|
22
22
|
before: async () => {
|
|
23
23
|
//debug(`<< Before`);
|
|
24
24
|
await initMongofixtures();
|
|
@@ -41,7 +41,7 @@ generateTests({
|
|
|
41
41
|
async function initMongofixtures() {
|
|
42
42
|
mongoFixtures = await mongoFixturesFactory({
|
|
43
43
|
recurse: false,
|
|
44
|
-
rootPath: [
|
|
44
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
|
|
45
45
|
gridFS: {bucketName: 'foobar'},
|
|
46
46
|
useObjectId: true
|
|
47
47
|
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
//import
|
|
1
|
+
//import assert from 'node:assert';
|
|
2
2
|
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 {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
10
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operations:test');
|
|
11
11
|
|
|
12
12
|
generateTests({
|
|
13
13
|
callback,
|
|
14
|
-
path: [
|
|
14
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
|
|
15
15
|
recurse: false,
|
|
16
16
|
useMetadataFile: true,
|
|
17
17
|
fixura: {
|
|
18
18
|
failWhenNotFound: true,
|
|
19
19
|
reader: READERS.JSON
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
hooks: {
|
|
22
22
|
before: async () => {
|
|
23
23
|
//debug(`<< Before`);
|
|
24
24
|
await initMongofixtures();
|
|
@@ -41,7 +41,7 @@ generateTests({
|
|
|
41
41
|
async function initMongofixtures() {
|
|
42
42
|
mongoFixtures = await mongoFixturesFactory({
|
|
43
43
|
recurse: false,
|
|
44
|
-
rootPath: [
|
|
44
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
|
|
45
45
|
gridFS: {bucketName: 'foobar'},
|
|
46
46
|
useObjectId: true
|
|
47
47
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//import
|
|
1
|
+
//import assert from 'node:assert';
|
|
2
|
+
import createDebugLogger from 'debug';
|
|
2
3
|
import {READERS} from '@natlibfi/fixura';
|
|
3
4
|
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
4
5
|
import generateTests from '@natlibfi/fixugen';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils.js';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
@@ -12,14 +12,14 @@ const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-st
|
|
|
12
12
|
|
|
13
13
|
generateTests({
|
|
14
14
|
callback,
|
|
15
|
-
path: [
|
|
15
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-state'],
|
|
16
16
|
recurse: false,
|
|
17
17
|
useMetadataFile: true,
|
|
18
18
|
fixura: {
|
|
19
19
|
failWhenNotFound: true,
|
|
20
20
|
reader: READERS.JSON
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
hooks: {
|
|
23
23
|
before: async () => {
|
|
24
24
|
//debug(`<< Before`);
|
|
25
25
|
await initMongofixtures();
|
|
@@ -42,7 +42,7 @@ generateTests({
|
|
|
42
42
|
async function initMongofixtures() {
|
|
43
43
|
mongoFixtures = await mongoFixturesFactory({
|
|
44
44
|
recurse: false,
|
|
45
|
-
rootPath: [
|
|
45
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongo', 'set-state'],
|
|
46
46
|
gridFS: {bucketName: 'foobar'},
|
|
47
47
|
useObjectId: true
|
|
48
48
|
});
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import assert from 'node:assert';
|
|
2
2
|
import {READERS} from '@natlibfi/fixura';
|
|
3
3
|
import generateTests from '@natlibfi/fixugen';
|
|
4
4
|
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
5
|
-
import
|
|
6
|
-
import createMongoLogOperator from '../src/mongoLog';
|
|
5
|
+
import createMongoLogOperator from '../src/mongoLog.js';
|
|
7
6
|
|
|
8
7
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
9
8
|
|
|
10
9
|
generateTests({
|
|
11
10
|
callback,
|
|
12
|
-
path: [
|
|
11
|
+
path: [import.meta.dirname, '..', 'test-fixtures', 'mongoLog'],
|
|
13
12
|
recurse: false,
|
|
14
13
|
useMetadataFile: true,
|
|
15
14
|
fixura: {
|
|
16
15
|
failWhenNotFound: true,
|
|
17
16
|
reader: READERS.JSON
|
|
18
17
|
},
|
|
19
|
-
|
|
18
|
+
hooks: {
|
|
20
19
|
before: async () => {
|
|
21
20
|
await initMongofixtures();
|
|
22
21
|
},
|
|
@@ -30,7 +29,7 @@ generateTests({
|
|
|
30
29
|
|
|
31
30
|
async function initMongofixtures() {
|
|
32
31
|
mongoFixtures = await mongoFixturesFactory({
|
|
33
|
-
rootPath: [
|
|
32
|
+
rootPath: [import.meta.dirname, '..', 'test-fixtures', 'mongoLog'],
|
|
34
33
|
gridFS: {bucketName: 'blobs'},
|
|
35
34
|
useObjectId: true,
|
|
36
35
|
format: {
|
|
@@ -51,34 +50,34 @@ async function callback({
|
|
|
51
50
|
const expectedResult = await getFixture('expectedResult.json');
|
|
52
51
|
// console.log(typeof mongoUri); // eslint-disable-line
|
|
53
52
|
|
|
54
|
-
if (preFillDb) {
|
|
53
|
+
if (preFillDb) {
|
|
55
54
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
if (functionName === 'addLogItem') {
|
|
59
58
|
await mongoLogOperator.addLogItem(params);
|
|
60
59
|
const dump = await mongoFixtures.dump();
|
|
61
|
-
return
|
|
60
|
+
return assert.deepStrictEqual(dump.logs[0]['0'], expectedResult);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
if (functionName === 'getListOfCatalogers') {
|
|
65
64
|
const result = await mongoLogOperator.getListOfCatalogers();
|
|
66
65
|
// console.log(result); // eslint-disable-line
|
|
67
66
|
|
|
68
|
-
return
|
|
67
|
+
return assert.deepEqual(result, expectedResult);
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
if (functionName === 'getExpandedListOfLogs') {
|
|
72
71
|
const result = await mongoLogOperator.getExpandedListOfLogs(params);
|
|
73
72
|
// console.log(result); // eslint-disable-line
|
|
74
73
|
|
|
75
|
-
return
|
|
74
|
+
return assert.deepEqual(result, expectedResult);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
if (functionName === 'getListOfLogs') {
|
|
79
78
|
const result = await mongoLogOperator.getListOfLogs(params);
|
|
80
79
|
// console.log(result); // eslint-disable-line
|
|
81
|
-
return
|
|
80
|
+
return assert.deepEqual(result, expectedResult);
|
|
82
81
|
}
|
|
83
82
|
throw new Error(`Unknown functionName: ${functionName}`);
|
|
84
83
|
}
|
package/tests/testUtils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
2
|
+
import assert from 'node:assert';
|
|
3
3
|
import createDebugLogger from 'debug';
|
|
4
|
-
import createMongoOperator from '../src/mongo';
|
|
4
|
+
import createMongoOperator from '../src/mongo.js';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
|
|
@@ -32,10 +32,10 @@ export async function compareToDbEntry({mongoFixtures, expectedResult, resultInd
|
|
|
32
32
|
|
|
33
33
|
if (formatDates && expectedResult !== undefined) {
|
|
34
34
|
const formattedResult = formatQueueItem(result);
|
|
35
|
-
|
|
35
|
+
assert.deepStrictEqual(formattedResult, expectedResult);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
assert.deepStrictEqual(result, expectedResult);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ function checkFileCount({dump, expectedFileCount}) {
|
|
|
43
43
|
if (expectedFileCount !== undefined) {
|
|
44
44
|
const fileCount = dump['foobar.files']?.length;
|
|
45
45
|
debug(`--- We have ${fileCount} files in db`);
|
|
46
|
-
|
|
46
|
+
assert.equal(fileCount, expectedFileCount);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
return;
|
|
@@ -53,7 +53,8 @@ function checkFileCount({dump, expectedFileCount}) {
|
|
|
53
53
|
function checkModificationTime({result, expectModificationTime}) {
|
|
54
54
|
if (expectModificationTime) {
|
|
55
55
|
debug('Check if modificationTime was edited');
|
|
56
|
-
|
|
56
|
+
const isNotEmpty = result.modificationTime !== '';
|
|
57
|
+
assert.equal(isNotEmpty, true);
|
|
57
58
|
debug(`OK. We have modified modificationTime`);
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
@@ -80,9 +81,9 @@ export function handleError({error, expectedToThrow, expectedErrorMessage, expec
|
|
|
80
81
|
if (expectedErrorMessage !== '' || expectedErrorStatus !== '') {
|
|
81
82
|
const errorMessage = error.message || error.payload.message || error.payload || '';
|
|
82
83
|
debug(errorMessage);
|
|
83
|
-
|
|
84
|
+
assert.equal(errorMessage, expectedErrorMessage);
|
|
84
85
|
const errorStatus = error.status || '';
|
|
85
|
-
|
|
86
|
+
assert.equal(errorStatus, expectedErrorStatus);
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
89
|
return;
|