-
Notifications
You must be signed in to change notification settings - Fork 118
My solution #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ravishyamsingh
wants to merge
2
commits into
rohit-ups:main
Choose a base branch
from
Ravishyamsingh:my-solution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
My solution #34
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Day 1 Test and Coverage Summary | ||
|
|
||
| - Command run: npm run coverage | ||
| - Test suites: 2 failed, 2 total | ||
| - Tests: 4 failed, 28 passed, 32 total | ||
|
|
||
| ## Coverage | ||
|
|
||
| - Statements: 94.77% | ||
| - Branches: 89.33% | ||
| - Functions: 92.3% | ||
| - Lines: 94.26% | ||
|
|
||
| ## Bugs Found by Tests | ||
|
|
||
| 1. Status filter bug: partial value like do matches tasks due to substring logic. | ||
| 2. Pagination bug: page 1 starts at wrong offset and skips first items. | ||
|
|
||
|  | ||
|  | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||
| # Day 2 | ||||||
|
|
||||||
| ## Bug Fix (Part B) | ||||||
|
|
||||||
| Primary bug fixed: pagination offset. | ||||||
|
|
||||||
| - Expected: `page=1&limit=2` should return the first two tasks. | ||||||
| - Fix: changed offset to `(page - 1) * limit` and guarded invalid page/limit values. | ||||||
|
|
||||||
| Additional fix applied: status filtering now uses exact match instead of substring match. | ||||||
|
|
||||||
| ## Assign Endpoint (Part C) | ||||||
|
|
||||||
| Added endpoint: `PATCH /tasks/:id/assign` | ||||||
|
|
||||||
| ### Behavior | ||||||
|
|
||||||
| - Stores assignee on task as `assignee`. | ||||||
| - Returns updated task with `200` when assignment succeeds. | ||||||
| - Returns `404` when task is not found. | ||||||
|
|
||||||
| ### Validation Decisions | ||||||
|
|
||||||
| 1. Empty or missing assignee | ||||||
| - Returns `400` with `assignee is required and must be a non-empty string`. | ||||||
|
|
||||||
| 2. Already assigned task | ||||||
| - Returns `409` with `Task is already assigned`. | ||||||
| - Rationale: prevents accidental overwrite of ownership. | ||||||
|
|
||||||
| 3. Normalization | ||||||
| - Assignee is stored as trimmed text (`assignee.trim()`). | ||||||
|
|
||||||
|  | ||||||
|
||||||
|  | |
| Screenshot omitted from the repository to avoid embedding a local binary asset in source control; attach or link it as an external artifact if needed. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| const app = require('../src/app'); | ||
|
|
||
| module.exports = app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| const taskService = require('../src/services/taskService'); | ||
|
|
||
| describe('taskService unit tests', () => { | ||
| beforeEach(() => { | ||
| taskService._reset(); | ||
| }); | ||
|
|
||
| test('create should persist a task with defaults', () => { | ||
| const task = taskService.create({ title: 'Write tests' }); | ||
|
|
||
| expect(task.id).toEqual(expect.any(String)); | ||
| expect(task.title).toBe('Write tests'); | ||
| expect(task.description).toBe(''); | ||
| expect(task.status).toBe('todo'); | ||
| expect(task.priority).toBe('medium'); | ||
| expect(task.dueDate).toBeNull(); | ||
| expect(task.completedAt).toBeNull(); | ||
| expect(task.createdAt).toEqual(expect.any(String)); | ||
| expect(taskService.getAll()).toHaveLength(1); | ||
| }); | ||
|
|
||
| test('create should persist provided fields', () => { | ||
| const dueDate = new Date(Date.now() + 3600000).toISOString(); | ||
| const task = taskService.create({ | ||
| title: 'High priority work', | ||
| description: 'Do this now', | ||
| status: 'in_progress', | ||
| priority: 'high', | ||
| dueDate, | ||
| }); | ||
|
|
||
| expect(task.description).toBe('Do this now'); | ||
| expect(task.status).toBe('in_progress'); | ||
| expect(task.priority).toBe('high'); | ||
| expect(task.dueDate).toBe(dueDate); | ||
| }); | ||
|
|
||
| test('getAll should return a copy of task list', () => { | ||
| taskService.create({ title: 'Original' }); | ||
|
|
||
| const snapshot = taskService.getAll(); | ||
| snapshot.push({ id: 'fake' }); | ||
|
|
||
| expect(taskService.getAll()).toHaveLength(1); | ||
| }); | ||
|
|
||
| test('findById should return matching task and undefined for unknown id', () => { | ||
| const created = taskService.create({ title: 'Lookup' }); | ||
|
|
||
| expect(taskService.findById(created.id)).toMatchObject({ title: 'Lookup' }); | ||
| expect(taskService.findById('missing-id')).toBeUndefined(); | ||
| }); | ||
|
|
||
| test('getByStatus should return only exact status matches', () => { | ||
| taskService.create({ title: 'Todo item', status: 'todo' }); | ||
| taskService.create({ title: 'Done item', status: 'done' }); | ||
|
|
||
| const result = taskService.getByStatus('todo'); | ||
|
|
||
| expect(result).toHaveLength(1); | ||
| expect(result[0].title).toBe('Todo item'); | ||
| }); | ||
|
|
||
| test('getByStatus should not treat partial status as a valid match', () => { | ||
| taskService.create({ title: 'Todo item', status: 'todo' }); | ||
| taskService.create({ title: 'Done item', status: 'done' }); | ||
|
|
||
| expect(taskService.getByStatus('do')).toEqual([]); | ||
| }); | ||
|
|
||
| test('getPaginated should use 1-based page numbers', () => { | ||
| for (let i = 1; i <= 5; i++) { | ||
| taskService.create({ title: `Task ${i}` }); | ||
| } | ||
|
|
||
| const pageOne = taskService.getPaginated(1, 2).map((task) => task.title); | ||
| const pageThree = taskService.getPaginated(3, 2).map((task) => task.title); | ||
|
|
||
| expect(pageOne).toEqual(['Task 1', 'Task 2']); | ||
| expect(pageThree).toEqual(['Task 5']); | ||
| }); | ||
|
|
||
| test('getStats should include status counts and overdue count', () => { | ||
| const past = new Date(Date.now() - 86400000).toISOString(); | ||
| const future = new Date(Date.now() + 86400000).toISOString(); | ||
|
|
||
| taskService.create({ title: 'A', status: 'todo', dueDate: past }); | ||
| taskService.create({ title: 'B', status: 'in_progress', dueDate: future }); | ||
| taskService.create({ title: 'C', status: 'done', dueDate: past }); | ||
|
|
||
| expect(taskService.getStats()).toEqual({ | ||
| todo: 1, | ||
| in_progress: 1, | ||
| done: 1, | ||
| overdue: 1, | ||
| }); | ||
| }); | ||
|
|
||
| test('update should patch an existing task and return null for unknown id', () => { | ||
| const created = taskService.create({ title: 'Before', priority: 'low' }); | ||
|
|
||
| const updated = taskService.update(created.id, { | ||
| title: 'After', | ||
| priority: 'high', | ||
| status: 'in_progress', | ||
| }); | ||
|
|
||
| expect(updated).toMatchObject({ | ||
| id: created.id, | ||
| title: 'After', | ||
| priority: 'high', | ||
| status: 'in_progress', | ||
| }); | ||
| expect(taskService.update('missing-id', { title: 'Nope' })).toBeNull(); | ||
| }); | ||
|
|
||
| test('remove should delete existing task and return false for unknown id', () => { | ||
| const created = taskService.create({ title: 'Delete me' }); | ||
|
|
||
| expect(taskService.remove(created.id)).toBe(true); | ||
| expect(taskService.findById(created.id)).toBeUndefined(); | ||
| expect(taskService.remove('missing-id')).toBe(false); | ||
| }); | ||
|
|
||
| test('completeTask should mark task done and set completedAt timestamp', () => { | ||
| const created = taskService.create({ title: 'Finish me', status: 'todo' }); | ||
|
|
||
| const completed = taskService.completeTask(created.id); | ||
|
|
||
| expect(completed).toMatchObject({ | ||
| id: created.id, | ||
| status: 'done', | ||
| }); | ||
| expect(completed.completedAt).toEqual(expect.any(String)); | ||
| expect(taskService.completeTask('missing-id')).toBeNull(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DAY1_SUMMARY.md currently documents a
npm run coveragerun with failing test suites/tests. If this file is meant to reflect the current state of the PR, please update it to match the current (passing) results or clearly label it as an historical snapshot to avoid confusing readers/CI triage.