You will build an application that lets users round up the change for each purchase and set it as a donation.
- Fork and clone this repository
- Open up the repository in your code editor.
- Start a new node project
- Set up a .gitignore file
- Install nanoid version 3
- Install chalk version 4
Build out the following functionality. Be sure to organize your code so that the functions stay small and have one job, and also, manage your files so that it is clear what kind of functions are within each file.
- A user can create a purchase. The purchased object will have the following:
id
- generated by nanoidname
- the name of the purchaseamount
- the purchase amountdonation
- the donation amount, rounded to two decimal places
- A user can see an index of all their purchases, showing the
id
and thename
. - A user can see a show view with all the purchase details. This view should have additional styling (see below).
- A user can update a purchase.
- A user can delete a purchase.
- A user can see the total amount of money for donation.
Here is an example of additional styling for the show view
Include Jest, and write a minimum of two tests. You could:
- Confirm all the correct fields exist when creating a new item.
- Make sure the correct datatype is being inserted into each field.
With the following functionality, you would likely want to make a sample data set that is always the same (you can create a small array of objects (~2-3 items) that is hard-coded in your test file, or you can create a separate file and import it). You would not use the fs
module to update any changes permanently. You can look for examples of using sample data with a previous lab you have completed.
- Confirm that the function to create one item creates only one item and appends it to the test array.
- Confirm that the delete function deletes the correct object in the test array.
- Confirm that the edit function edits the correct object in the test array.
- Confirm that the output for the show view matches your expected output.
- Confirm that the output for the index view matches your expected output.
Instead of your user remembering the order to enter data. Upgrade your functionality so your user can create key-value pairs and then the user can input them in any order:
npm run update amount="4.44" name="Mechanical Pencil" id=rSl_