Skip to content

Submission: Task Manager API Assignment - #67

Open
teena14 wants to merge 6 commits into
rohit-ups:mainfrom
teena14:submission/tests-bugs-feature
Open

Submission: Task Manager API Assignment#67
teena14 wants to merge 6 commits into
rohit-ups:mainfrom
teena14:submission/tests-bugs-feature

Conversation

@teena14

@teena14 teena14 commented Aug 15, 2026

Copy link
Copy Markdown

Please find my submission. Details are in SUBMISSION.md and BUG_REPORT.md.

…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
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.

1 participant