Submission: Task Manager API Assignment - #67
Open
teena14 wants to merge 6 commits into
Open
Conversation
…ss (Part B) Part A: BUG_REPORT.md documents 7 bugs found via TDD BUG-1 taskService.getPaginated - off-by-one offset (page*limit) BUG-2 taskService.getByStatus - String.includes() instead of === BUG-3 taskService.completeTask - hard-coded priority:'medium' overwrite BUG-4 GET /tasks?status= - no validation of query param BUG-5 PUT /tasks/:id - immutable fields (id,createdAt) overwriteable BUG-6 GET /tasks combined - status filter short-circuits pagination BUG-7 validators.js - falsy guard lets empty-string bypass enum check Part B: Fix BUG-7 validators.js: replace �ody.status && with �ody.status !== undefined && in both validateCreateTask and validateUpdateTask (4 guards total) Adds 11 regression tests across taskService.test.js and routes.test.js 85 tests passing, 0 failing
Service (taskService.js):
- create(): add assignee: null to task shape so every task carries
the field from birth (no undefined, clean GET /tasks output)
- assignTask(id, assignee): updates only the assignee field and
returns the task, or null if the id is not found
Validator (validators.js):
- validateAssignee(body): three-gate check:
1. assignee missing/null → 400 'assignee is required'
2. assignee not a string → 400 'assignee must be a string'
3. assignee empty after trim() → 400 'assignee must be a non-empty string'
Route (routes/tasks.js):
- PATCH /:id/assign: validate → assign → 404-guard → 200
- stores assignee.trim() so leading/trailing whitespace is normalised
Design decisions:
- Re-assignment is ALLOWED (200, overwrites): ownership transfers are
a normal workflow; blocking would require a separate unassign endpoint
- Completed tasks CAN be assigned (for audit trail)
- assignee field is NOT stripped by IMMUTABLE_FIELDS guard on PUT
Tests added (18 new, 103 total):
- 7 unit tests for assignTask (taskService.test.js)
- 11 integration tests for PATCH /tasks/:id/assign (routes.test.js)
including ⚠️ FM-1 missing field, FM-2 empty string, FM-3 non-string
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.
Please find my submission. Details are in SUBMISSION.md and BUG_REPORT.md.