You have been hired as a developer at Ali Snobba - a snobby Asian online store where customers purchase high-end merchandise like Louis Vuitton handbags and Rolex watches.
Your job is to implement a shopping cart that stores items while customers are in the process of ordering. Since Ali Snobba is a small company with only one server, you don't need to store the items in Redis or a database - you can keep them in an array in memory.
You also don't need to worry about authentication or session tracking. You can assume that Ali Snobba's infrastructure will create a new Docker container with a instance of node for each active user.
A shopping cart Item
should have the following model:
The shopping Cart
should have the following model:
addItem()
should take two parameters:
- An
Item
Object - An integer
quantity
itemQuantities()
should return an array with one String for each type of item in the cart in the following format:
[
'Handbag - x2',
'Watch - x4'
]
itemizedList()
should return an array with one String for each item in the cart in the following format:
[
'Handbag x1 - $500.00',
'Watch x2 - $40,000.00'
]
onSaleItems()
should return an array with on String for each item in the cart marked as onSale
in the following format:
[
'Handbag x1 - $250.00',
'Watch x2 - $20,000.00'
]
As a developer, your task is to implement the following user story, following the TDD workflow:
- Write (failing) tests before writing any code
- Only write code in response to failing test
- Make tests pass with simplest code possible
- After getting each test to pass, refactor your code and tests to be as concise as possible
Be sure to fork:
then Clone:
this repository!
When you are finished with the exercise, commit and push your work!
You will know you have forked and pushed properly if you see your work in Github under your github account:
not gSchool:
Be sure to make a commit in git each time you get a passing test!
- As a shopper
- I want to have a shopping cart
- So that I can store items until I am ready to checkout
- Given that I visit the site, when I begin shopping, then I expect my cart to be empty.
- Given I have an empty cart, when I add an Item, then I expect to see
totalPrice
reflect the sum of all the Items in my cart, times the quantities of each item. - Given I have an empty cart, when I add more than one of an item, then I expect
itemQuantities()
to show the number of items I have added. - Given I have an empty cart, when I add items, then I expect
itemizedList()
reflect the items I have added along with their price and quantity. - Given I have an empty cart, when I add more than one of an item, then I expect
totalPrice
to reflect both the item price and quantity. - Given I have a cart with items that are not on sale, when I add items that are on sale, I expect
onSaleItems()
to include only the items on sale.
- Use es6 getters to simpliify your task.
- Use es6 template litterals instead of String concatenation
- Use map, filter, and reduce to avoid looping