Skip to content

Commit aca9ce4

Browse files
authored
Add test for syncing images in a product (#1164)
1 parent cb99592 commit aca9ce4

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

src/integration-test/java/com/commercetools/sync/integration/externalsource/products/ProductSyncIT.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,51 @@ void sync_withProductContainingAttributeChanges_shouldSyncProductCorrectly() {
11081108
ProductPublishActionBuilder.of().build());
11091109
}
11101110

1111+
@Test
1112+
void sync_whenSourceProductHasNoImage_shouldSyncNewImages() {
1113+
final ProductDraft productDraftNoImages =
1114+
createProductDraft(
1115+
PRODUCT_KEY_7_NO_IMAGES,
1116+
ProductTypeResourceIdentifierBuilder.of().id(productType.getId()).build(),
1117+
null,
1118+
null,
1119+
null,
1120+
null);
1121+
1122+
TestClientUtils.CTP_TARGET_CLIENT
1123+
.products()
1124+
.create(productDraftNoImages)
1125+
.execute()
1126+
.thenApply(ApiHttpResponse::getBody)
1127+
.join();
1128+
1129+
final ProductDraft productDraftWithImages =
1130+
createProductDraft(
1131+
PRODUCT_KEY_7_WITH_IMAGES,
1132+
ProductTypeResourceIdentifierBuilder.of().id(productType.getKey()).build(),
1133+
null,
1134+
null,
1135+
null,
1136+
null);
1137+
1138+
final ProductSync productSync = new ProductSync(syncOptions);
1139+
final ProductSyncStatistics syncStatistics =
1140+
productSync.sync(singletonList(productDraftWithImages)).toCompletableFuture().join();
1141+
1142+
assertThat(syncStatistics).hasValues(1, 0, 1, 0, 0);
1143+
1144+
final ProductProjection productProjection =
1145+
TestClientUtils.CTP_TARGET_CLIENT
1146+
.productProjections()
1147+
.withKey(productDraftNoImages.getKey())
1148+
.get()
1149+
.execute()
1150+
.thenApply(ApiHttpResponse::getBody)
1151+
.join();
1152+
1153+
assertThat(productProjection.getMasterVariant().getImages()).hasSize(1);
1154+
}
1155+
11111156
@Nonnull
11121157
private static ProductDraft prefixDraftKey(
11131158
@Nonnull final ProductDraft productDraft, @Nonnull final String prefix) {

src/test/java/com/commercetools/sync/products/ProductSyncMockUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public class ProductSyncMockUtils {
9898
public static final String SIMPLE_PRODUCT_WITH_MULTIPLE_VARIANTS_RESOURCE_PATH =
9999
"simple-product-with-multiple-variants.json";
100100

101+
public static final String PRODUCT_KEY_7_WITH_IMAGES = "product-key-7-with-images.json";
102+
public static final String PRODUCT_KEY_7_NO_IMAGES = "product-key-7-no-images.json";
103+
101104
/**
102105
* Unfortunately, <a
103106
* href="http://dev.commercetools.com/http-api-projects-products.html#category-order-hints">
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "ba81a6da-cf83-435b-a89e-2afab579846f",
3+
"version": 10,
4+
"key": "productKey7",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "cda0dbf7-b42e-40bf-8453-241d5b587f93"
8+
},
9+
"catalogs": [],
10+
"masterData": {
11+
"staged": {
12+
"name": {
13+
"en": "english name"
14+
},
15+
"description": {
16+
"en": "english description."
17+
},
18+
"categories": [
19+
],
20+
"categoryOrderHints": {
21+
},
22+
"slug": {
23+
"en": "english-slug-7"
24+
},
25+
"masterVariant": {
26+
"id": 1,
27+
"key": "777777",
28+
"sku": "777777",
29+
"attributes": [
30+
],
31+
"assets": []
32+
},
33+
"variants": [],
34+
"searchKeywords": {}
35+
},
36+
"published": true,
37+
"hasStagedChanges": true
38+
},
39+
"catalogData": {},
40+
"taxCategory": {
41+
"typeId": "tax-category",
42+
"id": "ebbe95fb-2282-4f9a-8747-fbe440e02dc0"
43+
},
44+
"lastVariantId": 1,
45+
"createdAt": "2016-11-21T09:32:41.261Z",
46+
"lastModifiedAt": "2016-12-05T16:09:03.307Z",
47+
"lastMessageSequenceNumber": 3
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"id": "ba81a6da-cf83-435b-a89e-2afab579846f",
3+
"version": 10,
4+
"key": "productKey7",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "cda0dbf7-b42e-40bf-8453-241d5b587f93"
8+
},
9+
"catalogs": [],
10+
"masterData": {
11+
"staged": {
12+
"name": {
13+
"en": "english name"
14+
},
15+
"description": {
16+
"en": "english description."
17+
},
18+
"categories": [
19+
],
20+
"categoryOrderHints": {
21+
},
22+
"slug": {
23+
"en": "english-slug-7"
24+
},
25+
"masterVariant": {
26+
"id": 1,
27+
"key": "777777",
28+
"sku": "777777",
29+
"attributes": [
30+
],
31+
"assets": [],
32+
"images": [
33+
{
34+
"url": "https://53346cfbf3c7e017ed3d-6de74c3efa80f1c837c6a988b57abe66.ssl.cf3.rackcdn.com/old-image.png",
35+
"dimensions": {
36+
"w": 0,
37+
"h": 0
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {}
44+
},
45+
"published": true,
46+
"hasStagedChanges": true
47+
},
48+
"catalogData": {},
49+
"taxCategory": {
50+
"typeId": "tax-category",
51+
"id": "ebbe95fb-2282-4f9a-8747-fbe440e02dc0"
52+
},
53+
"lastVariantId": 1,
54+
"createdAt": "2016-11-21T09:32:41.261Z",
55+
"lastModifiedAt": "2016-12-05T16:09:03.307Z",
56+
"lastMessageSequenceNumber": 3
57+
}

0 commit comments

Comments
 (0)