@Test public void addLineItemWithExternalTotalPrice() { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final int quantity = 5; final int variantId = 1; final String productId = product.getId(); final MonetaryAmount price = EURO_20; final MonetaryAmount totalPrice = EURO_25; final ExternalLineItemTotalPrice externalLineItemTotalPrice = ExternalLineItemTotalPrice.ofPriceAndTotalPrice(price, totalPrice); final AddLineItem updateAction = AddLineItem.of(productId, variantId, quantity) .withExternalTotalPrice(externalLineItemTotalPrice); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction)); final LineItem lineItem = cartWithLineItem.getLineItems().get(0); assertThat(lineItem.getPrice().getValue()).isEqualTo(price); assertThat(lineItem.getTotalPrice()).isEqualTo(totalPrice); assertThat(lineItem.getPriceMode()).isEqualTo(EXTERNAL_TOTAL); }); }
@Test public void changeLineItemQuantityWithoutExternalTotalPrice() throws Exception { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).hasSize(0); final MonetaryAmount price = EURO_1; final MonetaryAmount totalPrice = EURO_5; final ExternalLineItemTotalPrice externalTotalPrice = ExternalLineItemTotalPrice.ofPriceAndTotalPrice(price, totalPrice); final AddLineItem action = AddLineItem.of(product.getId(), MASTER_VARIANT_ID, 3L).withExternalTotalPrice(externalTotalPrice); final Cart cartWith3 = client().executeBlocking(CartUpdateCommand.of(cart, action)); final LineItem lineItem = cartWith3.getLineItems().get(0); assertThat(lineItem.getQuantity()).isEqualTo(3); assertThat(lineItem.getPriceMode()).isEqualTo(EXTERNAL_TOTAL); assertThat(lineItem.getTotalPrice()).isEqualTo(totalPrice); assertThat(lineItem.getPrice().getValue()).isEqualTo(price); final Cart cartWith2 = client().executeBlocking(CartUpdateCommand.of(cartWith3, ChangeLineItemQuantity.of(lineItem, 2L))); final LineItem updatedLineItem = cartWith2.getLineItems().get(0); assertThat(updatedLineItem.getQuantity()).isEqualTo(2); assertThat(updatedLineItem.getPriceMode()).isEqualTo(PLATFORM); assertThat(updatedLineItem.getPrice().getValue()).isEqualTo(MoneyImpl.ofCents(1234, EUR)); }); }