Implement a simple "Shopping Cart" functionality within the application located in the /app/ directory.
Requirements:
Create a Cart class:
The class should have the following properties:
items: an array to hold the items added to the cart.
The following methods should be implemented:
addItem(item: CartItem): This method should take an object representing a cart item (which includes id, name, and price) and add it to the items array.
removeItem(itemId: string): This method should take an item ID as a parameter and remove the corresponding item from the items array.
getTotalPrice(): This method should return the total price of all items currently in the cart.
getItems(): This method should return the list of all items in the cart.
Create a CartItem type:
Define a type or interface for CartItem that includes:
id: a string that uniquely identifies the item.
name: a string representing the name of the item.
price: a number representing the price of the item.
Constraints:
The addItem method should ensure that duplicate items (same id) cannot be added to the cart.
The removeItem method should handle cases where the item does not exist in the cart by not throwing an error.
Once the above functionality is implemented and the classes are tested, the existing test code should pass successfully, confirming that the shopping cart functionalities are working as required.