use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplTest method fetchCartDiscount_WithEmptyKey_ShouldNotFetchAnyCartDiscount.
@Test
void fetchCartDiscount_WithEmptyKey_ShouldNotFetchAnyCartDiscount() {
// preparation
final SphereClient sphereClient = mock(SphereClient.class);
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(sphereClient).build();
final CartDiscountService cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
// test
final CompletionStage<Optional<CartDiscount>> result = cartDiscountService.fetchCartDiscount("");
// assertions
assertThat(result).isCompletedWithValue(Optional.empty());
verify(sphereClient, never()).execute(any());
}
use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountSyncUtilsTest method buildActions_FromDraftsWithDifferentNameValues_ShouldBuildUpdateActions.
@Test
void buildActions_FromDraftsWithDifferentNameValues_ShouldBuildUpdateActions() {
final LocalizedString newName = LocalizedString.of(Locale.GERMAN, "Neu Name", Locale.ENGLISH, "new name");
final CartDiscountDraft newCartDiscount = CartDiscountDraftBuilder.of(cartDiscountDraft).name(newName).build();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_CLIENT).build();
final List<UpdateAction<CartDiscount>> updateActions = buildActions(cartDiscount, newCartDiscount, cartDiscountSyncOptions);
assertThat(updateActions).isNotEmpty();
assertThat(updateActions).containsExactly(ChangeName.of(newName));
}
use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountSyncUtilsTest method buildActions_WithSameValues_ShouldNotBuildUpdateActions.
@Test
void buildActions_WithSameValues_ShouldNotBuildUpdateActions() {
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_CLIENT).build();
final List<UpdateAction<CartDiscount>> updateActions = buildActions(cartDiscount, cartDiscountDraft, cartDiscountSyncOptions);
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountSyncUtilsTest method buildActions_FromDraftsWithAllDifferentValues_ShouldBuildAllUpdateActions.
@Test
void buildActions_FromDraftsWithAllDifferentValues_ShouldBuildAllUpdateActions() {
final LocalizedString newName = LocalizedString.of(Locale.GERMAN, "Neu Name", Locale.ENGLISH, "new name");
final CartPredicate newCartDiscountPredicate = CartPredicate.of("1 = 1");
final CartDiscountValue newCartDiscountValue = CartDiscountValue.ofAbsolute(MoneyImpl.of(10, EUR));
final CartDiscountTarget newCartDiscountTarget = LineItemsTarget.of("quantity > 1");
final String newSortOrder = "0.3";
final LocalizedString newDesc = LocalizedString.of(Locale.GERMAN, "Neu Beschreibung", Locale.ENGLISH, "new description");
final ZonedDateTime newValidFrom = ZonedDateTime.parse("2019-11-01T00:00:00.000Z");
final ZonedDateTime newValidUntil = ZonedDateTime.parse("2019-11-15T00:00:00.000Z");
final boolean newIsActive = true;
final boolean newRequireDiscountCode = true;
final StackingMode newStackingMode = StackingMode.STOP_AFTER_THIS_DISCOUNT;
final CustomFieldsDraft newCustomFieldsDraft = CustomFieldsDraftBuilder.ofTypeId(UUID.randomUUID().toString()).build();
final CartDiscountDraft newCartDiscount = CartDiscountDraftBuilder.of(newName, newCartDiscountPredicate, newCartDiscountValue, newCartDiscountTarget, newSortOrder, newRequireDiscountCode).active(newIsActive).description(newDesc).validFrom(newValidFrom).validUntil(newValidUntil).stackingMode(newStackingMode).custom(newCustomFieldsDraft).build();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_CLIENT).build();
final List<UpdateAction<CartDiscount>> updateActions = buildActions(cartDiscount, newCartDiscount, cartDiscountSyncOptions);
assertThat(updateActions).containsExactly(ChangeValue.of(newCartDiscountValue), ChangeCartPredicate.of(newCartDiscountPredicate), ChangeTarget.of(newCartDiscountTarget), ChangeIsActive.of(newIsActive), ChangeName.of(newName), SetDescription.of(newDesc), ChangeSortOrder.of(newSortOrder), ChangeRequiresDiscountCode.of(newRequireDiscountCode), SetValidFromAndUntil.of(newValidFrom, newValidUntil), ChangeStackingMode.of(newStackingMode), SetCustomType.ofTypeIdAndJson(newCustomFieldsDraft.getType().getId(), emptyMap()));
}
use of com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions in project commercetools-sync-java by commercetools.
the class CartDiscountServiceImplIT method setup.
/**
* Deletes types & cart discounts from the target CTP project, then it populates the project with
* test data.
*/
@BeforeEach
void setup() {
deleteCartDiscountsFromTargetAndSource();
populateTargetProject();
errorCallBackMessages = new ArrayList<>();
errorCallBackExceptions = new ArrayList<>();
final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, actions) -> {
errorCallBackMessages.add(exception.getMessage());
errorCallBackExceptions.add(exception);
}).build();
cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
}
Aggregations