Skip to content

Add tests (97% coverage), fix pagination bug, document 5 remaining bugs, implement /assign endpointFeature/tests bugfix assign - #68

Open
tusharsach16 wants to merge 9 commits into
rohit-ups:mainfrom
tusharsach16:feature/tests-bugfix-assign
Open

Add tests (97% coverage), fix pagination bug, document 5 remaining bugs, implement /assign endpointFeature/tests bugfix assign#68
tusharsach16 wants to merge 9 commits into
rohit-ups:mainfrom
tusharsach16:feature/tests-bugfix-assign

Conversation

@tusharsach16

Copy link
Copy Markdown

Summary

Added unit and integration tests for the Task Manager API, identified and documented 6 bugs, fixed one, and implemented the PATCH /tasks/:id/assign endpoint.

Tests

  • 63 tests across 2 test files (29 unit, 34 integration)
  • 97.4% statement coverage, 95.3% branch coverage
  • Unit tests cover every exported function in taskService.js directly
  • Integration tests hit all 7 endpoints via Supertest, including validation edge cases
  • Tests that demonstrate unfixed bugs assert the current (buggy) behavior and are annotated with comments explaining the issue

Bug Fixed

Pagination off-by-one (taskService.js:12): getPaginated calculated the offset as page * limit instead of (page - 1) * limit, causing page 1 to skip all its results. One-line fix.

Bugs Documented (BUGS.md)

5 additional bugs identified and documented with expected/actual behavior, root cause, and proposed fix:

  1. getByStatus uses .includes() instead of === — partial strings like "do" match both "todo" and "done"
  2. completeTask() hardcodes priority: 'medium', overwriting the task's original priority
  3. Validators use truthiness checks (if (body.status)) — empty string "" bypasses enum validation
  4. GET /tasks has mutually exclusive branches for status filtering and pagination — combining both ignores pagination
  5. update() spreads all client fields without stripping id or createdAt — a PUT request can overwrite internal metadata

New Endpoint

PATCH /tasks/:id/assign — assigns a user to a task.

  • Body: { "assignee": "string" } (required, non-empty)
  • Returns the full updated task object (200)
  • 404 if task doesn't exist, 400 if assignee is missing/empty/non-string
  • Reassignment is allowed (overwrites previous assignee)
  • Does not change task status
  • Validation in validateAssignTask(), consistent with existing validator pattern
  • assignee: null added to create() for consistent task shape

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