Skip to content

Commit fa1fde2

Browse files
committed
DEVX-813: adding ProductVariantUtil tests
1 parent cec18a7 commit fa1fde2

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.commercetools.sdk;
2+
3+
import com.commercetools.api.models.product.ProductProjection;
4+
import io.vrap.rmf.base.client.utils.json.JsonUtils;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class ProductVariantUtilTest {
9+
private final ProductVariantUtil util = new ProductVariantUtil();
10+
11+
@Test
12+
void shouldIdentifyMasterVariant() {
13+
var product = JsonUtils.fromJsonString(TestUtils.stringFromResource("src/test/resources/product-projection.example.json"), ProductProjection.class);
14+
var result = util.toProductVariantImport(product, product.getMasterVariant());
15+
16+
Assertions.assertTrue(result.getIsMasterVariant());
17+
Assertions.assertEquals("masterVariantKey", result.getKey());
18+
}
19+
20+
@Test
21+
void shouldSetProductKeyReference() {
22+
var product = JsonUtils.fromJsonString(TestUtils.stringFromResource("src/test/resources/product-projection.example.json"), ProductProjection.class);
23+
var result = util.toProductVariantImport(product, product.getMasterVariant());
24+
25+
Assertions.assertEquals("productKey", result.getProduct().getKey());
26+
}
27+
28+
@Test
29+
void shouldIdentifyNonMasterVariant() {
30+
// use a fixture t at has at least one variant in "variants" array
31+
var product = JsonUtils.fromJsonString(TestUtils.stringFromResource("src/test/resources/product-projection.with-variants.json"), ProductProjection.class);
32+
var nonMaster = product.getVariants().get(0);
33+
var result = util.toProductVariantImport(product, nonMaster);
34+
35+
Assertions.assertFalse(result.getIsMasterVariant());
36+
}
37+
38+
@Test
39+
void shouldPassStagedFlag() {
40+
var product = JsonUtils.fromJsonString(TestUtils.stringFromResource("src/test/resources/product-projection.example.json"), ProductProjection.class);
41+
var result = util.toProductVariantImport(product, product.getMasterVariant());
42+
Assertions.assertFalse(result.getStaged());
43+
}
44+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [
43+
{
44+
"id": 2,
45+
"key": "variantKey1"
46+
}
47+
],
48+
"searchKeywords": {},
49+
"hasStagedChanges": false,
50+
"published": true,
51+
"createdAt": "1970-01-01T00:00:00.001Z",
52+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
53+
"attributes": []
54+
}

0 commit comments

Comments
 (0)