Get Person Count working correctly

Fix up some unit tests
This commit is contained in:
Amelia 2025-06-22 21:12:14 +02:00
parent 578c8b1e56
commit 8bc792e64a
5 changed files with 147 additions and 82 deletions

View file

@ -56,9 +56,9 @@ public class PersonRepositoryTests : AbstractDbTest
_restrictedAgeAccess.AgeRestriction = AgeRating.Teen;
_restrictedAgeAccess.AgeRestrictionIncludeUnknowns = true;
Context.Users.Add(_fullAccess);
Context.Users.Add(_restrictedAccess);
Context.Users.Add(_restrictedAgeAccess);
Context.AppUser.Add(_fullAccess);
Context.AppUser.Add(_restrictedAccess);
Context.AppUser.Add(_restrictedAgeAccess);
await Context.SaveChangesAsync();
Context.Person.AddRange(AllPeople);
@ -129,10 +129,10 @@ public class PersonRepositoryTests : AbstractDbTest
.WithPerson(Lib1ChaptersPerson, PersonRole.Team)
.Build())
.WithChapter(new ChapterBuilder("2")
.WithPerson(SharedSeriesChaptersPerson, PersonRole.Team)
.WithPerson(SharedChaptersPerson, PersonRole.Team)
.WithPerson(Lib1SeriesChaptersPerson, PersonRole.Team)
.WithPerson(Lib1ChaptersPerson, PersonRole.Team)
.WithPerson(SharedSeriesChaptersPerson, PersonRole.Translator)
.WithPerson(SharedChaptersPerson, PersonRole.Translator)
.WithPerson(Lib1SeriesChaptersPerson, PersonRole.Translator)
.WithPerson(Lib1ChaptersPerson, PersonRole.Translator)
.Build())
.Build())
.Build())
@ -186,19 +186,18 @@ public class PersonRepositoryTests : AbstractDbTest
Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(Lib1ChaptersPerson));
Assert.Contains(restrictedAccessPeople, ContainsPersonCheck(Lib1ChapterAgePerson));
// Count is not working when restricted
//Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).SeriesCount);
//Assert.Equal(4, restrictedAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).ChapterCount);
//Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == Lib1SeriesPerson.Id).SeriesCount);
Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).SeriesCount);
Assert.Equal(4, restrictedAccessPeople.First(dto => dto.Id == SharedSeriesChaptersPerson.Id).ChapterCount);
Assert.Equal(2, restrictedAccessPeople.First(dto => dto.Id == Lib1SeriesPerson.Id).SeriesCount);
// Fails because of the chapter - series issue
/*var restrictedAgeAccessPeople = await UnitOfWork.PersonRepository.GetBrowsePersonDtos(_restrictedAgeAccess.Id,
var restrictedAgeAccessPeople = await UnitOfWork.PersonRepository.GetBrowsePersonDtos(_restrictedAgeAccess.Id,
new BrowsePersonFilterDto(), new UserParams());
Assert.Equal(0, restrictedAgeAccessPeople.TotalCount);
// Note: There is a potential bug here where a person in a different chapter of an age restricted series will show up
Assert.Equal(6, restrictedAgeAccessPeople.TotalCount);
foreach (var person in AllPeople) Assert.DoesNotContain(fullAccessPeople, ContainsPersonCheck(person));*/
Assert.DoesNotContain(restrictedAgeAccessPeople, ContainsPersonCheck(Lib1ChapterAgePerson));
}
[Fact]
@ -210,16 +209,16 @@ public class PersonRepositoryTests : AbstractDbTest
var sharedSeriesRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(SharedSeriesPerson.Id, _fullAccess.Id);
var chapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(SharedChaptersPerson.Id, _fullAccess.Id);
var ageChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(Lib1ChapterAgePerson.Id, _fullAccess.Id);
Assert.Equal(2, sharedSeriesRoles.Count());
Assert.Equal(4, chapterRoles.Count());
Assert.Equal(3, sharedSeriesRoles.Count());
Assert.Equal(6, chapterRoles.Count());
Assert.Single(ageChapterRoles);
var restrictedRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(SharedSeriesPerson.Id, _restrictedAccess.Id);
var restrictedChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(SharedChaptersPerson.Id, _restrictedAccess.Id);
var restrictedAgePersonChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(Lib1ChapterAgePerson.Id, _restrictedAccess.Id);
Assert.Single(restrictedRoles);
Assert.Equal(2, restrictedChapterRoles.Count());
Assert.Equal(2, restrictedRoles.Count());
Assert.Equal(4, restrictedChapterRoles.Count());
Assert.Single(restrictedAgePersonChapterRoles);
var restrictedAgeRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(SharedSeriesPerson.Id, _restrictedAgeAccess.Id);
@ -227,8 +226,7 @@ public class PersonRepositoryTests : AbstractDbTest
var restrictedAgeAgePersonChapterRoles = await UnitOfWork.PersonRepository.GetRolesForPersonByName(Lib1ChapterAgePerson.Id, _restrictedAgeAccess.Id);
Assert.Single(restrictedAgeRoles);
Assert.Equal(2, restrictedAgeChapterRoles.Count());
// This works because both series & chapter have the correct age rating. The series-chapter issue is possible here
// Just not int he example I worked out in this scenario
// Note: There is a potential bug here where a person in a different chapter of an age restricted series will show up
Assert.Empty(restrictedAgeAgePersonChapterRoles);
}
@ -247,10 +245,9 @@ public class PersonRepositoryTests : AbstractDbTest
Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName(SharedSeriesPerson.Name, _restrictedAccess.Id));
Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName(Lib1SeriesPerson.Name, _restrictedAccess.Id));
// NOTE: The commend out Asserts fail because the chapter - series issue
Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName(Lib0ChaptersPerson.Name, _restrictedAgeAccess.Id));
//Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName(SharedSeriesPerson.Name, _restrictedAgeAccess.Id));
//Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName(Lib1SeriesPerson.Name, _restrictedAgeAccess.Id));
Assert.NotNull(await UnitOfWork.PersonRepository.GetPersonDtoByName(Lib1SeriesPerson.Name, _restrictedAgeAccess.Id));
// Note: There is a potential bug here where a person in a different chapter of an age restricted series will show up
Assert.Null(await UnitOfWork.PersonRepository.GetPersonDtoByName(Lib1ChapterAgePerson.Name, _restrictedAgeAccess.Id));
}
@ -293,14 +290,14 @@ public class PersonRepositoryTests : AbstractDbTest
restrictedAgeChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(SharedChaptersPerson.Id, _restrictedAgeAccess.Id, PersonRole.Imprint);
Assert.Single(chapters);
Assert.Single(restrictedChapters);
//Assert.Empty(restrictedAgeChapters); This passed because of the series-chapter issue. The user cannot see the series, but can see this chapter
Assert.Empty(restrictedAgeChapters);
// Lib1 - not age restricted
chapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(SharedChaptersPerson.Id, _fullAccess.Id, PersonRole.Team);
restrictedChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(SharedChaptersPerson.Id, _restrictedAccess.Id, PersonRole.Team);
restrictedAgeChapters = await UnitOfWork.PersonRepository.GetChaptersForPersonByRole(SharedChaptersPerson.Id, _restrictedAgeAccess.Id, PersonRole.Team);
Assert.Equal(2, chapters.Count());
Assert.Equal(2, restrictedChapters.Count());
Assert.Equal(2, restrictedAgeChapters.Count());
Assert.Single(chapters);
Assert.Single(restrictedChapters);
Assert.Single(restrictedAgeChapters);
}
}