Add expanded backend test suite for issue #335 - #338
Mansi2007275 wants to merge 5 commits into
Conversation
Refactor the Express app for testability, add unit and integration tests with mocked database queries, and run backend tests in CI on pull requests. Signed-off-by: Mansi2007275 <yadavmansi0111207@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
vmuralictr
left a comment
There was a problem hiding this comment.
Thanks for the test suite — the createApp(pool) factory pattern is exactly the right approach for testability, and the utils.js extraction looks clean.
Three things to address before merging:
- Swagger regression: app.js sets apis: ['./app.js'] but no @Swagger JSDoc comments were added there — they're being deleted from index.js. After merging, /api-docs will serve an empty spec. Please move the JSDoc annotations from index.js into app.js.
- Node.js version: CI uses node-version: '20' but the project requires Node 22 (see Installation.md). Please update to '22'.
- Deprecated CI actions: actions/checkout@v4 and actions/setup-node@v4 should be @v5 — master already has this update from #337.
…JSDoc, Node 22, action versions)
vmuralictr
left a comment
There was a problem hiding this comment.
CI is failing because package-lock.json has duplicate dependency entries at line 2327 (unresolved merge conflict). Please fix by running cd backend && rm package-lock.json && npm install and recommitting with --signoff (which will also fix the DCO failure). Tests pass locally once that's done.
|
please check @vmuralictr |
|
@vmuralictr please check now ... |
|
Tests are passing now — great fix! But the DCO check is still failing. Please rebase with --signoff on your recent commits: git rebase --signoff HEAD~2 && git push --force |
…JSDoc, Node 22, action versions) Signed-off-by: Mansi2007275 <yadavmansi0111207@gmail.com>
Signed-off-by: Mansi2007275 <yadavmansi0111207@gmail.com>
Signed-off-by: Mansi2007275 <yadavmansi0111207@gmail.com>
Signed-off-by: Mansi2007275 <yadavmansi0111207@gmail.com>
341c06d to
4225a74
Compare
|
@vmuralictr please review this ...... |
Problem
Issue #335 reported that the Node/Express backend had almost no test coverage after the Flask-to-Node migration. The existing setup only had a basic
backend/tests/api.test.jswith 2 tests, and one of those was outdated (it expectedFedora 40, which no longer exists indistros.json). Without proper tests, changes to API routes, database queries, or helper logic could introduce regressions without being caught early.What I solved
This PR addresses #335 by expanding the backend test suite and making the backend easier to test.
1. Made the backend testable
backend/utils.js:buildDistroBitMapgetTablesstringifyBigIntsbackend/app.jsusingcreateApp(pool)backend/index.jsas the server entry point that connects to the real MySQL pool2. Added unit tests
backend/tests/utils.test.js3. Added integration tests for major routes
backend/tests/getSupportedDistros.test.js/getSupportedDistros/sdt/getSupportedDistrosbackend/tests/searchPackages.test.js/searchPackages/sdt/searchPackagespage_numberlimitsearch_bit_flag4. Added mock database support
backend/tests/helpers/mockPool.jsto simulate MySQL query results and failures5. Improved test setup
backend/jest.config.jsbackend/tests/setup.jsto setNODE_ENV=testnpm testto work cross-platform (Windows + Linux CI)6. Added CI integration
.github/workflows/backend-tests.ymlAcceptance criteria covered
npm testscript works for backend testsHow to verify
Closes #335