Skip to content

feat: tested, fixed bugs and added new PATCH /tasks/:id/assign end point - #53

Open
redstonenight347-oss wants to merge 2 commits into
rohit-ups:mainfrom
redstonenight347-oss:main
Open

feat: tested, fixed bugs and added new PATCH /tasks/:id/assign end point#53
redstonenight347-oss wants to merge 2 commits into
rohit-ups:mainfrom
redstonenight347-oss:main

Conversation

@redstonenight347-oss

Copy link
Copy Markdown

Pull Request: Comprehensive Test Suite, Bug Fixes & PATCH /tasks/:id/assign Feature

📌 Summary of Changes

This PR delivers a comprehensive test suite (108 tests with >96% coverage), resolves critical bug fixes across the core API, and implements the PATCH /tasks/:id/assign endpoint with full validation and test coverage.


🚀 Key Improvements

1. Test Suite & Coverage (Day 1 Requirements)

  • Unit Tests (tests/taskService.test.js): 53 unit tests covering all functions in taskService.js.
  • Integration Tests (tests/tasks.test.js): 55 integration tests using supertest covering all API routes, edge cases, status validations, and failure modes.
  • Coverage Summary:
    • src/routes/tasks.js: 100%
    • src/services/taskService.js: 100% lines / 95% branch
    • src/utils/validators.js: 96.77%
    • Total Suite: 108 tests passing, 0 failing.

2. Bug Fixes (Day 2 Part A & B)

  • 🐛 Pagination Off-by-One Fix:
    • Updated getPaginated offset formula from page * limit to (page - 1) * limit. Page 1 now correctly returns items starting from index 0. Added fallback guards for negative/invalid page & limit values.
  • 🐛 Exact Status Matching Fix:
    • Replaced t.status.includes(status) substring matching with exact equality t.status === status in getByStatus.
  • 🐛 Priority Clobbering Fix on Task Completion:
    • Removed hardcoded priority: 'medium' overwrite inside completeTask, preserving the task's original priority (low/medium/high).
  • 🐛 Immutable Fields Protection in PUT:
    • Destructured and stripped protected fields (id, createdAt, completedAt) in update() so client request bodies cannot alter system-managed identifiers or timestamps.
  • 🐛 Query Parameter Validation:
    • Implemented validateGetTask in validators.js to return 400 Bad Request when filtering with an invalid status parameter (e.g., ?status=banana).

3. New Feature: PATCH /tasks/:id/assign (Day 2 Part C)

Implemented task assignment capabilities:

  • Route: PATCH /tasks/:id/assign
  • Body: { "assignee": "string" }
  • Behavior:
    • Validates assignee is a non-empty, non-whitespace string (returns 400 Bad Request otherwise).
    • Updates the task in the in-memory store and returns the full updated task object with 200 OK.
    • Returns 404 Not Found if the task ID does not exist.
    • Supports re-assigning existing tasks.
    • Updated task schema constructor to initialize assignee: null by default.

🧪 Verification & Test Results

npm run coverage
-----------------|---------|----------|---------|---------|-------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files        |   96.95 |    95.69 |   93.54 |   96.66 |
 src             |   69.23 |       75 |       0 |   69.23 |
  app.js         |   69.23 |       75 |       0 |   69.23 | 10-11,17-18
 src/routes      |     100 |      100 |     100 |     100 |
  tasks.js       |     100 |      100 |     100 |     100 |
 src/services    |     100 |       95 |     100 |     100 |
  taskService.js |     100 |       95 |     100 |     100 | 23
 src/utils       |   96.77 |    95.34 |     100 |   96.77 |
  validators.js  |   96.77 |    95.34 |     100 |   96.77 | 31
-----------------|---------|----------|---------|---------|-------------------
Test Suites: 2 passed, 2 total
Tests:       108 passed, 108 total
Snapshots:   0 total
Time:        2.939 s

📝 Notes for Submission

  • Design Decisions: assignee validation strictly checks for non-empty string types after trimming whitespace. Re-assignment is explicitly permitted.
  • Future Improvements:
    • Standardize pagination response format to return metadata (total, page, limit, totalPages).
    • Align README.md documentation status values (pending, in-progress, completed) with the active code implementation (todo, in_progress, done).

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