Skip to content

Commit 19158e2

Browse files
authored
Fix and test mongo.js ; Initialize setTimeOutPromise just once [MRA-845] ; Dependency & Maintenance Update (#298)
* Add test timeout * Node-tests: audit-level: moderate * [MRA-845] initialize setTimeOutPromise just once * Update deps * Update mongodb v6 * HealthCheck delay to integer * Fix and test mongo.js (#304) * Add db parameter to mongoOperator (defaults to 'rest-api') * Use returnDocument: 'after' instead of returnNewDocument to actually return updated document * Do not add queueItem if createBulk's stream fails * Return result for findOneAndUpdate if result.ok does not exist (mongodb update) * Fix setImportJobState errors * Fix checking queueItemState in checkTimeOut * Do not return _id in getOne() * Do not return _id in queryById() * Fix createProjection for query * Fix projection for queryById * Fix queryById to return timeouted queueItem * Add comments and debug * Add tests for mongo.js and comment non-tested parts in mongo.js * Use parseBoolean (note: any non-empty, non-"false" string === true) * Add debug * Fix removeContent & add tests * Move tests to tests-directory ; split mongo tests by function * 4.2.4-alpha.14
1 parent ae12025 commit 19158e2

File tree

235 files changed

+10310
-3903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+10310
-3903
lines changed

.github/workflows/melinda-node-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
env:
2626
NPM_CONFIG_IGNORE_SCRIPTS: true
2727
- run: npm update
28-
- run: npm audit --package-lock-only --production --audit-level=high
28+
- run: npm audit --package-lock-only --production --audit-level=moderate
2929
- run: npm i
3030
- run: npm test
3131
- run: npm run build --if-present

package-lock.json

+1,471-3,742
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+27-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"url": "[email protected]:natlibfi/melinda-rest-api-commons.git"
1515
},
1616
"license": "MIT",
17-
"version": "4.2.3",
17+
"version": "4.2.4-alpha.14",
1818
"main": "./dist/index.js",
1919
"engines": {
2020
"node": ">=18"
@@ -28,32 +28,32 @@
2828
"lint": "eslint ./src",
2929
"lint:dev": "eslint ./src --fix",
3030
"test": "npm run lint && npm run test:base",
31-
"test:base": "cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude src/amqp.health.spec.js --exclude src/amqp.tests.spec.js",
32-
"test:dev": "npm run lint:dev && cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude src/amqp.health.spec.js --exclude src/amqp.tests.spec.js",
33-
"test:local": "cross-env NODE_ENV=test nyc mocha --package ./package.json -- src/amqp.*.spec.js",
34-
"test:healthcheck": "cross-env NODE_ENV=test nyc mocha --require @babel/register -- src/amqp.health.spec.js",
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",
3535
"dev": "nodemon",
3636
"dev:debug": "cross-env LOG_LEVEL=debug DEBUG=@natlibfi/* NODE_ENV=test nodemon"
3737
},
3838
"dependencies": {
39-
"@natlibfi/marc-record": "^9.1.1",
40-
"@natlibfi/marc-record-serializers": "^10.1.4",
41-
"@natlibfi/marc-record-validate": "^8.0.11",
42-
"@natlibfi/marc-record-validators-melinda": "^11.4.8",
43-
"@natlibfi/melinda-backend-commons": "^2.3.5",
44-
"@natlibfi/melinda-commons": "^13.0.18",
45-
"amqplib": "^0.10.4",
46-
"debug": "^4.3.7",
39+
"@natlibfi/marc-record": "^9.1.3",
40+
"@natlibfi/marc-record-serializers": "^10.1.5",
41+
"@natlibfi/marc-record-validate": "^8.0.12",
42+
"@natlibfi/marc-record-validators-melinda": "^11.5.4",
43+
"@natlibfi/melinda-backend-commons": "^2.3.6",
44+
"@natlibfi/melinda-commons": "^13.0.19",
45+
"amqplib": "^0.10.5",
46+
"debug": "^4.4.0",
4747
"http-status": "^2.1.0",
4848
"moment": "^2.30.1",
4949
"mongo-sanitize": "^1.1.0",
50-
"mongodb": "^4.17.2"
50+
"mongodb": "^6.13.0"
5151
},
5252
"devDependencies": {
53-
"@babel/cli": "^7.25.9",
54-
"@babel/core": "^7.26.0",
55-
"@babel/plugin-transform-runtime": "^7.25.9",
56-
"@babel/preset-env": "^7.26.0",
53+
"@babel/cli": "^7.26.4",
54+
"@babel/core": "^7.26.8",
55+
"@babel/plugin-transform-runtime": "^7.26.8",
56+
"@babel/preset-env": "^7.26.8",
5757
"@babel/register": "^7.25.9",
5858
"@natlibfi/eslint-config-melinda-backend": "^3.0.5",
5959
"@natlibfi/fixugen": "^2.0.12",
@@ -64,8 +64,8 @@
6464
"chai": "^4.5.0",
6565
"cross-env": "^7.0.3",
6666
"eslint": "^8.57.1",
67-
"mocha": "^11.0.1",
68-
"nodemon": "^3.1.7",
67+
"mocha": "^11.1.0",
68+
"nodemon": "^3.1.9",
6969
"nyc": "^17.1.0"
7070
},
7171
"overrides": {
@@ -99,28 +99,30 @@
9999
},
100100
"mocha": {
101101
"spec": [
102-
"src/*.spec.js",
103-
"src/**/*.spec.js"
102+
"tests/*.spec.js",
103+
"tests/**/*.spec.js"
104104
],
105105
"require": [
106106
"@babel/register"
107107
],
108108
"inline-diffs": true,
109109
"maxDiffSize": 25000,
110110
"bail": true,
111-
"exit": true
111+
"exit": true,
112+
"timeout": 10000
112113
},
113114
"nodemonConfig": {
114115
"exec": "npm run test:dev",
115116
"watch": [
117+
"tests/*",
116118
"src/*",
117119
"test-fixtures/*"
118120
]
119121
},
120122
"nyc": {
121123
"exclude": [
122-
"src/*.spec.js",
123-
"src/**/*.spec.js"
124+
"tests/*.spec.js",
125+
"tests/**/*.spec.js"
124126
],
125127
"reporter": [
126128
"text"

src/amqp.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default async function (AMQP_URL, runHealthCheck = false) {
1313
const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp');
1414
const debugHC = debug.extend('HC');
1515
const debugData = debug.extend('data');
16+
const setTimeoutPromise = promisify(setTimeout);
1617

1718
debug(`Creating an AMQP operator to ${AMQP_URL}`);
1819
const connection = await amqplib.connect(AMQP_URL);
@@ -39,7 +40,6 @@ export default async function (AMQP_URL, runHealthCheck = false) {
3940
}
4041

4142
async function healthCheck(wait = false) {
42-
const setTimeoutPromise = promisify(setTimeout);
4343
if (wait) {
4444
await setTimeoutPromise(wait);
4545
return healthCheck(false);
@@ -49,7 +49,7 @@ export default async function (AMQP_URL, runHealthCheck = false) {
4949
debugHC(`Health checking amqp by asserting a queue`);
5050
await channel.assertQueue('HEALTHCHECK', {durable: false});
5151
debugHC(`Waiting 200ms before running healthCheck next`);
52-
return healthCheck('200');
52+
return healthCheck(200);
5353
} catch (error) {
5454
debugHC(`HealthCheck error ${JSON.stringify(error)}`);
5555
handleAmqpErrors(error);

0 commit comments

Comments
 (0)