changes#31
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a Jest/Supertest test suite for the Task API, fixes multiple bugs discovered via testing, and implements the new PATCH /tasks/:id/assign feature with validation and documentation notes.
Changes:
- Added unit tests for
taskServiceand integration tests for/tasksendpoints (including the new assign endpoint). - Fixed status filtering to match exact statuses and prevented
completeTaskfrom overwriting priority. - Added
PATCH /tasks/:id/assignwith request validation, and adjusted pagination parsing to allowpage=0.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| task-api/tests/tasks.api.test.js | Adds API integration coverage for stats/list/create/update/delete/complete/assign. |
| task-api/tests/taskService.test.js | Adds unit coverage and regression tests for previously buggy service behaviors. |
| task-api/src/utils/validators.js | Adds validateAssignTask and exports it for route usage. |
| task-api/src/services/taskService.js | Fixes getByStatus exact matching, removes priority override in completeTask, adds assignTask. |
| task-api/src/routes/tasks.js | Fixes page=0 parsing issue and adds the /assign route handler. |
| SUBMISSION.md | Adds coverage summary, bug fix summary, and design notes for the assign endpoint. |
| BUG_REPORT.md | Documents the three discovered bugs and their fixes. |
| .claude/settings.json | Adds Claude tooling permission configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const validateAssignTask = (body) => { | ||
| if (!body.assignee || typeof body.assignee !== 'string' || body.assignee.trim() === '') { | ||
| return 'assignee is required and must be a non-empty string'; | ||
| } | ||
| return null; |
There was a problem hiding this comment.
validateAssignTask assumes body is a non-null object and will throw if it’s called with undefined/null (e.g., when the request has no JSON body or a non-JSON Content-Type, req.body can be undefined). Consider defensively handling a falsy body (treat as {}) and returning a 400 validation message instead of letting the request fall into the 500 error handler.
| const parsedPage = parseInt(page); | ||
| const pageNum = isNaN(parsedPage) ? 1 : parsedPage; | ||
| const parsedLimit = parseInt(limit); | ||
| const limitNum = isNaN(parsedLimit) ? 10 : parsedLimit; |
There was a problem hiding this comment.
Pagination defaults look inconsistent with the (now-supported) page=0 / zero-based paging model: when limit is provided without page (e.g. /tasks?limit=2), parsedPage becomes NaN and pageNum defaults to 1, which skips the first page (offset = page * limit). Consider defaulting pageNum to 0 when page is missing, or (if the API is intended to be 1-based) adjusting the service call to use (pageNum - 1) when computing the offset. Also consider rejecting negative page/limit values to avoid Array.slice's surprising behavior with negatives.
| const parsedPage = parseInt(page); | |
| const pageNum = isNaN(parsedPage) ? 1 : parsedPage; | |
| const parsedLimit = parseInt(limit); | |
| const limitNum = isNaN(parsedLimit) ? 10 : parsedLimit; | |
| const parsedPage = page === undefined ? 0 : parseInt(page, 10); | |
| const parsedLimit = limit === undefined ? 10 : parseInt(limit, 10); | |
| if (Number.isNaN(parsedPage) || parsedPage < 0) { | |
| return res.status(400).json({ error: 'page must be a non-negative integer' }); | |
| } | |
| if (Number.isNaN(parsedLimit) || parsedLimit < 0) { | |
| return res.status(400).json({ error: 'limit must be a non-negative integer' }); | |
| } | |
| const pageNum = parsedPage; | |
| const limitNum = parsedLimit; |
| tasks.js | 100.00 | 91.66 | 100.00 | 100.00 | 21-23 | ||
| src/services | 100.00 | 94.73 | 100.00 | 100.00 | | ||
| taskService.js | 100.00 | 94.73 | 100.00 | 100.00 | 22 |
There was a problem hiding this comment.
The pasted coverage table appears internally inconsistent: it reports tasks.js (and taskService.js) at 100% lines/statements while also listing uncovered line numbers (e.g. tasks.js | ... | 21-23). If these line numbers are truly uncovered, the percentages should be <100; otherwise the uncovered-line column should be empty. Please re-run npm run coverage and update this snippet so the numbers match the actual output.
| tasks.js | 100.00 | 91.66 | 100.00 | 100.00 | 21-23 | |
| src/services | 100.00 | 94.73 | 100.00 | 100.00 | | |
| taskService.js | 100.00 | 94.73 | 100.00 | 100.00 | 22 | |
| tasks.js | 100.00 | 91.66 | 100.00 | 100.00 | | |
| src/services | 100.00 | 94.73 | 100.00 | 100.00 | | |
| taskService.js | 100.00 | 94.73 | 100.00 | 100.00 | |
No description provided.