|
2 | 2 |
|
3 | 3 | import static com.commercetools.api.models.common.LocalizedString.ofEnglish; |
4 | 4 | import static com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat; |
| 5 | +import static com.commercetools.sync.integration.commons.utils.CustomerITUtils.ensureStore; |
5 | 6 | import static com.commercetools.sync.integration.commons.utils.ShoppingListITUtils.*; |
6 | 7 | import static com.commercetools.sync.integration.commons.utils.TestClientUtils.CTP_SOURCE_CLIENT; |
7 | 8 | import static com.commercetools.sync.integration.commons.utils.TestClientUtils.CTP_TARGET_CLIENT; |
|
36 | 37 | import com.commercetools.api.models.shopping_list.TextLineItem; |
37 | 38 | import com.commercetools.api.models.shopping_list.TextLineItemDraft; |
38 | 39 | import com.commercetools.api.models.shopping_list.TextLineItemDraftBuilder; |
| 40 | +import com.commercetools.api.models.store.StoreResourceIdentifier; |
39 | 41 | import com.commercetools.api.models.type.CustomFields; |
40 | 42 | import com.commercetools.api.models.type.CustomFieldsDraftBuilder; |
41 | 43 | import com.commercetools.api.models.type.TypeReference; |
@@ -521,4 +523,62 @@ private List<ShoppingListLineItemDraft> setNullToAddedAtValuesForLineItems( |
521 | 523 | ShoppingListLineItemDraftBuilder.of(lineItemDraft).addedAt(null).build()) |
522 | 524 | .collect(toList()); |
523 | 525 | } |
| 526 | + |
| 527 | + @Test |
| 528 | + void sync_WithStoreChange_ShouldUpdateShoppingListStore() { |
| 529 | + // Create the store that will be referenced |
| 530 | + ensureStore(CTP_TARGET_CLIENT, "different-store-key"); |
| 531 | + |
| 532 | + // Create a shopping list draft with a different store |
| 533 | + final ShoppingListDraft modifiedDraft = |
| 534 | + ShoppingListDraftBuilder.of(shoppingListDraftSampleCarrotCake) |
| 535 | + .store( |
| 536 | + storeResourceIdentifierBuilder -> |
| 537 | + storeResourceIdentifierBuilder.key("different-store-key")) |
| 538 | + .build(); |
| 539 | + |
| 540 | + final ShoppingListSyncStatistics shoppingListSyncStatistics = |
| 541 | + shoppingListSync.sync(singletonList(modifiedDraft)).toCompletableFuture().join(); |
| 542 | + |
| 543 | + assertThat(errorMessages).isEmpty(); |
| 544 | + assertThat(warningMessages).isEmpty(); |
| 545 | + assertThat(exceptions).isEmpty(); |
| 546 | + |
| 547 | + // Verify that a setStore update action was generated |
| 548 | + assertThat(updateActionList) |
| 549 | + .anySatisfy( |
| 550 | + action -> { |
| 551 | + assertThat(action.getAction()).isEqualTo("setStore"); |
| 552 | + }); |
| 553 | + |
| 554 | + assertThat(shoppingListSyncStatistics).hasValues(1, 0, 1, 0); |
| 555 | + } |
| 556 | + |
| 557 | + @Test |
| 558 | + void sync_WithNullStore_ShouldUpdateShoppingListStoreToNull() { |
| 559 | + // Create a shopping list draft with null store |
| 560 | + final StoreResourceIdentifier nullStore = null; |
| 561 | + final ShoppingListDraft modifiedDraft = |
| 562 | + ShoppingListDraftBuilder.of(shoppingListDraftSampleCarrotCake).store(nullStore).build(); |
| 563 | + |
| 564 | + final ShoppingListSyncStatistics shoppingListSyncStatistics = |
| 565 | + shoppingListSync.sync(singletonList(modifiedDraft)).toCompletableFuture().join(); |
| 566 | + |
| 567 | + assertThat(errorMessages).isEmpty(); |
| 568 | + assertThat(warningMessages).isEmpty(); |
| 569 | + assertThat(exceptions).isEmpty(); |
| 570 | + |
| 571 | + // If the original had a store and we set it to null, we should see an update |
| 572 | + if (shoppingListSampleCarrotCake.getStore() != null) { |
| 573 | + assertThat(updateActionList) |
| 574 | + .anySatisfy( |
| 575 | + action -> { |
| 576 | + assertThat(action.getAction()).isEqualTo("setStore"); |
| 577 | + }); |
| 578 | + assertThat(shoppingListSyncStatistics).hasValues(1, 0, 1, 0); |
| 579 | + } else { |
| 580 | + // If both are null, no update should occur |
| 581 | + assertThat(shoppingListSyncStatistics).hasValues(1, 0, 0, 0); |
| 582 | + } |
| 583 | + } |
524 | 584 | } |
0 commit comments