use of com.commercetools.sync.integration.commons.utils.ITUtils.LOCALISED_STRING_CUSTOM_FIELD_NAME in project commercetools-sync-java by commercetools.
the class ProductSyncWithPricesIT method withMixedCasesOfPriceMatches_ShouldBuildActions.
@Test
void withMixedCasesOfPriceMatches_ShouldBuildActions() {
// Preparation
createExistingProductWithPrices();
final ProductDraft newProductDraft = createProductDraftWithNewPrices();
final ObjectNode lTextWithEnDe = JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red");
final PriceDraft de222EurCust1Ofid = PriceDraftBuilder.of(DRAFT_DE_222_EUR_CUST1).customerGroup(cust1).build();
final PriceDraft de333UsdCust1Ofid = PriceDraftBuilder.of(DRAFT_DE_333_USD_CUST1).customerGroup(cust1).build();
final PriceDraft us666Usd0102Cust2OfId = PriceDraftBuilder.of(DRAFT_US_666_USD_CUST2_01_02).customerGroup(cust2).build();
final CustomFieldsDraft customType1WithEnDeOfId = CustomFieldsDraft.ofTypeIdAndJson(customType1.getId(), createCustomFieldsJsonMap(LOCALISED_STRING_CUSTOM_FIELD_NAME, lTextWithEnDe));
final PriceDraft withChannel1CustomType1WithEnDeOfId = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel1.getId(), customType1WithEnDeOfId);
final PriceDraft withChannel2CustomType1WithEnDeOfId = getPriceDraft(BigDecimal.valueOf(100), EUR, DE, null, byMonth(1), byMonth(2), channel2.getId(), customType1WithEnDeOfId);
// test
final ProductSyncStatistics syncStatistics = executeBlocking(productSync.sync(singletonList(newProductDraft)));
// assertion
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
final Integer masterVariantId = product.getMasterData().getStaged().getMasterVariant().getId();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof RemovePrice).hasSize(5);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof ChangePrice).hasSize(3);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomType).hasSize(1);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof SetProductPriceCustomField).hasSize(1);
assertThat(updateActionsFromSync).filteredOn(action -> action instanceof AddPrice).hasSize(9).containsExactlyInAnyOrder(AddPrice.ofVariantId(masterVariantId, de222EurCust1Ofid, true), AddPrice.ofVariantId(masterVariantId, DRAFT_DE_111_EUR_01_02, true), AddPrice.ofVariantId(masterVariantId, DRAFT_DE_111_EUR_03_04, true), AddPrice.ofVariantId(masterVariantId, de333UsdCust1Ofid, true), AddPrice.ofVariantId(masterVariantId, DRAFT_UK_999_GBP, true), AddPrice.ofVariantId(masterVariantId, us666Usd0102Cust2OfId, true), AddPrice.ofVariantId(masterVariantId, DRAFT_FR_888_EUR_01_03, true), AddPrice.ofVariantId(masterVariantId, DRAFT_FR_999_EUR_03_06, true), AddPrice.ofVariantId(masterVariantId, DRAFT_NE_777_EUR_05_07, true));
final ProductProjection productProjection = CTP_TARGET_CLIENT.execute(ProductProjectionByKeyGet.of(newProductDraft.getKey(), ProductProjectionType.STAGED)).toCompletableFuture().join();
assertThat(productProjection).isNotNull();
final List<PriceDraft> newPricesWithReferenceIds = asList(DRAFT_DE_111_EUR, de222EurCust1Ofid, DRAFT_DE_111_EUR_01_02, DRAFT_DE_111_EUR_03_04, withChannel1CustomType1WithEnDeOfId, withChannel2CustomType1WithEnDeOfId, de333UsdCust1Ofid, DRAFT_DE_22_USD, DRAFT_UK_111_GBP_01_02, DRAFT_UK_999_GBP, us666Usd0102Cust2OfId, DRAFT_FR_888_EUR_01_03, DRAFT_FR_999_EUR_03_06, DRAFT_NE_777_EUR_01_04, DRAFT_NE_777_EUR_05_07);
assertPricesAreEqual(productProjection.getMasterVariant().getPrices(), newPricesWithReferenceIds);
}
Aggregations