Search in sources :

Example 1 with Cart

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);
}
Also used : Cart(io.ionic.demo.ecommerce.data.model.Cart) ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) Test(org.junit.Test)

Example 2 with 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);
}
Also used : Product(io.ionic.demo.ecommerce.data.model.Product) Cart(io.ionic.demo.ecommerce.data.model.Cart) ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) Test(org.junit.Test)

Example 3 with Cart

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);
}
Also used : Product(io.ionic.demo.ecommerce.data.model.Product) Cart(io.ionic.demo.ecommerce.data.model.Cart) ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) Test(org.junit.Test)

Example 4 with Cart

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);
}
Also used : Product(io.ionic.demo.ecommerce.data.model.Product) Cart(io.ionic.demo.ecommerce.data.model.Cart) ShoppingCart(io.ionic.demo.ecommerce.data.ShoppingCart) Test(org.junit.Test)

Example 5 with Cart

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;
}
Also used : Product(io.ionic.demo.ecommerce.data.model.Product) CartItem(io.ionic.demo.ecommerce.data.model.CartItem) Map(java.util.Map) HashMap(java.util.HashMap) Cart(io.ionic.demo.ecommerce.data.model.Cart)

Aggregations

Cart (io.ionic.demo.ecommerce.data.model.Cart)7 ShoppingCart (io.ionic.demo.ecommerce.data.ShoppingCart)6 Product (io.ionic.demo.ecommerce.data.model.Product)5 Test (org.junit.Test)5 JSObject (com.getcapacitor.JSObject)1 PluginMethod (com.getcapacitor.PluginMethod)1 Gson (com.google.gson.Gson)1 CartItem (io.ionic.demo.ecommerce.data.model.CartItem)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1