Improve unit test coverage to 96% (from 87%)#757
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
Improve unit test coverage to 96% (from 87%)#757devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
- 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
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- 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)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Improved backend unit test coverage from 87.33% → 96.28% line coverage (target was ≥85%). All 171 tests pass.
Key changes:
pipe/end.DELETE /api/clients(delete all) route including success, zero-count, and error cases. Added parameterized tests for updatingdepartmentandemailfields.setupDb,setupClientWithEntries,requestPdf,mockCreatePdfDoc) and useddescribe.each/test.eachto minimize duplication.Coverage Summary
Review & Testing Checklist for Human
cd backend && npm test -- --coverageto verify all 171 tests pass and coverage ≥85%pipe/endwith stream forwarding) doesn't break existing PDF testsNotes
reports.js(127-134) are the CSV file download + cleanup path (res.downloadcallback), which requires real filesystem access incompatible with the globally mockedfsmodule used by the test suite.database/init.jsremains at 85.71% — the uncovered lines (91-97, 102-103) are theisClosingconcurrency guard and the no-db-connection path incloseDatabase.Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/bbec873172d64916bf698c03eb27c5cc