public final class PriceChangedError extends SphereError
withTaxedProduct(client(), product -> {
withUpdateableShippingMethodForGermany(client(), shippingMethod -> {
final int quantity = 2;
final int variantId = 1;
final CartDraftDsl draft = CartDraft.of(DefaultCurrencyUnits.EUR)
.withCountry(CountryCode.DE)
.withShippingAddress(Address.of(CountryCode.DE))
.withLineItems(singletonList(LineItemDraft.of(product, variantId, quantity)))
.withShippingMethod(shippingMethod);
final Cart cart = client().executeBlocking(CartCreateCommand.of(draft));
//change the product price
final List<UpdateActionImpl<Product>> productUpdates = asList(
SetPrices.ofVariantId(variantId, singletonList(PriceDraft.of(SphereTestUtils.EURO_20))),
Publish.of()
);
client().executeBlocking(ProductUpdateCommand.of(product, productUpdates));
//also change the zone rate
final ZoneRate zoneRate = shippingMethod.getZoneRates().get(0);
final ShippingRate oldShippingRate = zoneRate.getShippingRates().get(0);
final Reference<Zone> zone = zoneRate.getZone();
final ShippingMethod updatedShippingMethod = client().executeBlocking(ShippingMethodUpdateCommand.of(shippingMethod, asList(RemoveShippingRate.of(oldShippingRate, zone), AddShippingRate.of(ShippingRate.of(EURO_10, EURO_10), zone))));
//see the order creation fail
final Throwable throwable = catchThrowable(() -> client().executeBlocking(OrderFromCartCreateCommand.of(cart)));
assertThat(throwable).isInstanceOf(ErrorResponseException.class);
final ErrorResponseException e = (ErrorResponseException) throwable;
assertThat(e.hasErrorCode(PriceChangedError.CODE));
final PriceChangedError error = e.getErrors().stream()
.filter(err -> err.getCode().equals(PriceChangedError.CODE))
.findFirst().get().as(PriceChangedError.class);
assertThat(error.getLineItems())
.as("the changed line items can be found")
.containsExactly(cart.getLineItems().get(0).getId());
assertThat(error.isShipping())
.as("the rate change can be diagnosed")
.isTrue();
//clean up
client().executeBlocking(CartDeleteCommand.of(cart));
return updatedShippingMethod;
});
});
See the test code.
Modifier and Type | Method and Description |
---|---|
List<String> |
getLineItems() |
boolean |
isShipping() |
static PriceChangedError |
of(String message,
List<String> lineItems,
boolean shipping) |
as, getCode, getMessage, of
public static final String CODE