|
| 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 | +} |
0 commit comments