|
| 1 | +package com.commercetools.sdk; |
| 2 | + |
| 3 | +import com.commercetools.api.models.inventory.InventoryEntry; |
| 4 | +import io.vrap.rmf.base.client.utils.json.JsonUtils; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import static com.commercetools.sdk.TestUtils.stringFromResource; |
| 8 | +import static org.junit.jupiter.api.Assertions.*; |
| 9 | + |
| 10 | +public class InventoryUtilTest { |
| 11 | + private final InventoryUtil util = new InventoryUtil(); |
| 12 | + |
| 13 | + @Test |
| 14 | + void shouldMapRequiredFields() { |
| 15 | + var entry = JsonUtils.fromJsonString(stringFromResource("src/test/resources/inventory.example.json"), InventoryEntry.class); |
| 16 | + var result = util.toInventoryImport(entry); |
| 17 | + |
| 18 | + assertEquals("inventory-key", result.getKey()); |
| 19 | + assertEquals("sku-001", result.getSku()); |
| 20 | + assertEquals(100L, result.getQuantityOnStock()); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + void shouldMapSupplyChannelKeyFromExpandedObj() { |
| 25 | + var entry = JsonUtils.fromJsonString(stringFromResource("src/test/resources/inventory.example.json"), InventoryEntry.class); |
| 26 | + var result = util.toInventoryImport(entry); |
| 27 | + |
| 28 | + assertNotNull(result.getSupplyChannel()); |
| 29 | + assertEquals("channel-key", result.getSupplyChannel().getKey()); // catches getId() bug |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void shouldHandleNullSupplyChannel() { |
| 34 | + var entry = JsonUtils.fromJsonString(stringFromResource("src/test/resources/inventory.no-channel.json"), InventoryEntry.class); |
| 35 | + var result = util.toInventoryImport(entry); |
| 36 | + assertNull(result.getSupplyChannel()); |
| 37 | + } |
| 38 | +} |
0 commit comments