-
Notifications
You must be signed in to change notification settings - Fork 4
[CDX-380] Add support for variationId param in RecommendationsRequest #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7c488f3
07c0301
1a46519
1a6c884
6a38c34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1811,6 +1811,17 @@ public String recommendationsAsJSON(RecommendationsRequest req, UserInfo userInf | |
| } | ||
| } | ||
|
|
||
| if (StringUtils.isNotBlank(req.getVariationId())) { | ||
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (req.getItemIds() == null || req.getItemIds().size() != 1) { | ||
| throw new IllegalArgumentException( | ||
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: The The integration tests correctly use More importantly: consider whether this validation belongs here (in |
||
| "variationId requires exactly one itemId to be specified"); | ||
| } | ||
| url = | ||
| url.newBuilder() | ||
| .addQueryParameter("variation_id", req.getVariationId()) | ||
| .build(); | ||
| } | ||
|
Comment on lines
+1814
to
+1823
|
||
|
|
||
| if (StringUtils.isNotBlank(req.getTerm())) { | ||
| url = url.newBuilder().addQueryParameter("term", req.getTerm()).build(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,43 @@ public void getRecommendationsShouldReturnAResultWithSingleItemId() throws Excep | |
| assertTrue("recommendation result id exists", response.getResultId() != null); | ||
| } | ||
|
|
||
| @Test | ||
| public void getRecommendationsShouldReturnAResultWithItemIdAndVariationId() throws Exception { | ||
| ConstructorIO constructor = new ConstructorIO("", apiKey, true, null); | ||
| UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie"); | ||
| RecommendationsRequest request = new RecommendationsRequest("item_page_1"); | ||
| request.setItemIds(Arrays.asList("power_drill")); | ||
| request.setVariationId("power_drill_variation"); | ||
| RecommendationsResponse response = constructor.recommendations(request, userInfo); | ||
| assertTrue("recommendation results exist", response.getResponse().getResults().size() >= 0); | ||
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important Issue: The assertion Consider asserting something more meaningful. For example, if a valid assertNotNull("recommendation response exists", response.getResponse());
assertNotNull("recommendation result id exists", response.getResultId()); |
||
| assertTrue("recommendation result id exists", response.getResultId() != null); | ||
|
Comment on lines
+39
to
+41
|
||
| } | ||
|
|
||
| @Test | ||
| public void getRecommendationsShouldErrorWithVariationIdAndNoItemIds() throws Exception { | ||
| ConstructorIO constructor = new ConstructorIO("", apiKey, true, null); | ||
| UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie"); | ||
| RecommendationsRequest request = new RecommendationsRequest("item_page_1"); | ||
| request.setVariationId("power_drill_variation"); | ||
|
|
||
| thrown.expect(ConstructorException.class); | ||
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The two error-case tests ( For completeness, consider also asserting on the cause: the wrapped thrown.expectCause(instanceOf(IllegalArgumentException.class));This is a minor suggestion and is not blocking. |
||
| thrown.expectMessage("variationId requires exactly one itemId to be specified"); | ||
| constructor.recommendations(request, userInfo); | ||
| } | ||
|
|
||
| @Test | ||
| public void getRecommendationsShouldErrorWithVariationIdAndMultipleItemIds() throws Exception { | ||
| ConstructorIO constructor = new ConstructorIO("", apiKey, true, null); | ||
| UserInfo userInfo = new UserInfo(3, "c62a-2a09-faie"); | ||
| RecommendationsRequest request = new RecommendationsRequest("item_page_1"); | ||
| request.setItemIds(Arrays.asList("power_drill", "drill")); | ||
| request.setVariationId("power_drill_variation"); | ||
|
|
||
| thrown.expect(ConstructorException.class); | ||
| thrown.expectMessage("variationId requires exactly one itemId to be specified"); | ||
| constructor.recommendations(request, userInfo); | ||
| } | ||
|
|
||
| @Test | ||
| public void getRecommendationsShouldReturnAResultWithMultipleItemIds() throws Exception { | ||
| ConstructorIO constructor = new ConstructorIO("", apiKey, true, null); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ public void newShouldReturnDefaultProperties() throws Exception { | |
| assertEquals(request.getPodId(), podId); | ||
| assertEquals(request.getNumResults(), 10); | ||
| assertNull(request.getItemIds()); | ||
| assertNull(request.getVariationId()); | ||
| assertNull(request.getTerm()); | ||
| assertEquals(request.getSection(), "Products"); | ||
| assertEquals(request.getFacets().size(), 0); | ||
|
|
@@ -54,6 +55,7 @@ public void settersShouldSet() throws Exception { | |
| request.setPodId("zero_results_1"); | ||
| request.setNumResults(3); | ||
| request.setItemIds(Arrays.asList("1", "2", "3")); | ||
| request.setVariationId("variation-1"); | ||
| request.setSection("Search Suggestions"); | ||
| request.setFacets(facets); | ||
| request.setTerm(term); | ||
|
|
@@ -62,6 +64,7 @@ public void settersShouldSet() throws Exception { | |
|
|
||
| assertEquals(request.getPodId(), "zero_results_1"); | ||
| assertEquals(request.getNumResults(), 3); | ||
| assertEquals(request.getVariationId(), "variation-1"); | ||
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
constructor-claude-bedrock[bot] marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The |
||
| assertEquals(request.getSection(), "Search Suggestions"); | ||
| assertEquals(request.getFacets(), facets); | ||
| assertEquals(request.getTerm(), term); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.