Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ See [ASSIGNMENT.md](./ASSIGNMENT.md) for full submission requirements. At minimu
- **Bug report** — what you found, where in the code, and why it's a bug (not just symptoms)
- **At least one fix** — with a note on your approach
- **`PATCH /tasks/:id/assign` implementation** — plus a short explanation of any design decisions (validation, edge cases, etc.)

Empty file added screenshots/tests-passed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 206 additions & 0 deletions task-api/BUG_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Bug Report – Task Manager API

**Author:** Himesh
**Date:** 2026-07-15

## Overview

While writing unit and integration tests for the Task Manager API, I identified several issues related to pagination, task filtering, and task completion. The bugs below were discovered through a combination of code review and automated testing.

---

## Summary

| Bug | Severity | Status |
| ---------------------------------------- | -------- | ------- |
| Pagination offset calculation | Critical | Fixed |
| Status filtering uses substring matching | Medium | Fixed |
| Task completion resets priority | Medium | Fixed |

---

# Bug #1 – Pagination Returns Incorrect Results

**Severity:** Critical

## Expected Behavior

Pagination should treat the `page` parameter as **1-indexed**.

Example:

```
GET /tasks?page=1&limit=5
```

should return the first five tasks.

---

## Actual Behavior

The pagination offset was calculated using:

```javascript
const offset = page * limit;
```

As a result:

| Request | Expected Items | Actual Items |
| --------------- | -------------- | ------------ |
| page=1, limit=5 | 1–5 | 6–10 |
| page=2, limit=5 | 6–10 | 11–15 |

Every paginated request skipped the first page of results.

---

## How It Was Discovered

While writing pagination tests, the first task returned for page 1 did not match the expected data. Reviewing the pagination logic revealed an incorrect offset calculation.

---

## Fix

Changed:

```javascript
const offset = page * limit;
```

to:

```javascript
const offset = (page - 1) * limit;
```

---

## Test Coverage

Verified by:

* Unit tests for `taskService.getPaginated()`
* Integration tests for `GET /tasks?page=&limit=`

---

# Bug #2 – Status Filtering Used Substring Matching

**Severity:** Medium

## Expected Behavior

Filtering tasks by status should return only tasks whose status exactly matches the requested value.

Example:

```
GET /tasks?status=todo
```

should only return tasks with status `"todo"`.

---

## Actual Behavior

The filtering logic used substring matching.

Example:

```
GET /tasks?status=do
```

incorrectly returned tasks whose status was `"done"`.

---

## How It Was Discovered

A unit test querying `"do"` unexpectedly matched `"done"` tasks. Code review showed that the implementation used `String.prototype.includes()` instead of strict equality.

---

## Fix

Changed:

```javascript
task.status.includes(status)
```

to:

```javascript
task.status === status
```

---

## Test Coverage

Verified by:

* Unit tests for `taskService.getByStatus()`
* Integration tests for `GET /tasks?status=`

---

# Bug #3 – Completing a Task Reset Priority

**Severity:** Medium

## Expected Behavior

Completing a task should only update:

* `status`
* `completedAt`

All other task properties should remain unchanged.

---

## Actual Behavior

Completing a task overwrote the existing priority, causing a task marked as `"high"` priority to become `"medium"` after completion.

This resulted in unintended modification of task data unrelated to completion.

---

## How It Was Discovered

A unit test created a high-priority task, completed it, and verified that the priority should remain unchanged. The test exposed the issue during implementation.

---

## Fix

Updated the completion logic to preserve all existing task properties and modify only:

* `status`
* `completedAt`

The original priority is now retained after task completion.

---

## Test Coverage

Verified by:

* Unit tests for `taskService.completeTask()`
* Integration tests for `PATCH /tasks/:id/complete`

---

# Conclusion

Automated testing helped uncover issues that were not immediately visible during manual inspection. These tests now serve as regression tests to ensure that the corrected behavior remains intact in future changes.

The identified issues have been documented, reproduced through automated tests, and fixed as part of this submission.
186 changes: 186 additions & 0 deletions task-api/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Task Manager API – Take-Home Assignment

## Overview

This repository contains my solution for the Task Manager API take-home assignment.

The objective of the assignment was to understand an unfamiliar codebase, write automated tests, identify bugs, fix one bug, and implement a new feature while maintaining good code quality.

---

# Completed Tasks

## Unit Tests

Added comprehensive unit tests for `taskService.js`, covering:

* Task creation
* Task retrieval
* Find by ID
* Status filtering
* Pagination
* Statistics
* Task updates
* Task deletion
* Task completion
* Task assignment
* Reset functionality

---

## Integration Tests

Added API integration tests using **Jest** and **Supertest** covering:

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

Each endpoint includes both happy-path and edge-case scenarios.

---

## Bug Investigation

During testing, multiple issues were identified and documented in **BUG_REPORT.md**.

The report includes:

* Expected behavior
* Actual behavior
* How each issue was discovered
* Suggested fix
* Fix status

---

## Bug Fixed

Fixed identified issues in the application and updated the corresponding tests to verify the corrected behavior.

---

## New Feature Added

Implemented the required endpoint:

```http
PATCH /tasks/:id/assign
```

### Request Body

```json
{
"assignee": "Alice"
}
```

### Behavior

* Assigns a user to a task
* Allows reassignment
* Returns the updated task
* Returns **404** if the task does not exist
* Validates missing, empty, whitespace-only, and invalid assignee values

---

# Test Coverage

The project includes:

* Unit tests
* Integration tests
* Validation tests
* Edge-case tests
* Regression tests for discovered bugs

Coverage summary:

```text
Paste your coverage summary here.

Example:

Test Suites: 2 passed
Tests: 79 passed

Statements : 96.81%
Branches : 94.5%
Functions : 93.33%
Lines : 95.6%
```

---

## Test Results

### All Tests Passing

![All Tests Passing](screenshots/tests-passed.png)

### Test Coverage

![Coverage Report](screenshots/coverage.png)


# Project Structure

```text
task-api/
├── src/
├── tests/
├── screenshots/
│ ├── coverage.png
│ └── tests-passed.png
├── BUG_REPORT.md
├── README.md
├── package.json
└── .gitignore
```

---

# Assumptions

* Pagination is 1-indexed.
* Tasks can be reassigned.
* Statistics are computed dynamically.
* The application uses an in-memory data store for simplicity.

---

# Additional Documentation

* **BUG_REPORT.md** – Details of the bugs identified during testing and their resolutions.

---

# Future Improvements

Given additional time, I would focus on:

* Authentication and authorization
* Persistent database storage
* Concurrency testing
* Performance and load testing
* Security-focused validation
* API documentation (OpenAPI/Swagger)
* CI/CD integration with automated test execution

---

# Author

**Himesh**

Take-Home Assignment Submission – 2026

Binary file added task-api/screenshots/coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added task-api/screenshots/tests-passed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading