Add missing Jest unit tests for backend API routes and service layer#483
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Add missing Jest unit tests for backend API routes and service layer#483devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
- Add 13 new tests for routes/reports.js: PDF generation (pipe/end, empty entries, page breaks, separator lines, null descriptions, response headers) and CSV export (writeRecords, error paths) - Add 10 new tests for routes/clients.js: bulk delete, department/email field updates, unexpected error handling - Add 3 new tests for database/init.js: closeDatabase edge cases (no-db, already closed, concurrent close) - Add 2 new tests for routes/workEntries.js: unexpected error handling for create and update Coverage improved from 87% to 98.69% statements overall. Per-file coverage: clients.js 100%, workEntries.js 100%, auth.js 100%, init.js 100%, reports.js 94.33%
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:
|
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
Adds 28 new Jest unit tests across 4 test files to improve backend test coverage from ~87% to ~98.7% statements. No production code changes.
New tests by file:
reports.test.js(+8 tests): PDF export success path — generation with entries, empty entries, page break wheny > 700, separator lines every 5 entries, null description fallback, response headers. CSV export writer configuration verification.clients.test.js(+10 tests): BulkDELETE /api/clients, department/email field updates (including empty-string-to-null coercion), unexpected error handling in POST/PUT try-catch blocks.database/init.test.js(+3 tests):closeDatabaseedge cases — no existing connection, already-closed state, concurrent close calls (isClosing race condition).workEntries.test.js(+2 tests): Unexpected error handling in POST/PUT try-catch blocks.Remaining uncovered lines:
reports.js:127-134(theres.downloadcallback +fs.unlinkcleanup). This path cannot be reliably tested via supertest becausejest.mock('fs')interferes with Express's internalres.download/sendFileimplementation, causing the response to hang.Review & Testing Checklist for Human
capturedRespattern wherepipecaptures the Express response andendcallscapturedRes.end()to unblock supertest. Verify this exercises the actual PDF generation code paths (lines 187-240 ofreports.js) and not just the mock wiring.writeRecordsto avoid theres.downloadhang, so it validates csvWriter configuration but doesn't cover the download callback (lines 127-134). Verify the test name/comments are not misleading.closeDatabaseconcurrent close test: Confirm the deferred-callback pattern (closeCallbackstored then resolved later) actually exercises theisClosingbranch indatabase/init.jsrather than just theisClosedearly return.cd backend && npm run test:coveragelocally and confirm 182 tests pass with 0 failures and coverage thresholds are met.Notes
clients.test.jsusecallback.call(this, null)withthis.changesto mimic sqlite3's callback context — worth a glance to confirm this matches the actual sqlite3 behavior the route depends on.Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/81daa0376237441192fea8e5830fddf3
Requested by: @VedantKh