Search in sources :

Example 16 with CartDiscountService

use of com.commercetools.sync.services.CartDiscountService in project commercetools-sync-java by commercetools.

the class CartDiscountServiceImplTest method updateCartDiscount_WithMockSuccessfulCtpResponse_ShouldCallCartDiscountUpdateCommand.

@Test
void updateCartDiscount_WithMockSuccessfulCtpResponse_ShouldCallCartDiscountUpdateCommand() {
    // preparation
    final CartDiscount mockCartDiscount = mock(CartDiscount.class);
    final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    when(cartDiscountSyncOptions.getCtpClient().execute(any())).thenReturn(completedFuture(mockCartDiscount));
    final CartDiscountService cartDiscountService = new CartDiscountServiceImpl(cartDiscountSyncOptions);
    final List<UpdateAction<CartDiscount>> updateActions = singletonList(SetDescription.of(LocalizedString.ofEnglish("new_desc")));
    // test
    final CompletionStage<CartDiscount> result = cartDiscountService.updateCartDiscount(mockCartDiscount, updateActions);
    // assertions
    assertThat(result).isCompletedWithValue(mockCartDiscount);
    verify(cartDiscountSyncOptions.getCtpClient()).execute(eq(CartDiscountUpdateCommand.of(mockCartDiscount, updateActions)));
}
Also used : CartDiscountService(com.commercetools.sync.services.CartDiscountService) UpdateAction(io.sphere.sdk.commands.UpdateAction) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) Test(org.junit.jupiter.api.Test)

Aggregations

CartDiscountService (com.commercetools.sync.services.CartDiscountService)16 Test (org.junit.jupiter.api.Test)16 CartDiscountSyncOptions (com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions)13 CartDiscount (io.sphere.sdk.cartdiscounts.CartDiscount)13 SphereClient (io.sphere.sdk.client.SphereClient)12 Optional (java.util.Optional)12 CartDiscountDraft (io.sphere.sdk.cartdiscounts.CartDiscountDraft)9 CartDiscountQuery (io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery)9 Collections.singletonList (java.util.Collections.singletonList)9 List (java.util.List)9 ExecutionException (java.util.concurrent.ExecutionException)9 Assertions.as (org.assertj.core.api.Assertions.as)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 STRING (org.assertj.core.api.InstanceOfAssertFactories.STRING)9 CartDiscountSyncOptionsBuilder (com.commercetools.sync.cartdiscounts.CartDiscountSyncOptionsBuilder)8 TimeUnit (java.util.concurrent.TimeUnit)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 Mockito.when (org.mockito.Mockito.when)8 CartDiscountDraftBuilder (io.sphere.sdk.cartdiscounts.CartDiscountDraftBuilder)6 String.format (java.lang.String.format)6