@natlibfi/melinda-rest-api-commons 6.2.0-alpha.0 → 6.2.0-alpha.2
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/README.md +165 -14
- package/dist/amqp.d.ts.map +1 -1
- package/dist/amqp.js +14 -0
- package/dist/amqp.js.map +1 -1
- package/dist/helpers/conversion.d.ts.map +1 -1
- package/dist/helpers/conversion.js.map +1 -1
- package/dist/helpers/fix-constants.d.ts.map +1 -1
- package/dist/helpers/fix-constants.js.map +1 -1
- package/dist/helpers/fix-strip-f884s.js.map +1 -1
- package/dist/mongo.d.ts +1 -0
- package/dist/mongo.d.ts.map +1 -1
- package/dist/mongo.js +25 -2
- package/dist/mongo.js.map +1 -1
- package/dist/mongoLog.d.ts +1 -0
- package/dist/mongoLog.d.ts.map +1 -1
- package/dist/mongoLog.js +12 -3
- package/dist/mongoLog.js.map +1 -1
- package/package.json +3 -1
- package/test/amqp-error-branches.test.ts +67 -9
- package/test/amqp.healthtest.ts +12 -8
- package/test/mongo-add-blob-size.test.ts +6 -0
- package/test/mongo-check-and-check-state.test.ts +6 -0
- package/test/mongo-check-and-set-import-job-state.test.ts +6 -0
- package/test/mongo-check-timeout.test.ts +6 -0
- package/test/mongo-create-bulk.test.ts +6 -0
- package/test/mongo-create-prio.test.ts +6 -0
- package/test/mongo-error-branches.test.ts +118 -18
- package/test/mongo-get-one.test.ts +6 -0
- package/test/mongo-get-stream.test.ts +6 -0
- package/test/mongo-push-ids.test.ts +6 -0
- package/test/mongo-push-messages.test.ts +6 -0
- package/test/mongo-query-by-id.test.ts +6 -0
- package/test/mongo-query.test.ts +6 -0
- package/test/mongo-read-content.test.ts +6 -0
- package/test/mongo-remove.test.ts +6 -0
- package/test/mongo-set-blob-size.test.ts +6 -0
- package/test/mongo-set-import-job-state.test.ts +6 -0
- package/test/mongo-set-operation.test.ts +6 -0
- package/test/mongo-set-operations.test.ts +6 -0
- package/test/mongo-set-state.test.ts +6 -0
- package/test/mongoLog-protect.test.ts +1 -0
- package/test/mongoLog.test.ts +6 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
|
-
import {test} from 'node:test';
|
|
2
|
+
import {test, after} from 'node:test';
|
|
3
3
|
import {Readable, PassThrough} from 'node:stream';
|
|
4
4
|
import httpStatus from 'http-status';
|
|
5
5
|
import {MongoDriverError} from 'mongodb';
|
|
@@ -9,6 +9,9 @@ import createMongoLog from '../src/mongoLog.ts';
|
|
|
9
9
|
|
|
10
10
|
const DUMMY_URI = 'mongodb://stub:27017/rest-api';
|
|
11
11
|
const COLLECTION = 'foobar';
|
|
12
|
+
// every test creates its own (stubbed) operators; close them all at the
|
|
13
|
+
// end - close is a no-op for stubbed factories, which is the point
|
|
14
|
+
const stubOperators: any[] = [];
|
|
12
15
|
|
|
13
16
|
// the deps seam takes unknown-typed dependencies, so plain stub objects
|
|
14
17
|
// are fine to inject (the driver types are never exercised here)
|
|
@@ -35,7 +38,9 @@ function makeGridFSBucket(overrides: Record<string, any> = {}) {
|
|
|
35
38
|
* @param deps the injected stub operator/gridFSBucket
|
|
36
39
|
*/
|
|
37
40
|
async function makeMongo(deps: Record<string, any>) {
|
|
38
|
-
|
|
41
|
+
const mongo = await createMongo(DUMMY_URI, COLLECTION, 'rest-api', deps);
|
|
42
|
+
stubOperators.push(mongo);
|
|
43
|
+
return mongo;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
// The 400-guard tests pass intentionally malformed inputs (non-string
|
|
@@ -214,6 +219,88 @@ test('checkTimeOut returns false (no crash) when the queueItem does not exist',
|
|
|
214
219
|
assert.equal(result, false);
|
|
215
220
|
});
|
|
216
221
|
|
|
222
|
+
// checkAndSetState / checkAndSetImportJobState must report a missing item
|
|
223
|
+
// as 'unchanged' (with a null queueItem) — not as a timeout
|
|
224
|
+
|
|
225
|
+
test('checkAndSetState returns {status: "unchanged", queueItem: null} when the queueItem does not exist', async () => {
|
|
226
|
+
const mongo = await makeMongo({
|
|
227
|
+
operator: makeOperator({findOne: async () => null}),
|
|
228
|
+
gridFSBucket: makeGridFSBucket()
|
|
229
|
+
});
|
|
230
|
+
const result = await mongo.checkAndSetState({correlationId: 'NOPE', state: 'VALIDATING'});
|
|
231
|
+
assert.deepStrictEqual(result, {status: 'unchanged', queueItem: null});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('checkAndSetImportJobState returns {status: "unchanged", queueItem: null} when the queueItem does not exist', async () => {
|
|
235
|
+
const mongo = await makeMongo({
|
|
236
|
+
operator: makeOperator({findOne: async () => null}),
|
|
237
|
+
gridFSBucket: makeGridFSBucket()
|
|
238
|
+
});
|
|
239
|
+
const result = await mongo.checkAndSetImportJobState({correlationId: 'NOPE', operation: 'FIX', importJobState: 'DONE'});
|
|
240
|
+
assert.deepStrictEqual(result, {status: 'unchanged', queueItem: null});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// a pre-existing ABORT item must be reported as 'unchanged' (not
|
|
244
|
+
// 'timeout', which is reserved for items aborted by checkTimeOut in this
|
|
245
|
+
// call) and the document must be left untouched
|
|
246
|
+
|
|
247
|
+
test('checkAndSetState reports a pre-existing ABORT as "unchanged" without writing', async () => {
|
|
248
|
+
const doc = {correlationId: 'FOO', queueItemState: 'ABORT', errorStatus: 408, errorMessage: 'Timeout in VALIDATING'};
|
|
249
|
+
const writes: unknown[] = [];
|
|
250
|
+
const mongo = await makeMongo({
|
|
251
|
+
operator: makeOperator({
|
|
252
|
+
findOne: async () => doc,
|
|
253
|
+
findOneAndUpdate: async (filter: unknown, update: unknown) => {
|
|
254
|
+
writes.push({filter, update});
|
|
255
|
+
return doc;
|
|
256
|
+
}
|
|
257
|
+
}),
|
|
258
|
+
gridFSBucket: makeGridFSBucket()
|
|
259
|
+
});
|
|
260
|
+
const result = await mongo.checkAndSetState({correlationId: 'FOO', state: 'VALIDATING'});
|
|
261
|
+
assert.deepStrictEqual(result, {status: 'unchanged', queueItem: doc});
|
|
262
|
+
assert.deepStrictEqual(writes, []);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('checkAndSetImportJobState reports a pre-existing ABORT as "unchanged" without writing', async () => {
|
|
266
|
+
const doc = {correlationId: 'FOO', queueItemState: 'ABORT', errorStatus: 408, errorMessage: 'Timeout in VALIDATING'};
|
|
267
|
+
const writes: unknown[] = [];
|
|
268
|
+
const mongo = await makeMongo({
|
|
269
|
+
operator: makeOperator({
|
|
270
|
+
findOne: async () => doc,
|
|
271
|
+
findOneAndUpdate: async (filter: unknown, update: unknown) => {
|
|
272
|
+
writes.push({filter, update});
|
|
273
|
+
return doc;
|
|
274
|
+
}
|
|
275
|
+
}),
|
|
276
|
+
gridFSBucket: makeGridFSBucket()
|
|
277
|
+
});
|
|
278
|
+
const result = await mongo.checkAndSetImportJobState({correlationId: 'FOO', operation: 'FIX', importJobState: 'DONE'});
|
|
279
|
+
assert.deepStrictEqual(result, {status: 'unchanged', queueItem: doc});
|
|
280
|
+
assert.deepStrictEqual(writes, []);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// a pre-existing DONE item is terminal too (like ABORT/ERROR) and must be
|
|
284
|
+
// reported as 'unchanged' without touching the document
|
|
285
|
+
|
|
286
|
+
test('checkAndSetState reports a pre-existing DONE as "unchanged" without writing', async () => {
|
|
287
|
+
const doc = {correlationId: 'FOO', queueItemState: 'DONE'};
|
|
288
|
+
const writes: unknown[] = [];
|
|
289
|
+
const mongo = await makeMongo({
|
|
290
|
+
operator: makeOperator({
|
|
291
|
+
findOne: async () => doc,
|
|
292
|
+
findOneAndUpdate: async (filter: unknown, update: unknown) => {
|
|
293
|
+
writes.push({filter, update});
|
|
294
|
+
return doc;
|
|
295
|
+
}
|
|
296
|
+
}),
|
|
297
|
+
gridFSBucket: makeGridFSBucket()
|
|
298
|
+
});
|
|
299
|
+
const result = await mongo.checkAndSetState({correlationId: 'FOO', state: 'VALIDATING'});
|
|
300
|
+
assert.deepStrictEqual(result, {status: 'unchanged', queueItem: doc});
|
|
301
|
+
assert.deepStrictEqual(writes, []);
|
|
302
|
+
});
|
|
303
|
+
|
|
217
304
|
test('setOperation rejects with ApiError 404 for a non-matching correlationId', async () => {
|
|
218
305
|
const mongo = await makeMongo({
|
|
219
306
|
operator: makeOperator({findOne: async () => null}),
|
|
@@ -286,21 +373,26 @@ test('createBulk (stream) returns the normalized {correlationId, acknowledged, q
|
|
|
286
373
|
|
|
287
374
|
test('checkTimeOut honours MONGO_TIMEOUT_MINUTES (older item than the window is aborted)', async () => {
|
|
288
375
|
process.env['MONGO_TIMEOUT_MINUTES'] = '5';
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
376
|
+
try {
|
|
377
|
+
const oldDate = new Date(Date.now() - 4 * 60 * 1000); // 4 min old: fine at 5m, not at 1m
|
|
378
|
+
const mongo = await makeMongo({
|
|
379
|
+
operator: makeOperator({
|
|
380
|
+
findOne: async () => ({
|
|
381
|
+
correlationId: 'FOO',
|
|
382
|
+
queueItemState: 'VALIDATING',
|
|
383
|
+
modificationTime: oldDate,
|
|
384
|
+
importJobState: {CREATE: 'DONE', UPDATE: 'DONE', FIX: 'DONE'}
|
|
385
|
+
})
|
|
386
|
+
}),
|
|
387
|
+
gridFSBucket: makeGridFSBucket()
|
|
388
|
+
});
|
|
389
|
+
const result = await mongo.checkTimeOut({correlationId: 'FOO'});
|
|
390
|
+
assert.equal(result, true);
|
|
391
|
+
} finally {
|
|
392
|
+
// restore the env even on failure so a later operator does not inherit a
|
|
393
|
+
// 5-minute timeout window
|
|
394
|
+
delete process.env['MONGO_TIMEOUT_MINUTES'];
|
|
395
|
+
}
|
|
304
396
|
});
|
|
305
397
|
|
|
306
398
|
// createBulk stream path used to have no error handling on the GridFS
|
|
@@ -745,9 +837,17 @@ function makeLogCollection(overrides: Record<string, any> = {}) {
|
|
|
745
837
|
* @param deps the injected stub collection
|
|
746
838
|
*/
|
|
747
839
|
async function makeMongoLog(deps: Record<string, any>) {
|
|
748
|
-
|
|
840
|
+
const mongoLog = await createMongoLog(DUMMY_URI, 'rest-api', deps);
|
|
841
|
+
stubOperators.push(mongoLog);
|
|
842
|
+
return mongoLog;
|
|
749
843
|
}
|
|
750
844
|
|
|
845
|
+
after(async () => {
|
|
846
|
+
for (const op of stubOperators) {
|
|
847
|
+
await op.close();
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
|
|
751
851
|
function mongoErrored500(text: string) {
|
|
752
852
|
return (error: unknown) => {
|
|
753
853
|
assert.ok(error instanceof ApiError);
|
|
@@ -8,6 +8,7 @@ import {getMongoOperator, handleError} from './testUtils.ts';
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures: any;
|
|
11
|
+
const openedOperators: any[] = [];
|
|
11
12
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:get-one:test');
|
|
12
13
|
|
|
13
14
|
generateTests({
|
|
@@ -34,6 +35,10 @@ generateTests({
|
|
|
34
35
|
},
|
|
35
36
|
after: async () => {
|
|
36
37
|
//debug(`<< After`);
|
|
38
|
+
// close the operators the tests opened (one per test) before the server
|
|
39
|
+
for (const op of openedOperators) {
|
|
40
|
+
await op.close();
|
|
41
|
+
}
|
|
37
42
|
await mongoFixtures.close();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -60,6 +65,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
60
65
|
} = callbackParams;
|
|
61
66
|
|
|
62
67
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
68
|
+
openedOperators.push(mongoOperator);
|
|
63
69
|
//const expectedResult = await getFixture('expectedResult.json');
|
|
64
70
|
|
|
65
71
|
await doPreFillDb(preFillDb);
|
|
@@ -7,6 +7,7 @@ import createDebugLogger from 'debug';
|
|
|
7
7
|
import {getMongoOperator, handleError, streamToString} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:get-stream:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -60,6 +65,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
60
65
|
} = callbackParams;
|
|
61
66
|
|
|
62
67
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
68
|
+
openedOperators.push(mongoOperator);
|
|
63
69
|
//const expectedResult = await getFixture('expectedResult.json');
|
|
64
70
|
|
|
65
71
|
await doPreFillDb(preFillDb);
|
|
@@ -7,6 +7,7 @@ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:push-ids:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -59,6 +64,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
59
64
|
} = callbackParams;
|
|
60
65
|
|
|
61
66
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
67
|
+
openedOperators.push(mongoOperator);
|
|
62
68
|
const expectedResult = await getFixture('expectedResult.json');
|
|
63
69
|
|
|
64
70
|
await doPreFillDb(preFillDb);
|
|
@@ -7,6 +7,7 @@ import createDebugLogger from 'debug';
|
|
|
7
7
|
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:push-messages:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -59,6 +64,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
59
64
|
} = callbackParams;
|
|
60
65
|
|
|
61
66
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
67
|
+
openedOperators.push(mongoOperator);
|
|
62
68
|
const expectedResult = await getFixture('expectedResult.json');
|
|
63
69
|
|
|
64
70
|
await doPreFillDb(preFillDb);
|
|
@@ -8,6 +8,7 @@ import {getMongoOperator, handleError, compareToDbEntry, formatQueueItem} from '
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures: any;
|
|
11
|
+
const openedOperators: any[] = [];
|
|
11
12
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:query-by-id:test');
|
|
12
13
|
|
|
13
14
|
generateTests({
|
|
@@ -34,6 +35,10 @@ generateTests({
|
|
|
34
35
|
},
|
|
35
36
|
after: async () => {
|
|
36
37
|
//debug(`<< After`);
|
|
38
|
+
// close the operators the tests opened (one per test) before the server
|
|
39
|
+
for (const op of openedOperators) {
|
|
40
|
+
await op.close();
|
|
41
|
+
}
|
|
37
42
|
await mongoFixtures.close();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -63,6 +68,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
63
68
|
} = callbackParams;
|
|
64
69
|
|
|
65
70
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
71
|
+
openedOperators.push(mongoOperator);
|
|
66
72
|
const expectedResult = await getFixture('expectedResult.json');
|
|
67
73
|
|
|
68
74
|
await doPreFillDb(preFillDb);
|
package/test/mongo-query.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import createDebugLogger from 'debug';
|
|
|
7
7
|
import {getMongoOperator, handleError} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -59,6 +64,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
59
64
|
} = callbackParams;
|
|
60
65
|
|
|
61
66
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
67
|
+
openedOperators.push(mongoOperator);
|
|
62
68
|
//const expectedResult = await getFixture('expectedResult.json');
|
|
63
69
|
|
|
64
70
|
await doPreFillDb(preFillDb);
|
|
@@ -8,6 +8,7 @@ import {getMongoOperator, handleError, streamToString} from './testUtils.ts';
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures: any;
|
|
11
|
+
const openedOperators: any[] = [];
|
|
11
12
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:read-content:test');
|
|
12
13
|
|
|
13
14
|
generateTests({
|
|
@@ -34,6 +35,10 @@ generateTests({
|
|
|
34
35
|
},
|
|
35
36
|
after: async () => {
|
|
36
37
|
//debug(`<< After`);
|
|
38
|
+
// close the operators the tests opened (one per test) before the server
|
|
39
|
+
for (const op of openedOperators) {
|
|
40
|
+
await op.close();
|
|
41
|
+
}
|
|
37
42
|
await mongoFixtures.close();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -61,6 +66,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
61
66
|
} = callbackParams;
|
|
62
67
|
|
|
63
68
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
69
|
+
openedOperators.push(mongoOperator);
|
|
64
70
|
//const expectedResult = await getFixture('expectedResult.json');
|
|
65
71
|
|
|
66
72
|
await doPreFillDb(preFillDb);
|
|
@@ -8,6 +8,7 @@ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures: any;
|
|
11
|
+
const openedOperators: any[] = [];
|
|
11
12
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:remove:test');
|
|
12
13
|
|
|
13
14
|
generateTests({
|
|
@@ -34,6 +35,10 @@ generateTests({
|
|
|
34
35
|
},
|
|
35
36
|
after: async () => {
|
|
36
37
|
//debug(`<< After`);
|
|
38
|
+
// close the operators the tests opened (one per test) before the server
|
|
39
|
+
for (const op of openedOperators) {
|
|
40
|
+
await op.close();
|
|
41
|
+
}
|
|
37
42
|
await mongoFixtures.close();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -64,6 +69,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
64
69
|
} = callbackParams;
|
|
65
70
|
|
|
66
71
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
72
|
+
openedOperators.push(mongoOperator);
|
|
67
73
|
const expectedResult = await getFixture('expectedResult.json');
|
|
68
74
|
|
|
69
75
|
await doPreFillDb(preFillDb);
|
|
@@ -7,6 +7,7 @@ import createDebugLogger from 'debug';
|
|
|
7
7
|
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-blob-size:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -59,6 +64,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
59
64
|
} = callbackParams;
|
|
60
65
|
|
|
61
66
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
67
|
+
openedOperators.push(mongoOperator);
|
|
62
68
|
const expectedResult = await getFixture('expectedResult.json');
|
|
63
69
|
|
|
64
70
|
await doPreFillDb(preFillDb);
|
|
@@ -8,6 +8,7 @@ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures: any;
|
|
11
|
+
const openedOperators: any[] = [];
|
|
11
12
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-import-job-state:test');
|
|
12
13
|
|
|
13
14
|
generateTests({
|
|
@@ -34,6 +35,10 @@ generateTests({
|
|
|
34
35
|
},
|
|
35
36
|
after: async () => {
|
|
36
37
|
//debug(`<< After`);
|
|
38
|
+
// close the operators the tests opened (one per test) before the server
|
|
39
|
+
for (const op of openedOperators) {
|
|
40
|
+
await op.close();
|
|
41
|
+
}
|
|
37
42
|
await mongoFixtures.close();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -60,6 +65,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
60
65
|
} = callbackParams;
|
|
61
66
|
|
|
62
67
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
68
|
+
openedOperators.push(mongoOperator);
|
|
63
69
|
const expectedResult = await getFixture('expectedResult.json');
|
|
64
70
|
|
|
65
71
|
await doPreFillDb(preFillDb);
|
|
@@ -7,6 +7,7 @@ import createDebugLogger from 'debug';
|
|
|
7
7
|
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operation:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -59,6 +64,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
59
64
|
} = callbackParams;
|
|
60
65
|
|
|
61
66
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
67
|
+
openedOperators.push(mongoOperator);
|
|
62
68
|
const expectedResult = await getFixture('expectedResult.json');
|
|
63
69
|
|
|
64
70
|
await doPreFillDb(preFillDb);
|
|
@@ -7,6 +7,7 @@ import createDebugLogger from 'debug';
|
|
|
7
7
|
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.ts';
|
|
8
8
|
|
|
9
9
|
let mongoFixtures: any;
|
|
10
|
+
const openedOperators: any[] = [];
|
|
10
11
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operations:test');
|
|
11
12
|
|
|
12
13
|
generateTests({
|
|
@@ -33,6 +34,10 @@ generateTests({
|
|
|
33
34
|
},
|
|
34
35
|
after: async () => {
|
|
35
36
|
//debug(`<< After`);
|
|
37
|
+
// close the operators the tests opened (one per test) before the server
|
|
38
|
+
for (const op of openedOperators) {
|
|
39
|
+
await op.close();
|
|
40
|
+
}
|
|
36
41
|
await mongoFixtures.close();
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -59,6 +64,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
59
64
|
} = callbackParams;
|
|
60
65
|
|
|
61
66
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
67
|
+
openedOperators.push(mongoOperator);
|
|
62
68
|
const expectedResult = await getFixture('expectedResult.json');
|
|
63
69
|
|
|
64
70
|
await doPreFillDb(preFillDb);
|
|
@@ -8,6 +8,7 @@ import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils.
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
let mongoFixtures: any;
|
|
11
|
+
const openedOperators: any[] = [];
|
|
11
12
|
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-state:test');
|
|
12
13
|
|
|
13
14
|
generateTests({
|
|
@@ -34,6 +35,10 @@ generateTests({
|
|
|
34
35
|
},
|
|
35
36
|
after: async () => {
|
|
36
37
|
//debug(`<< After`);
|
|
38
|
+
// close the operators the tests opened (one per test) before the server
|
|
39
|
+
for (const op of openedOperators) {
|
|
40
|
+
await op.close();
|
|
41
|
+
}
|
|
37
42
|
await mongoFixtures.close();
|
|
38
43
|
}
|
|
39
44
|
}
|
|
@@ -60,6 +65,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
60
65
|
} = callbackParams;
|
|
61
66
|
|
|
62
67
|
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
68
|
+
openedOperators.push(mongoOperator);
|
|
63
69
|
const expectedResult = await getFixture('expectedResult.json');
|
|
64
70
|
|
|
65
71
|
await doPreFillDb(preFillDb);
|
package/test/mongoLog.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
|
6
6
|
import createMongoLogOperator from '../src/mongoLog.ts';
|
|
7
7
|
|
|
8
8
|
let mongoFixtures: any;
|
|
9
|
+
const openedOperators: any[] = [];
|
|
9
10
|
|
|
10
11
|
generateTests({
|
|
11
12
|
callback,
|
|
@@ -23,6 +24,10 @@ generateTests({
|
|
|
23
24
|
beforeEach: () => mongoFixtures.clear(),
|
|
24
25
|
afterEach: () => mongoFixtures.clear(),
|
|
25
26
|
after: async () => {
|
|
27
|
+
// close the operators the tests opened (one per test) before the server
|
|
28
|
+
for (const op of openedOperators) {
|
|
29
|
+
await op.close();
|
|
30
|
+
}
|
|
26
31
|
await mongoFixtures.close();
|
|
27
32
|
}
|
|
28
33
|
}
|
|
@@ -58,6 +63,7 @@ async function callback(callbackParams: Record<string, any>) {
|
|
|
58
63
|
} = callbackParams;
|
|
59
64
|
const mongoUri = await mongoFixtures.getUri();
|
|
60
65
|
const mongoLogOperator = await createMongoLogOperator(mongoUri, '');
|
|
66
|
+
openedOperators.push(mongoLogOperator);
|
|
61
67
|
const expectedResult = expectError ? undefined : await getFixture('expectedResult.json');
|
|
62
68
|
|
|
63
69
|
if (expectError) {
|