Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ConstructorItem {
private String imageUrl;
private String id;
private String description;
private Boolean active;
private Map<String, List<Object>> facets;
private Map<String, Object> metadata;
private List<String> groupIds;
Expand All @@ -37,6 +38,7 @@ public ConstructorItem(String id, String name) throws IllegalArgumentException {
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand All @@ -54,6 +56,7 @@ public ConstructorItem(String id) throws IllegalArgumentException {
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand Down Expand Up @@ -82,6 +85,7 @@ public Map<String, Object> toMap() {
dataMap.put("facets", this.facets);
dataMap.put("group_ids", this.groupIds);
dataMap.put("description", this.description);
dataMap.put("active", this.active);
params.put("data", dataMap);

return params;
Expand Down Expand Up @@ -171,6 +175,20 @@ public void setDescription(String description) {
this.description = description;
}

/**
* @return the active status of the item
*/
public Boolean getActive() {
return active;
}

/**
* @param active the active status to set for the item
*/
public void setActive(Boolean active) {
this.active = active;
}

/**
* @return the id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class ConstructorVariation {
private String id;
private String itemId;
private String description;
private Boolean active;
private Map<String, List<Object>> facets;
private Map<String, Object> metadata;
private List<String> groupIds;

/**
* Creates a variation. Optional public fields are in the <a
* href="https://docs.constructor.com/docs/integrating-with-constructor-product-catalog-items-variations">API documentation</a>
* href="https://docs.constructor.com/docs/integrating-with-constructor-product-catalog-items-variations">API
* documentation</a>
*
* @param id the id of the variation that you are adding.
* @param itemId the id of the item this variation is attached to.
Expand All @@ -45,6 +47,7 @@ public ConstructorVariation(String id, String itemId, String name)
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand All @@ -67,6 +70,7 @@ public ConstructorVariation(String id, String itemId) throws IllegalArgumentExce
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand All @@ -85,6 +89,7 @@ public ConstructorVariation(String id) throws IllegalArgumentException {
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand Down Expand Up @@ -114,6 +119,7 @@ public Map<String, Object> toMap() {
dataMap.put("facets", this.facets);
dataMap.put("group_ids", this.groupIds);
dataMap.put("description", this.description);
dataMap.put("active", this.active);
params.put("data", dataMap);

return params;
Expand Down Expand Up @@ -203,6 +209,20 @@ public void setDescription(String description) {
this.description = description;
}

/**
* @return the active status of the variation
*/
public Boolean getActive() {
return active;
}

/**
* @param active the active status to set for the variation
*/
public void setActive(Boolean active) {
this.active = active;
}

/**
* @return the id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void newShouldReturnDefaultProperties() throws Exception {
assertEquals(item.getUrl(), null);
assertEquals(item.getImageUrl(), null);
assertEquals(item.getDescription(), null);
assertEquals(item.getActive(), null);
assertEquals(item.getId(), itemName);
assertEquals(item.getFacets(), null);
assertEquals(item.getGroupIds(), null);
Expand All @@ -60,6 +61,7 @@ public void settersShouldSet() throws Exception {
item.setUrl("https://constructor.io/test");
item.setImageUrl("https://constructor.io/test.png");
item.setDescription("See the world!");
item.setActive(true);
item.setId("TICK-007");
item.setGroupIds(Arrays.asList("Lucky Tickets", "Special Tickets", "Fancy Tickets"));

Expand All @@ -69,6 +71,7 @@ public void settersShouldSet() throws Exception {
assertEquals(item.getUrl(), "https://constructor.io/test");
assertEquals(item.getImageUrl(), "https://constructor.io/test.png");
assertEquals(item.getDescription(), "See the world!");
assertEquals(item.getActive(), true);
assertEquals(item.getId(), "TICK-007");
assertEquals(item.getFacets(), null);
assertEquals(item.getMetadata(), null);
Expand Down Expand Up @@ -97,4 +100,25 @@ public void toMapShouldHaveADataObject() throws Exception {
assertEquals(metadataFields.get("image_url"), "https://constructor.io/test.png");
assertEquals(metadataFields.get("test_field"), "test");
}

@Test
public void toMapShouldIncludeActiveWhenSet() throws Exception {
String itemName = this.getRandomProductName();
String itemId = itemName;
ConstructorItem item = new ConstructorItem(itemId, itemName);
item.setActive(true);

Map<String, Object> dataFields = (Map<String, Object>) item.toMap().get("data");
assertEquals(dataFields.get("active"), true);
}

@Test
public void toMapShouldIncludeActiveAsNullWhenNotSet() throws Exception {
String itemName = this.getRandomProductName();
String itemId = itemName;
ConstructorItem item = new ConstructorItem(itemId, itemName);

Map<String, Object> dataFields = (Map<String, Object>) item.toMap().get("data");
assertEquals(dataFields.get("active"), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void newShouldReturnDefaultProperties() throws Exception {
assertEquals(variation.getUrl(), null);
assertEquals(variation.getImageUrl(), null);
assertEquals(variation.getDescription(), null);
assertEquals(variation.getActive(), null);
assertEquals(variation.getId(), variationName);
assertEquals(variation.getItemId(), itemId);
assertEquals(variation.getFacets(), null);
Expand All @@ -67,6 +68,7 @@ public void settersShouldSet() throws Exception {
variation.setUrl("https://constructor.io/test");
variation.setImageUrl("https://constructor.io/test.png");
variation.setDescription("See the world!");
variation.setActive(false);
variation.setId("TICK-007");
variation.setItemId("TICK");
variation.setGroupIds(Arrays.asList("Lucky Tickets", "Special Tickets", "Fancy Tickets"));
Expand All @@ -77,6 +79,7 @@ public void settersShouldSet() throws Exception {
assertEquals(variation.getUrl(), "https://constructor.io/test");
assertEquals(variation.getImageUrl(), "https://constructor.io/test.png");
assertEquals(variation.getDescription(), "See the world!");
assertEquals(variation.getActive(), false);
assertEquals(variation.getId(), "TICK-007");
assertEquals(variation.getItemId(), "TICK");
assertEquals(variation.getFacets(), null);
Expand Down Expand Up @@ -108,4 +111,27 @@ public void toMapShouldHaveADataObject() throws Exception {
assertEquals(metadataFields.get("image_url"), "https://constructor.io/test.png");
assertEquals(metadataFields.get("test_field"), "test");
}

@Test
public void toMapShouldIncludeActiveWhenSet() throws Exception {
String variationName = this.getRandomProductName();
String itemId = this.getRandomProductName();
ConstructorVariation variation =
new ConstructorVariation(variationName, itemId, variationName);
variation.setActive(false);

Map<String, Object> dataFields = (Map<String, Object>) variation.toMap().get("data");
assertEquals(dataFields.get("active"), false);
}

@Test
public void toMapShouldIncludeActiveAsNullWhenNotSet() throws Exception {
String variationName = this.getRandomProductName();
String itemId = this.getRandomProductName();
ConstructorVariation variation =
new ConstructorVariation(variationName, itemId, variationName);

Map<String, Object> dataFields = (Map<String, Object>) variation.toMap().get("data");
assertEquals(dataFields.get("active"), null);
}
}
Loading