Skip to content

Commit 97c29cd

Browse files
authored
[CI-4518] Expose is_slotted in Search/Browse API Responses (#159)
* expose is_slotted in Search/Browse responses * fix tests * lint
1 parent 4f0e309 commit 97c29cd

File tree

8 files changed

+53
-8
lines changed

8 files changed

+53
-8
lines changed

constructorio-client/src/main/java/io/constructor/client/models/Result.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class Result {
2222
@SerializedName("variations_map")
2323
private Object variationsMap;
2424

25+
@SerializedName("is_slotted")
26+
private boolean isSlotted;
27+
2528
@SerializedName("labels")
2629
private Map<String, Object> labels;
2730

@@ -77,6 +80,13 @@ public Map<String, String> getStrategy() {
7780
return strategy;
7881
}
7982

83+
/**
84+
* @return isSlotted boolean
85+
*/
86+
public boolean getIsSlotted() {
87+
return isSlotted;
88+
}
89+
8090
public void setValue(String value) {
8191
this.value = value;
8292
}
@@ -104,4 +114,8 @@ public void setLabels(Map<String, Object> labels) {
104114
public void setStrategy(Map<String, String> strategy) {
105115
this.strategy = strategy;
106116
}
117+
118+
public void setIsSlotted(boolean isSlotted) {
119+
this.isSlotted = isSlotted;
120+
}
107121
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,18 @@ public void createBrowseResponseShouldReturnAResultWithLabels() throws Exception
286286
.get("display_name"),
287287
"New Arrival");
288288
}
289+
290+
@Test
291+
public void createBrowseResponseShouldReturnAResultWithIsSlotted() throws Exception {
292+
String string = Utils.getTestResource("response.browse.color.blue.json");
293+
BrowseResponse response = ConstructorIO.createBrowseResponse(string);
294+
assertEquals(
295+
"search result [labels] exists",
296+
response.getResponse().getResults().get(0).getIsSlotted(),
297+
true);
298+
assertEquals(
299+
"search result [labels] exists",
300+
response.getResponse().getResults().get(1).getIsSlotted(),
301+
false);
302+
}
289303
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void autocompleteShouldReturnAResultWithOneFilter() throws Exception {
171171
public void autocompleteShouldReturnAResultWithMultipleFilters() throws Exception {
172172
ConstructorIO constructor = new ConstructorIO("", apiKey, true, null);
173173
UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie");
174-
AutocompleteRequest request = new AutocompleteRequest("item1");
174+
AutocompleteRequest request = new AutocompleteRequest("item2");
175175
request.getFilters().put("group_id", Arrays.asList("All"));
176176
request.getFilters().put("Brand", Arrays.asList("XYZ"));
177177
AutocompleteResponse response = constructor.autocomplete(request, userInfo);
@@ -224,7 +224,8 @@ public void AutocompleteShouldReturnAResultProvidedVariationsMapAsArray() throws
224224
variationsMap.addValueRule(
225225
"size", VariationsMap.AggregationTypes.first, "data.facets.size");
226226
variationsMap.setFilterBy(
227-
"{\"and\":[{\"not\":{\"field\":\"data.brand\",\"value\":\"Best Brand\"}}]}");
227+
"{\"and\":[{\"not\":{\"field\":\"data.brand\",\"type\":\"single\",\"value\":\"Best"
228+
+ " Brand\"},\"type\":\"not\"}],\"type\":\"and\"}");
228229
request.setVariationsMap(variationsMap);
229230
AutocompleteResponse response = constructor.autocomplete(request, userInfo);
230231

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ public void BrowseShouldReturnAResultProvidedVariationsMapAsArray() throws Excep
368368
variationsMap.addValueRule(
369369
"size", VariationsMap.AggregationTypes.first, "data.facets.size");
370370
variationsMap.setFilterBy(
371-
"{\"and\":[{\"not\":{\"field\":\"data.brand\",\"value\":\"Best Brand\"}}]}");
371+
"{\"and\":[{\"not\":{\"field\":\"data.brand\",\"type\":\"single\",\"value\":\"Best"
372+
+ " Brand\"},\"type\":\"not\"}],\"type\":\"and\"}");
372373
request.setVariationsMap(variationsMap);
373374
BrowseResponse response = constructor.browse(request, userInfo);
374375

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public void SearchShouldReturnAResultWithGroupId() throws Exception {
100100
public void SearchShouldReturnAResultWithColorFacets() throws Exception {
101101
ConstructorIO constructor = new ConstructorIO("", apiKey, true, null);
102102
UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie");
103-
SearchRequest request = new SearchRequest("item1");
104-
request.getFacets().put("Color", Arrays.asList("Blue"));
103+
SearchRequest request = new SearchRequest("item2");
104+
request.getFacets().put("Color", Arrays.asList("yellow"));
105105
SearchResponse response = constructor.search(request, userInfo);
106106
assertEquals("search results exist", response.getResponse().getResults().size(), 1);
107107
assertEquals(
@@ -359,7 +359,8 @@ public void SearchShouldReturnAResultProvidedVariationsMapAsArray() throws Excep
359359
variationsMap.addValueRule(
360360
"size", VariationsMap.AggregationTypes.first, "data.facets.size");
361361
variationsMap.setFilterBy(
362-
"{\"and\":[{\"not\":{\"field\":\"data.brand\",\"value\":\"Best Brand\"}}]}");
362+
"{\"and\":[{\"not\":{\"field\":\"data.brand\",\"type\":\"single\",\"value\":\"Best"
363+
+ " Brand\"},\"type\":\"not\"}],\"type\":\"and\"}");
363364
System.out.println(variationsMap.getFilterBy());
364365
request.setVariationsMap(variationsMap);
365366
SearchResponse response = constructor.search(request, userInfo);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void hierarchicalFacet() throws Exception {
6565
assertEquals(facet.getName(), "Size");
6666
assertEquals(facet.getType(), "hierarchical");
6767
assertEquals(facet.getOptions().get(0).getValue(), "Mens");
68-
assertEquals(facet.getOptions().get(0).getOptions().get(0), "Mens/Small");
68+
assertEquals(facet.getOptions().get(0).getOptions().get(0).getValue(), "Mens/Small");
6969
assertNull(facet.getMax());
7070
assertNull(facet.getMin());
7171
assertNull(facet.getStatus());

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,18 @@ public void createSearchResponseShouldReturnAResultWithLabels() throws Exception
262262
.get("display_name"),
263263
"New Arrival");
264264
}
265+
266+
@Test
267+
public void createSearchResponseShouldReturnAResultWithIsSlotted() throws Exception {
268+
String string = Utils.getTestResource("response.search.item.json");
269+
SearchResponse response = ConstructorIO.createSearchResponse(string);
270+
assertEquals(
271+
"search result [isSlotted] exists",
272+
response.getResponse().getResults().get(0).getIsSlotted(),
273+
true);
274+
assertEquals(
275+
"search result [isSlotted] exists",
276+
response.getResponse().getResults().get(1).getIsSlotted(),
277+
false);
278+
}
265279
}

constructorio-client/src/test/resources/response.browse.color.blue.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@
10511051
"url": "https://demo.commercetools.com/en/aspesi-coat-I502997385098-blue.html",
10521052
"variation_id": "M0E20000000ECTT"
10531053
},
1054-
"is_slotted": false,
1054+
"is_slotted": true,
10551055
"matched_terms": [],
10561056
"value": "Coat Aspesi blue",
10571057
"variations": [{

0 commit comments

Comments
 (0)