This Lab will be your first chance to apply the concepts of Test Driven Development and also introduce you to CRUD by building out the logic for a simple Todo List Application.
CRUD is an acronym that stands for Create, Read, Update, Destroy. These are the basic operations that you can perform on data. Most websites and applications you interact with contain some CRUD actions: Creating a user (create), Listing comments (read), editing your profile (update), or deleting a video you uploaded (destroy).
- Fork and clone this repository
- Run
npm install
to install dependencies npm test
- run test suitenpm start
- run the REPL
You will write your tests one at a time using the Node Assert Package. After writing a test, and verifying that it fails, you should proceed to write the code required to pass the test.
Your tests should be written inside the test/todo_tests.js
file and your implementation inside models/todo.js
.
Todos should be stored as an array of Todo Objects. Each instance of a Todo should store a unique id that can be used to find it later. Use the included UUID generator to add one upon creation.
You should as a minimum implement the following features. Each will likely require more than one test to ensure that the requirement is met and robust.
Hint: Write tests in whichever order makes the most sense, not from top to bottom.
- Should be able to create a new Todo with the following KVPs in the
params
object:name
description
completed
(true/false)
- Should automatically create an
_id
property for each new TODO and assign it a UUID - Should be able to create a new Todo with just
name
, sensible defaults will be used for other fields. - Should NOT be able to create a new Todo without a
name
being provided - Should NOT allow a
name
less than 5 characters long
- Should return an array of all todos
- Should return the Todo Object with the specified
id
- Should return null if no TODO with that
id
exists
- Should be able to update the Todo with the given id, using the following KVPs in the
updatedParams
object:name
description
completed
(true/false)
- Should allow individual fields to be updated
- Should NOT allow a
name
to be changed to blank or less than 5 characters in length - Should return
true
if an update is successful,false
if otherwise
- Should be able to delete the Todo with the given
id
- Should return
true
if the delete is successful,false
if otherwise
- Should be able to delete all the Todos and return true
Currently the TODOs will disappear whenever the application is restarted. We can however, save the the TODOs array to a JSON file and load it again whenever the application starts. Find out how to do this and do it.
hint: check the Node.js documentation for 'fs'
- All content is licensed under a CC-BY-NC-SA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.