diff --git a/src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs b/src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs index 4661a5bdda..0a1ff48ca0 100644 --- a/src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs +++ b/src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs @@ -82,13 +82,11 @@ public class QueryLayerComposer : IQueryLayerComposer ExpressionInScope[] constraints = _constraintProviders.SelectMany(provider => provider.GetConstraints()).ToArray(); - var secondaryScope = new ResourceFieldChainExpression(hasManyRelationship); - // @formatter:wrap_chained_method_calls chop_always // @formatter:keep_existing_linebreaks true FilterExpression[] filtersInSecondaryScope = constraints - .Where(constraint => secondaryScope.Equals(constraint.Scope)) + .Where(constraint => constraint.Scope == null) .Select(constraint => constraint.Expression) .OfType() .ToArray(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/SupportTicket.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/SupportTicket.cs index 619542ad6d..9ce245e951 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/SupportTicket.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/SupportTicket.cs @@ -10,4 +10,7 @@ public sealed class SupportTicket : Identifiable { [Attr] public string Description { get; set; } = null!; + + [HasOne] + public ProductFamily? ProductFamily { get; set; } } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs index f9639c99bc..53d6841b10 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs @@ -32,19 +32,51 @@ public TopLevelCountTests(IntegrationTestContext, } [Fact] - public async Task Renders_resource_count_for_collection() + public async Task Renders_resource_count_for_primary_resources_endpoint_with_filter() { // Arrange - SupportTicket ticket = _fakers.SupportTicket.Generate(); + List tickets = _fakers.SupportTicket.Generate(2); + + tickets[1].Description = "Update firmware version"; await _testContext.RunOnDatabaseAsync(async dbContext => { await dbContext.ClearTableAsync(); - dbContext.SupportTickets.Add(ticket); + dbContext.SupportTickets.AddRange(tickets); await dbContext.SaveChangesAsync(); }); - const string route = "/supportTickets"; + const string route = "/supportTickets?filter=startsWith(description,'Update ')"; + + // Act + (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync(route); + + // Assert + httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK); + + responseDocument.Meta.ShouldContainKey("total").With(value => + { + JsonElement element = value.Should().BeOfType().Subject; + element.GetInt32().Should().Be(1); + }); + } + + [Fact] + public async Task Renders_resource_count_for_secondary_resources_endpoint_with_filter() + { + // Arrange + ProductFamily family = _fakers.ProductFamily.Generate(); + family.Tickets = _fakers.SupportTicket.Generate(2); + + family.Tickets[1].Description = "Update firmware version"; + + await _testContext.RunOnDatabaseAsync(async dbContext => + { + dbContext.ProductFamilies.Add(family); + await dbContext.SaveChangesAsync(); + }); + + string route = $"/productFamilies/{family.StringId}/tickets?filter=contains(description,'firmware')"; // Act (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync(route);