@natlibfi/melinda-rest-api-commons 4.2.4-alpha.7 → 4.2.4
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/dist/mongo.js +15 -9
- package/dist/mongo.js.map +1 -1
- package/package.json +15 -14
- 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 -768
- package/dist/mongo.spec.js.map +0 -1
- package/dist/mongoLog.spec.js.map +0 -1
|
@@ -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
|
+
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operation:test');
|
|
11
|
+
|
|
12
|
+
generateTests({
|
|
13
|
+
callback,
|
|
14
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
|
|
15
|
+
recurse: false,
|
|
16
|
+
useMetadataFile: true,
|
|
17
|
+
fixura: {
|
|
18
|
+
failWhenNotFound: true,
|
|
19
|
+
reader: READERS.JSON
|
|
20
|
+
},
|
|
21
|
+
mocha: {
|
|
22
|
+
before: async () => {
|
|
23
|
+
//debug(`<< Before`);
|
|
24
|
+
await initMongofixtures();
|
|
25
|
+
},
|
|
26
|
+
beforeEach: async () => {
|
|
27
|
+
//debug(`<< BeforeEach`);
|
|
28
|
+
await mongoFixtures.clear();
|
|
29
|
+
},
|
|
30
|
+
afterEach: async () => {
|
|
31
|
+
//debug(`<< AfterEach`);
|
|
32
|
+
await mongoFixtures.clear();
|
|
33
|
+
},
|
|
34
|
+
after: async () => {
|
|
35
|
+
//debug(`<< After`);
|
|
36
|
+
await mongoFixtures.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
async function initMongofixtures() {
|
|
42
|
+
mongoFixtures = await mongoFixturesFactory({
|
|
43
|
+
recurse: false,
|
|
44
|
+
rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operation'],
|
|
45
|
+
gridFS: {bucketName: 'foobar'},
|
|
46
|
+
useObjectId: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function callback({
|
|
51
|
+
getFixture,
|
|
52
|
+
functionName,
|
|
53
|
+
params,
|
|
54
|
+
expectModificationTime = false,
|
|
55
|
+
preFillDb = false,
|
|
56
|
+
expectedToThrow = false,
|
|
57
|
+
expectedErrorMessage = '',
|
|
58
|
+
expectedErrorStatus = ''
|
|
59
|
+
}) {
|
|
60
|
+
|
|
61
|
+
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
62
|
+
const expectedResult = await getFixture('expectedResult.json');
|
|
63
|
+
|
|
64
|
+
await doPreFillDb(preFillDb);
|
|
65
|
+
|
|
66
|
+
async function doPreFillDb(preFillDb) {
|
|
67
|
+
if (preFillDb) {
|
|
68
|
+
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (functionName === 'setOperation') {
|
|
75
|
+
try {
|
|
76
|
+
debug(`setOperation`);
|
|
77
|
+
debug(JSON.stringify(params));
|
|
78
|
+
//{correlationId, operation}
|
|
79
|
+
const opResult = await mongoOperator.setOperation(params);
|
|
80
|
+
debug(`setOperation result: ${JSON.stringify(opResult)}`);
|
|
81
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
82
|
+
|
|
83
|
+
} catch (error) {
|
|
84
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//import {expect} from 'chai';
|
|
2
|
+
import {READERS} from '@natlibfi/fixura';
|
|
3
|
+
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
4
|
+
import generateTests from '@natlibfi/fixugen';
|
|
5
|
+
import createDebugLogger from 'debug';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
8
|
+
|
|
9
|
+
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
10
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-operations:test');
|
|
11
|
+
|
|
12
|
+
generateTests({
|
|
13
|
+
callback,
|
|
14
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
|
|
15
|
+
recurse: false,
|
|
16
|
+
useMetadataFile: true,
|
|
17
|
+
fixura: {
|
|
18
|
+
failWhenNotFound: true,
|
|
19
|
+
reader: READERS.JSON
|
|
20
|
+
},
|
|
21
|
+
mocha: {
|
|
22
|
+
before: async () => {
|
|
23
|
+
//debug(`<< Before`);
|
|
24
|
+
await initMongofixtures();
|
|
25
|
+
},
|
|
26
|
+
beforeEach: async () => {
|
|
27
|
+
//debug(`<< BeforeEach`);
|
|
28
|
+
await mongoFixtures.clear();
|
|
29
|
+
},
|
|
30
|
+
afterEach: async () => {
|
|
31
|
+
//debug(`<< AfterEach`);
|
|
32
|
+
await mongoFixtures.clear();
|
|
33
|
+
},
|
|
34
|
+
after: async () => {
|
|
35
|
+
//debug(`<< After`);
|
|
36
|
+
await mongoFixtures.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
async function initMongofixtures() {
|
|
42
|
+
mongoFixtures = await mongoFixturesFactory({
|
|
43
|
+
recurse: false,
|
|
44
|
+
rootPath: [__dirname, '..', 'test-fixtures', 'mongo', 'set-operations'],
|
|
45
|
+
gridFS: {bucketName: 'foobar'},
|
|
46
|
+
useObjectId: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function callback({
|
|
51
|
+
getFixture,
|
|
52
|
+
functionName,
|
|
53
|
+
params,
|
|
54
|
+
expectModificationTime = false,
|
|
55
|
+
preFillDb = false,
|
|
56
|
+
expectedToThrow = false,
|
|
57
|
+
expectedErrorMessage = '',
|
|
58
|
+
expectedErrorStatus = ''
|
|
59
|
+
}) {
|
|
60
|
+
|
|
61
|
+
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
62
|
+
const expectedResult = await getFixture('expectedResult.json');
|
|
63
|
+
|
|
64
|
+
await doPreFillDb(preFillDb);
|
|
65
|
+
|
|
66
|
+
async function doPreFillDb(preFillDb) {
|
|
67
|
+
if (preFillDb) {
|
|
68
|
+
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if (functionName === 'setOperations') {
|
|
76
|
+
try {
|
|
77
|
+
debug(`setOperations`);
|
|
78
|
+
debug(JSON.stringify(params));
|
|
79
|
+
//{correlationId, addOperation, removeOperation = undefined}
|
|
80
|
+
const opResult = await mongoOperator.setOperations(params);
|
|
81
|
+
debug(`setOperations result: ${JSON.stringify(opResult)}`);
|
|
82
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//import {expect} from 'chai';
|
|
2
|
+
import {READERS} from '@natlibfi/fixura';
|
|
3
|
+
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
4
|
+
import generateTests from '@natlibfi/fixugen';
|
|
5
|
+
import createDebugLogger from 'debug';
|
|
6
|
+
//import {handleError, compareToFirstDbEntry, compareToDbEntry, formatQueueItem, streamToString} from './testUtils';
|
|
7
|
+
import {getMongoOperator, handleError, compareToFirstDbEntry} from './testUtils';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
11
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:set-state:test');
|
|
12
|
+
|
|
13
|
+
generateTests({
|
|
14
|
+
callback,
|
|
15
|
+
path: [__dirname, '..', 'test-fixtures', 'mongo', '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', '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
|
+
}) {
|
|
61
|
+
|
|
62
|
+
const mongoOperator = await getMongoOperator(mongoFixtures);
|
|
63
|
+
const expectedResult = await getFixture('expectedResult.json');
|
|
64
|
+
|
|
65
|
+
await doPreFillDb(preFillDb);
|
|
66
|
+
|
|
67
|
+
async function doPreFillDb(preFillDb) {
|
|
68
|
+
if (preFillDb) {
|
|
69
|
+
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if (functionName === 'setState') {
|
|
77
|
+
try {
|
|
78
|
+
debug(`setState`);
|
|
79
|
+
debug(JSON.stringify(params));
|
|
80
|
+
//{correlationId, state, errorMessage = undefined, errorStatus = undefined}
|
|
81
|
+
const opResult = await mongoOperator.setState(params);
|
|
82
|
+
debug(`setState result: ${JSON.stringify(opResult)}`);
|
|
83
|
+
await compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime, formatDates: true});
|
|
84
|
+
|
|
85
|
+
} catch (error) {
|
|
86
|
+
handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Unknown functionName: ${functionName}`);
|
|
92
|
+
}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _fixura = require("@natlibfi/fixura");
|
|
5
|
-
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
6
|
-
var _fixuraMongo = _interopRequireDefault(require("@natlibfi/fixura-mongo"));
|
|
7
|
-
var _chai = require("chai");
|
|
8
|
-
var _mongoLog = _interopRequireDefault(require("./mongoLog"));
|
|
9
1
|
// import {expect} from 'chai';
|
|
2
|
+
import {READERS} from '@natlibfi/fixura';
|
|
3
|
+
import generateTests from '@natlibfi/fixugen';
|
|
4
|
+
import mongoFixturesFactory from '@natlibfi/fixura-mongo';
|
|
5
|
+
import {expect} from 'chai';
|
|
6
|
+
import createMongoLogOperator from '../src/mongoLog';
|
|
10
7
|
|
|
11
8
|
let mongoFixtures; // eslint-disable-line functional/no-let
|
|
12
9
|
|
|
13
|
-
(
|
|
10
|
+
generateTests({
|
|
14
11
|
callback,
|
|
15
12
|
path: [__dirname, '..', 'test-fixtures', 'mongoLog'],
|
|
16
13
|
recurse: false,
|
|
17
14
|
useMetadataFile: true,
|
|
18
15
|
fixura: {
|
|
19
16
|
failWhenNotFound: true,
|
|
20
|
-
reader:
|
|
17
|
+
reader: READERS.JSON
|
|
21
18
|
},
|
|
22
19
|
mocha: {
|
|
23
20
|
before: async () => {
|
|
@@ -30,12 +27,11 @@ let mongoFixtures; // eslint-disable-line functional/no-let
|
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
29
|
});
|
|
30
|
+
|
|
33
31
|
async function initMongofixtures() {
|
|
34
|
-
mongoFixtures = await (
|
|
32
|
+
mongoFixtures = await mongoFixturesFactory({
|
|
35
33
|
rootPath: [__dirname, '..', 'test-fixtures', 'mongoLog'],
|
|
36
|
-
gridFS: {
|
|
37
|
-
bucketName: 'blobs'
|
|
38
|
-
},
|
|
34
|
+
gridFS: {bucketName: 'blobs'},
|
|
39
35
|
useObjectId: true,
|
|
40
36
|
format: {
|
|
41
37
|
creationTime: v => new Date(v),
|
|
@@ -43,6 +39,7 @@ async function initMongofixtures() {
|
|
|
43
39
|
}
|
|
44
40
|
});
|
|
45
41
|
}
|
|
42
|
+
|
|
46
43
|
async function callback({
|
|
47
44
|
getFixture,
|
|
48
45
|
functionName,
|
|
@@ -50,36 +47,39 @@ async function callback({
|
|
|
50
47
|
preFillDb = false
|
|
51
48
|
}) {
|
|
52
49
|
const mongoUri = await mongoFixtures.getUri();
|
|
53
|
-
const mongoLogOperator = await (
|
|
50
|
+
const mongoLogOperator = await createMongoLogOperator(mongoUri, '');
|
|
54
51
|
const expectedResult = await getFixture('expectedResult.json');
|
|
55
52
|
// console.log(typeof mongoUri); // eslint-disable-line
|
|
56
53
|
|
|
57
|
-
if (preFillDb) {
|
|
58
|
-
// eslint-disable-line functional/no-conditional-statements
|
|
54
|
+
if (preFillDb) { // eslint-disable-line functional/no-conditional-statements
|
|
59
55
|
await mongoFixtures.populate(getFixture('dbContents.json'));
|
|
60
56
|
}
|
|
57
|
+
|
|
61
58
|
if (functionName === 'addLogItem') {
|
|
62
59
|
await mongoLogOperator.addLogItem(params);
|
|
63
60
|
const dump = await mongoFixtures.dump();
|
|
64
|
-
return
|
|
61
|
+
return expect(dump.logs[0]['0']).to.eql(expectedResult);
|
|
65
62
|
}
|
|
63
|
+
|
|
66
64
|
if (functionName === 'getListOfCatalogers') {
|
|
67
65
|
const result = await mongoLogOperator.getListOfCatalogers();
|
|
68
66
|
// console.log(result); // eslint-disable-line
|
|
69
67
|
|
|
70
|
-
return
|
|
68
|
+
return expect(result).to.eql(expectedResult);
|
|
71
69
|
}
|
|
70
|
+
|
|
72
71
|
if (functionName === 'getExpandedListOfLogs') {
|
|
73
72
|
const result = await mongoLogOperator.getExpandedListOfLogs(params);
|
|
74
73
|
// console.log(result); // eslint-disable-line
|
|
75
74
|
|
|
76
|
-
return
|
|
75
|
+
return expect(result).to.eql(expectedResult);
|
|
77
76
|
}
|
|
77
|
+
|
|
78
78
|
if (functionName === 'getListOfLogs') {
|
|
79
79
|
const result = await mongoLogOperator.getListOfLogs(params);
|
|
80
80
|
// console.log(result); // eslint-disable-line
|
|
81
|
-
return
|
|
81
|
+
return expect(result).to.eql(expectedResult);
|
|
82
82
|
}
|
|
83
83
|
throw new Error(`Unknown functionName: ${functionName}`);
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
|
|
2
|
+
import {expect} from 'chai';
|
|
3
|
+
import createDebugLogger from 'debug';
|
|
4
|
+
import createMongoOperator from '../src/mongo';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
|
|
8
|
+
|
|
9
|
+
export async function getMongoOperator(mongoFixtures) {
|
|
10
|
+
const mongoUri = await mongoFixtures.getUri();
|
|
11
|
+
const mongoOperator = await createMongoOperator(mongoUri, 'foobar', '');
|
|
12
|
+
return mongoOperator;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime = false, formatDates = true, expectedFileCount = undefined}) {
|
|
16
|
+
const result = await compareToDbEntry({mongoFixtures, expectedResult, resultIndex: 0, expectModificationTime, formatDates, expectedFileCount});
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function compareToDbEntry({mongoFixtures, expectedResult, resultIndex = 0, expectModificationTime = false, formatDates = true, expectedFileCount = undefined}) {
|
|
21
|
+
const dump = await mongoFixtures.dump();
|
|
22
|
+
debug(`--- We have ${dump.foobar.length} documents in db`);
|
|
23
|
+
debug(dump.foobar);
|
|
24
|
+
const result = await dump.foobar[resultIndex];
|
|
25
|
+
debug(`db result (document ${resultIndex}): ${JSON.stringify(result)}`);
|
|
26
|
+
const dump2 = await mongoFixtures.dump();
|
|
27
|
+
debug(`--- We have ${dump2.foobar.length} documents in db now`);
|
|
28
|
+
|
|
29
|
+
checkFileCount({dump, expectedFileCount});
|
|
30
|
+
|
|
31
|
+
checkModificationTime({result, expectModificationTime});
|
|
32
|
+
|
|
33
|
+
if (formatDates && expectedResult !== undefined) {
|
|
34
|
+
const formattedResult = formatQueueItem(result);
|
|
35
|
+
expect(formattedResult).to.eql(expectedResult);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
expect(result).to.eql(expectedResult);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function checkFileCount({dump, expectedFileCount}) {
|
|
43
|
+
if (expectedFileCount !== undefined) {
|
|
44
|
+
const fileCount = dump['foobar.files']?.length;
|
|
45
|
+
debug(`--- We have ${fileCount} files in db`);
|
|
46
|
+
expect(fileCount).to.eql(expectedFileCount);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function checkModificationTime({result, expectModificationTime}) {
|
|
54
|
+
if (expectModificationTime) {
|
|
55
|
+
debug('Check if modificationTime was edited');
|
|
56
|
+
expect(result.modificationTime).to.not.eql('');
|
|
57
|
+
debug(`OK. We have modified modificationTime`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export function formatQueueItem(queueItem) {
|
|
65
|
+
const filteredQueueItem = {
|
|
66
|
+
...queueItem,
|
|
67
|
+
creationTime: '',
|
|
68
|
+
modificationTime: ''
|
|
69
|
+
};
|
|
70
|
+
debug(`Formatted result: ${JSON.stringify(filteredQueueItem)}`);
|
|
71
|
+
return filteredQueueItem;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus}) {
|
|
75
|
+
debug(error);
|
|
76
|
+
if (expectedToThrow) {
|
|
77
|
+
debug('OK. Expected to throw');
|
|
78
|
+
debug(JSON.stringify(error));
|
|
79
|
+
// eslint-disable-next-line max-lines
|
|
80
|
+
if (expectedErrorMessage !== '' || expectedErrorStatus !== '') {
|
|
81
|
+
const errorMessage = error.message || error.payload.message || error.payload || '';
|
|
82
|
+
debug(errorMessage);
|
|
83
|
+
expect(errorMessage).to.eql(expectedErrorMessage);
|
|
84
|
+
const errorStatus = error.status || '';
|
|
85
|
+
expect(errorStatus).to.eql(expectedErrorStatus);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
debug('NOT OK. Not expexted to throw');
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function streamToString(stream) {
|
|
95
|
+
const chunks = [];
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
// eslint-disable-next-line functional/immutable-data
|
|
98
|
+
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
99
|
+
stream.on('error', (err) => reject(err));
|
|
100
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amqp.health.spec.js","names":["_debug","_interopRequireDefault","require","_index","_util","debug","createDebugLogger","setTimeoutPromise","promisify","setTimeout","describe","it","amqpUrl","amqpOperator","amqpFactory","awaitTime","closeConnection","close","closeChannel"],"sources":["../src/amqp.health.spec.js"],"sourcesContent":["//import {expect} from 'chai';\nimport createDebugLogger from 'debug';\nimport {amqpFactory} from './index';\n\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');\n//const debugData = debug.extend('data');\n\nimport {promisify} from 'util';\nconst setTimeoutPromise = promisify(setTimeout);\n\ndescribe('HealthCheck: amqpOperator should error if channel or connection fails', () => {\n\n it('FIX: test healthCheck - this test does not really test anything, but error can be seen in debug!', async () => {\n debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);\n const amqpUrl = 'amqp://127.0.0.1:5672/';\n\n const amqpOperator = await amqpFactory(amqpUrl, true);\n debug(`Connecting to ${amqpUrl}, with healthCheck running`);\n await awaitTime(amqpOperator, false);\n\n debug(`Testing healthCheckLoop for ${amqpOperator}`);\n debug(`Waiting 0.5s and expecting healthCheckLoop to work`);\n await awaitTime(amqpOperator, false);\n debug(`Amqp Operator should have been alive.`);\n\n debug(`Testing healthCheckLoop with closed channel`);\n debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);\n await awaitTime(amqpOperator, true);\n debug(`Amqp Operator should have been errored.`);\n\n debug(`Closing connection`);\n await amqpOperator.closeConnection();\n\n async function awaitTime(amqpOperator, close) {\n if (close) {\n await amqpOperator.closeChannel();\n await setTimeoutPromise(500);\n return;\n }\n\n await setTimeoutPromise(500);\n return;\n }\n\n });\n});\n\n"],"mappings":";;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AARA;;AAKA,MAAMG,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;AAC/E;;AAGA,MAAMC,iBAAiB,GAAG,IAAAC,eAAS,EAACC,UAAU,CAAC;AAE/CC,QAAQ,CAAC,uEAAuE,EAAE,MAAM;EAEtFC,EAAE,CAAC,kGAAkG,EAAE,YAAY;IACjHN,KAAK,CAAC,sFAAsF,CAAC;IAC7F,MAAMO,OAAO,GAAG,wBAAwB;IAExC,MAAMC,YAAY,GAAG,MAAM,IAAAC,kBAAW,EAACF,OAAO,EAAE,IAAI,CAAC;IACrDP,KAAK,CAAC,iBAAiBO,OAAO,4BAA4B,CAAC;IAC3D,MAAMG,SAAS,CAACF,YAAY,EAAE,KAAK,CAAC;IAEpCR,KAAK,CAAC,+BAA+BQ,YAAY,EAAE,CAAC;IACpDR,KAAK,CAAC,oDAAoD,CAAC;IAC3D,MAAMU,SAAS,CAACF,YAAY,EAAE,KAAK,CAAC;IACpCR,KAAK,CAAC,uCAAuC,CAAC;IAE9CA,KAAK,CAAC,6CAA6C,CAAC;IACpDA,KAAK,CAAC,2DAA2D,CAAC;IAClE,MAAMU,SAAS,CAACF,YAAY,EAAE,IAAI,CAAC;IACnCR,KAAK,CAAC,yCAAyC,CAAC;IAEhDA,KAAK,CAAC,oBAAoB,CAAC;IAC3B,MAAMQ,YAAY,CAACG,eAAe,CAAC,CAAC;IAEpC,eAAeD,SAASA,CAACF,YAAY,EAAEI,KAAK,EAAE;MAC5C,IAAIA,KAAK,EAAE;QACT,MAAMJ,YAAY,CAACK,YAAY,CAAC,CAAC;QACjC,MAAMX,iBAAiB,CAAC,GAAG,CAAC;QAC5B;MACF;MAEA,MAAMA,iBAAiB,CAAC,GAAG,CAAC;MAC5B;IACF;EAEF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|