Add integration tests for POST /todos and DELETE /todos/:id #6

Open
opened 2026-05-12 06:54:31 +00:00 by danny8632 · 0 comments
Owner

Goal

Add an integration test suite (using supertest against the Express app) that covers the two new endpoints added in the previous issue. The test file should import or start the Express app, not spawn a separate process. Add an npm test script to package.json that runs the suite. Tests must be self-contained: each test resets or accounts for shared in-memory state so they pass in isolation and together.

Done criteria

  • A test file exists at test/api.test.js (or test/api.spec.js)
  • npm test exits with code 0
  • Test suite contains at least one test asserting POST /todos returns 201 with correct JSON shape (id, title, done)
  • Test suite contains at least one test asserting DELETE /todos/:id returns 204 and the item is gone from GET /todos
  • Test suite contains at least one test asserting DELETE /todos/:id for a missing id returns 404
  • supertest is listed as a devDependency in package.json

Hints

Export the Express app object from index.js without calling app.listen() at module level (guard it with if (require.main === module)) so supertest can bind its own port. Use a test runner already available in Node (e.g., node:test + assert) to avoid adding an extra dependency, or add jest/mocha — either is fine as long as npm test drives it.

Model

sonnet

## Goal Add an integration test suite (using supertest against the Express app) that covers the two new endpoints added in the previous issue. The test file should import or start the Express app, not spawn a separate process. Add an `npm test` script to package.json that runs the suite. Tests must be self-contained: each test resets or accounts for shared in-memory state so they pass in isolation and together. ## Done criteria - [ ] A test file exists at `test/api.test.js` (or `test/api.spec.js`) - [ ] `npm test` exits with code 0 - [ ] Test suite contains at least one test asserting POST /todos returns 201 with correct JSON shape (`id`, `title`, `done`) - [ ] Test suite contains at least one test asserting DELETE /todos/:id returns 204 and the item is gone from GET /todos - [ ] Test suite contains at least one test asserting DELETE /todos/:id for a missing id returns 404 - [ ] `supertest` is listed as a devDependency in package.json ## Hints Export the Express `app` object from index.js without calling `app.listen()` at module level (guard it with `if (require.main === module)`) so supertest can bind its own port. Use a test runner already available in Node (e.g., node:test + assert) to avoid adding an extra dependency, or add jest/mocha — either is fine as long as `npm test` drives it. ## Model sonnet
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: danny8632/todo-app#6