-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(featured): encode onlyFeatured only if the user specifies it
Neos' Cloud will only do filtering on the "featured" state of a world IF the search parameters include it. Json serialization was including it because CloudX does not implement SearchParameters.OnlyFeatured as a nullable type. Our custom extension of this, resolves this problem. fixes #192
- Loading branch information
GuVAnj8Gv3RJ
committed
Sep 3, 2023
1 parent
67ad6d0
commit aa79209
Showing
5 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 11 additions & 4 deletions
15
AccountDownloaderLibrary/Implementations/PaginatedRecordSearch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
AccountDownloaderLibrary/Models/AccountDownloaderSearchParameters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using CloudX.Shared; | ||
using Newtonsoft.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AccountDownloaderLibrary.Models; | ||
|
||
/** | ||
* CloudX will filter on OnlyFeatured defaulting it to false, even if the user hasn't specified their preference. | ||
* | ||
* This is rather silly. So we extend the class and re-define it as a nullable. This allows it to be ignored when sent to the cloud. | ||
* | ||
* We'll have to log this as a bug for Neos to fix in CloudX too. | ||
*/ | ||
|
||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | ||
public class AccountDownloaderSearchParameters : SearchParameters | ||
{ | ||
[JsonProperty(PropertyName = "onlyFeatured", NullValueHandling = NullValueHandling.Ignore)] | ||
[JsonPropertyName("onlyFeatured")] | ||
public new bool? OnlyFeatured { get; set; } = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using AccountDownloaderLibrary.Models; | ||
using Newtonsoft.Json; | ||
|
||
namespace AcountDownloaderLibrary.Tests; | ||
|
||
|
||
[TestClass] | ||
public class SearchParameterTests | ||
{ | ||
[TestMethod] | ||
public void TestFeaturedNullNewtonSoft() | ||
{ | ||
var ap = new AccountDownloaderSearchParameters(); | ||
|
||
ap.OnlyFeatured = null; | ||
|
||
var jsonA = JsonConvert.SerializeObject(ap); | ||
var deSerialize = JsonConvert.DeserializeObject<AccountDownloaderSearchParameters>(jsonA); | ||
|
||
Assert.IsNull(deSerialize?.OnlyFeatured, "OnlyFeatured should only be present if the user included it"); | ||
|
||
ap.OnlyFeatured = false; | ||
jsonA = JsonConvert.SerializeObject(ap); | ||
|
||
deSerialize = JsonConvert.DeserializeObject<AccountDownloaderSearchParameters>(jsonA); | ||
|
||
Assert.IsFalse(deSerialize?.OnlyFeatured, "OnlyFeatured was included and should be false"); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public void TestFeaturedNullNET() | ||
{ | ||
var ap = new AccountDownloaderSearchParameters(); | ||
|
||
ap.OnlyFeatured = null; | ||
|
||
var jsonA = System.Text.Json.JsonSerializer.Serialize(ap); | ||
var deSerialize = System.Text.Json.JsonSerializer.Deserialize<AccountDownloaderSearchParameters>(jsonA); | ||
|
||
Assert.IsNull(deSerialize?.OnlyFeatured, "OnlyFeatured should only be present if the user included it"); | ||
|
||
ap.OnlyFeatured = false; | ||
jsonA = JsonConvert.SerializeObject(ap); | ||
|
||
deSerialize = JsonConvert.DeserializeObject<AccountDownloaderSearchParameters>(jsonA); | ||
|
||
Assert.IsFalse(deSerialize?.OnlyFeatured, "OnlyFeatured was included and should be false"); | ||
|
||
} | ||
} |