use of io.ionic.demo.ecommerce.data.model.Cart in project portals-ecommerce-demo by ionic-team.
the class ShoppingCartTest method getCartShouldReturnCart.
@Test
public void getCartShouldReturnCart() {
Cart cart = shoppingCart.getCart();
assertNotNull(cart);
}
use of io.ionic.demo.ecommerce.data.model.Cart in project portals-ecommerce-demo by ionic-team.
the class ShoppingCartTest method addingTwoOfSameItemToCartShouldCalcSubTotal.
@Test
public void addingTwoOfSameItemToCartShouldCalcSubTotal() {
Product product = new Product();
product.id = 1;
product.price = 5;
shoppingCart.addItem(product, 2);
Cart cart = shoppingCart.getCart();
assertEquals(10, cart.subTotal, 0);
}
use of io.ionic.demo.ecommerce.data.model.Cart in project portals-ecommerce-demo by ionic-team.
the class ShoppingCartTest method callingCheckoutWithSuccessShouldClearCart.
@Test
public void callingCheckoutWithSuccessShouldClearCart() {
Product product = new Product();
product.id = 1;
product.price = 5;
shoppingCart.addItem(product, 2);
Cart cart = shoppingCart.getCart();
assertEquals(1, cart.basket.size());
assertEquals(10, cart.subTotal, 0);
shoppingCart.checkout("success");
cart = shoppingCart.getCart();
assertEquals(0, cart.basket.size());
assertEquals(0, cart.subTotal, 0);
}
use of io.ionic.demo.ecommerce.data.model.Cart in project portals-ecommerce-demo by ionic-team.
the class ShoppingCartTest method addingTwoOfSameItemToCartShouldBeInBasket.
@Test
public void addingTwoOfSameItemToCartShouldBeInBasket() {
Product product = new Product();
product.id = 1;
product.price = 5;
shoppingCart.addItem(product, 2);
Cart cart = shoppingCart.getCart();
assertEquals(1, cart.basket.get(0).productId);
assertEquals(2, cart.basket.get(0).quantity);
}
use of io.ionic.demo.ecommerce.data.model.Cart in project portals-ecommerce-demo by ionic-team.
the class ShoppingCart method getCart.
public Cart getCart() {
Cart cart = new Cart();
cart.id = 1;
for (Map.Entry<Product, Integer> entry : contents.entrySet()) {
Product product = entry.getKey();
int quantity = entry.getValue();
CartItem cartItem = new CartItem();
cartItem.productId = product.id;
cartItem.quantity = quantity;
cart.subTotal += product.price * quantity;
cart.basket.add(cartItem);
}
return cart;
}
Aggregations