mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2026-08-13 12:33:07 +02:00
Add backend test infrastructure with vitest and initial tests for CommonService and LoggerService
- Add vitest configuration for backend testing - Add test:backend and test:backend:coverage npm scripts - Add comprehensive tests for server/utils/common.ts (61 tests) - Tests for maskPasswords, sortAscByKey, sortDescByKey, sortAscByStrKey, sortDescByStrKey - Tests for convertTimeToEpoch, convertTimestampToTime, isVersionCompatible - Tests for handleError, getRequestIP, findNode, removeSecureData - Tests for runWithConcurrencyLimit, camelCase, titleCase, getMonthDays - Add tests for server/utils/logger.ts (22 tests) - Tests for ERROR, WARN, INFO, DEBUG log levels - Tests for log file writing and console output Generated with [Continue](https://continue.dev) Co-Authored-By: Continue <noreply@continue.dev> Co-authored-by: shahana-farooqui <shahana.farooqui@gmail.com>
This commit is contained in:
parent
d8e6bb1b68
commit
ca050f62aa
5 changed files with 1395 additions and 9 deletions
474
package-lock.json
generated
474
package-lock.json
generated
|
|
@ -71,6 +71,7 @@
|
|||
"@types/node": "20.19.30",
|
||||
"@typescript-eslint/eslint-plugin": "8.53.0",
|
||||
"@typescript-eslint/parser": "8.53.0",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"dotenv": "17.2.3",
|
||||
"eslint": "9.39.2",
|
||||
"eslint-plugin-deprecation": "3.0.0",
|
||||
|
|
@ -86,7 +87,8 @@
|
|||
"protractor": "7.0.0",
|
||||
"roboto-fontface": "0.10.0",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "5.8.3"
|
||||
"typescript": "5.8.3",
|
||||
"vitest": "^4.0.18"
|
||||
}
|
||||
},
|
||||
"node_modules/@algolia/abtesting": {
|
||||
|
|
@ -1436,13 +1438,13 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@babel/parser": {
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.6.tgz",
|
||||
"integrity": "sha512-TeR9zWR18BvbfPmGbLampPMW+uW1NZnJlRuuHso8i87QZNq2JRF9i6RgxRqtEq+wQGsS19NNTWr2duhnE49mfQ==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.0.tgz",
|
||||
"integrity": "sha512-IyDgFV5GeDUVX4YdF/3CPULtVGSXXMLh1xVIgdCgxApktqnQV0r7/8Nqthg+8YLGaAtdyIlo2qIdZrbCv4+7ww==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.28.6"
|
||||
"@babel/types": "^7.29.0"
|
||||
},
|
||||
"bin": {
|
||||
"parser": "bin/babel-parser.js"
|
||||
|
|
@ -2656,9 +2658,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@babel/types": {
|
||||
"version": "7.28.6",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.28.6.tgz",
|
||||
"integrity": "sha512-0ZrskXVEHSWIqZM/sQZ4EV3jZJXRkio/WCxaqKZP1g//CEWEPSfeZFcms4XeKBCHU0ZKnIkdJeU/kF+eRp5lBg==",
|
||||
"version": "7.29.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.0.tgz",
|
||||
"integrity": "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
@ -2669,6 +2671,16 @@
|
|||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@bcoe/v8-coverage": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz",
|
||||
"integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@colors/colors": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz",
|
||||
|
|
@ -6159,6 +6171,13 @@
|
|||
"integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@standard-schema/spec": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",
|
||||
"integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@swc/helpers": {
|
||||
"version": "0.5.18",
|
||||
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.18.tgz",
|
||||
|
|
@ -6300,6 +6319,17 @@
|
|||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/chai": {
|
||||
"version": "5.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",
|
||||
"integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/deep-eql": "*",
|
||||
"assertion-error": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/connect": {
|
||||
"version": "3.4.38",
|
||||
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz",
|
||||
|
|
@ -6331,6 +6361,13 @@
|
|||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/deep-eql": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
|
||||
"integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/eslint": {
|
||||
"version": "9.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.1.tgz",
|
||||
|
|
@ -6857,6 +6894,168 @@
|
|||
"vite": "^6.0.0 || ^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/coverage-v8": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.0.18.tgz",
|
||||
"integrity": "sha512-7i+N2i0+ME+2JFZhfuz7Tg/FqKtilHjGyGvoHYQ6iLV0zahbsJ9sljC9OcFcPDbhYKCet+sG8SsVqlyGvPflZg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@bcoe/v8-coverage": "^1.0.2",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"ast-v8-to-istanbul": "^0.3.10",
|
||||
"istanbul-lib-coverage": "^3.2.2",
|
||||
"istanbul-lib-report": "^3.0.1",
|
||||
"istanbul-reports": "^3.2.0",
|
||||
"magicast": "^0.5.1",
|
||||
"obug": "^2.1.1",
|
||||
"std-env": "^3.10.0",
|
||||
"tinyrainbow": "^3.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vitest/browser": "4.0.18",
|
||||
"vitest": "4.0.18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@vitest/browser": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.18.tgz",
|
||||
"integrity": "sha512-8sCWUyckXXYvx4opfzVY03EOiYVxyNrHS5QxX3DAIi5dpJAAkyJezHCP77VMX4HKA2LDT/Jpfo8i2r5BE3GnQQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.0.0",
|
||||
"@types/chai": "^5.2.2",
|
||||
"@vitest/spy": "4.0.18",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"chai": "^6.2.1",
|
||||
"tinyrainbow": "^3.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/mocker": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.0.18.tgz",
|
||||
"integrity": "sha512-HhVd0MDnzzsgevnOWCBj5Otnzobjy5wLBe4EdeeFGv8luMsGcYqDuFRMcttKWZA5vVO8RFjexVovXvAM4JoJDQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/spy": "4.0.18",
|
||||
"estree-walker": "^3.0.3",
|
||||
"magic-string": "^0.30.21"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"msw": "^2.4.9",
|
||||
"vite": "^6.0.0 || ^7.0.0-0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"msw": {
|
||||
"optional": true
|
||||
},
|
||||
"vite": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/mocker/node_modules/magic-string": {
|
||||
"version": "0.30.21",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
||||
"integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/pretty-format": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.0.18.tgz",
|
||||
"integrity": "sha512-P24GK3GulZWC5tz87ux0m8OADrQIUVDPIjjj65vBXYG17ZeU3qD7r+MNZ1RNv4l8CGU2vtTRqixrOi9fYk/yKw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tinyrainbow": "^3.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/runner": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.0.18.tgz",
|
||||
"integrity": "sha512-rpk9y12PGa22Jg6g5M3UVVnTS7+zycIGk9ZNGN+m6tZHKQb7jrP7/77WfZy13Y/EUDd52NDsLRQhYKtv7XfPQw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/utils": "4.0.18",
|
||||
"pathe": "^2.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/snapshot": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.0.18.tgz",
|
||||
"integrity": "sha512-PCiV0rcl7jKQjbgYqjtakly6T1uwv/5BQ9SwBLekVg/EaYeQFPiXcgrC2Y7vDMA8dM1SUEAEV82kgSQIlXNMvA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "4.0.18",
|
||||
"magic-string": "^0.30.21",
|
||||
"pathe": "^2.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/snapshot/node_modules/magic-string": {
|
||||
"version": "0.30.21",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
||||
"integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/spy": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.0.18.tgz",
|
||||
"integrity": "sha512-cbQt3PTSD7P2OARdVW3qWER5EGq7PHlvE+QfzSC0lbwO+xnt7+XH06ZzFjFRgzUX//JmpxrCu92VdwvEPlWSNw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/utils": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.0.18.tgz",
|
||||
"integrity": "sha512-msMRKLMVLWygpK3u2Hybgi4MNjcYJvwTb0Ru09+fOyCXIgT5raYP041DRRdiJiI3k/2U6SEbAETB3YtBrUkCFA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "4.0.18",
|
||||
"tinyrainbow": "^3.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@webassemblyjs/ast": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.14.1.tgz",
|
||||
|
|
@ -7437,6 +7636,35 @@
|
|||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/assertion-error": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
|
||||
"integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ast-v8-to-istanbul": {
|
||||
"version": "0.3.12",
|
||||
"resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-0.3.12.tgz",
|
||||
"integrity": "sha512-BRRC8VRZY2R4Z4lFIL35MwNXmwVqBityvOIwETtsCSwvjl0IdgFsy9NhdaA6j74nUdtJJlIypeRhpDam19Wq3g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/trace-mapping": "^0.3.31",
|
||||
"estree-walker": "^3.0.3",
|
||||
"js-tokens": "^10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ast-v8-to-istanbul/node_modules/js-tokens": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz",
|
||||
"integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
|
|
@ -8291,6 +8519,16 @@
|
|||
"integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/chai": {
|
||||
"version": "6.2.2",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz",
|
||||
"integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
|
||||
|
|
@ -10633,6 +10871,16 @@
|
|||
"node": ">=4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/estree-walker": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
|
||||
"integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/estree": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/esutils": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
|
||||
|
|
@ -10711,6 +10959,16 @@
|
|||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/expect-type": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
|
||||
"integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/exponential-backoff": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.3.tgz",
|
||||
|
|
@ -13829,6 +14087,18 @@
|
|||
"@jridgewell/sourcemap-codec": "^1.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/magicast": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.2.tgz",
|
||||
"integrity": "sha512-E3ZJh4J3S9KfwdjZhe2afj6R9lGIN5Pher1pF39UGrXRqq/VDaGVIGN13BjHd2u8B61hArAGOnso7nBOouW3TQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.29.0",
|
||||
"@babel/types": "^7.29.0",
|
||||
"source-map-js": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/make-dir": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz",
|
||||
|
|
@ -14992,6 +15262,17 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/obug": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/obug/-/obug-2.1.1.tgz",
|
||||
"integrity": "sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
"https://github.com/sponsors/sxzz",
|
||||
"https://opencollective.com/debug"
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/on-finished": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
||||
|
|
@ -15520,6 +15801,13 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/pathe": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
|
||||
"integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pbkdf2": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.5.tgz",
|
||||
|
|
@ -17677,6 +17965,13 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/siginfo": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",
|
||||
"integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/signal-exit": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
|
||||
|
|
@ -18147,6 +18442,13 @@
|
|||
"node": "^18.17.0 || >=20.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/stackback": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
|
||||
"integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
|
||||
|
|
@ -18156,6 +18458,13 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/std-env": {
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz",
|
||||
"integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/stdin-discarder": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz",
|
||||
|
|
@ -18556,12 +18865,29 @@
|
|||
"integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinybench": {
|
||||
"version": "2.9.0",
|
||||
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
|
||||
"integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinycolor2": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.6.0.tgz",
|
||||
"integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinyexec": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.2.tgz",
|
||||
"integrity": "sha512-W/KYk+NFhkmsYpuHq5JykngiOCnxeVL8v8dFnqxSD8qEEdRfXk1SDM6JzNqcERbcGYj9tMrDQBYV9cjgnunFIg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.14",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz",
|
||||
|
|
@ -18589,6 +18915,16 @@
|
|||
"tinycolor2": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyrainbow": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.0.3.tgz",
|
||||
"integrity": "sha512-PSkbLUoxOFRzJYjjxHJt9xro7D+iilgMX/C9lawzVuYiIdcihh9DXmVibBe8lmcFrRi/VzlPjBxbN7rH24q8/Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tmp": {
|
||||
"version": "0.2.5",
|
||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.5.tgz",
|
||||
|
|
@ -19259,6 +19595,111 @@
|
|||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/vitest": {
|
||||
"version": "4.0.18",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-4.0.18.tgz",
|
||||
"integrity": "sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/expect": "4.0.18",
|
||||
"@vitest/mocker": "4.0.18",
|
||||
"@vitest/pretty-format": "4.0.18",
|
||||
"@vitest/runner": "4.0.18",
|
||||
"@vitest/snapshot": "4.0.18",
|
||||
"@vitest/spy": "4.0.18",
|
||||
"@vitest/utils": "4.0.18",
|
||||
"es-module-lexer": "^1.7.0",
|
||||
"expect-type": "^1.2.2",
|
||||
"magic-string": "^0.30.21",
|
||||
"obug": "^2.1.1",
|
||||
"pathe": "^2.0.3",
|
||||
"picomatch": "^4.0.3",
|
||||
"std-env": "^3.10.0",
|
||||
"tinybench": "^2.9.0",
|
||||
"tinyexec": "^1.0.2",
|
||||
"tinyglobby": "^0.2.15",
|
||||
"tinyrainbow": "^3.0.3",
|
||||
"vite": "^6.0.0 || ^7.0.0",
|
||||
"why-is-node-running": "^2.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"vitest": "vitest.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.0.0 || ^22.0.0 || >=24.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@edge-runtime/vm": "*",
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",
|
||||
"@vitest/browser-playwright": "4.0.18",
|
||||
"@vitest/browser-preview": "4.0.18",
|
||||
"@vitest/browser-webdriverio": "4.0.18",
|
||||
"@vitest/ui": "4.0.18",
|
||||
"happy-dom": "*",
|
||||
"jsdom": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@edge-runtime/vm": {
|
||||
"optional": true
|
||||
},
|
||||
"@opentelemetry/api": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/node": {
|
||||
"optional": true
|
||||
},
|
||||
"@vitest/browser-playwright": {
|
||||
"optional": true
|
||||
},
|
||||
"@vitest/browser-preview": {
|
||||
"optional": true
|
||||
},
|
||||
"@vitest/browser-webdriverio": {
|
||||
"optional": true
|
||||
},
|
||||
"@vitest/ui": {
|
||||
"optional": true
|
||||
},
|
||||
"happy-dom": {
|
||||
"optional": true
|
||||
},
|
||||
"jsdom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vitest/node_modules/magic-string": {
|
||||
"version": "0.30.21",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
||||
"integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/vitest/node_modules/tinyglobby": {
|
||||
"version": "0.2.15",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz",
|
||||
"integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fdir": "^6.5.0",
|
||||
"picomatch": "^4.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/vm-browserify": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-1.1.2.tgz",
|
||||
|
|
@ -20146,6 +20587,23 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/why-is-node-running": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",
|
||||
"integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"siginfo": "^2.0.0",
|
||||
"stackback": "0.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"why-is-node-running": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/wildcard": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.1.tgz",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
"serverUbuntu": "NODE_ENV=development nodemon --watch backend --watch server ./rtl.js",
|
||||
"testdev": "ng test --watch=true --code-coverage",
|
||||
"test": "ng test --watch=false --browsers=ChromeHeadless",
|
||||
"test:backend": "vitest run",
|
||||
"test:backend:coverage": "vitest run --coverage",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"private": true,
|
||||
|
|
@ -83,6 +85,7 @@
|
|||
"@types/node": "20.19.30",
|
||||
"@typescript-eslint/eslint-plugin": "8.53.0",
|
||||
"@typescript-eslint/parser": "8.53.0",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"dotenv": "17.2.3",
|
||||
"eslint": "9.39.2",
|
||||
"eslint-plugin-deprecation": "3.0.0",
|
||||
|
|
@ -98,7 +101,8 @@
|
|||
"protractor": "7.0.0",
|
||||
"roboto-fontface": "0.10.0",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "5.8.3"
|
||||
"typescript": "5.8.3",
|
||||
"vitest": "^4.0.18"
|
||||
},
|
||||
"overrides": {
|
||||
"chalk": "4.1.0",
|
||||
|
|
|
|||
591
server/utils/__tests__/common.test.ts
Normal file
591
server/utils/__tests__/common.test.ts
Normal file
|
|
@ -0,0 +1,591 @@
|
|||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { CommonService } from '../common.js';
|
||||
|
||||
describe('CommonService', () => {
|
||||
let commonService: CommonService;
|
||||
|
||||
beforeEach(() => {
|
||||
commonService = new CommonService();
|
||||
});
|
||||
|
||||
describe('maskPasswords', () => {
|
||||
it('should mask password fields', () => {
|
||||
const obj = {
|
||||
username: 'admin',
|
||||
password: 'secretPassword123'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.username).toBe('admin');
|
||||
expect(result.password).toBe('********************');
|
||||
});
|
||||
|
||||
it('should mask rpcpassword fields', () => {
|
||||
const obj = {
|
||||
rpcuser: 'user',
|
||||
rpcpassword: 'secretRpcPass'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.rpcpassword).toBe('********************');
|
||||
});
|
||||
|
||||
it('should mask multipass fields', () => {
|
||||
const obj = {
|
||||
multipass: 'secretMultiPass'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.multipass).toBe('********************');
|
||||
});
|
||||
|
||||
it('should not mask allowPasswordUpdate field', () => {
|
||||
const obj = {
|
||||
allowPasswordUpdate: true
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.allowPasswordUpdate).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle nested objects', () => {
|
||||
const obj = {
|
||||
level1: {
|
||||
password: 'secret',
|
||||
level2: {
|
||||
rpcpass: 'rpcSecret'
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.level1.password).toBe('********************');
|
||||
expect(result.level1.level2.rpcpass).toBe('********************');
|
||||
});
|
||||
|
||||
it('should handle empty objects', () => {
|
||||
const obj = {};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertTimeToEpoch', () => {
|
||||
it('should convert Date to epoch seconds', () => {
|
||||
const date = new Date('2023-01-01T00:00:00.000Z');
|
||||
const result = commonService.convertTimeToEpoch(date);
|
||||
expect(result).toBe(1672531200);
|
||||
});
|
||||
|
||||
it('should handle different dates', () => {
|
||||
const date = new Date('2024-06-15T12:30:45.000Z');
|
||||
const result = commonService.convertTimeToEpoch(date);
|
||||
expect(result).toBe(Math.floor(date.getTime() / 1000));
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertTimestampToTime', () => {
|
||||
it('should convert epoch to formatted date string', () => {
|
||||
const timestamp = 1672531200; // 2023-01-01T00:00:00.000Z
|
||||
const result = commonService.convertTimestampToTime(timestamp);
|
||||
expect(result).toMatch(/\d{2}\/[A-Z]{3}\/\d{4} \d{2}:\d{2}:\d{2}/);
|
||||
});
|
||||
|
||||
it('should pad single digit days, hours, minutes, seconds', () => {
|
||||
// Use a timestamp that results in single digits
|
||||
const date = new Date('2023-01-01T01:02:03.000Z');
|
||||
const timestamp = Math.floor(date.getTime() / 1000);
|
||||
const result = commonService.convertTimestampToTime(timestamp);
|
||||
// The result depends on timezone, but format should be correct
|
||||
expect(result).toMatch(/\d{2}\/JAN\/2023 \d{2}:\d{2}:\d{2}/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortAscByKey', () => {
|
||||
it('should sort array ascending by numeric key', () => {
|
||||
const arr = [
|
||||
{ id: 3, name: 'c' },
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 2, name: 'b' }
|
||||
];
|
||||
const result = commonService.sortAscByKey(arr, 'id');
|
||||
expect(result[0].id).toBe(1);
|
||||
expect(result[1].id).toBe(2);
|
||||
expect(result[2].id).toBe(3);
|
||||
});
|
||||
|
||||
it('should handle string numeric values', () => {
|
||||
const arr = [
|
||||
{ amount: '300' },
|
||||
{ amount: '100' },
|
||||
{ amount: '200' }
|
||||
];
|
||||
const result = commonService.sortAscByKey(arr, 'amount');
|
||||
expect(result[0].amount).toBe('100');
|
||||
expect(result[1].amount).toBe('200');
|
||||
expect(result[2].amount).toBe('300');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortAscByStrKey', () => {
|
||||
it('should sort array ascending by string key', () => {
|
||||
const arr = [
|
||||
{ name: 'Charlie' },
|
||||
{ name: 'Alice' },
|
||||
{ name: 'Bob' }
|
||||
];
|
||||
const result = commonService.sortAscByStrKey(arr, 'name');
|
||||
expect(result[0].name).toBe('Alice');
|
||||
expect(result[1].name).toBe('Bob');
|
||||
expect(result[2].name).toBe('Charlie');
|
||||
});
|
||||
|
||||
it('should handle case insensitivity', () => {
|
||||
const arr = [
|
||||
{ name: 'charlie' },
|
||||
{ name: 'ALICE' },
|
||||
{ name: 'Bob' }
|
||||
];
|
||||
const result = commonService.sortAscByStrKey(arr, 'name');
|
||||
expect(result[0].name).toBe('ALICE');
|
||||
expect(result[1].name).toBe('Bob');
|
||||
expect(result[2].name).toBe('charlie');
|
||||
});
|
||||
|
||||
it('should handle undefined values', () => {
|
||||
const arr = [
|
||||
{ name: 'Bob' },
|
||||
{ name: undefined },
|
||||
{ name: 'Alice' }
|
||||
];
|
||||
const result = commonService.sortAscByStrKey(arr, 'name');
|
||||
expect(result[0].name).toBeUndefined();
|
||||
expect(result[1].name).toBe('Alice');
|
||||
expect(result[2].name).toBe('Bob');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortDescByKey', () => {
|
||||
it('should sort array descending by numeric key', () => {
|
||||
const arr = [
|
||||
{ id: 1 },
|
||||
{ id: 3 },
|
||||
{ id: 2 }
|
||||
];
|
||||
const result = commonService.sortDescByKey(arr, 'id');
|
||||
expect(result[0].id).toBe(3);
|
||||
expect(result[1].id).toBe(2);
|
||||
expect(result[2].id).toBe(1);
|
||||
});
|
||||
|
||||
it('should handle falsy values as 0', () => {
|
||||
const arr = [
|
||||
{ amount: 100 },
|
||||
{ amount: null },
|
||||
{ amount: 50 }
|
||||
];
|
||||
const result = commonService.sortDescByKey(arr, 'amount');
|
||||
expect(result[0].amount).toBe(100);
|
||||
expect(result[1].amount).toBe(50);
|
||||
expect(result[2].amount).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortDescByStrKey', () => {
|
||||
it('should sort array descending by string key', () => {
|
||||
const arr = [
|
||||
{ name: 'Alice' },
|
||||
{ name: 'Charlie' },
|
||||
{ name: 'Bob' }
|
||||
];
|
||||
const result = commonService.sortDescByStrKey(arr, 'name');
|
||||
expect(result[0].name).toBe('Charlie');
|
||||
expect(result[1].name).toBe('Bob');
|
||||
expect(result[2].name).toBe('Alice');
|
||||
});
|
||||
});
|
||||
|
||||
describe('newestOnTop', () => {
|
||||
it('should move matching item to top of array', () => {
|
||||
const arr = [
|
||||
{ id: 1, name: 'first' },
|
||||
{ id: 2, name: 'second' },
|
||||
{ id: 3, name: 'third' }
|
||||
];
|
||||
const result = commonService.newestOnTop(arr, 'id', 3);
|
||||
expect(result[0].id).toBe(3);
|
||||
expect(result[1].id).toBe(1);
|
||||
expect(result[2].id).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('camelCase', () => {
|
||||
it('should convert string to camel case', () => {
|
||||
const result = commonService.camelCase('hello world');
|
||||
expect(result).toBe('HelloWorld');
|
||||
});
|
||||
|
||||
it('should handle hyphenated strings', () => {
|
||||
const result = commonService.camelCase('my-test-string');
|
||||
expect(result).toBe('My Test String');
|
||||
});
|
||||
|
||||
it('should handle undefined', () => {
|
||||
const result = commonService.camelCase(undefined as any);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('titleCase', () => {
|
||||
it('should convert string to title case', () => {
|
||||
const result = commonService.titleCase('hello world');
|
||||
expect(result).toBe('Hello World ');
|
||||
});
|
||||
|
||||
it('should handle single word', () => {
|
||||
const result = commonService.titleCase('hello');
|
||||
expect(result).toBe('Hello');
|
||||
});
|
||||
|
||||
it('should handle multiline with period', () => {
|
||||
const result = commonService.titleCase('HELLO WORLD.\nGOODBYE WORLD');
|
||||
expect(result).toBe('Hello world.\nGoodbye world\n');
|
||||
});
|
||||
|
||||
it('should handle multiline with exclamation', () => {
|
||||
const result = commonService.titleCase('HELLO!\nWORLD');
|
||||
expect(result).toBe('Hello!\nWorld\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isVersionCompatible', () => {
|
||||
it('should return true when current version is greater', () => {
|
||||
expect(commonService.isVersionCompatible('v0.15.0', '0.14.0')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when versions are equal', () => {
|
||||
expect(commonService.isVersionCompatible('0.15.0', '0.15.0')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when current version is lower', () => {
|
||||
expect(commonService.isVersionCompatible('0.14.0', '0.15.0')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle version with v prefix', () => {
|
||||
expect(commonService.isVersionCompatible('v1.2.3', '1.2.0')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for empty version', () => {
|
||||
expect(commonService.isVersionCompatible('', '0.15.0')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for invalid version string', () => {
|
||||
expect(commonService.isVersionCompatible('invalid', '0.15.0')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle major version difference', () => {
|
||||
expect(commonService.isVersionCompatible('2.0.0', '1.99.99')).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle minor version difference', () => {
|
||||
expect(commonService.isVersionCompatible('1.15.0', '1.14.99')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMonthDays', () => {
|
||||
it('should return correct days for January', () => {
|
||||
expect(commonService.getMonthDays(0, 2023)).toBe(31);
|
||||
});
|
||||
|
||||
it('should return 28 for February in non-leap year', () => {
|
||||
expect(commonService.getMonthDays(1, 2023)).toBe(28);
|
||||
});
|
||||
|
||||
it('should return 29 for February in leap year', () => {
|
||||
expect(commonService.getMonthDays(1, 2024)).toBe(29);
|
||||
});
|
||||
|
||||
it('should return correct days for April', () => {
|
||||
expect(commonService.getMonthDays(3, 2023)).toBe(30);
|
||||
});
|
||||
|
||||
it('should return correct days for December', () => {
|
||||
expect(commonService.getMonthDays(11, 2023)).toBe(31);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAuthSecureData', () => {
|
||||
it('should remove sensitive authentication data', () => {
|
||||
const node = {
|
||||
index: 1,
|
||||
lnNode: 'TestNode',
|
||||
authentication: {
|
||||
macaroonPath: '/path/to/macaroon',
|
||||
runePath: '/path/to/rune',
|
||||
runeValue: 'secret-rune',
|
||||
lnApiPassword: 'secret-password',
|
||||
options: { some: 'option' }
|
||||
}
|
||||
};
|
||||
const result = commonService.removeAuthSecureData(node as any);
|
||||
expect(result.authentication.macaroonPath).toBeUndefined();
|
||||
expect(result.authentication.runePath).toBeUndefined();
|
||||
expect(result.authentication.runeValue).toBeUndefined();
|
||||
expect(result.authentication.lnApiPassword).toBeUndefined();
|
||||
expect(result.authentication.options).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle node without authentication', () => {
|
||||
const node = {
|
||||
index: 1,
|
||||
lnNode: 'TestNode'
|
||||
};
|
||||
const result = commonService.removeAuthSecureData(node as any);
|
||||
expect(result).toEqual(node);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeSecureData', () => {
|
||||
it('should remove sensitive config data', () => {
|
||||
const config = {
|
||||
defaultNodeIndex: 0,
|
||||
selectedNodeIndex: 0,
|
||||
rtlConfFilePath: '/path/to/config',
|
||||
rtlPass: 'secret',
|
||||
multiPass: 'multiSecret',
|
||||
multiPassHashed: 'hashedSecret',
|
||||
secret2FA: '2faSecret',
|
||||
nodes: []
|
||||
};
|
||||
const result = commonService.removeSecureData(config as any);
|
||||
expect(result.rtlConfFilePath).toBeUndefined();
|
||||
expect(result.rtlPass).toBeUndefined();
|
||||
expect(result.multiPass).toBeUndefined();
|
||||
expect(result.multiPassHashed).toBeUndefined();
|
||||
expect(result.secret2FA).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('findNode', () => {
|
||||
it('should find node by index', () => {
|
||||
commonService.nodes = [
|
||||
{ index: 1, lnNode: 'Node1' },
|
||||
{ index: 2, lnNode: 'Node2' }
|
||||
] as any;
|
||||
const result = commonService.findNode(2);
|
||||
expect(result?.lnNode).toBe('Node2');
|
||||
});
|
||||
|
||||
it('should return undefined for non-existent index', () => {
|
||||
commonService.nodes = [
|
||||
{ index: 1, lnNode: 'Node1' }
|
||||
] as any;
|
||||
const result = commonService.findNode(99);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRequestIP', () => {
|
||||
it('should return x-forwarded-for header if present', () => {
|
||||
const req = {
|
||||
headers: { 'x-forwarded-for': '192.168.1.1, 10.0.0.1' },
|
||||
ip: '127.0.0.1',
|
||||
connection: { remoteAddress: '127.0.0.2' },
|
||||
socket: { remoteAddress: '127.0.0.3' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req as any);
|
||||
expect(result).toBe('192.168.1.1');
|
||||
});
|
||||
|
||||
it('should return req.ip if no x-forwarded-for', () => {
|
||||
const req = {
|
||||
headers: {},
|
||||
ip: '192.168.1.100',
|
||||
connection: { remoteAddress: '127.0.0.2' },
|
||||
socket: { remoteAddress: '127.0.0.3' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req as any);
|
||||
expect(result).toBe('192.168.1.100');
|
||||
});
|
||||
|
||||
it('should fallback to connection.remoteAddress', () => {
|
||||
const req = {
|
||||
headers: {},
|
||||
ip: null,
|
||||
connection: { remoteAddress: '10.0.0.5' },
|
||||
socket: { remoteAddress: '127.0.0.3' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req as any);
|
||||
expect(result).toBe('10.0.0.5');
|
||||
});
|
||||
|
||||
it('should fallback to socket.remoteAddress', () => {
|
||||
const req = {
|
||||
headers: {},
|
||||
ip: null,
|
||||
connection: { remoteAddress: null },
|
||||
socket: { remoteAddress: '10.0.0.10' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req as any);
|
||||
expect(result).toBe('10.0.0.10');
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleError', () => {
|
||||
beforeEach(() => {
|
||||
commonService.selectedNode = { lnImplementation: 'LND' } as any;
|
||||
// Mock logger to suppress console output in tests
|
||||
commonService.logger = { log: vi.fn() } as any;
|
||||
});
|
||||
|
||||
it('should handle ENOENT error', () => {
|
||||
const err = { code: 'ENOENT', path: '/missing/file' };
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test error', commonService.selectedNode);
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toContain('No such file or directory');
|
||||
expect(result.message).toContain('/missing/file');
|
||||
});
|
||||
|
||||
it('should handle connection refused error', () => {
|
||||
const err = { error: { code: 'ECONNREFUSED' } };
|
||||
const result = commonService.handleError(err, 'TestFile', 'Connection failed', commonService.selectedNode);
|
||||
expect(result.statusCode).toBe(503);
|
||||
});
|
||||
|
||||
it('should extract message from nested error', () => {
|
||||
const err = { error: { message: 'Nested error message' } };
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test', commonService.selectedNode);
|
||||
expect(result.message).toBe('Nested error message');
|
||||
});
|
||||
|
||||
it('should sanitize LND macaroon from error for logging', () => {
|
||||
// handleError creates a deep copy, sanitizes it for logging, and returns error info
|
||||
// The original object is passed to handleError but a copy is made internally
|
||||
const err = {
|
||||
options: { headers: { 'Grpc-Metadata-macaroon': 'secret-macaroon' } },
|
||||
message: 'Test error'
|
||||
};
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test', commonService.selectedNode);
|
||||
// The returned result should have sanitized error info
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toBe('Test error');
|
||||
});
|
||||
|
||||
it('should handle CLN implementation errors', () => {
|
||||
commonService.selectedNode = { lnImplementation: 'CLN' } as any;
|
||||
const err = {
|
||||
options: { headers: { rune: 'secret-rune' } },
|
||||
message: 'CLN Test error'
|
||||
};
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test', commonService.selectedNode);
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toBe('CLN Test error');
|
||||
});
|
||||
|
||||
it('should handle ECL implementation errors', () => {
|
||||
commonService.selectedNode = { lnImplementation: 'ECL' } as any;
|
||||
const err = {
|
||||
options: { headers: { authorization: 'Basic secret' } },
|
||||
message: 'ECL Test error'
|
||||
};
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test', commonService.selectedNode);
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toBe('ECL Test error');
|
||||
});
|
||||
|
||||
it('should use provided statusCode', () => {
|
||||
const err = { statusCode: 404, message: 'Not found' };
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test', commonService.selectedNode);
|
||||
expect(result.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
it('should use status if statusCode is not present', () => {
|
||||
const err = { status: 403, message: 'Forbidden' };
|
||||
const result = commonService.handleError(err, 'TestFile', 'Test', commonService.selectedNode);
|
||||
expect(result.statusCode).toBe(403);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runWithConcurrencyLimit', () => {
|
||||
it('should run tasks with concurrency limit', async () => {
|
||||
const results: number[] = [];
|
||||
const tasks = [
|
||||
() => Promise.resolve(1),
|
||||
() => Promise.resolve(2),
|
||||
() => Promise.resolve(3)
|
||||
];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, (res) => {
|
||||
results.push(...res);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
expect(results).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('should handle errors in tasks', async () => {
|
||||
const tasks = [
|
||||
() => Promise.resolve(1),
|
||||
() => Promise.reject(new Error('Task 2 failed')),
|
||||
() => Promise.resolve(3)
|
||||
];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, (res) => {
|
||||
expect(res[0]).toBe(1);
|
||||
expect(res[1]).toHaveProperty('error');
|
||||
expect(res[2]).toBe(3);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle invalid tasks', async () => {
|
||||
const tasks = [
|
||||
() => Promise.resolve(1),
|
||||
'not a function' as any,
|
||||
() => Promise.resolve(3)
|
||||
];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, (res) => {
|
||||
expect(res[0]).toBe(1);
|
||||
expect(res[1]).toHaveProperty('error');
|
||||
expect(res[2]).toBe(3);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle single task array', async () => {
|
||||
// Test with a single task to verify basic functionality
|
||||
const tasks = [() => Promise.resolve(42)];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, (res) => {
|
||||
expect(res).toEqual([42]);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should respect concurrency limit', async () => {
|
||||
let concurrentCount = 0;
|
||||
let maxConcurrent = 0;
|
||||
|
||||
const createTask = (id: number) => async () => {
|
||||
concurrentCount++;
|
||||
maxConcurrent = Math.max(maxConcurrent, concurrentCount);
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
concurrentCount--;
|
||||
return id;
|
||||
};
|
||||
|
||||
const tasks = [1, 2, 3, 4, 5].map(createTask);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, () => {
|
||||
expect(maxConcurrent).toBeLessThanOrEqual(2);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
318
server/utils/__tests__/logger.test.ts
Normal file
318
server/utils/__tests__/logger.test.ts
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
||||
import { LoggerService } from '../logger.js';
|
||||
|
||||
// Mock fs module
|
||||
vi.mock('fs', () => ({
|
||||
appendFile: vi.fn((path, data, callback) => callback())
|
||||
}));
|
||||
|
||||
describe('LoggerService', () => {
|
||||
let loggerService: LoggerService;
|
||||
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
|
||||
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
loggerService = new LoggerService();
|
||||
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('ERROR level', () => {
|
||||
it('should log error message without error object', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error message'
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleErrorSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('ERROR');
|
||||
expect(loggedMessage).toContain('TestFile');
|
||||
expect(loggedMessage).toContain('Test error message');
|
||||
expect(loggedMessage).toContain('.\r\n');
|
||||
});
|
||||
|
||||
it('should log error message with error string', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error',
|
||||
error: 'Error string message'
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleErrorSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('Error string message');
|
||||
});
|
||||
|
||||
it('should log error message with error object containing message', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error',
|
||||
error: { message: 'Error object message' }
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleErrorSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('Error object message');
|
||||
});
|
||||
|
||||
it('should log error message with nested error object', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error',
|
||||
error: { error: { message: 'Nested error message' } }
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleErrorSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('Nested error message');
|
||||
});
|
||||
|
||||
it('should log error message with error object containing stack', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error',
|
||||
error: { stack: 'Error stack trace' }
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleErrorSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('Error stack trace');
|
||||
});
|
||||
|
||||
it('should log error message with plain object error', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error',
|
||||
error: { code: 500, details: 'Some details' }
|
||||
});
|
||||
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleErrorSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('code');
|
||||
expect(loggedMessage).toContain('500');
|
||||
});
|
||||
|
||||
it('should write to log file when selectedNode has logFile setting', async () => {
|
||||
const fs = await import('fs');
|
||||
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logFile: '/path/to/log.txt' } } as any,
|
||||
level: 'ERROR',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test error message'
|
||||
});
|
||||
|
||||
expect(fs.appendFile).toHaveBeenCalledWith(
|
||||
'/path/to/log.txt',
|
||||
expect.any(String),
|
||||
expect.any(Function)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('WARN level', () => {
|
||||
it('should log warning with data', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'WARN' } } as any,
|
||||
level: 'WARN',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test warning',
|
||||
data: 'Warning data'
|
||||
});
|
||||
|
||||
// WARN doesn't console.log, only writes to file if configured
|
||||
});
|
||||
|
||||
it('should log warning without data', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'WARN' } } as any,
|
||||
level: 'WARN',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test warning'
|
||||
});
|
||||
});
|
||||
|
||||
it('should write to log file when log level allows', async () => {
|
||||
const fs = await import('fs');
|
||||
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'DEBUG', logFile: '/path/to/log.txt' } } as any,
|
||||
level: 'WARN',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test warning'
|
||||
});
|
||||
|
||||
expect(fs.appendFile).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should log warning with object data containing message', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'WARN', logFile: '/path/to/log.txt' } } as any,
|
||||
level: 'WARN',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test warning',
|
||||
data: { message: 'Warning message from object' }
|
||||
});
|
||||
});
|
||||
|
||||
it('should log warning with object data containing stack', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'WARN', logFile: '/path/to/log.txt' } } as any,
|
||||
level: 'WARN',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Test warning',
|
||||
data: { stack: 'Warning stack trace' }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('INFO level', () => {
|
||||
it('should log info when no selectedNode and fileName is RTL', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'INFO',
|
||||
fileName: 'RTL',
|
||||
msg: 'RTL startup message'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleLogSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('INFO');
|
||||
expect(loggedMessage).toContain('RTL');
|
||||
});
|
||||
|
||||
it('should log info when selectedNode has INFO log level', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'INFO' } } as any,
|
||||
level: 'INFO',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Info message'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleLogSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('INFO');
|
||||
});
|
||||
|
||||
it('should log info with data when selectedNode has DEBUG log level', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'DEBUG' } } as any,
|
||||
level: 'INFO',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Info message',
|
||||
data: 'Additional info'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleLogSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('Additional info');
|
||||
});
|
||||
|
||||
it('should write to log file when INFO level and logFile configured', async () => {
|
||||
const fs = await import('fs');
|
||||
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'INFO', logFile: '/path/to/log.txt' } } as any,
|
||||
level: 'INFO',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Info message'
|
||||
});
|
||||
|
||||
expect(fs.appendFile).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not log info when selectedNode has different log level', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'ERROR' } } as any,
|
||||
level: 'INFO',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Info message'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('DEBUG level', () => {
|
||||
it('should log debug when no selectedNode', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'DEBUG',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Debug message'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should log debug when selectedNode has DEBUG log level', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'DEBUG' } } as any,
|
||||
level: 'DEBUG',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Debug message',
|
||||
data: { key: 'value' }
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleLogSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('DEBUG');
|
||||
});
|
||||
|
||||
it('should write to log file when DEBUG level and logFile configured', async () => {
|
||||
const fs = await import('fs');
|
||||
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'DEBUG', logFile: '/path/to/log.txt' } } as any,
|
||||
level: 'DEBUG',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Debug message'
|
||||
});
|
||||
|
||||
expect(fs.appendFile).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not log debug when selectedNode has higher log level', () => {
|
||||
loggerService.log({
|
||||
selectedNode: { settings: { logLevel: 'INFO' } } as any,
|
||||
level: 'DEBUG',
|
||||
fileName: 'TestFile',
|
||||
msg: 'Debug message'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('default level', () => {
|
||||
it('should log unknown level to console', () => {
|
||||
loggerService.log({
|
||||
selectedNode: null,
|
||||
level: 'UNKNOWN' as any,
|
||||
fileName: 'TestFile',
|
||||
msg: 'Unknown level message'
|
||||
});
|
||||
|
||||
expect(consoleLogSpy).toHaveBeenCalled();
|
||||
const loggedMessage = consoleLogSpy.mock.calls[0][0];
|
||||
expect(loggedMessage).toContain('UNKNOWN');
|
||||
});
|
||||
});
|
||||
});
|
||||
15
vitest.config.ts
Normal file
15
vitest.config.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
include: ['server/**/*.test.ts'],
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['text', 'json', 'html'],
|
||||
include: ['server/**/*.ts'],
|
||||
exclude: ['server/**/*.test.ts', 'server/models/**']
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue