mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2026-08-13 12:33:07 +02:00
Add backend test infrastructure and CommonService tests
- Add vitest configuration for backend tests - Add comprehensive test suite for CommonService (57 tests) - Add npm scripts for running backend tests with coverage - Tests cover: password masking, secure data handling, sorting functions, date/time conversions, error handling, version compatibility, and more Generated with [Continue](https://continue.dev) Co-authored-by: shahana-farooqui <shahana.farooqui@gmail.com> Co-Authored-By: Continue <noreply@continue.dev>
This commit is contained in:
parent
d8e6bb1b68
commit
0040e01c9d
4 changed files with 1082 additions and 9 deletions
494
package-lock.json
generated
494
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.1.2",
|
||||
"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.1.2"
|
||||
}
|
||||
},
|
||||
"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.2",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.2.tgz",
|
||||
"integrity": "sha512-4GgRzy/+fsBa72/RZVJmGKPmZu9Byn8o4MoLpmNe1m8ZfYnz5emHLQz3U4gLud6Zwl0RZIcgiLD7Uq7ySFuDLA==",
|
||||
"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,177 @@
|
|||
"vite": "^6.0.0 || ^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/coverage-v8": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.1.2.tgz",
|
||||
"integrity": "sha512-sPK//PHO+kAkScb8XITeB1bf7fsk85Km7+rt4eeuRR3VS1/crD47cmV5wicisJmjNdfeokTZwjMk4Mj2d58Mgg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@bcoe/v8-coverage": "^1.0.2",
|
||||
"@vitest/utils": "4.1.2",
|
||||
"ast-v8-to-istanbul": "^1.0.0",
|
||||
"istanbul-lib-coverage": "^3.2.2",
|
||||
"istanbul-lib-report": "^3.0.1",
|
||||
"istanbul-reports": "^3.2.0",
|
||||
"magicast": "^0.5.2",
|
||||
"obug": "^2.1.1",
|
||||
"std-env": "^4.0.0-rc.1",
|
||||
"tinyrainbow": "^3.1.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vitest/browser": "4.1.2",
|
||||
"vitest": "4.1.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@vitest/browser": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.2.tgz",
|
||||
"integrity": "sha512-gbu+7B0YgUJ2nkdsRJrFFW6X7NTP44WlhiclHniUhxADQJH5Szt9mZ9hWnJPJ8YwOK5zUOSSlSvyzRf0u1DSBQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@standard-schema/spec": "^1.1.0",
|
||||
"@types/chai": "^5.2.2",
|
||||
"@vitest/spy": "4.1.2",
|
||||
"@vitest/utils": "4.1.2",
|
||||
"chai": "^6.2.2",
|
||||
"tinyrainbow": "^3.1.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/mocker": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.2.tgz",
|
||||
"integrity": "sha512-Ize4iQtEALHDttPRCmN+FKqOl2vxTiNUhzobQFFt/BM1lRUTG7zRCLOykG/6Vo4E4hnUdfVLo5/eqKPukcWW7Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/spy": "4.1.2",
|
||||
"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 || ^8.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.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.2.tgz",
|
||||
"integrity": "sha512-dwQga8aejqeuB+TvXCMzSQemvV9hNEtDDpgUKDzOmNQayl2OG241PSWeJwKRH3CiC+sESrmoFd49rfnq7T4RnA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tinyrainbow": "^3.1.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/runner": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.2.tgz",
|
||||
"integrity": "sha512-Gr+FQan34CdiYAwpGJmQG8PgkyFVmARK8/xSijia3eTFgVfpcpztWLuP6FttGNfPLJhaZVP/euvujeNYar36OQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/utils": "4.1.2",
|
||||
"pathe": "^2.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/snapshot": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.2.tgz",
|
||||
"integrity": "sha512-g7yfUmxYS4mNxk31qbOYsSt2F4m1E02LFqO53Xpzg3zKMhLAPZAjjfyl9e6z7HrW6LvUdTwAQR3HHfLjpko16A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "4.1.2",
|
||||
"@vitest/utils": "4.1.2",
|
||||
"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.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.2.tgz",
|
||||
"integrity": "sha512-DU4fBnbVCJGNBwVA6xSToNXrkZNSiw59H8tcuUspVMsBDBST4nfvsPsEHDHGtWRRnqBERBQu7TrTKskmjqTXKA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/utils": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.2.tgz",
|
||||
"integrity": "sha512-xw2/TiX82lQHA06cgbqRKFb5lCAy3axQ4H4SoUFhUsg+wztiet+co86IAMDtF6Vm1hc7J6j09oh/rgDn+JdKIQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "4.1.2",
|
||||
"convert-source-map": "^2.0.0",
|
||||
"tinyrainbow": "^3.1.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/utils/node_modules/convert-source-map": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
|
||||
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@webassemblyjs/ast": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.14.1.tgz",
|
||||
|
|
@ -7437,6 +7645,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": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.0.tgz",
|
||||
"integrity": "sha512-1fSfIwuDICFA4LKkCzRPO7F0hzFf0B7+Xqrl27ynQaa+Rh0e1Es0v6kWHPott3lU10AyAr7oKHa65OppjLn3Rg==",
|
||||
"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 +8528,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 +10880,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 +10968,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 +14096,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 +15271,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 +15810,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 +17974,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 +18451,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 +18467,13 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/std-env": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/std-env/-/std-env-4.0.0.tgz",
|
||||
"integrity": "sha512-zUMPtQ/HBY3/50VbpkupYHbRroTRZJPRLvreamgErJVys0ceuzMkD44J/QjqhHjOzK42GQ3QZIeFG1OYfOtKqQ==",
|
||||
"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 +18874,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.4",
|
||||
"resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.4.tgz",
|
||||
"integrity": "sha512-u9r3uZC0bdpGOXtlxUIdwf9pkmvhqJdrVCH9fapQtgy/OeTTMZ1nqH7agtvEfmGui6e1XxjcdrlxvxJvc3sMqw==",
|
||||
"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 +18924,16 @@
|
|||
"tinycolor2": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyrainbow": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.0.tgz",
|
||||
"integrity": "sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==",
|
||||
"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 +19604,122 @@
|
|||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/vitest": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.2.tgz",
|
||||
"integrity": "sha512-xjR1dMTVHlFLh98JE3i/f/WePqJsah4A0FK9cc8Ehp9Udk0AZk6ccpIZhh1qJ/yxVWRZ+Q54ocnD8TXmkhspGg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/expect": "4.1.2",
|
||||
"@vitest/mocker": "4.1.2",
|
||||
"@vitest/pretty-format": "4.1.2",
|
||||
"@vitest/runner": "4.1.2",
|
||||
"@vitest/snapshot": "4.1.2",
|
||||
"@vitest/spy": "4.1.2",
|
||||
"@vitest/utils": "4.1.2",
|
||||
"es-module-lexer": "^2.0.0",
|
||||
"expect-type": "^1.3.0",
|
||||
"magic-string": "^0.30.21",
|
||||
"obug": "^2.1.1",
|
||||
"pathe": "^2.0.3",
|
||||
"picomatch": "^4.0.3",
|
||||
"std-env": "^4.0.0-rc.1",
|
||||
"tinybench": "^2.9.0",
|
||||
"tinyexec": "^1.0.2",
|
||||
"tinyglobby": "^0.2.15",
|
||||
"tinyrainbow": "^3.1.0",
|
||||
"vite": "^6.0.0 || ^7.0.0 || ^8.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.1.2",
|
||||
"@vitest/browser-preview": "4.1.2",
|
||||
"@vitest/browser-webdriverio": "4.1.2",
|
||||
"@vitest/ui": "4.1.2",
|
||||
"happy-dom": "*",
|
||||
"jsdom": "*",
|
||||
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
||||
},
|
||||
"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
|
||||
},
|
||||
"vite": {
|
||||
"optional": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vitest/node_modules/es-module-lexer": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.0.0.tgz",
|
||||
"integrity": "sha512-5POEcUuZybH7IdmGsD8wlf0AI55wMecM9rVBTI/qEAy2c1kTOm3DjFYjrBdI2K3BaJjJYfYFeRtM0t9ssnRuxw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"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 +20607,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.1.2",
|
||||
"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.1.2"
|
||||
},
|
||||
"overrides": {
|
||||
"chalk": "4.1.0",
|
||||
|
|
|
|||
576
server/utils/common.spec.ts
Normal file
576
server/utils/common.spec.ts
Normal file
|
|
@ -0,0 +1,576 @@
|
|||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { CommonService } from './common.js';
|
||||
import { SelectedNode, ApplicationConfig } from '../models/config.model.js';
|
||||
|
||||
describe('CommonService', () => {
|
||||
let commonService: CommonService;
|
||||
|
||||
beforeEach(() => {
|
||||
commonService = new CommonService();
|
||||
// Mock the logger to avoid console output during tests
|
||||
commonService.logger = {
|
||||
log: vi.fn()
|
||||
} as any;
|
||||
});
|
||||
|
||||
describe('maskPasswords', () => {
|
||||
it('should mask password fields', () => {
|
||||
const obj = {
|
||||
username: 'admin',
|
||||
password: 'secret123',
|
||||
rpcpass: 'rpcpassword',
|
||||
data: 'some data'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.username).toBe('admin');
|
||||
expect(result.password).toBe('********************');
|
||||
expect(result.rpcpass).toBe('********************');
|
||||
expect(result.data).toBe('some data');
|
||||
});
|
||||
|
||||
it('should mask nested password fields', () => {
|
||||
const obj = {
|
||||
level1: {
|
||||
password: 'nested_secret',
|
||||
rpcpassword: 'rpc_secret'
|
||||
}
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.level1.password).toBe('********************');
|
||||
expect(result.level1.rpcpassword).toBe('********************');
|
||||
});
|
||||
|
||||
it('should not mask allowPasswordUpdate', () => {
|
||||
const obj = {
|
||||
allowPasswordUpdate: true,
|
||||
password: 'secret'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.allowPasswordUpdate).toBe(true);
|
||||
expect(result.password).toBe('********************');
|
||||
});
|
||||
|
||||
it('should handle empty objects', () => {
|
||||
const obj = {};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
it('should mask rpcuser field', () => {
|
||||
const obj = {
|
||||
rpcuser: 'myuser',
|
||||
otherField: 'value'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.rpcuser).toBe('********************');
|
||||
expect(result.otherField).toBe('value');
|
||||
});
|
||||
|
||||
it('should mask multipass field', () => {
|
||||
const obj = {
|
||||
multipass: 'multipassvalue'
|
||||
};
|
||||
const result = commonService.maskPasswords(obj);
|
||||
expect(result.multipass).toBe('********************');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAuthSecureData', () => {
|
||||
it('should remove authentication secure data', () => {
|
||||
const node: SelectedNode = {
|
||||
index: 1,
|
||||
lnNode: 'Test Node',
|
||||
authentication: {
|
||||
macaroonPath: '/path/to/macaroon',
|
||||
runePath: '/path/to/rune',
|
||||
runeValue: 'runevalue',
|
||||
lnApiPassword: 'password',
|
||||
options: { someOption: true }
|
||||
}
|
||||
};
|
||||
const result = commonService.removeAuthSecureData(node);
|
||||
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: SelectedNode = {
|
||||
index: 1,
|
||||
lnNode: 'Test Node'
|
||||
};
|
||||
const result = commonService.removeAuthSecureData(node);
|
||||
expect(result).toEqual(node);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeSecureData', () => {
|
||||
it('should remove secure data from config', () => {
|
||||
const config: ApplicationConfig = {
|
||||
defaultNodeIndex: 0,
|
||||
selectedNodeIndex: 0,
|
||||
rtlConfFilePath: '/path/to/config',
|
||||
rtlPass: 'password',
|
||||
multiPass: 'multipass',
|
||||
multiPassHashed: 'hashedpass',
|
||||
secret2FA: 'secret',
|
||||
nodes: [{
|
||||
index: 1,
|
||||
lnNode: 'Test',
|
||||
authentication: {
|
||||
macaroonPath: '/path'
|
||||
}
|
||||
}]
|
||||
};
|
||||
const result = commonService.removeSecureData(config);
|
||||
expect(result.rtlConfFilePath).toBeUndefined();
|
||||
expect(result.rtlPass).toBeUndefined();
|
||||
expect(result.multiPass).toBeUndefined();
|
||||
expect(result.multiPassHashed).toBeUndefined();
|
||||
expect(result.secret2FA).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
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:00.000Z');
|
||||
const result = commonService.convertTimeToEpoch(date);
|
||||
expect(result).toBe(Math.floor(date.getTime() / 1000));
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertTimestampToTime', () => {
|
||||
it('should convert epoch timestamp to formatted string', () => {
|
||||
const timestamp = 1672531200; // 2023-01-01 00:00:00 UTC
|
||||
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 values with zero', () => {
|
||||
const timestamp = 1672531205; // 2023-01-01 00:00:05 UTC
|
||||
const result = commonService.convertTimestampToTime(timestamp);
|
||||
expect(result).toMatch(/\d{2}:\d{2}:\d{2}/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortAscByKey', () => {
|
||||
it('should sort array ascending by numeric key', () => {
|
||||
const array = [
|
||||
{ id: 3, name: 'c' },
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 2, name: 'b' }
|
||||
];
|
||||
const result = commonService.sortAscByKey(array, 'id');
|
||||
expect(result[0].id).toBe(1);
|
||||
expect(result[1].id).toBe(2);
|
||||
expect(result[2].id).toBe(3);
|
||||
});
|
||||
|
||||
it('should handle empty array', () => {
|
||||
const result = commonService.sortAscByKey([], 'id');
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortAscByStrKey', () => {
|
||||
it('should sort array ascending by string key', () => {
|
||||
const array = [
|
||||
{ id: 1, name: 'charlie' },
|
||||
{ id: 2, name: 'alpha' },
|
||||
{ id: 3, name: 'bravo' }
|
||||
];
|
||||
const result = commonService.sortAscByStrKey(array, 'name');
|
||||
expect(result[0].name).toBe('alpha');
|
||||
expect(result[1].name).toBe('bravo');
|
||||
expect(result[2].name).toBe('charlie');
|
||||
});
|
||||
|
||||
it('should handle null/undefined values', () => {
|
||||
const array = [
|
||||
{ id: 1, name: 'charlie' },
|
||||
{ id: 2, name: null },
|
||||
{ id: 3, name: 'alpha' }
|
||||
];
|
||||
const result = commonService.sortAscByStrKey(array, 'name');
|
||||
expect(result[0].name).toBe(null);
|
||||
expect(result[1].name).toBe('alpha');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortDescByKey', () => {
|
||||
it('should sort array descending by numeric key', () => {
|
||||
const array = [
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 3, name: 'c' },
|
||||
{ id: 2, name: 'b' }
|
||||
];
|
||||
const result = commonService.sortDescByKey(array, 'id');
|
||||
expect(result[0].id).toBe(3);
|
||||
expect(result[1].id).toBe(2);
|
||||
expect(result[2].id).toBe(1);
|
||||
});
|
||||
|
||||
it('should handle zero and undefined values', () => {
|
||||
const array = [
|
||||
{ id: 0, name: 'a' },
|
||||
{ id: undefined, name: 'b' },
|
||||
{ id: 5, name: 'c' }
|
||||
];
|
||||
const result = commonService.sortDescByKey(array, 'id');
|
||||
expect(result[0].id).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortDescByStrKey', () => {
|
||||
it('should sort array descending by string key', () => {
|
||||
const array = [
|
||||
{ id: 1, name: 'alpha' },
|
||||
{ id: 2, name: 'charlie' },
|
||||
{ id: 3, name: 'bravo' }
|
||||
];
|
||||
const result = commonService.sortDescByStrKey(array, 'name');
|
||||
expect(result[0].name).toBe('charlie');
|
||||
expect(result[1].name).toBe('bravo');
|
||||
expect(result[2].name).toBe('alpha');
|
||||
});
|
||||
});
|
||||
|
||||
describe('newestOnTop', () => {
|
||||
it('should move matching item to top of array', () => {
|
||||
const array = [
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 2, name: 'b' },
|
||||
{ id: 3, name: 'c' }
|
||||
];
|
||||
const result = commonService.newestOnTop(array, 'id', 3);
|
||||
expect(result[0].id).toBe(3);
|
||||
expect(result.length).toBe(3);
|
||||
});
|
||||
|
||||
it('should handle item already at top', () => {
|
||||
const array = [
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 2, name: 'b' }
|
||||
];
|
||||
const result = commonService.newestOnTop(array, 'id', 1);
|
||||
expect(result[0].id).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('camelCase', () => {
|
||||
it('should convert string to camel case', () => {
|
||||
expect(commonService.camelCase('hello world')).toBe('HelloWorld');
|
||||
});
|
||||
|
||||
it('should handle hyphens', () => {
|
||||
expect(commonService.camelCase('hello-world')).toBe('Hello World');
|
||||
});
|
||||
|
||||
it('should handle null/undefined', () => {
|
||||
expect(commonService.camelCase(null as any)).toBeUndefined();
|
||||
expect(commonService.camelCase(undefined as any)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('titleCase', () => {
|
||||
it('should convert string to title case', () => {
|
||||
expect(commonService.titleCase('HELLO WORLD')).toBe('Hello World ');
|
||||
});
|
||||
|
||||
it('should handle single word', () => {
|
||||
expect(commonService.titleCase('HELLO')).toBe('Hello');
|
||||
});
|
||||
|
||||
it('should handle multiline with exclamation', () => {
|
||||
const input = 'HELLO!\nWORLD';
|
||||
const result = commonService.titleCase(input);
|
||||
expect(result).toContain('Hello!');
|
||||
});
|
||||
|
||||
it('should handle multiline with period', () => {
|
||||
const input = 'HELLO.\nWORLD';
|
||||
const result = commonService.titleCase(input);
|
||||
expect(result).toContain('Hello.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleError', () => {
|
||||
it('should create error object with statusCode', () => {
|
||||
const errRes = { statusCode: 404, message: 'Not found' };
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'LND' } as SelectedNode);
|
||||
expect(result.statusCode).toBe(404);
|
||||
expect(result.message).toBe('Not found');
|
||||
});
|
||||
|
||||
it('should handle ENOENT error code', () => {
|
||||
const errRes = { code: 'ENOENT', path: '/some/path' };
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'LND' } as SelectedNode);
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toContain('No such file or directory');
|
||||
expect(result.message).toContain('/some/path');
|
||||
});
|
||||
|
||||
it('should handle ECONNREFUSED with 503 status', () => {
|
||||
const errRes = { error: { code: 'ECONNREFUSED' } };
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'LND' } as SelectedNode);
|
||||
expect(result.statusCode).toBe(503);
|
||||
});
|
||||
|
||||
it('should return sanitized error for LND without exposing macaroon', () => {
|
||||
const errRes = {
|
||||
statusCode: 500,
|
||||
options: { headers: { 'Grpc-Metadata-macaroon': 'secret' } },
|
||||
message: 'Test error'
|
||||
};
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'LND' } as SelectedNode);
|
||||
// The function should return a sanitized error object
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toBe('Test error');
|
||||
});
|
||||
|
||||
it('should return sanitized error for CLN without exposing rune', () => {
|
||||
const errRes = {
|
||||
statusCode: 500,
|
||||
options: { headers: { rune: 'secret' } },
|
||||
message: 'Test error'
|
||||
};
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'CLN' } as SelectedNode);
|
||||
// The function should return a sanitized error object
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toBe('Test error');
|
||||
});
|
||||
|
||||
it('should return sanitized error for ECL without exposing authorization', () => {
|
||||
const errRes = {
|
||||
statusCode: 500,
|
||||
options: { headers: { authorization: 'secret' } },
|
||||
message: 'Test error'
|
||||
};
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'ECL' } as SelectedNode);
|
||||
// The function should return a sanitized error object
|
||||
expect(result.statusCode).toBe(500);
|
||||
expect(result.message).toBe('Test error');
|
||||
});
|
||||
|
||||
it('should use status when statusCode is not available', () => {
|
||||
const errRes = { status: 400, message: 'Bad request' };
|
||||
const result = commonService.handleError(errRes, 'TestFile', 'Test error', { lnImplementation: 'LND' } as SelectedNode);
|
||||
expect(result.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRequestIP', () => {
|
||||
it('should get IP from x-forwarded-for header', () => {
|
||||
const req = {
|
||||
headers: { 'x-forwarded-for': '192.168.1.1, 10.0.0.1' },
|
||||
ip: '127.0.0.1',
|
||||
connection: { remoteAddress: '127.0.0.1' },
|
||||
socket: { remoteAddress: '127.0.0.1' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req);
|
||||
expect(result).toBe('192.168.1.1');
|
||||
});
|
||||
|
||||
it('should get IP from req.ip', () => {
|
||||
const req = {
|
||||
headers: {},
|
||||
ip: '10.0.0.1',
|
||||
connection: { remoteAddress: '127.0.0.1' },
|
||||
socket: { remoteAddress: '127.0.0.1' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req);
|
||||
expect(result).toBe('10.0.0.1');
|
||||
});
|
||||
|
||||
it('should get IP from connection.remoteAddress', () => {
|
||||
const req = {
|
||||
headers: {},
|
||||
ip: null,
|
||||
connection: { remoteAddress: '192.168.0.1' },
|
||||
socket: { remoteAddress: '127.0.0.1' }
|
||||
};
|
||||
const result = commonService.getRequestIP(req);
|
||||
expect(result).toBe('192.168.0.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isVersionCompatible', () => {
|
||||
it('should return true for compatible version', () => {
|
||||
const result = commonService.isVersionCompatible('v0.15.0', '0.14.0');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for exact version match', () => {
|
||||
const result = commonService.isVersionCompatible('v0.15.0', '0.15.0');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for incompatible version', () => {
|
||||
const result = commonService.isVersionCompatible('v0.14.0', '0.15.0');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for empty version', () => {
|
||||
const result = commonService.isVersionCompatible('', '0.15.0');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for null version', () => {
|
||||
const result = commonService.isVersionCompatible(null as any, '0.15.0');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle version without v prefix', () => {
|
||||
const result = commonService.isVersionCompatible('0.15.0', '0.14.0');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle major version comparison', () => {
|
||||
const result = commonService.isVersionCompatible('v1.0.0', '0.99.99');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMonthDays', () => {
|
||||
it('should return correct days for January', () => {
|
||||
const result = commonService.getMonthDays(0, 2023);
|
||||
expect(result).toBe(31);
|
||||
});
|
||||
|
||||
it('should return 28 days for February in non-leap year', () => {
|
||||
const result = commonService.getMonthDays(1, 2023);
|
||||
expect(result).toBe(28);
|
||||
});
|
||||
|
||||
it('should return 29 days for February in leap year', () => {
|
||||
const result = commonService.getMonthDays(1, 2024);
|
||||
expect(result).toBe(29);
|
||||
});
|
||||
|
||||
it('should return correct days for April', () => {
|
||||
const result = commonService.getMonthDays(3, 2023);
|
||||
expect(result).toBe(30);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findNode', () => {
|
||||
it('should find node by index', () => {
|
||||
commonService.nodes = [
|
||||
{ index: 1, lnNode: 'Node1' } as SelectedNode,
|
||||
{ index: 2, lnNode: 'Node2' } as SelectedNode
|
||||
];
|
||||
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 SelectedNode
|
||||
];
|
||||
const result = commonService.findNode(99);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('replaceNode', () => {
|
||||
it('should replace node at correct index', () => {
|
||||
commonService.nodes = [
|
||||
{ index: 1, lnNode: 'Node1' } as SelectedNode,
|
||||
{ index: 2, lnNode: 'Node2' } as SelectedNode
|
||||
];
|
||||
const req = {
|
||||
session: {
|
||||
selectedNode: { index: 1 }
|
||||
}
|
||||
};
|
||||
const newNode = { index: 1, lnNode: 'NewNode1' } as SelectedNode;
|
||||
commonService.replaceNode(req as any, newNode);
|
||||
expect(commonService.nodes[0].lnNode).toBe('NewNode1');
|
||||
});
|
||||
});
|
||||
|
||||
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 failed')),
|
||||
() => Promise.resolve(3)
|
||||
];
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, (res) => {
|
||||
expect(res[0]).toBe(1);
|
||||
expect(res[1].error).toBeDefined();
|
||||
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].error).toBeDefined();
|
||||
expect(res[2]).toBe(3);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should respect concurrency limit', async () => {
|
||||
let maxConcurrent = 0;
|
||||
let currentConcurrent = 0;
|
||||
|
||||
const tasks = Array.from({ length: 5 }, () => {
|
||||
return async () => {
|
||||
currentConcurrent++;
|
||||
maxConcurrent = Math.max(maxConcurrent, currentConcurrent);
|
||||
await new Promise(resolve => setTimeout(resolve, 10));
|
||||
currentConcurrent--;
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
commonService.runWithConcurrencyLimit(tasks, 2, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
expect(maxConcurrent).toBeLessThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
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/**/*.spec.ts'],
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['text', 'html'],
|
||||
include: ['server/**/*.ts'],
|
||||
exclude: ['server/**/*.spec.ts', 'server/models/**']
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue