Skip to content

Take-home: add full test coverage, fix core API bugs, and implement task assignment endpoint#27

Open
nikkkhil2935 wants to merge 4 commits into
rohit-ups:mainfrom
nikkkhil2935:main
Open

Take-home: add full test coverage, fix core API bugs, and implement task assignment endpoint#27
nikkkhil2935 wants to merge 4 commits into
rohit-ups:mainfrom
nikkkhil2935:main

Conversation

@nikkkhil2935
Copy link
Copy Markdown

Submission Notes

Summary

  • Added a full test suite covering service, validators, routes, and app bootstrap behavior
  • Implemented PATCH /tasks/:id/assign with payload validation, conflict handling, and idempotent repeat behavior
  • Added GET /tasks/:id for direct single-task retrieval
  • Added optional ?assignee= filtering on GET /tasks
  • Fixed multiple behavior defects discovered through test-driven development
  • Documented all findings in task-api/BUG_REPORT.md with root-cause analysis and fix rationale

Bugs Fixed

# Location Defect
1 taskService.jsgetPaginated Pagination off-by-one — page * limit skipped the first page entirely
2 taskService.jsgetByStatus Status filter used partial string match instead of exact enum equality
3 taskService.jscompleteTask Completion flow silently reset priority to medium
4 taskService.jsupdate Unrestricted object spread allowed id and createdAt to be overwritten
5 routes/tasks.js + validators.js No validation on status, page, or limit query params

Design Decisions

PATCH /tasks/:id/assign returns 409 Conflict on reassignment
The request payload is valid, but it conflicts with current ownership state. 409 is semantically correct here — it signals a state conflict, not a client input error, which distinguishes it from 400 Bad Request.

Idempotent repeat assignment returns 200 OK
Repeating the same assignee is treated as a no-op success. This keeps the operation retry-safe and consistent with REST idempotency principles — the resource state does not change, so 201 would be misleading.

Assignee filtering is case-insensitive
Clients may send Alice, alice, or ALICE depending on their input layer. Case-insensitive matching at the service boundary prevents silent filter misses without requiring callers to normalize strings.

Update uses a mutable-field allow-list
Rather than blocking specific immutable fields, the update flow only accepts an explicit set of mutable fields: title, description, status, priority, dueDate, assignee. Unknown or immutable keys (including id and createdAt) are silently ignored, protecting data integrity without throwing errors on extra fields.


Test Results

Test Suites: 4 passed, 4 total
Tests: 47 passed, 47 total
Coverage: 100% statements | 100% branches | 100% functions | 100% lines

- Updated README to reflect new query parameters for task listing and added examples for task assignment.
- Introduced a new endpoint PATCH /tasks/:id/assign to assign tasks to users, with validation and conflict handling.
- Enhanced task shape to include assignee field and updated status values for consistency.
- Implemented validation for task assignment and list query parameters to ensure robust input handling.
- Added unit and integration tests for new features, including task assignment and query validation.
- Fixed bugs related to pagination, status filtering, and task completion logic.
- Improved error handling for unknown routes and internal server errors.
- Added a bug report document detailing identified issues and their resolutions.
… logic

- Added detailed JSDoc comments throughout taskService.js to clarify purpose and behavior of functions.
- Implemented in-memory task management with functions for creating, updating, retrieving, and deleting tasks.
- Introduced pagination and filtering capabilities for task retrieval.
- Added a completion function to standardize task completion behavior.
- Enhanced assignment functionality to handle conflicts and idempotent assignments.
- Created a stats function to aggregate task status counts and overdue tasks.
- Developed a validators module to centralize input validation for task creation, updates, and queries.
- Implemented unit tests for taskService and validators to ensure contract adherence and functionality.
- Established integration tests for task routes to validate HTTP behavior and response consistency.
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