From 856c75852ea9d0f1936b5e5cfc250bbb686b9726 Mon Sep 17 00:00:00 2001 From: Mazin Date: Mon, 20 Oct 2025 19:34:42 +0200 Subject: [PATCH] feature: Add active flag to ConstructorItem and related test case --- .../constructor/client/ConstructorItem.java | 29 +++++++++++++++++++ .../client/ConstructorIOItemsTest.java | 22 ++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java b/constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java index 9212a2fc..894c9e93 100644 --- a/constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java +++ b/constructorio-client/src/main/java/io/constructor/client/ConstructorItem.java @@ -14,10 +14,29 @@ public class ConstructorItem { private String imageUrl; private String id; private String description; + private Boolean active = true; private Map> facets; private Map metadata; private List groupIds; + public ConstructorItem(String id, String name, Boolean active) throws IllegalArgumentException { + if (id == null) { + throw new IllegalArgumentException("id is required"); + } + + this.id = id; + this.name = name; + this.active = active; + this.suggestedScore = null; + this.keywords = null; + this.url = null; + this.imageUrl = null; + this.description = null; + this.facets = null; + this.metadata = null; + this.groupIds = null; + } + /** * Creates an item. Optional public fields are in the API documentation @@ -171,6 +190,16 @@ public void setDescription(String description) { this.description = description; } + /** + * @return the active + */ + public Boolean getActive() { return active; } + + /** + * @param active the active to set + */ + public void setActive(Boolean active) { this.active = active; } + /** * @return the id */ diff --git a/constructorio-client/src/test/java/io/constructor/client/ConstructorIOItemsTest.java b/constructorio-client/src/test/java/io/constructor/client/ConstructorIOItemsTest.java index bb21f24f..02ff9c16 100644 --- a/constructorio-client/src/test/java/io/constructor/client/ConstructorIOItemsTest.java +++ b/constructorio-client/src/test/java/io/constructor/client/ConstructorIOItemsTest.java @@ -64,6 +64,28 @@ public void createOrReplaceItemsShouldReturnAResponseWithAllParameters() throws addItemsToCleanUpArray(items); } + @Test + public void createOrReplaceItemsShouldRespectActiveFlag() throws Exception + { + ConstructorIO constructor = new ConstructorIO(token, apiKey, true, null); + + ConstructorItem item = Utils.createProductItem(); + item.setActive(true); + + constructor.createOrReplaceItems(new ConstructorItem[]{item}, "Products"); + + Thread.sleep(2000); + + ItemsRequest request = new ItemsRequest(); + request.setIds(Arrays.asList(item.getId())); + ItemsResponse response = constructor.retrieveItems(request); + + assertTrue("Item should exist", response.getTotalCount() >= 1); + assertTrue("Item should be active", response.getItems().get(0).getActive()); + + addItemsToCleanUpArray(new ConstructorItem[]{item}); + } + @Test public void updateItemsShouldReturnAResponse() throws Exception { ConstructorIO constructor = new ConstructorIO(token, apiKey, true, null);