Skip to content

Commit 856c758

Browse files
committed
feature: Add active flag to ConstructorItem and related test case
1 parent 83b0cef commit 856c758

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,29 @@ public class ConstructorItem {
1414
private String imageUrl;
1515
private String id;
1616
private String description;
17+
private Boolean active = true;
1718
private Map<String, List<Object>> facets;
1819
private Map<String, Object> metadata;
1920
private List<String> groupIds;
2021

22+
public ConstructorItem(String id, String name, Boolean active) throws IllegalArgumentException {
23+
if (id == null) {
24+
throw new IllegalArgumentException("id is required");
25+
}
26+
27+
this.id = id;
28+
this.name = name;
29+
this.active = active;
30+
this.suggestedScore = null;
31+
this.keywords = null;
32+
this.url = null;
33+
this.imageUrl = null;
34+
this.description = null;
35+
this.facets = null;
36+
this.metadata = null;
37+
this.groupIds = null;
38+
}
39+
2140
/**
2241
* Creates an item. Optional public fields are in the <a
2342
* href="https://docs.constructor.com/reference/catalog-items">API documentation</a>
@@ -171,6 +190,16 @@ public void setDescription(String description) {
171190
this.description = description;
172191
}
173192

193+
/**
194+
* @return the active
195+
*/
196+
public Boolean getActive() { return active; }
197+
198+
/**
199+
* @param active the active to set
200+
*/
201+
public void setActive(Boolean active) { this.active = active; }
202+
174203
/**
175204
* @return the id
176205
*/

constructorio-client/src/test/java/io/constructor/client/ConstructorIOItemsTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ public void createOrReplaceItemsShouldReturnAResponseWithAllParameters() throws
6464
addItemsToCleanUpArray(items);
6565
}
6666

67+
@Test
68+
public void createOrReplaceItemsShouldRespectActiveFlag() throws Exception
69+
{
70+
ConstructorIO constructor = new ConstructorIO(token, apiKey, true, null);
71+
72+
ConstructorItem item = Utils.createProductItem();
73+
item.setActive(true);
74+
75+
constructor.createOrReplaceItems(new ConstructorItem[]{item}, "Products");
76+
77+
Thread.sleep(2000);
78+
79+
ItemsRequest request = new ItemsRequest();
80+
request.setIds(Arrays.asList(item.getId()));
81+
ItemsResponse response = constructor.retrieveItems(request);
82+
83+
assertTrue("Item should exist", response.getTotalCount() >= 1);
84+
assertTrue("Item should be active", response.getItems().get(0).getActive());
85+
86+
addItemsToCleanUpArray(new ConstructorItem[]{item});
87+
}
88+
6789
@Test
6890
public void updateItemsShouldReturnAResponse() throws Exception {
6991
ConstructorIO constructor = new ConstructorIO(token, apiKey, true, null);

0 commit comments

Comments
 (0)