@natlibfi/melinda-rest-api-commons 4.2.4-alpha.8 → 4.2.5-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/melinda-node-tests.yml +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +28 -27
- package/{dist → tests}/amqp.health.spec.js +17 -10
- package/tests/amqp.tests.spec.js +301 -0
- package/tests/helpers/conversion.spec.js +95 -0
- package/tests/helpers/fix.spec.js +41 -0
- package/tests/helpers/validation.spec.js +58 -0
- package/tests/mongo-add-blob-size.spec.js +92 -0
- package/tests/mongo-check-and-check-state.spec.js +105 -0
- package/tests/mongo-check-and-set-import-job-state.spec.js +104 -0
- package/tests/mongo-check-timeout.spec.js +104 -0
- package/tests/mongo-create-bulk.spec.js +93 -0
- package/tests/mongo-create-prio.spec.js +89 -0
- package/tests/mongo-get-one.spec.js +93 -0
- package/tests/mongo-get-stream.spec.js +112 -0
- package/tests/mongo-push-ids.spec.js +91 -0
- package/tests/mongo-push-messages.spec.js +89 -0
- package/tests/mongo-query-by-id.spec.js +106 -0
- package/tests/mongo-query.spec.js +98 -0
- package/tests/mongo-read-content.spec.js +115 -0
- package/tests/mongo-remove.spec.js +110 -0
- package/tests/mongo-set-blob-size.spec.js +89 -0
- package/tests/mongo-set-import-job-state.spec.js +92 -0
- package/tests/mongo-set-operation.spec.js +92 -0
- package/tests/mongo-set-operations.spec.js +91 -0
- package/tests/mongo-set-state.spec.js +92 -0
- package/{dist → tests}/mongoLog.spec.js +22 -22
- package/tests/testUtils.js +102 -0
- package/dist/amqp.health.spec.js.map +0 -1
- package/dist/amqp.tests.spec.js +0 -310
- package/dist/amqp.tests.spec.js.map +0 -1
- package/dist/helpers/conversion.spec.js +0 -88
- package/dist/helpers/conversion.spec.js.map +0 -1
- package/dist/helpers/fix.spec.js +0 -46
- package/dist/helpers/fix.spec.js.map +0 -1
- package/dist/helpers/validation.spec.js +0 -47
- package/dist/helpers/validation.spec.js.map +0 -1
- package/dist/mongo.spec.js +0 -792
- package/dist/mongo.spec.js.map +0 -1
- package/dist/mongoLog.spec.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -105,6 +105,5 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
|
-
function
|
|
109
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
108
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
110
109
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_mongo","_interopRequireDefault","require","_mongoLog","_amqp","_conversion","_validation","fixes","_interopRequireWildcard","exports","_utils","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_mongo","_interopRequireDefault","require","_mongoLog","_amqp","_conversion","_validation","fixes","_interopRequireWildcard","exports","_utils","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","set","getOwnPropertyDescriptor"],"sources":["../src/index.js"],"sourcesContent":["\n\nimport mongoFactory from './mongo';\nimport mongoLogFactory from './mongoLog';\nimport amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as fixes from './helpers/fix';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, fixes, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAC,uBAAA,CAAAN,OAAA;AAAuCO,OAAA,CAAAF,KAAA,GAAAA,KAAA;AACvC,IAAAG,MAAA,GAAAR,OAAA;AAGA,IAAAS,UAAA,GAAAT,OAAA;AAAAU,MAAA,CAAAC,IAAA,CAAAF,UAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAN,OAAA,IAAAA,OAAA,CAAAM,GAAA,MAAAJ,UAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAQ,cAAA,CAAAX,OAAA,EAAAM,GAAA;IAAAM,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAX,UAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAA4B,SAAAP,wBAAAe,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAjB,uBAAA,YAAAA,CAAAe,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAP,GAAA,CAAAC,CAAA,GAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAP,cAAA,CAAAC,IAAA,CAAAK,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAjB,MAAA,CAAAQ,cAAA,KAAAR,MAAA,CAAAwB,wBAAA,CAAAb,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAR,GAAA,IAAAQ,CAAA,CAAAK,GAAA,IAAAN,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"version": "4.2.
|
|
17
|
+
"version": "4.2.5-alpha.1",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18"
|
|
@@ -28,44 +28,44 @@
|
|
|
28
28
|
"lint": "eslint ./src",
|
|
29
29
|
"lint:dev": "eslint ./src --fix",
|
|
30
30
|
"test": "npm run lint && npm run test:base",
|
|
31
|
-
"test:base": "cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude
|
|
32
|
-
"test:dev": "npm run lint:dev && cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude
|
|
33
|
-
"test:local": "cross-env NODE_ENV=test nyc mocha --package ./package.json --
|
|
34
|
-
"test:healthcheck": "cross-env NODE_ENV=test nyc mocha --require @babel/register --
|
|
31
|
+
"test:base": "cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude tests/amqp.health.spec.js --exclude tests/amqp.tests.spec.js",
|
|
32
|
+
"test:dev": "npm run lint:dev && cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude tests/amqp.health.spec.js --exclude tests/amqp.tests.spec.js",
|
|
33
|
+
"test:local": "cross-env NODE_ENV=test nyc mocha --package ./package.json -- tests/amqp.*.spec.js",
|
|
34
|
+
"test:healthcheck": "cross-env NODE_ENV=test nyc mocha --require @babel/register -- tests/amqp.health.spec.js",
|
|
35
35
|
"dev": "nodemon",
|
|
36
36
|
"dev:debug": "cross-env LOG_LEVEL=debug DEBUG=@natlibfi/* NODE_ENV=test nodemon"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@natlibfi/marc-record": "^9.1.
|
|
40
|
-
"@natlibfi/marc-record-serializers": "^10.1.
|
|
41
|
-
"@natlibfi/marc-record-validate": "^8.0.
|
|
42
|
-
"@natlibfi/marc-record-validators-melinda": "^11.
|
|
43
|
-
"@natlibfi/melinda-backend-commons": "^2.3.
|
|
44
|
-
"@natlibfi/melinda-commons": "^13.0.
|
|
45
|
-
"amqplib": "^0.10.
|
|
39
|
+
"@natlibfi/marc-record": "^9.1.5",
|
|
40
|
+
"@natlibfi/marc-record-serializers": "^10.1.6",
|
|
41
|
+
"@natlibfi/marc-record-validate": "^8.0.14",
|
|
42
|
+
"@natlibfi/marc-record-validators-melinda": "^11.6.2",
|
|
43
|
+
"@natlibfi/melinda-backend-commons": "^2.3.8",
|
|
44
|
+
"@natlibfi/melinda-commons": "^13.0.20",
|
|
45
|
+
"amqplib": "^0.10.8",
|
|
46
46
|
"debug": "^4.4.0",
|
|
47
47
|
"http-status": "^2.1.0",
|
|
48
48
|
"moment": "^2.30.1",
|
|
49
49
|
"mongo-sanitize": "^1.1.0",
|
|
50
|
-
"mongodb": "^6.
|
|
50
|
+
"mongodb": "^6.16.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@babel/cli": "^7.
|
|
54
|
-
"@babel/core": "^7.
|
|
55
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
56
|
-
"@babel/preset-env": "^7.
|
|
57
|
-
"@babel/register": "^7.
|
|
53
|
+
"@babel/cli": "^7.27.1",
|
|
54
|
+
"@babel/core": "^7.27.1",
|
|
55
|
+
"@babel/plugin-transform-runtime": "^7.27.1",
|
|
56
|
+
"@babel/preset-env": "^7.27.1",
|
|
57
|
+
"@babel/register": "^7.27.1",
|
|
58
58
|
"@natlibfi/eslint-config-melinda-backend": "^3.0.5",
|
|
59
|
-
"@natlibfi/fixugen": "^2.0.
|
|
60
|
-
"@natlibfi/fixura": "^3.0.
|
|
61
|
-
"@natlibfi/fixura-mongo": "^2.0.
|
|
59
|
+
"@natlibfi/fixugen": "^2.0.14",
|
|
60
|
+
"@natlibfi/fixura": "^3.0.13",
|
|
61
|
+
"@natlibfi/fixura-mongo": "^2.0.24",
|
|
62
62
|
"babel-plugin-istanbul": "^7.0.0",
|
|
63
63
|
"babel-plugin-rewire": "^1.2.0",
|
|
64
64
|
"chai": "^4.5.0",
|
|
65
65
|
"cross-env": "^7.0.3",
|
|
66
66
|
"eslint": "^8.57.1",
|
|
67
|
-
"mocha": "^11.
|
|
68
|
-
"nodemon": "^3.1.
|
|
67
|
+
"mocha": "^11.2.2",
|
|
68
|
+
"nodemon": "^3.1.10",
|
|
69
69
|
"nyc": "^17.1.0"
|
|
70
70
|
},
|
|
71
71
|
"overrides": {
|
|
@@ -99,8 +99,8 @@
|
|
|
99
99
|
},
|
|
100
100
|
"mocha": {
|
|
101
101
|
"spec": [
|
|
102
|
-
"
|
|
103
|
-
"
|
|
102
|
+
"tests/*.spec.js",
|
|
103
|
+
"tests/**/*.spec.js"
|
|
104
104
|
],
|
|
105
105
|
"require": [
|
|
106
106
|
"@babel/register"
|
|
@@ -114,14 +114,15 @@
|
|
|
114
114
|
"nodemonConfig": {
|
|
115
115
|
"exec": "npm run test:dev",
|
|
116
116
|
"watch": [
|
|
117
|
+
"tests/*",
|
|
117
118
|
"src/*",
|
|
118
119
|
"test-fixtures/*"
|
|
119
120
|
]
|
|
120
121
|
},
|
|
121
122
|
"nyc": {
|
|
122
123
|
"exclude": [
|
|
123
|
-
"
|
|
124
|
-
"
|
|
124
|
+
"tests/*.spec.js",
|
|
125
|
+
"tests/**/*.spec.js"
|
|
125
126
|
],
|
|
126
127
|
"reporter": [
|
|
127
128
|
"text"
|
|
@@ -1,41 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
5
|
-
var _index = require("./index");
|
|
6
|
-
var _util = require("util");
|
|
7
1
|
//import {expect} from 'chai';
|
|
2
|
+
import createDebugLogger from 'debug';
|
|
3
|
+
import {amqpFactory} from '../src/index';
|
|
4
|
+
|
|
8
5
|
|
|
9
|
-
const debug = (
|
|
6
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');
|
|
10
7
|
//const debugData = debug.extend('data');
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
import {promisify} from 'util';
|
|
10
|
+
const setTimeoutPromise = promisify(setTimeout);
|
|
11
|
+
|
|
13
12
|
describe('HealthCheck: amqpOperator should error if channel or connection fails', () => {
|
|
13
|
+
|
|
14
14
|
it('FIX: test healthCheck - this test does not really test anything, but error can be seen in debug!', async () => {
|
|
15
15
|
debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);
|
|
16
16
|
const amqpUrl = 'amqp://127.0.0.1:5672/';
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
const amqpOperator = await amqpFactory(amqpUrl, true);
|
|
18
19
|
debug(`Connecting to ${amqpUrl}, with healthCheck running`);
|
|
19
20
|
await awaitTime(amqpOperator, false);
|
|
21
|
+
|
|
20
22
|
debug(`Testing healthCheckLoop for ${amqpOperator}`);
|
|
21
23
|
debug(`Waiting 0.5s and expecting healthCheckLoop to work`);
|
|
22
24
|
await awaitTime(amqpOperator, false);
|
|
23
25
|
debug(`Amqp Operator should have been alive.`);
|
|
26
|
+
|
|
24
27
|
debug(`Testing healthCheckLoop with closed channel`);
|
|
25
28
|
debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);
|
|
26
29
|
await awaitTime(amqpOperator, true);
|
|
27
30
|
debug(`Amqp Operator should have been errored.`);
|
|
31
|
+
|
|
28
32
|
debug(`Closing connection`);
|
|
29
33
|
await amqpOperator.closeConnection();
|
|
34
|
+
|
|
30
35
|
async function awaitTime(amqpOperator, close) {
|
|
31
36
|
if (close) {
|
|
32
37
|
await amqpOperator.closeChannel();
|
|
33
38
|
await setTimeoutPromise(500);
|
|
34
39
|
return;
|
|
35
40
|
}
|
|
41
|
+
|
|
36
42
|
await setTimeoutPromise(500);
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
45
|
+
|
|
39
46
|
});
|
|
40
47
|
});
|
|
41
|
-
|
|
48
|
+
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import {READERS} from '@natlibfi/fixura';
|
|
3
|
+
import createDebugLogger from 'debug';
|
|
4
|
+
import generateTests from '@natlibfi/fixugen';
|
|
5
|
+
import {amqpFactory} from '../src/index';
|
|
6
|
+
import {Error as ApiError} from '@natlibfi/melinda-commons';
|
|
7
|
+
import {promisify} from 'util';
|
|
8
|
+
|
|
9
|
+
const setTimeoutPromise = promisify(setTimeout);
|
|
10
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');
|
|
11
|
+
//const debugData = debug.extend('data');
|
|
12
|
+
|
|
13
|
+
const testData = {
|
|
14
|
+
queue: 'TESTQUEUE',
|
|
15
|
+
correlationId: 'aaaaaaaa-0000-aaaa-0000-000000000000',
|
|
16
|
+
data: {'leader': '02518cam a2200745zi 4500', 'fields': [{'tag': '001', 'value': '000019640'}]}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);
|
|
20
|
+
const amqpUrl = 'amqp://127.0.0.1:5672/';
|
|
21
|
+
// eslint-disable-next-line functional/no-let
|
|
22
|
+
let amqpOperator;
|
|
23
|
+
|
|
24
|
+
generateTests({
|
|
25
|
+
callback,
|
|
26
|
+
path: [__dirname, '..', 'test-fixtures', 'amqp'],
|
|
27
|
+
recurse: false,
|
|
28
|
+
useMetadataFile: true,
|
|
29
|
+
fixura: {
|
|
30
|
+
failWhenNotFound: true,
|
|
31
|
+
reader: READERS.JSON
|
|
32
|
+
},
|
|
33
|
+
mocha: {
|
|
34
|
+
before: async () => {
|
|
35
|
+
debug(`Connecting to ${amqpUrl}, with healthCheck running`);
|
|
36
|
+
amqpOperator = await amqpFactory(amqpUrl, true);
|
|
37
|
+
},
|
|
38
|
+
beforeEach: async () => {
|
|
39
|
+
await amqpOperator.checkQueue({queue: testData.queue, toRecord: false, purge: true});
|
|
40
|
+
},
|
|
41
|
+
afterEach: async () => {
|
|
42
|
+
await amqpOperator.removeQueue(testData.queue);
|
|
43
|
+
},
|
|
44
|
+
after: async () => {
|
|
45
|
+
await amqpOperator.closeConnection();
|
|
46
|
+
//await testHeathCheck();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line max-statements
|
|
52
|
+
async function callback({
|
|
53
|
+
getFixture,
|
|
54
|
+
expectToFail = false,
|
|
55
|
+
expectedErrorStatus = '',
|
|
56
|
+
ackMessages = false,
|
|
57
|
+
nackMessages = false,
|
|
58
|
+
checkNextMessage = false,
|
|
59
|
+
checkQueueStyle = false,
|
|
60
|
+
queue = testData.queue,
|
|
61
|
+
sentToQueue,
|
|
62
|
+
expectedMessageCount,
|
|
63
|
+
removeQueue = false,
|
|
64
|
+
expectedErrorMessage = undefined,
|
|
65
|
+
expectApiError = false,
|
|
66
|
+
expectFalseCheckResult = false
|
|
67
|
+
}) {
|
|
68
|
+
try {
|
|
69
|
+
await sendMessagesToQueue();
|
|
70
|
+
|
|
71
|
+
await ackOrNackMessages();
|
|
72
|
+
|
|
73
|
+
await checkQueue();
|
|
74
|
+
|
|
75
|
+
await queueRemoval();
|
|
76
|
+
|
|
77
|
+
const messageCount = await amqpOperator.checkQueue({queue, style: 'messages'});
|
|
78
|
+
debug(`MessageCount: ${messageCount}`);
|
|
79
|
+
expect(messageCount).to.eql(expectedMessageCount);
|
|
80
|
+
|
|
81
|
+
if (checkNextMessage) {
|
|
82
|
+
const {headers, records} = await queueCheckNextMessage();
|
|
83
|
+
const nextMessage = {headers, records};
|
|
84
|
+
const expectedNextMessage = getFixture('expectedMessage.json');
|
|
85
|
+
expect(nextMessage).to.eql(expectedNextMessage);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!expectToFail) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
expect(expectToFail, 'This is expected to fail').to.equal(true);
|
|
94
|
+
testErrors(error);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function testErrors(error) {
|
|
98
|
+
|
|
99
|
+
if (expectApiError) {
|
|
100
|
+
expect(error).to.be.instanceOf(ApiError);
|
|
101
|
+
debug(`We expected and got an ApiError`);
|
|
102
|
+
expect(error.status).to.equal(expectedErrorStatus);
|
|
103
|
+
|
|
104
|
+
if (expectedErrorMessage) {
|
|
105
|
+
expect(error.payload).to.eql(expectedErrorMessage);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
expect(error).not.to.be.instanceOf(ApiError);
|
|
112
|
+
debug(`We expected and got an non-ApiError`);
|
|
113
|
+
debug(`Error is a ${error.constructor.name}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function queueRemoval() {
|
|
117
|
+
if (removeQueue) {
|
|
118
|
+
return amqpOperator.removeQueue(removeQueue);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function queueCheckNextMessage() {
|
|
125
|
+
if (checkNextMessage) {
|
|
126
|
+
return amqpOperator.consumeOne(testData.queue, true);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// eslint-disable-next-line max-statements
|
|
133
|
+
async function checkQueue() {
|
|
134
|
+
debug(`checkQueueStyle: ${checkQueueStyle}`);
|
|
135
|
+
|
|
136
|
+
if (checkQueueStyle === 'oneToRecord') {
|
|
137
|
+
const result = await amqpOperator.checkQueue({queue, style: 'one', toRecord: true, purge: false});
|
|
138
|
+
|
|
139
|
+
if (expectFalseCheckResult) {
|
|
140
|
+
expect(result).to.eql(false);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
expect(result).to.have.property('headers');
|
|
145
|
+
expect(result).to.have.property('records');
|
|
146
|
+
expect(result).to.have.property('messages');
|
|
147
|
+
expect(result.records.length).to.eql(1);
|
|
148
|
+
expect(result.messages.length).to.eql(1);
|
|
149
|
+
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (checkQueueStyle === 'oneNotRecord') {
|
|
154
|
+
const result = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});
|
|
155
|
+
const {fields} = result;
|
|
156
|
+
|
|
157
|
+
if (expectFalseCheckResult) {
|
|
158
|
+
expect(result).to.eql(false);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
expect(fields).to.have.property('deliveryTag');
|
|
163
|
+
expect(fields).to.have.property('exchange');
|
|
164
|
+
expect(fields).to.have.property('messageCount');
|
|
165
|
+
expect(fields).to.have.property('redelivered');
|
|
166
|
+
expect(fields).to.have.property('routingKey');
|
|
167
|
+
expect(typeof fields.deliveryTag).to.be.eql('number');
|
|
168
|
+
expect(typeof fields.messageCount).to.be.eql('number');
|
|
169
|
+
expect(typeof fields.redelivered).to.be.eql('boolean');
|
|
170
|
+
expect(typeof fields.routingKey).to.be.eql('string');
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (checkQueueStyle === 'basicToRecord') {
|
|
176
|
+
const result = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: true, purge: false});
|
|
177
|
+
|
|
178
|
+
if (expectFalseCheckResult) {
|
|
179
|
+
expect(result).to.eql(false);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
expect(result).to.have.property('headers');
|
|
184
|
+
expect(result).to.have.property('records');
|
|
185
|
+
expect(result).to.have.property('messages');
|
|
186
|
+
expect(result.records.length).to.eql(3);
|
|
187
|
+
expect(result.messages.length).to.eql(3);
|
|
188
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
189
|
+
expect(result.records).to.eql(expectedResult);
|
|
190
|
+
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (checkQueueStyle === 'basicNotRecord') {
|
|
195
|
+
const result = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});
|
|
196
|
+
|
|
197
|
+
if (expectFalseCheckResult) {
|
|
198
|
+
expect(result).to.eql(false);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
expect(result).to.have.property('headers');
|
|
203
|
+
expect(result).to.have.property('messages');
|
|
204
|
+
expect(result.messages.length).to.eql(3);
|
|
205
|
+
|
|
206
|
+
const [{fields}] = result.messages;
|
|
207
|
+
|
|
208
|
+
expect(fields).to.have.property('deliveryTag');
|
|
209
|
+
expect(fields).to.have.property('exchange');
|
|
210
|
+
expect(fields).to.have.property('messageCount');
|
|
211
|
+
expect(fields).to.have.property('redelivered');
|
|
212
|
+
expect(fields).to.have.property('routingKey');
|
|
213
|
+
|
|
214
|
+
expect(typeof fields.deliveryTag).to.be.eql('number');
|
|
215
|
+
expect(typeof fields.messageCount).to.be.eql('number');
|
|
216
|
+
expect(typeof fields.redelivered).to.be.eql('boolean');
|
|
217
|
+
expect(typeof fields.routingKey).to.be.eql('string');
|
|
218
|
+
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (checkQueueStyle === 'purge') {
|
|
223
|
+
return amqpOperator.checkQueue({queue, style: 'messages', purge: true});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (checkQueueStyle === 'foobar') {
|
|
227
|
+
return amqpOperator.checkQueue({queue, style: 'foobar', toRecord: false, purge: false});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function ackOrNackMessages() {
|
|
234
|
+
if (ackMessages) {
|
|
235
|
+
const message = await amqpOperator.consumeOne(testData.queue, false);
|
|
236
|
+
await amqpOperator.ackMessages([message]);
|
|
237
|
+
|
|
238
|
+
return setTimeoutPromise(10);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (nackMessages) {
|
|
242
|
+
const message = await amqpOperator.consumeOne(testData.queue, false);
|
|
243
|
+
await amqpOperator.nackMessages([message]);
|
|
244
|
+
|
|
245
|
+
return setTimeoutPromise(10);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function sendMessagesToQueue() {
|
|
252
|
+
if (sentToQueue) {
|
|
253
|
+
const messages = getFixture('input.json');
|
|
254
|
+
// {queue, correlationId, headers, data}
|
|
255
|
+
|
|
256
|
+
const promises = messages.map(message => amqpOperator.sendToQueue(message));
|
|
257
|
+
await Promise.all(promises);
|
|
258
|
+
|
|
259
|
+
return setTimeoutPromise(10);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/*
|
|
267
|
+
function testHeathCheck() {
|
|
268
|
+
return it('expects healthCheck', async () => {
|
|
269
|
+
|
|
270
|
+
const amqpOperator2 = await amqpFactory(amqpUrl, true);
|
|
271
|
+
try {
|
|
272
|
+
|
|
273
|
+
debug(`**********`);
|
|
274
|
+
await testHealthCheckLoopWorking(amqpOperator2);
|
|
275
|
+
|
|
276
|
+
debug(`**********`);
|
|
277
|
+
await testHealthCheckLoopErroring(amqpOperator2);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
debug(error);
|
|
280
|
+
expect(error).to.eql('');
|
|
281
|
+
} finally {
|
|
282
|
+
amqpOperator2.closeConnection();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function testHealthCheckLoopWorking(amqpOperator) {
|
|
286
|
+
debug(`Testing healthCheckLoop for ${amqpOperator}`);
|
|
287
|
+
debug(`Waiting 0.5s and expecting healthCheckLoop to work`);
|
|
288
|
+
await setTimeoutPromise('500');
|
|
289
|
+
debug(`Amqp Operator should have been alive.`);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async function testHealthCheckLoopErroring(amqpOperator) {
|
|
293
|
+
debug(`Testing healthCheckLoop with closed channel`);
|
|
294
|
+
amqpOperator.closeChannel();
|
|
295
|
+
debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);
|
|
296
|
+
await setTimeoutPromise('500');
|
|
297
|
+
debug(`amqpOperator should have errored`);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
*/
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import {expect} from 'chai';
|
|
4
|
+
import fixtureFactory from '@natlibfi/fixura';
|
|
5
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
6
|
+
import {Error as ConversionError} from '@natlibfi/melinda-commons';
|
|
7
|
+
import createConversionService from '../../src/helpers/conversion';
|
|
8
|
+
import {CONVERSION_FORMATS} from '../../src/constants';
|
|
9
|
+
|
|
10
|
+
describe('services/conversion', () => {
|
|
11
|
+
const {getFixture} = fixtureFactory({root: [
|
|
12
|
+
__dirname,
|
|
13
|
+
'..',
|
|
14
|
+
'..',
|
|
15
|
+
'test-fixtures',
|
|
16
|
+
'conversion'
|
|
17
|
+
]});
|
|
18
|
+
const conversionService = createConversionService();
|
|
19
|
+
|
|
20
|
+
const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});
|
|
21
|
+
const marcXml = getFixture({components: ['marcxml1']});
|
|
22
|
+
const iso2709 = getFixture({components: ['iso2709_1']});
|
|
23
|
+
const json = getFixture({components: ['json1']});
|
|
24
|
+
const alephSeq = getFixture({components: ['aleph_sequential']});
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
describe('factory', () => {
|
|
28
|
+
it('Should create the expected object', () => {
|
|
29
|
+
const service = createConversionService();
|
|
30
|
+
expect(service).to.be.an('object').and
|
|
31
|
+
.respondTo('serialize')
|
|
32
|
+
.respondTo('unserialize');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('#serialize', () => {
|
|
37
|
+
it('Should throw because of unsupported format', () => {
|
|
38
|
+
expect(conversionService.serialize).to.throw();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('Should serialize to MARCXML', () => {
|
|
42
|
+
const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);
|
|
43
|
+
expect(data).to.equal(marcXml);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('Should serialize to ISO2709', () => {
|
|
47
|
+
const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);
|
|
48
|
+
expect(data).to.equal(iso2709);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('Should serialize to JSON', () => {
|
|
52
|
+
const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);
|
|
53
|
+
expect(data).to.equal(json);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('Should serialize to aleph sequential', () => {
|
|
57
|
+
const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);
|
|
58
|
+
expect(data).to.equal(alephSeq);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('#unserialize', () => {
|
|
64
|
+
it('Should throw because of unsupported format', () => {
|
|
65
|
+
expect(conversionService.unserialize).to.throw();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Should unserialize from MARCXML', async () => {
|
|
69
|
+
const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);
|
|
70
|
+
expect(record.equalsTo(marcRecord)).to.equal(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('Should unserialize from ISO2709', () => {
|
|
74
|
+
const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);
|
|
75
|
+
expect(record.equalsTo(marcRecord)).to.equal(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('Should unserialize from JSON', () => {
|
|
79
|
+
const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);
|
|
80
|
+
expect(record.equalsTo(marcRecord)).to.equal(true);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('Should unserialize from Aleph sequential', () => {
|
|
84
|
+
const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);
|
|
85
|
+
expect(record.equalsTo(marcRecord)).to.equal(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
it('Should throw because the record could not be unserialized', () => {
|
|
90
|
+
expect(() => {
|
|
91
|
+
conversionService.unserialize('', CONVERSION_FORMATS.JSON);
|
|
92
|
+
}).to.throw(ConversionError);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
3
|
+
import {READERS} from '@natlibfi/fixura';
|
|
4
|
+
import generateTests from '@natlibfi/fixugen';
|
|
5
|
+
import {fixRecord} from '../../src/helpers/fix';
|
|
6
|
+
import * as fixSettings from '../../src/helpers/fix-constants';
|
|
7
|
+
import createDebugLogger from 'debug';
|
|
8
|
+
// import inspect from 'util';
|
|
9
|
+
|
|
10
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fix:test');
|
|
11
|
+
const debugData = debug.extend('data');
|
|
12
|
+
|
|
13
|
+
generateTests({
|
|
14
|
+
callback,
|
|
15
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'fix'],
|
|
16
|
+
recurse: true,
|
|
17
|
+
useMetadataFile: true,
|
|
18
|
+
fixura: {
|
|
19
|
+
failWhenNotFound: false,
|
|
20
|
+
reader: READERS.JSON
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function callback({getFixture, settings = undefined}) {
|
|
25
|
+
if (settings !== undefined && fixSettings[settings] === undefined) {
|
|
26
|
+
throw new Error(`There are no settings ${settings} defined!`);
|
|
27
|
+
}
|
|
28
|
+
const runSettings = fixSettings[settings] || settings;
|
|
29
|
+
|
|
30
|
+
const record = new MarcRecord(getFixture('record.json'), {subfieldValues: false});
|
|
31
|
+
const expectedRecord = getFixture('expectedRecord.json');
|
|
32
|
+
|
|
33
|
+
debug(`Running fixer with settings ${settings}.`);
|
|
34
|
+
debugData(JSON.stringify(runSettings, null, 2));
|
|
35
|
+
|
|
36
|
+
const resultRecord = fixRecord(record, runSettings);
|
|
37
|
+
debugData(`Result: ${JSON.stringify(resultRecord)}`);
|
|
38
|
+
debugData(`Expected: ${JSON.stringify(expectedRecord)}`);
|
|
39
|
+
expect(resultRecord).to.eql(expectedRecord);
|
|
40
|
+
|
|
41
|
+
}
|