Feature/add api endpoint - #2
Merged
Merged
Conversation
lorisnve
approved these changes
Jun 22, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a Tasks REST API to the TaskFlow API Express app, along with Jest/Supertest coverage and some healthcheck enhancements.
Changes:
- Added
/api/tasksCRUD endpoints (list/create/get/update/delete) backed by the existing MongooseTaskmodel. - Updated
/healthto return a structured payload includingstatus,uptime, andversion. - Added unit + integration tests and updated tooling/config (Jest timeout, Supertest, mongodb-memory-server, ESLint rules).
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/tasks.test.js | Adds Supertest-based unit tests for basic tasks route validation and list behavior. |
| tests/unit/health.test.js | Adds unit test asserting the new health payload shape. |
| tests/integration/tasks.integration.test.js | Adds an integration test using mongodb-memory-server to verify create + fetch-by-id flows. |
| src/routes/tasks.js | Implements /api/tasks CRUD routes with basic validation and Mongoose operations. |
| src/routes/health.js | Changes health response schema and includes app version/uptime. |
| src/index.js | Mounts the new /api/tasks router. |
| package.json | Adds Jest config and dev deps for integration testing (supertest, mongodb-memory-server). |
| package-lock.json | Locks in new test dependencies (including node engine constraints). |
| .eslintrc.json | Tightens lint rules (no-var, prefer-const, eqeqeq). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+13
| const tasks = await Task.find().sort({ createdAt: -1 }); | ||
| res.status(200).json(tasks); | ||
| } catch (err) { | ||
| res.status(500).json({ error: err.message }); | ||
| } |
Comment on lines
+31
to
+36
| } catch (err) { | ||
| if (err.name === 'ValidationError') { | ||
| return res.status(400).json({ error: err.message }); | ||
| } | ||
| return res.status(500).json({ error: err.message }); | ||
| } |
Comment on lines
+18
to
+28
| const { title, description, status } = req.body || {}; | ||
|
|
||
| if (typeof title !== 'string' || title.trim() === '') { | ||
| return res.status(400).json({ error: 'title is required' }); | ||
| } | ||
|
|
||
| const task = await Task.create({ | ||
| title: title.trim(), | ||
| ...(description !== undefined && { description }), | ||
| ...(status !== undefined && { status }), | ||
| }); |
Comment on lines
+51
to
+54
| return res.status(200).json(task); | ||
| } catch (err) { | ||
| return res.status(500).json({ error: err.message }); | ||
| } |
Comment on lines
+89
to
+94
| } catch (err) { | ||
| if (err.name === 'ValidationError') { | ||
| return res.status(400).json({ error: err.message }); | ||
| } | ||
| return res.status(500).json({ error: err.message }); | ||
| } |
Comment on lines
+72
to
+73
| if (description !== undefined) update.description = description; | ||
| if (status !== undefined) update.status = status; |
Comment on lines
+109
to
+112
| return res.status(204).send(); | ||
| } catch (err) { | ||
| return res.status(500).json({ error: err.message }); | ||
| } |
Comment on lines
+57
to
+77
| router.put('/:id', async (req, res) => { | ||
| try { | ||
| if (!mongoose.isValidObjectId(req.params.id)) { | ||
| return res.status(400).json({ error: 'invalid id' }); | ||
| } | ||
|
|
||
| const { title, description, status } = req.body || {}; | ||
| const update = {}; | ||
|
|
||
| if (title !== undefined) { | ||
| if (typeof title !== 'string' || title.trim() === '') { | ||
| return res.status(400).json({ error: 'title must be a non-empty string' }); | ||
| } | ||
| update.title = title.trim(); | ||
| } | ||
| if (description !== undefined) update.description = description; | ||
| if (status !== undefined) update.status = status; | ||
|
|
||
| if (Object.keys(update).length === 0) { | ||
| return res.status(400).json({ error: 'no fields to update' }); | ||
| } |
Comment on lines
6
to
+11
| router.get('/', (req, res) => { | ||
| res.json({ status: 'OK', message: 'Server is running' }); | ||
| res.status(200).json({ | ||
| status: 'ok', | ||
| uptime: process.uptime(), | ||
| version, | ||
| }); |
Comment on lines
29
to
35
| "devDependencies": { | ||
| "eslint": "^8.45.0", | ||
| "jest": "^29.6.2", | ||
| "mongodb-memory-server": "^11.2.0", | ||
| "nodemon": "^3.0.1", | ||
| "jest": "^29.6.2" | ||
| "supertest": "^7.2.2" | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.