This is Part 3.1 (optional) of a series of labs working towards building your first full stack web app.
- Part 1 - TDD todo list
- Part 2 - Mongo todo list
- Part 3 - Express todo list pt1
- Part 3.1 - (this repo, which is optional)
- Part 4 - Express todo list pt2
- Part 5 - Multi Model todo list
- Part 6 - Users todo list
Note: This can be a pair programming activity or done independently.
Now that we've written a few tests in our Express application, let's practice writing tests for a more complex application, our TODO list, an app that uses Mongo.
- Setup the app to run mocha, chai and supertest
- Implement these tests:
GET /todos
✓ should return a 200 response
✓ should return an array
✓ should return all the records in the database
GET /todos/:id
✓ should return a 200 response
✓ should return an object containing the fields 'name', 'description' and 'completed'
POST /todos
✓ should return a 200 response
✓ should return a 422 response if the field name is wrong
✓ should return an error message if the name field is wrong
✓ should add a new todo to the database
PUT /todos/:id
✓ should return a 200 response
✓ should update a todo document
DELETE /todos/:id
✓ should remove a todo document
- If you include the model todo in your spec file, you can execute requests to MongoDB directly from the test file, allowing you to watch the database directly before or after an action made by a test
Bonus:
- Add more validations in the models and add the tests for them, too
- Add fields with different datatypes and write tests for them
No starter code... use the output of the previous Express Todo Lab.
You should expect something like this in the terminal: