Skip to content

Improve unit test coverage to 96% (from 87%)#757

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1778662953-improve-unit-test-coverage
Open

Improve unit test coverage to 96% (from 87%)#757
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1778662953-improve-unit-test-coverage

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented May 13, 2026

Summary

Improved backend unit test coverage from 87.33% → 96.28% line coverage (target was ≥85%). All 171 tests pass.

Key changes:

  • reports.js (64% → 94%): Added PDF export success path tests covering generation with work entries, empty entries, null descriptions, separator lines every 5 entries, and page breaks when y > 700. Fixed PDFDocument mock to properly end the response stream via pipe/end.
  • clients.js (89% → 98%): Added tests for DELETE /api/clients (delete all) route including success, zero-count, and error cases. Added parameterized tests for updating department and email fields.
  • Code quality: Extracted shared helpers (setupDb, setupClientWithEntries, requestPdf, mockCreatePdfDoc) and used describe.each/test.each to minimize duplication.

Coverage Summary

File Before After
All files 87.33% 96.28%
reports.js 64.42% 94.23%
clients.js 88.88% 98.14%
workEntries.js 98.41% 98.41%
middleware 100% 100%
validation 100% 100%

Review & Testing Checklist for Human

  • Run cd backend && npm test -- --coverage to verify all 171 tests pass and coverage ≥85%
  • Verify the new PDF mock pattern (pipe/end with stream forwarding) doesn't break existing PDF tests

Notes

  • The remaining uncovered lines in reports.js (127-134) are the CSV file download + cleanup path (res.download callback), which requires real filesystem access incompatible with the globally mocked fs module used by the test suite.
  • database/init.js remains at 85.71% — the uncovered lines (91-97, 102-103) are the isClosing concurrency guard and the no-db-connection path in closeDatabase.

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/bbec873172d64916bf698c03eb27c5cc


Open in Devin Review

- Add PDF export success path tests (generation, empty entries, null
  description, separator lines, page breaks)
- Fix PDFDocument mock to properly end response stream
- Add DELETE all clients route tests
- Add client update tests for department and email fields
- All 171 tests pass with 96.28% line coverage
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

- Extract helper functions (mockClientFound, mockClientWithEntries,
  mockCsvWriterRejected, getLastPdfInstance) to eliminate repeated
  mock setup patterns in reports tests
- Use test.each for parameterized client update field tests
- Reduces code duplication to satisfy SonarCloud quality gate
- Extract setupDb, setupClientWithEntries, requestPdf helpers
- Use describe.each to consolidate CSV/PDF error handling tests
- Use test.each for hours calculation and temp dir tests
- Extract createPdfMock factory to eliminate page-break mock duplication
- Use shared constants (TEST_CLIENT, SAMPLE_ENTRY, INTERNAL_ERROR)
@sonarqubecloud
Copy link
Copy Markdown

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.

0 participants