Skip to content

Commit

Permalink
Fixed up a broken unit test. For People restriction, IncludeUnknowns …
Browse files Browse the repository at this point in the history
…doesn't really do much.
  • Loading branch information
majora2007 committed Dec 8, 2024
1 parent e41eddb commit 3b5189c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions API.Tests/Extensions/QueryableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ public void RestrictAgainstAgeRestriction_Tag_ShouldRestrictEverythingAboveTeen(

[Theory]
[InlineData(true, 2)]
[InlineData(false, 1)]
public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedCount)
[InlineData(false, 2)]
public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedPeopleCount)
{
// Arrange
var items = new List<Person>
{
CreatePersonWithSeriesMetadata("Test1", AgeRating.Teen),
CreatePersonWithSeriesMetadata("Test2", AgeRating.Unknown, AgeRating.Teen),
CreatePersonWithSeriesMetadata("Test2", AgeRating.Unknown, AgeRating.Teen), // 2 series on this person, restrict will still allow access
CreatePersonWithSeriesMetadata("Test3", AgeRating.X18Plus)
};

Expand All @@ -144,7 +144,7 @@ public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTe
var filtered = items.AsQueryable().RestrictAgainstAgeRestriction(ageRestriction);

// Assert
Assert.Equal(expectedCount, filtered.Count());
Assert.Equal(expectedPeopleCount, filtered.Count());
}

private static Person CreatePersonWithSeriesMetadata(string name, params AgeRating[] ageRatings)
Expand Down
7 changes: 4 additions & 3 deletions API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ public static IQueryable<Person> RestrictAgainstAgeRestriction(this IQueryable<P

if (restriction.IncludeUnknowns)
{
return queryable.Where(c => c.SeriesMetadataPeople.All(sm =>
sm.SeriesMetadata.AgeRating <= restriction.AgeRating));
return queryable.Where(c =>
c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating) ||
c.ChapterPeople.Any(cp => cp.Chapter.AgeRating <= restriction.AgeRating));
}

return queryable.Where(c =>
c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating && sm.SeriesMetadata.AgeRating != AgeRating.Unknown) &&
c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating && sm.SeriesMetadata.AgeRating != AgeRating.Unknown) ||
c.ChapterPeople.Any(cp => cp.Chapter.AgeRating <= restriction.AgeRating && cp.Chapter.AgeRating != AgeRating.Unknown)
);
}
Expand Down

0 comments on commit 3b5189c

Please sign in to comment.