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
15 changes: 15 additions & 0 deletions src/Models/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,24 @@ public class ChannelRequest : CustomDataBase
public ConfigOverridesRequest ConfigOverrides { get; set; }
}

public class ParsedPredefinedFilterResponse
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("filter")]
public Dictionary<string, object> Filter { get; set; }

[JsonProperty("sort", NullValueHandling = NullValueHandling.Ignore)]
public List<SortParameter> Sort { get; set; }
}

public class QueryChannelResponse : ApiResponse
{
public List<ChannelGetResponse> Channels { get; set; }

[JsonProperty("predefined_filter", NullValueHandling = NullValueHandling.Ignore)]
public ParsedPredefinedFilterResponse PredefinedFilter { get; set; }
}

public class QueryMembersResponse : ApiResponse
Expand Down
73 changes: 73 additions & 0 deletions tests/ParsedPredefinedFilterResponseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections.Generic;
using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework;
using StreamChat.Models;

namespace StreamChatTests
{
/// <summary>Tests for <see cref="ParsedPredefinedFilterResponse"/>.
/// </summary>
/// <remarks>
/// The tests follow arrange-act-assert pattern divided by empty lines.
/// Please make sure to follow the pattern to keep the consistency.
/// </remarks>
[TestFixture]
public class ParsedPredefinedFilterResponseTests
{
[Test]
public void TestDeserializePredefinedFilterResponse()
{
var json = @"{
""channels"": [],
""predefined_filter"": {
""name"": ""user_messaging"",
""filter"": {""type"": ""messaging"", ""members"": {""$in"": [""user123""]}},
""sort"": [{""Field"": ""last_message_at"", ""Direction"": -1}]
},
""duration"": ""0.01s""
}";

var response = JsonConvert.DeserializeObject<QueryChannelResponse>(json);

response.PredefinedFilter.Should().NotBeNull();
response.PredefinedFilter.Name.Should().Be("user_messaging");
response.PredefinedFilter.Filter.Should().NotBeNull();
response.PredefinedFilter.Filter["type"].Should().Be("messaging");
response.PredefinedFilter.Sort.Should().HaveCount(1);
response.PredefinedFilter.Sort[0].Field.Should().Be("last_message_at");
}

[Test]
public void TestDeserializeResponseWithoutPredefinedFilter()
{
var json = @"{
""channels"": [],
""duration"": ""0.01s""
}";

var response = JsonConvert.DeserializeObject<QueryChannelResponse>(json);

response.PredefinedFilter.Should().BeNull();
}

[Test]
public void TestDeserializePredefinedFilterWithoutSort()
{
var json = @"{
""channels"": [],
""predefined_filter"": {
""name"": ""simple_filter"",
""filter"": {""type"": ""messaging""}
},
""duration"": ""0.01s""
}";

var response = JsonConvert.DeserializeObject<QueryChannelResponse>(json);

response.PredefinedFilter.Should().NotBeNull();
response.PredefinedFilter.Name.Should().Be("simple_filter");
response.PredefinedFilter.Sort.Should().BeNull();
}
}
}
Loading