Skip to content

Commit 91c9f06

Browse files
committed
DEVX-813: adding tests for StandalonePriceUtil
1 parent 4700565 commit 91c9f06

4 files changed

Lines changed: 157 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.commercetools.sdk;
2+
3+
import com.commercetools.api.models.standalone_price.StandalonePrice;
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+
class StandalonePriceUtilTest {
11+
private final StandalonePriceUtil util = new StandalonePriceUtil();
12+
@Test
13+
void shouldMapRequiredFields() {
14+
var price = JsonUtils.fromJsonString(stringFromResource("src/test/resources/standalone-price.example.json"), StandalonePrice.class);
15+
var result = util.toStandalonePriceImport(price);
16+
17+
assertEquals("price-key", result.getKey());
18+
assertEquals("sku-001", result.getSku());
19+
assertNotNull(result.getValue());
20+
}
21+
22+
@Test
23+
void shouldMapChannelKeyFromExpandedObj() {
24+
var price = JsonUtils.fromJsonString(stringFromResource("src/test/resources/standalone-price.example.json"), StandalonePrice.class);
25+
var result = util.toStandalonePriceImport(price);
26+
assertEquals("channel-key", result.getChannel().getKey()); // catches getId() bug
27+
}
28+
29+
@Test
30+
void shouldHandleNullDiscounted() {
31+
// fixture without "discounted" field
32+
var price = JsonUtils.fromJsonString(stringFromResource("src/test/resources/standalone-price.no-discount.json"), StandalonePrice.class);
33+
assertDoesNotThrow(() -> util.toStandalonePriceImport(price));
34+
}
35+
36+
@Test
37+
void shouldMapPriceTiers() {
38+
var price = JsonUtils.fromJsonString(stringFromResource("src/test/resources/standalone-price.with-tiers.json"), StandalonePrice.class);
39+
var result = util.toStandalonePriceImport(price);
40+
assertEquals(2, result.getTiers().size());
41+
assertEquals(10L, result.getTiers().get(0).getMinimumQuantity());
42+
}
43+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"id": "price-id-001",
3+
"version": 1,
4+
"key": "price-key",
5+
"sku": "sku-001",
6+
"value": {
7+
"type": "centPrecision",
8+
"currencyCode": "EUR",
9+
"centAmount": 1000,
10+
"fractionDigits": 2
11+
},
12+
"country": "DE",
13+
"customerGroup": {
14+
"typeId": "customer-group",
15+
"id": "cg-id-001",
16+
"obj": {
17+
"id": "cg-id-001",
18+
"version": 1,
19+
"key": "cg-key",
20+
"name": "VIP",
21+
"createdAt": "1970-01-01T00:00:00.001Z",
22+
"lastModifiedAt": "1970-01-01T00:00:00.001Z"
23+
}
24+
},
25+
"channel": {
26+
"typeId": "channel",
27+
"id": "channel-id-001",
28+
"obj": {
29+
"id": "channel-id-001",
30+
"version": 1,
31+
"key": "channel-key",
32+
"roles": [],
33+
"createdAt": "1970-01-01T00:00:00.001Z",
34+
"lastModifiedAt": "1970-01-01T00:00:00.001Z"
35+
}
36+
},
37+
"discounted": {
38+
"value": {
39+
"type": "centPrecision",
40+
"currencyCode": "EUR",
41+
"centAmount": 800,
42+
"fractionDigits": 2
43+
},
44+
"discount": {
45+
"typeId": "product-discount",
46+
"id": "discount-id-001",
47+
"obj": {
48+
"id": "discount-id-001",
49+
"version": 1,
50+
"key": "discount-key",
51+
"name": { "en": "10% off" },
52+
"isActive": true,
53+
"value": { "type": "relative", "permyriad": 1000 },
54+
"predicate": "1=1",
55+
"sortOrder": "0.5",
56+
"createdAt": "1970-01-01T00:00:00.001Z",
57+
"lastModifiedAt": "1970-01-01T00:00:00.001Z"
58+
}
59+
}
60+
},
61+
"active": true,
62+
"createdAt": "1970-01-01T00:00:00.001Z",
63+
"lastModifiedAt": "1970-01-01T00:00:00.001Z"
64+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "price-id-002",
3+
"version": 1,
4+
"key": "price-key-no-discount",
5+
"sku": "sku-002",
6+
"value": {
7+
"type": "centPrecision",
8+
"currencyCode": "USD",
9+
"centAmount": 2000,
10+
"fractionDigits": 2
11+
},
12+
"active": true,
13+
"createdAt": "1970-01-01T00:00:00.001Z",
14+
"lastModifiedAt": "1970-01-01T00:00:00.001Z"
15+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"id": "price-id-003",
3+
"version": 1,
4+
"key": "price-key-tiers",
5+
"sku": "sku-003",
6+
"value": {
7+
"type": "centPrecision",
8+
"currencyCode": "EUR",
9+
"centAmount": 1000,
10+
"fractionDigits": 2
11+
},
12+
"tiers": [
13+
{
14+
"minimumQuantity": 10,
15+
"value": {
16+
"type": "centPrecision",
17+
"currencyCode": "EUR",
18+
"centAmount": 900,
19+
"fractionDigits": 2
20+
}
21+
},
22+
{
23+
"minimumQuantity": 50,
24+
"value": {
25+
"type": "centPrecision",
26+
"currencyCode": "EUR",
27+
"centAmount": 800,
28+
"fractionDigits": 2
29+
}
30+
}
31+
],
32+
"active": true,
33+
"createdAt": "1970-01-01T00:00:00.001Z",
34+
"lastModifiedAt": "1970-01-01T00:00:00.001Z"
35+
}

0 commit comments

Comments
 (0)