Skip to content

Add Jest coverage for donors API and model - #1

Draft
Shrichackran with Copilot wants to merge 1 commit into
mainfrom
copilot/analyze-test-coverage
Draft

Add Jest coverage for donors API and model#1
Shrichackran with Copilot wants to merge 1 commit into
mainfrom
copilot/analyze-test-coverage

Conversation

Copilot AI commented Apr 28, 2026

Copy link
Copy Markdown

Test coverage was missing for the donors API and its database query logic, leaving core matching behavior unverified. This adds focused tests around request validation, error handling, and query construction.

  • Test scaffolding
    • Introduced Jest + Supertest configuration and test script
  • HTTP/controller coverage
    • Added /donors route tests for missing params, success, and model errors
  • Model query coverage
    • Added unit test to assert SQL shape and parameter binding

Example (route error handling):

const response = await request(app)
  .get("/donors")
  .query({ bloodGroup: "O+" });

expect(response.status).toBe(400);
expect(response.body).toEqual({ message: "Missing parameters" });

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds Jest-based test coverage for the donors API endpoint and the donor model’s query construction, enabling safer refactors of core donor-matching behavior.

Changes:

  • Add Jest + Supertest dev dependencies and npm test script/config.
  • Refactor app.js to be importable in tests (only listen when run as main).
  • Add route-level tests for /donors validation/success/error paths and a unit test for model SQL + parameter binding.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
package.json Adds Jest/Supertest and Jest config; introduces npm test.
package-lock.json Locks new dev dependencies required for tests.
app.js Exports Express app and guards listen() for testability.
tests/donorRoutes.test.js Adds Supertest coverage for /donors request handling.
tests/donorModel.test.js Adds unit test asserting SQL shape and bound params for getDonors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


expect(donorModel.getDonors).toHaveBeenCalledWith("A+", "Chennai", expect.any(Function));
expect(response.status).toBe(500);
expect(response.body).toEqual(error);
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.

3 participants