Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 additions & 0 deletions src/Constructorio_NET.Tests/client/modules/RecommendationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,38 @@ public async Task GetRecommendationsResultsWithPreFilterExpression()
Assert.IsNotNull(res.Request["pre_filter_expression"], "PreFilterExpression was passed as parameter");
}

[Test]
public async Task GetRecommendationsResultsShouldReturnResultWithHiddenFields()
{
string requestedHiddenField = "testField";
RecommendationsRequest req = new RecommendationsRequest("item_page_1")
{
UserInfo = this.UserInfo,
ItemIds = new List<string> { "power_drill" },
FmtOptions = new FmtOptions { HiddenFields = new List<string> { requestedHiddenField } }
};
ConstructorIO constructorio = new ConstructorIO(this.Config);
RecommendationsResponse res = await constructorio.Recommendations.GetRecommendationsResults(req);

Assert.NotNull(res.ResultId, "Result id exists");

// If we received at least one result, verify that the requested hidden field
// is present in the metadata of the first result.
if (res.Response.Results.Count > 0)
{
var metadata = res.Response.Results[0].Data?.Metadata;
Assert.IsNotNull(metadata, "Result metadata exists");
Assert.IsTrue(
metadata.ContainsKey(requestedHiddenField),
"Requested hidden field is present in result metadata"
);
Assert.IsNotNull(
metadata[requestedHiddenField],
"Requested hidden field has a non-null value in result metadata"
);
}
}

[Test]
public async Task GetRecommendationsResultsWithPreFilterExpressionJson()
{
Expand Down
6 changes: 4 additions & 2 deletions src/Constructorio_NET.Tests/client/modules/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public async Task GetSearchResultsShouldReturnResultWithVaritionsSlice()
SearchRequest req = new SearchRequest("item1") { UserInfo = this.UserInfo };
ConstructorIO constructorio = new ConstructorIO(this.Config);
SearchResponse res = await constructorio.Search.GetSearchResults(req);
string sliceAttribute = res.Response.Results[0].VariationSlice["Color"][0];

Assert.AreEqual("Blue", sliceAttribute);
Assert.IsNotNull(res.Response.Results[0].VariationSlice, "VariationSlice should exist");
Assert.IsTrue(res.Response.Results[0].VariationSlice.ContainsKey("Color"), "VariationSlice should contain Color key");
Assert.Greater(res.Response.Results[0].VariationSlice["Color"].Count, 0, "Color slice should have at least one value");
Assert.IsNotEmpty(res.Response.Results[0].VariationSlice["Color"][0], "Color slice value should not be empty");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ public void GetRequestParametersWithVariationIds()
Assert.AreEqual(this.VariationIds, requestParameters["variation_id"]);
}

[Test]
public void GetRequestParametersWithFmtOptions()
{
RecommendationsRequest req = new RecommendationsRequest(this.Pod)
{
UserInfo = this.UserInfo,
FmtOptions = new FmtOptions
{
HiddenFields = new List<string> { "inventory" },
},
};

Hashtable requestParameters = req.GetRequestParameters();
List<string> hiddenFields = (List<string>)requestParameters[$"{Constants.FMT_OPTIONS}[{Constants.HIDDEN_FIELDS}]"];
Assert.AreEqual(new List<string> { "inventory" }, hiddenFields);
}

[Test]
public void RecommendationsRequestWithInvalidPod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public RecommendationsRequest(string podId)
/// </summary>
public PreFilterExpression PreFilterExpression { get; set; }

/// <summary>
/// Gets or sets format options to control result formatting.
/// </summary>
public FmtOptions FmtOptions { get; set; }

/// <summary>
/// Get request parameters.
/// </summary>
Expand Down Expand Up @@ -158,6 +163,14 @@ public Hashtable GetRequestParameters()
parameters.Add(Constants.PRE_FILTER_EXPRESSION, preFilterJson);
}

if (this.FmtOptions != null)
{
foreach (DictionaryEntry entry in this.FmtOptions.GetQueryParameters())
{
parameters.Add(entry.Key, entry.Value);
}
}

return parameters;
}

Expand Down
Loading