@natlibfi/melinda-rest-api-commons 4.2.3 → 4.2.4-alpha.11
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/amqp.js +2 -2
- package/dist/amqp.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mongo.js +158 -80
- package/dist/mongo.js.map +1 -1
- package/dist/mongoLog.js +1 -4
- package/dist/mongoLog.js.map +1 -1
- package/package.json +26 -24
- 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 +100 -0
- package/tests/mongo-check-and-check-state.spec.js +112 -0
- package/tests/mongo-check-and-set-import-job-state.spec.js +112 -0
- package/tests/mongo-check-timeout.spec.js +111 -0
- package/tests/mongo-create-bulk.spec.js +100 -0
- package/tests/mongo-create-prio.spec.js +98 -0
- package/tests/mongo-get-one.spec.js +103 -0
- package/tests/mongo-get-stream.spec.js +120 -0
- package/tests/mongo-push-ids.spec.js +101 -0
- package/tests/mongo-push-messages.spec.js +99 -0
- package/tests/mongo-query-by-id.spec.js +112 -0
- package/tests/mongo-query.spec.js +108 -0
- package/tests/mongo-read-content.spec.js +123 -0
- package/tests/mongo-remove.spec.js +115 -0
- package/tests/mongo-set-blob-size.spec.js +99 -0
- package/tests/mongo-set-import-job-state.spec.js +102 -0
- package/tests/mongo-set-operation.spec.js +102 -0
- package/tests/mongo-set-operations.spec.js +101 -0
- package/tests/mongo-set-state.spec.js +102 -0
- package/{dist → tests}/mongoLog.spec.js +22 -22
- package/tests/testUtils.js +94 -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.draft +0 -54
- package/dist/mongoLog.spec.js.map +0 -1
|
@@ -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,94 @@
|
|
|
1
|
+
|
|
2
|
+
import {expect} from 'chai';
|
|
3
|
+
import createDebugLogger from 'debug';
|
|
4
|
+
|
|
5
|
+
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons/mongo:test');
|
|
6
|
+
|
|
7
|
+
export async function compareToFirstDbEntry({mongoFixtures, expectedResult, expectModificationTime = false, formatDates = true, expectedFileCount = undefined}) {
|
|
8
|
+
const result = await compareToDbEntry({mongoFixtures, expectedResult, resultIndex: 0, expectModificationTime, formatDates, expectedFileCount});
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function compareToDbEntry({mongoFixtures, expectedResult, resultIndex = 0, expectModificationTime = false, formatDates = true, expectedFileCount = undefined}) {
|
|
13
|
+
const dump = await mongoFixtures.dump();
|
|
14
|
+
debug(`--- We have ${dump.foobar.length} documents in db`);
|
|
15
|
+
debug(dump.foobar);
|
|
16
|
+
const result = await dump.foobar[resultIndex];
|
|
17
|
+
debug(`db result (document ${resultIndex}): ${JSON.stringify(result)}`);
|
|
18
|
+
const dump2 = await mongoFixtures.dump();
|
|
19
|
+
debug(`--- We have ${dump2.foobar.length} documents in db now`);
|
|
20
|
+
|
|
21
|
+
checkFileCount({dump, expectedFileCount});
|
|
22
|
+
|
|
23
|
+
checkModificationTime({result, expectModificationTime});
|
|
24
|
+
|
|
25
|
+
if (formatDates && expectedResult !== undefined) {
|
|
26
|
+
const formattedResult = formatQueueItem(result);
|
|
27
|
+
expect(formattedResult).to.eql(expectedResult);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
expect(result).to.eql(expectedResult);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function checkFileCount({dump, expectedFileCount}) {
|
|
35
|
+
if (expectedFileCount !== undefined) {
|
|
36
|
+
const fileCount = dump['foobar.files']?.length;
|
|
37
|
+
debug(`--- We have ${fileCount} files in db`);
|
|
38
|
+
expect(fileCount).to.eql(expectedFileCount);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function checkModificationTime({result, expectModificationTime}) {
|
|
46
|
+
if (expectModificationTime) {
|
|
47
|
+
debug('Check if modificationTime was edited');
|
|
48
|
+
expect(result.modificationTime).to.not.eql('');
|
|
49
|
+
debug(`OK. We have modified modificationTime`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
export function formatQueueItem(queueItem) {
|
|
57
|
+
const filteredQueueItem = {
|
|
58
|
+
...queueItem,
|
|
59
|
+
creationTime: '',
|
|
60
|
+
modificationTime: ''
|
|
61
|
+
};
|
|
62
|
+
debug(`Formatted result: ${JSON.stringify(filteredQueueItem)}`);
|
|
63
|
+
return filteredQueueItem;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function handleError({error, expectedToThrow, expectedErrorMessage, expectedErrorStatus}) {
|
|
67
|
+
debug(error);
|
|
68
|
+
if (expectedToThrow) {
|
|
69
|
+
debug('OK. Expected to throw');
|
|
70
|
+
debug(JSON.stringify(error));
|
|
71
|
+
// eslint-disable-next-line max-lines
|
|
72
|
+
if (expectedErrorMessage !== '' || expectedErrorStatus !== '') {
|
|
73
|
+
const errorMessage = error.message || error.payload.message || error.payload || '';
|
|
74
|
+
debug(errorMessage);
|
|
75
|
+
expect(errorMessage).to.eql(expectedErrorMessage);
|
|
76
|
+
const errorStatus = error.status || '';
|
|
77
|
+
expect(errorStatus).to.eql(expectedErrorStatus);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
debug('NOT OK. Not expexted to throw');
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function streamToString(stream) {
|
|
87
|
+
const chunks = [];
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
// eslint-disable-next-line functional/immutable-data
|
|
90
|
+
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
91
|
+
stream.on('error', (err) => reject(err));
|
|
92
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -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":[]}
|
package/dist/amqp.tests.spec.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _fixura = require("@natlibfi/fixura");
|
|
6
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
7
|
-
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
-
var _index = require("./index");
|
|
9
|
-
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
10
|
-
var _util = require("util");
|
|
11
|
-
const setTimeoutPromise = (0, _util.promisify)(setTimeout);
|
|
12
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:amqp:test');
|
|
13
|
-
//const debugData = debug.extend('data');
|
|
14
|
-
|
|
15
|
-
const testData = {
|
|
16
|
-
queue: 'TESTQUEUE',
|
|
17
|
-
correlationId: 'aaaaaaaa-0000-aaaa-0000-000000000000',
|
|
18
|
-
data: {
|
|
19
|
-
'leader': '02518cam a2200745zi 4500',
|
|
20
|
-
'fields': [{
|
|
21
|
-
'tag': '001',
|
|
22
|
-
'value': '000019640'
|
|
23
|
-
}]
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);
|
|
27
|
-
const amqpUrl = 'amqp://127.0.0.1:5672/';
|
|
28
|
-
// eslint-disable-next-line functional/no-let
|
|
29
|
-
let amqpOperator;
|
|
30
|
-
(0, _fixugen.default)({
|
|
31
|
-
callback,
|
|
32
|
-
path: [__dirname, '..', 'test-fixtures', 'amqp'],
|
|
33
|
-
recurse: false,
|
|
34
|
-
useMetadataFile: true,
|
|
35
|
-
fixura: {
|
|
36
|
-
failWhenNotFound: true,
|
|
37
|
-
reader: _fixura.READERS.JSON
|
|
38
|
-
},
|
|
39
|
-
mocha: {
|
|
40
|
-
before: async () => {
|
|
41
|
-
debug(`Connecting to ${amqpUrl}, with healthCheck running`);
|
|
42
|
-
amqpOperator = await (0, _index.amqpFactory)(amqpUrl, true);
|
|
43
|
-
},
|
|
44
|
-
beforeEach: async () => {
|
|
45
|
-
await amqpOperator.checkQueue({
|
|
46
|
-
queue: testData.queue,
|
|
47
|
-
toRecord: false,
|
|
48
|
-
purge: true
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
afterEach: async () => {
|
|
52
|
-
await amqpOperator.removeQueue(testData.queue);
|
|
53
|
-
},
|
|
54
|
-
after: async () => {
|
|
55
|
-
await amqpOperator.closeConnection();
|
|
56
|
-
//await testHeathCheck();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// eslint-disable-next-line max-statements
|
|
62
|
-
async function callback({
|
|
63
|
-
getFixture,
|
|
64
|
-
expectToFail = false,
|
|
65
|
-
expectedErrorStatus = '',
|
|
66
|
-
ackMessages = false,
|
|
67
|
-
nackMessages = false,
|
|
68
|
-
checkNextMessage = false,
|
|
69
|
-
checkQueueStyle = false,
|
|
70
|
-
queue = testData.queue,
|
|
71
|
-
sentToQueue,
|
|
72
|
-
expectedMessageCount,
|
|
73
|
-
removeQueue = false,
|
|
74
|
-
expectedErrorMessage = undefined,
|
|
75
|
-
expectApiError = false,
|
|
76
|
-
expectFalseCheckResult = false
|
|
77
|
-
}) {
|
|
78
|
-
try {
|
|
79
|
-
await sendMessagesToQueue();
|
|
80
|
-
await ackOrNackMessages();
|
|
81
|
-
await checkQueue();
|
|
82
|
-
await queueRemoval();
|
|
83
|
-
const messageCount = await amqpOperator.checkQueue({
|
|
84
|
-
queue,
|
|
85
|
-
style: 'messages'
|
|
86
|
-
});
|
|
87
|
-
debug(`MessageCount: ${messageCount}`);
|
|
88
|
-
(0, _chai.expect)(messageCount).to.eql(expectedMessageCount);
|
|
89
|
-
if (checkNextMessage) {
|
|
90
|
-
const {
|
|
91
|
-
headers,
|
|
92
|
-
records
|
|
93
|
-
} = await queueCheckNextMessage();
|
|
94
|
-
const nextMessage = {
|
|
95
|
-
headers,
|
|
96
|
-
records
|
|
97
|
-
};
|
|
98
|
-
const expectedNextMessage = getFixture('expectedMessage.json');
|
|
99
|
-
(0, _chai.expect)(nextMessage).to.eql(expectedNextMessage);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if (!expectToFail) {
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
(0, _chai.expect)(expectToFail, 'This is expected to fail').to.equal(true);
|
|
107
|
-
testErrors(error);
|
|
108
|
-
}
|
|
109
|
-
function testErrors(error) {
|
|
110
|
-
if (expectApiError) {
|
|
111
|
-
(0, _chai.expect)(error).to.be.instanceOf(_melindaCommons.Error);
|
|
112
|
-
debug(`We expected and got an ApiError`);
|
|
113
|
-
(0, _chai.expect)(error.status).to.equal(expectedErrorStatus);
|
|
114
|
-
if (expectedErrorMessage) {
|
|
115
|
-
(0, _chai.expect)(error.payload).to.eql(expectedErrorMessage);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
(0, _chai.expect)(error).not.to.be.instanceOf(_melindaCommons.Error);
|
|
121
|
-
debug(`We expected and got an non-ApiError`);
|
|
122
|
-
debug(`Error is a ${error.constructor.name}`);
|
|
123
|
-
}
|
|
124
|
-
function queueRemoval() {
|
|
125
|
-
if (removeQueue) {
|
|
126
|
-
return amqpOperator.removeQueue(removeQueue);
|
|
127
|
-
}
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
function queueCheckNextMessage() {
|
|
131
|
-
if (checkNextMessage) {
|
|
132
|
-
return amqpOperator.consumeOne(testData.queue, true);
|
|
133
|
-
}
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// eslint-disable-next-line max-statements
|
|
138
|
-
async function checkQueue() {
|
|
139
|
-
debug(`checkQueueStyle: ${checkQueueStyle}`);
|
|
140
|
-
if (checkQueueStyle === 'oneToRecord') {
|
|
141
|
-
const result = await amqpOperator.checkQueue({
|
|
142
|
-
queue,
|
|
143
|
-
style: 'one',
|
|
144
|
-
toRecord: true,
|
|
145
|
-
purge: false
|
|
146
|
-
});
|
|
147
|
-
if (expectFalseCheckResult) {
|
|
148
|
-
(0, _chai.expect)(result).to.eql(false);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
(0, _chai.expect)(result).to.have.property('headers');
|
|
152
|
-
(0, _chai.expect)(result).to.have.property('records');
|
|
153
|
-
(0, _chai.expect)(result).to.have.property('messages');
|
|
154
|
-
(0, _chai.expect)(result.records.length).to.eql(1);
|
|
155
|
-
(0, _chai.expect)(result.messages.length).to.eql(1);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (checkQueueStyle === 'oneNotRecord') {
|
|
159
|
-
const result = await amqpOperator.checkQueue({
|
|
160
|
-
queue,
|
|
161
|
-
style: 'one',
|
|
162
|
-
toRecord: false,
|
|
163
|
-
purge: false
|
|
164
|
-
});
|
|
165
|
-
const {
|
|
166
|
-
fields
|
|
167
|
-
} = result;
|
|
168
|
-
if (expectFalseCheckResult) {
|
|
169
|
-
(0, _chai.expect)(result).to.eql(false);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
(0, _chai.expect)(fields).to.have.property('deliveryTag');
|
|
173
|
-
(0, _chai.expect)(fields).to.have.property('exchange');
|
|
174
|
-
(0, _chai.expect)(fields).to.have.property('messageCount');
|
|
175
|
-
(0, _chai.expect)(fields).to.have.property('redelivered');
|
|
176
|
-
(0, _chai.expect)(fields).to.have.property('routingKey');
|
|
177
|
-
(0, _chai.expect)(typeof fields.deliveryTag).to.be.eql('number');
|
|
178
|
-
(0, _chai.expect)(typeof fields.messageCount).to.be.eql('number');
|
|
179
|
-
(0, _chai.expect)(typeof fields.redelivered).to.be.eql('boolean');
|
|
180
|
-
(0, _chai.expect)(typeof fields.routingKey).to.be.eql('string');
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (checkQueueStyle === 'basicToRecord') {
|
|
184
|
-
const result = await amqpOperator.checkQueue({
|
|
185
|
-
queue,
|
|
186
|
-
style: 'basic',
|
|
187
|
-
toRecord: true,
|
|
188
|
-
purge: false
|
|
189
|
-
});
|
|
190
|
-
if (expectFalseCheckResult) {
|
|
191
|
-
(0, _chai.expect)(result).to.eql(false);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
(0, _chai.expect)(result).to.have.property('headers');
|
|
195
|
-
(0, _chai.expect)(result).to.have.property('records');
|
|
196
|
-
(0, _chai.expect)(result).to.have.property('messages');
|
|
197
|
-
(0, _chai.expect)(result.records.length).to.eql(3);
|
|
198
|
-
(0, _chai.expect)(result.messages.length).to.eql(3);
|
|
199
|
-
const expectedResult = getFixture('expectedResult.json');
|
|
200
|
-
(0, _chai.expect)(result.records).to.eql(expectedResult);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
if (checkQueueStyle === 'basicNotRecord') {
|
|
204
|
-
const result = await amqpOperator.checkQueue({
|
|
205
|
-
queue,
|
|
206
|
-
style: 'basic',
|
|
207
|
-
toRecord: false,
|
|
208
|
-
purge: false
|
|
209
|
-
});
|
|
210
|
-
if (expectFalseCheckResult) {
|
|
211
|
-
(0, _chai.expect)(result).to.eql(false);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
(0, _chai.expect)(result).to.have.property('headers');
|
|
215
|
-
(0, _chai.expect)(result).to.have.property('messages');
|
|
216
|
-
(0, _chai.expect)(result.messages.length).to.eql(3);
|
|
217
|
-
const [{
|
|
218
|
-
fields
|
|
219
|
-
}] = result.messages;
|
|
220
|
-
(0, _chai.expect)(fields).to.have.property('deliveryTag');
|
|
221
|
-
(0, _chai.expect)(fields).to.have.property('exchange');
|
|
222
|
-
(0, _chai.expect)(fields).to.have.property('messageCount');
|
|
223
|
-
(0, _chai.expect)(fields).to.have.property('redelivered');
|
|
224
|
-
(0, _chai.expect)(fields).to.have.property('routingKey');
|
|
225
|
-
(0, _chai.expect)(typeof fields.deliveryTag).to.be.eql('number');
|
|
226
|
-
(0, _chai.expect)(typeof fields.messageCount).to.be.eql('number');
|
|
227
|
-
(0, _chai.expect)(typeof fields.redelivered).to.be.eql('boolean');
|
|
228
|
-
(0, _chai.expect)(typeof fields.routingKey).to.be.eql('string');
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (checkQueueStyle === 'purge') {
|
|
232
|
-
return amqpOperator.checkQueue({
|
|
233
|
-
queue,
|
|
234
|
-
style: 'messages',
|
|
235
|
-
purge: true
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
if (checkQueueStyle === 'foobar') {
|
|
239
|
-
return amqpOperator.checkQueue({
|
|
240
|
-
queue,
|
|
241
|
-
style: 'foobar',
|
|
242
|
-
toRecord: false,
|
|
243
|
-
purge: false
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
async function ackOrNackMessages() {
|
|
249
|
-
if (ackMessages) {
|
|
250
|
-
const message = await amqpOperator.consumeOne(testData.queue, false);
|
|
251
|
-
await amqpOperator.ackMessages([message]);
|
|
252
|
-
return setTimeoutPromise(10);
|
|
253
|
-
}
|
|
254
|
-
if (nackMessages) {
|
|
255
|
-
const message = await amqpOperator.consumeOne(testData.queue, false);
|
|
256
|
-
await amqpOperator.nackMessages([message]);
|
|
257
|
-
return setTimeoutPromise(10);
|
|
258
|
-
}
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
async function sendMessagesToQueue() {
|
|
262
|
-
if (sentToQueue) {
|
|
263
|
-
const messages = getFixture('input.json');
|
|
264
|
-
// {queue, correlationId, headers, data}
|
|
265
|
-
|
|
266
|
-
const promises = messages.map(message => amqpOperator.sendToQueue(message));
|
|
267
|
-
await Promise.all(promises);
|
|
268
|
-
return setTimeoutPromise(10);
|
|
269
|
-
}
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/*
|
|
275
|
-
function testHeathCheck() {
|
|
276
|
-
return it('expects healthCheck', async () => {
|
|
277
|
-
|
|
278
|
-
const amqpOperator2 = await amqpFactory(amqpUrl, true);
|
|
279
|
-
try {
|
|
280
|
-
|
|
281
|
-
debug(`**********`);
|
|
282
|
-
await testHealthCheckLoopWorking(amqpOperator2);
|
|
283
|
-
|
|
284
|
-
debug(`**********`);
|
|
285
|
-
await testHealthCheckLoopErroring(amqpOperator2);
|
|
286
|
-
} catch (error) {
|
|
287
|
-
debug(error);
|
|
288
|
-
expect(error).to.eql('');
|
|
289
|
-
} finally {
|
|
290
|
-
amqpOperator2.closeConnection();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
async function testHealthCheckLoopWorking(amqpOperator) {
|
|
294
|
-
debug(`Testing healthCheckLoop for ${amqpOperator}`);
|
|
295
|
-
debug(`Waiting 0.5s and expecting healthCheckLoop to work`);
|
|
296
|
-
await setTimeoutPromise('500');
|
|
297
|
-
debug(`Amqp Operator should have been alive.`);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
async function testHealthCheckLoopErroring(amqpOperator) {
|
|
301
|
-
debug(`Testing healthCheckLoop with closed channel`);
|
|
302
|
-
amqpOperator.closeChannel();
|
|
303
|
-
debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);
|
|
304
|
-
await setTimeoutPromise('500');
|
|
305
|
-
debug(`amqpOperator should have errored`);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
*/
|
|
310
|
-
//# sourceMappingURL=amqp.tests.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amqp.tests.spec.js","names":["_chai","require","_fixura","_debug","_interopRequireDefault","_fixugen","_index","_melindaCommons","_util","setTimeoutPromise","promisify","setTimeout","debug","createDebugLogger","testData","queue","correlationId","data","amqpUrl","amqpOperator","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","mocha","before","amqpFactory","beforeEach","checkQueue","toRecord","purge","afterEach","removeQueue","after","closeConnection","getFixture","expectToFail","expectedErrorStatus","ackMessages","nackMessages","checkNextMessage","checkQueueStyle","sentToQueue","expectedMessageCount","expectedErrorMessage","undefined","expectApiError","expectFalseCheckResult","sendMessagesToQueue","ackOrNackMessages","queueRemoval","messageCount","style","expect","to","eql","headers","records","queueCheckNextMessage","nextMessage","expectedNextMessage","error","equal","testErrors","be","instanceOf","ApiError","status","payload","not","constructor","name","consumeOne","result","have","property","length","messages","fields","deliveryTag","redelivered","routingKey","expectedResult","message","promises","map","sendToQueue","Promise","all"],"sources":["../src/amqp.tests.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport createDebugLogger from 'debug';\nimport generateTests from '@natlibfi/fixugen';\nimport {amqpFactory} from './index';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {promisify} from 'util';\n\nconst setTimeoutPromise = promisify(setTimeout);\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');\n//const debugData = debug.extend('data');\n\nconst testData = {\n queue: 'TESTQUEUE',\n correlationId: 'aaaaaaaa-0000-aaaa-0000-000000000000',\n data: {'leader': '02518cam a2200745zi 4500', 'fields': [{'tag': '001', 'value': '000019640'}]}\n};\n\ndebug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);\nconst amqpUrl = 'amqp://127.0.0.1:5672/';\n// eslint-disable-next-line functional/no-let\nlet amqpOperator;\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'amqp'],\n recurse: false,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: true,\n reader: READERS.JSON\n },\n mocha: {\n before: async () => {\n debug(`Connecting to ${amqpUrl}, with healthCheck running`);\n amqpOperator = await amqpFactory(amqpUrl, true);\n },\n beforeEach: async () => {\n await amqpOperator.checkQueue({queue: testData.queue, toRecord: false, purge: true});\n },\n afterEach: async () => {\n await amqpOperator.removeQueue(testData.queue);\n },\n after: async () => {\n await amqpOperator.closeConnection();\n //await testHeathCheck();\n }\n }\n});\n\n// eslint-disable-next-line max-statements\nasync function callback({\n getFixture,\n expectToFail = false,\n expectedErrorStatus = '',\n ackMessages = false,\n nackMessages = false,\n checkNextMessage = false,\n checkQueueStyle = false,\n queue = testData.queue,\n sentToQueue,\n expectedMessageCount,\n removeQueue = false,\n expectedErrorMessage = undefined,\n expectApiError = false,\n expectFalseCheckResult = false\n}) {\n try {\n await sendMessagesToQueue();\n\n await ackOrNackMessages();\n\n await checkQueue();\n\n await queueRemoval();\n\n const messageCount = await amqpOperator.checkQueue({queue, style: 'messages'});\n debug(`MessageCount: ${messageCount}`);\n expect(messageCount).to.eql(expectedMessageCount);\n\n if (checkNextMessage) {\n const {headers, records} = await queueCheckNextMessage();\n const nextMessage = {headers, records};\n const expectedNextMessage = getFixture('expectedMessage.json');\n expect(nextMessage).to.eql(expectedNextMessage);\n return;\n }\n\n } catch (error) {\n if (!expectToFail) {\n throw error;\n }\n expect(expectToFail, 'This is expected to fail').to.equal(true);\n testErrors(error);\n }\n\n function testErrors(error) {\n\n if (expectApiError) {\n expect(error).to.be.instanceOf(ApiError);\n debug(`We expected and got an ApiError`);\n expect(error.status).to.equal(expectedErrorStatus);\n\n if (expectedErrorMessage) {\n expect(error.payload).to.eql(expectedErrorMessage);\n return;\n }\n\n return;\n }\n expect(error).not.to.be.instanceOf(ApiError);\n debug(`We expected and got an non-ApiError`);\n debug(`Error is a ${error.constructor.name}`);\n }\n\n function queueRemoval() {\n if (removeQueue) {\n return amqpOperator.removeQueue(removeQueue);\n }\n\n return;\n }\n\n function queueCheckNextMessage() {\n if (checkNextMessage) {\n return amqpOperator.consumeOne(testData.queue, true);\n }\n\n return false;\n }\n\n // eslint-disable-next-line max-statements\n async function checkQueue() {\n debug(`checkQueueStyle: ${checkQueueStyle}`);\n\n if (checkQueueStyle === 'oneToRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'one', toRecord: true, purge: false});\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(result).to.have.property('headers');\n expect(result).to.have.property('records');\n expect(result).to.have.property('messages');\n expect(result.records.length).to.eql(1);\n expect(result.messages.length).to.eql(1);\n\n return;\n }\n\n if (checkQueueStyle === 'oneNotRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});\n const {fields} = result;\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(fields).to.have.property('deliveryTag');\n expect(fields).to.have.property('exchange');\n expect(fields).to.have.property('messageCount');\n expect(fields).to.have.property('redelivered');\n expect(fields).to.have.property('routingKey');\n expect(typeof fields.deliveryTag).to.be.eql('number');\n expect(typeof fields.messageCount).to.be.eql('number');\n expect(typeof fields.redelivered).to.be.eql('boolean');\n expect(typeof fields.routingKey).to.be.eql('string');\n\n return;\n }\n\n if (checkQueueStyle === 'basicToRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: true, purge: false});\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(result).to.have.property('headers');\n expect(result).to.have.property('records');\n expect(result).to.have.property('messages');\n expect(result.records.length).to.eql(3);\n expect(result.messages.length).to.eql(3);\n const expectedResult = getFixture('expectedResult.json');\n expect(result.records).to.eql(expectedResult);\n\n return;\n }\n\n if (checkQueueStyle === 'basicNotRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(result).to.have.property('headers');\n expect(result).to.have.property('messages');\n expect(result.messages.length).to.eql(3);\n\n const [{fields}] = result.messages;\n\n expect(fields).to.have.property('deliveryTag');\n expect(fields).to.have.property('exchange');\n expect(fields).to.have.property('messageCount');\n expect(fields).to.have.property('redelivered');\n expect(fields).to.have.property('routingKey');\n\n expect(typeof fields.deliveryTag).to.be.eql('number');\n expect(typeof fields.messageCount).to.be.eql('number');\n expect(typeof fields.redelivered).to.be.eql('boolean');\n expect(typeof fields.routingKey).to.be.eql('string');\n\n return;\n }\n\n if (checkQueueStyle === 'purge') {\n return amqpOperator.checkQueue({queue, style: 'messages', purge: true});\n }\n\n if (checkQueueStyle === 'foobar') {\n return amqpOperator.checkQueue({queue, style: 'foobar', toRecord: false, purge: false});\n }\n\n return false;\n }\n\n async function ackOrNackMessages() {\n if (ackMessages) {\n const message = await amqpOperator.consumeOne(testData.queue, false);\n await amqpOperator.ackMessages([message]);\n\n return setTimeoutPromise(10);\n }\n\n if (nackMessages) {\n const message = await amqpOperator.consumeOne(testData.queue, false);\n await amqpOperator.nackMessages([message]);\n\n return setTimeoutPromise(10);\n }\n\n return;\n }\n\n async function sendMessagesToQueue() {\n if (sentToQueue) {\n const messages = getFixture('input.json');\n // {queue, correlationId, headers, data}\n\n const promises = messages.map(message => amqpOperator.sendToQueue(message));\n await Promise.all(promises);\n\n return setTimeoutPromise(10);\n }\n\n return;\n }\n}\n\n/*\nfunction testHeathCheck() {\n return it('expects healthCheck', async () => {\n\n const amqpOperator2 = await amqpFactory(amqpUrl, true);\n try {\n\n debug(`**********`);\n await testHealthCheckLoopWorking(amqpOperator2);\n\n debug(`**********`);\n await testHealthCheckLoopErroring(amqpOperator2);\n } catch (error) {\n debug(error);\n expect(error).to.eql('');\n } finally {\n amqpOperator2.closeConnection();\n }\n\n async function testHealthCheckLoopWorking(amqpOperator) {\n debug(`Testing healthCheckLoop for ${amqpOperator}`);\n debug(`Waiting 0.5s and expecting healthCheckLoop to work`);\n await setTimeoutPromise('500');\n debug(`Amqp Operator should have been alive.`);\n }\n\n async function testHealthCheckLoopErroring(amqpOperator) {\n debug(`Testing healthCheckLoop with closed channel`);\n amqpOperator.closeChannel();\n debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);\n await setTimeoutPromise('500');\n debug(`amqpOperator should have errored`);\n }\n });\n}\n*/\n"],"mappings":";;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AAEA,MAAMQ,iBAAiB,GAAG,IAAAC,eAAS,EAACC,UAAU,CAAC;AAC/C,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;AAC/E;;AAEA,MAAMC,QAAQ,GAAG;EACfC,KAAK,EAAE,WAAW;EAClBC,aAAa,EAAE,sCAAsC;EACrDC,IAAI,EAAE;IAAC,QAAQ,EAAE,0BAA0B;IAAE,QAAQ,EAAE,CAAC;MAAC,KAAK,EAAE,KAAK;MAAE,OAAO,EAAE;IAAW,CAAC;EAAC;AAC/F,CAAC;AAEDL,KAAK,CAAC,sFAAsF,CAAC;AA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E,YAAY,CAAC4D,UAAU,CAACjE,QAAQ,CAACC,KAAK,EAAE,KAAK,CAAC;MACpE,MAAMI,YAAY,CAAC0B,WAAW,CAAC,CAAC6C,OAAO,CAAC,CAAC;MAEzC,OAAOjF,iBAAiB,CAAC,EAAE,CAAC;IAC9B;IAEA,IAAIqC,YAAY,EAAE;MAChB,MAAM4C,OAAO,GAAG,MAAMvE,YAAY,CAAC4D,UAAU,CAACjE,QAAQ,CAACC,KAAK,EAAE,KAAK,CAAC;MACpE,MAAMI,YAAY,CAAC2B,YAAY,CAAC,CAAC4C,OAAO,CAAC,CAAC;MAE1C,OAAOjF,iBAAiB,CAAC,EAAE,CAAC;IAC9B;IAEA;EACF;EAEA,eAAe8C,mBAAmBA,CAAA,EAAG;IACnC,IAAIN,WAAW,EAAE;MACf,MAAMmC,QAAQ,GAAG1C,UAAU,CAAC,YAAY,CAAC;MACzC;;MAEA,MAAMiD,QAAQ,GAAGP,QAAQ,CAACQ,GAAG,CAACF,OAAO,IAAIvE,YAAY,CAAC0E,WAAW,CAACH,OAAO,CAAC,CAAC;MAC3E,MAAMI,OAAO,CAACC,GAAG,CAACJ,QAAQ,CAAC;MAE3B,OAAOlF,iBAAiB,CAAC,EAAE,CAAC;IAC9B;IAEA;EACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _chai = require("chai");
|
|
5
|
-
var _fixura = _interopRequireDefault(require("@natlibfi/fixura"));
|
|
6
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
7
|
-
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
8
|
-
var _conversion = _interopRequireDefault(require("./conversion"));
|
|
9
|
-
var _constants = require("../constants");
|
|
10
|
-
describe('services/conversion', () => {
|
|
11
|
-
const {
|
|
12
|
-
getFixture
|
|
13
|
-
} = (0, _fixura.default)({
|
|
14
|
-
root: [__dirname, '..', '..', 'test-fixtures', 'conversion']
|
|
15
|
-
});
|
|
16
|
-
const conversionService = (0, _conversion.default)();
|
|
17
|
-
const marcRecord = new _marcRecord.MarcRecord(JSON.parse(getFixture({
|
|
18
|
-
components: ['json1']
|
|
19
|
-
})), {
|
|
20
|
-
subfieldValues: false
|
|
21
|
-
});
|
|
22
|
-
const marcXml = getFixture({
|
|
23
|
-
components: ['marcxml1']
|
|
24
|
-
});
|
|
25
|
-
const iso2709 = getFixture({
|
|
26
|
-
components: ['iso2709_1']
|
|
27
|
-
});
|
|
28
|
-
const json = getFixture({
|
|
29
|
-
components: ['json1']
|
|
30
|
-
});
|
|
31
|
-
const alephSeq = getFixture({
|
|
32
|
-
components: ['aleph_sequential']
|
|
33
|
-
});
|
|
34
|
-
describe('factory', () => {
|
|
35
|
-
it('Should create the expected object', () => {
|
|
36
|
-
const service = (0, _conversion.default)();
|
|
37
|
-
(0, _chai.expect)(service).to.be.an('object').and.respondTo('serialize').respondTo('unserialize');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe('#serialize', () => {
|
|
41
|
-
it('Should throw because of unsupported format', () => {
|
|
42
|
-
(0, _chai.expect)(conversionService.serialize).to.throw();
|
|
43
|
-
});
|
|
44
|
-
it('Should serialize to MARCXML', () => {
|
|
45
|
-
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.MARCXML);
|
|
46
|
-
(0, _chai.expect)(data).to.equal(marcXml);
|
|
47
|
-
});
|
|
48
|
-
it('Should serialize to ISO2709', () => {
|
|
49
|
-
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.ISO2709);
|
|
50
|
-
(0, _chai.expect)(data).to.equal(iso2709);
|
|
51
|
-
});
|
|
52
|
-
it('Should serialize to JSON', () => {
|
|
53
|
-
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.JSON);
|
|
54
|
-
(0, _chai.expect)(data).to.equal(json);
|
|
55
|
-
});
|
|
56
|
-
it('Should serialize to aleph sequential', () => {
|
|
57
|
-
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.ALEPHSEQ);
|
|
58
|
-
(0, _chai.expect)(data).to.equal(alephSeq);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe('#unserialize', () => {
|
|
62
|
-
it('Should throw because of unsupported format', () => {
|
|
63
|
-
(0, _chai.expect)(conversionService.unserialize).to.throw();
|
|
64
|
-
});
|
|
65
|
-
it('Should unserialize from MARCXML', async () => {
|
|
66
|
-
const record = await conversionService.unserialize(marcXml, _constants.CONVERSION_FORMATS.MARCXML);
|
|
67
|
-
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
68
|
-
});
|
|
69
|
-
it('Should unserialize from ISO2709', () => {
|
|
70
|
-
const record = conversionService.unserialize(iso2709, _constants.CONVERSION_FORMATS.ISO2709);
|
|
71
|
-
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
72
|
-
});
|
|
73
|
-
it('Should unserialize from JSON', () => {
|
|
74
|
-
const record = conversionService.unserialize(json, _constants.CONVERSION_FORMATS.JSON);
|
|
75
|
-
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
76
|
-
});
|
|
77
|
-
it('Should unserialize from Aleph sequential', () => {
|
|
78
|
-
const record = conversionService.unserialize(alephSeq, _constants.CONVERSION_FORMATS.ALEPHSEQ);
|
|
79
|
-
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
80
|
-
});
|
|
81
|
-
it('Should throw because the record could not be unserialized', () => {
|
|
82
|
-
(0, _chai.expect)(() => {
|
|
83
|
-
conversionService.unserialize('', _constants.CONVERSION_FORMATS.JSON);
|
|
84
|
-
}).to.throw(_melindaCommons.Error);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
//# sourceMappingURL=conversion.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.spec.js","names":["_chai","require","_fixura","_interopRequireDefault","_marcRecord","_melindaCommons","_conversion","_constants","describe","getFixture","fixtureFactory","root","__dirname","conversionService","createConversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","expect","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"sources":["../../src/helpers/conversion.spec.js"],"sourcesContent":["\n\nimport {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"mappings":";;;AAEA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAEAO,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpC,MAAM;IAACC;EAAU,CAAC,GAAG,IAAAC,eAAc,EAAC;IAACC,IAAI,EAAE,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