Skip to content

Add expanded backend test suite for issue #335 - #338

Open
Mansi2007275 wants to merge 5 commits into
openmainframeproject:masterfrom
Mansi2007275:feature/backend-test-suite-335
Open

Mansi2007275 wants to merge 5 commits into
openmainframeproject:masterfrom
Mansi2007275:feature/backend-test-suite-335

Conversation

@Mansi2007275

Copy link
Copy Markdown
Contributor

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.js with 2 tests, and one of those was outdated (it expected Fedora 40, which no longer exists in distros.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

  • Moved helper logic into backend/utils.js:
    • buildDistroBitMap
    • getTables
    • stringifyBigInts
  • Moved Express route logic into backend/app.js using createApp(pool)
  • Kept backend/index.js as the server entry point that connects to the real MySQL pool
  • This allows tests to run without a live database by injecting a mock pool

2. Added unit tests

  • Created backend/tests/utils.test.js
  • Covers bitmask generation, table selection, and BigInt serialization

3. Added integration tests for major routes

backend/tests/getSupportedDistros.test.js

  • Tests /getSupportedDistros
  • Tests legacy route /sdt/getSupportedDistros
  • Verifies response data and cache headers

backend/tests/searchPackages.test.js

  • Tests /searchPackages
  • Tests legacy route /sdt/searchPackages
  • Covers:
    • missing/blank search term
    • invalid page_number
    • invalid limit
    • invalid search_bit_flag
    • no matching distros for a bitmask
    • successful mocked DB search response
    • database failure returning 500

4. Added mock database support

  • Added backend/tests/helpers/mockPool.js to simulate MySQL query results and failures

5. Improved test setup

  • Added backend/jest.config.js
  • Added backend/tests/setup.js to set NODE_ENV=test
  • Updated npm test to work cross-platform (Windows + Linux CI)

6. Added CI integration

  • Added .github/workflows/backend-tests.yml
  • Backend tests now run automatically on PRs that change backend code

Acceptance criteria covered

  • Testing framework (Jest) already present and used in backend tests
  • At least one test file per major route
  • npm test script works for backend tests
  • CI runs backend tests on PRs
  • Error handling and invalid input cases included
  • Mock DB setup added for DB-dependent route tests

How to verify

cd backend
npm install
npm test

Closes #335

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 vmuralictr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Mansi2007275 added a commit to Mansi2007275/software-discovery-tool that referenced this pull request Sep 21, 2026

@vmuralictr vmuralictr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Mansi2007275

Copy link
Copy Markdown
Contributor Author

please check @vmuralictr

@Mansi2007275

Copy link
Copy Markdown
Contributor Author

@vmuralictr please check now ...

@vmuralictr

Copy link
Copy Markdown
Collaborator

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>
@Mansi2007275
Mansi2007275 force-pushed the feature/backend-test-suite-335 branch from 341c06d to 4225a74 Compare September 23, 2026 13:20
@Mansi2007275

Copy link
Copy Markdown
Contributor Author

@vmuralictr please review this ......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add test suite for backend

2 participants