Skip to content

Assignment Completed: Added Unit & Integration testing, fix pagination/priority bugs, implement task assignment endpoint - #51

Open
Adamkoda2306 wants to merge 23 commits into
rohit-ups:mainfrom
Adamkoda2306:main
Open

Assignment Completed: Added Unit & Integration testing, fix pagination/priority bugs, implement task assignment endpoint#51
Adamkoda2306 wants to merge 23 commits into
rohit-ups:mainfrom
Adamkoda2306:main

Conversation

@Adamkoda2306

Copy link
Copy Markdown

Summary

This pull request improves the reliability and maintainability of the Task Manager API by adding comprehensive automated tests, fixing identified bugs, and implementing a new task assignment feature.


Changes Made

✅ Added Unit Tests

Implemented 28 unit tests for the taskService covering:

  • Task creation
  • Retrieving all tasks
  • Finding tasks by ID
  • Filtering tasks by status
  • Updating tasks
  • Deleting tasks
  • Completing tasks
  • Pagination
  • Statistics
  • Task assignment

✅ Added Integration Tests

Implemented 32 API integration tests using Supertest for all endpoints, including the new one:

  • GET /tasks
  • GET /tasks?status=
  • GET /tasks?page=&limit=
  • POST /tasks
  • PUT /tasks/:id
  • DELETE /tasks/:id
  • PATCH /tasks/:id/complete
  • PATCH /tasks/:id/assign
  • GET /tasks/stats

The tests cover both successful requests and common error scenarios such as invalid input and missing resources.

✅ Bug Fixes

Pagination Bug

  • Fixed incorrect pagination offset calculation.
  • Updated the offset formula from page * limit to (page - 1) * limit so the first page returns the correct records.

Task Completion Bug

  • Fixed an issue where completing a task unintentionally reset its priority to "medium".
  • Task completion now updates only the task status and completion timestamp while preserving the existing priority.

✅ New Feature

Implemented a new endpoint:

PATCH /tasks/:id/assign

Features include:

  • Assigns an assignee to an existing task.
  • Returns the updated task.
  • Returns 404 Not Found if the task does not exist.
  • Returns 400 Bad Request for invalid or empty assignee values.
  • Added both unit and integration tests for the new endpoint.

Test Coverage

Coverage results:

Metric Coverage
Statements 94.8%
Branches 90.8%
Functions 93.33%
Lines 94.28%

A total of 60 automated tests have been added (28 unit, 32 integration), all of which are passing.


Testing

Executed:

npm test
npm run coverage

Result:

  • ✅ 60/60 tests passing
  • ✅ All endpoints verified
  • ✅ New feature fully tested
  • ✅ Existing bugs identified and resolved

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