Chapter/Issue level Reviews and Ratings (#3778)
Co-authored-by: Joseph Milazzo <josephmajora@gmail.com>
This commit is contained in:
parent
3b8997e46e
commit
4f7625ea77
60 changed files with 5097 additions and 497 deletions
|
@ -590,164 +590,6 @@ public class SeriesServiceTests : AbstractDbTest
|
|||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region UpdateRating
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateRating_ShouldSetRating()
|
||||
{
|
||||
await ResetDb();
|
||||
|
||||
_context.Library.Add(new LibraryBuilder("Test LIb")
|
||||
.WithAppUser(new AppUserBuilder("majora2007", string.Empty).Build())
|
||||
.WithSeries(new SeriesBuilder("Test")
|
||||
|
||||
.WithVolume(new VolumeBuilder("1")
|
||||
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
|
||||
.Build())
|
||||
.Build())
|
||||
.Build());
|
||||
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings);
|
||||
|
||||
JobStorage.Current = new InMemoryStorage();
|
||||
var result = await _seriesService.UpdateRating(user, new UpdateSeriesRatingDto
|
||||
{
|
||||
SeriesId = 1,
|
||||
UserRating = 3,
|
||||
});
|
||||
|
||||
Assert.True(result);
|
||||
|
||||
var ratings = (await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings))!
|
||||
.Ratings;
|
||||
Assert.NotEmpty(ratings);
|
||||
Assert.Equal(3, ratings.First().Rating);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateRating_ShouldUpdateExistingRating()
|
||||
{
|
||||
await ResetDb();
|
||||
|
||||
_context.Library.Add(new LibraryBuilder("Test LIb")
|
||||
.WithAppUser(new AppUserBuilder("majora2007", string.Empty).Build())
|
||||
.WithSeries(new SeriesBuilder("Test")
|
||||
|
||||
.WithVolume(new VolumeBuilder("1")
|
||||
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
|
||||
.Build())
|
||||
.Build())
|
||||
.Build());
|
||||
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings);
|
||||
|
||||
var result = await _seriesService.UpdateRating(user, new UpdateSeriesRatingDto
|
||||
{
|
||||
SeriesId = 1,
|
||||
UserRating = 3,
|
||||
});
|
||||
|
||||
Assert.True(result);
|
||||
|
||||
JobStorage.Current = new InMemoryStorage();
|
||||
var ratings = (await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings))
|
||||
.Ratings;
|
||||
Assert.NotEmpty(ratings);
|
||||
Assert.Equal(3, ratings.First().Rating);
|
||||
|
||||
// Update the DB again
|
||||
|
||||
var result2 = await _seriesService.UpdateRating(user, new UpdateSeriesRatingDto
|
||||
{
|
||||
SeriesId = 1,
|
||||
UserRating = 5,
|
||||
});
|
||||
|
||||
Assert.True(result2);
|
||||
|
||||
var ratings2 = (await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings))
|
||||
.Ratings;
|
||||
Assert.NotEmpty(ratings2);
|
||||
Assert.True(ratings2.Count == 1);
|
||||
Assert.Equal(5, ratings2.First().Rating);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateRating_ShouldClampRatingAt5()
|
||||
{
|
||||
await ResetDb();
|
||||
|
||||
_context.Library.Add(new LibraryBuilder("Test LIb")
|
||||
.WithAppUser(new AppUserBuilder("majora2007", string.Empty).Build())
|
||||
.WithSeries(new SeriesBuilder("Test")
|
||||
|
||||
.WithVolume(new VolumeBuilder("1")
|
||||
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
|
||||
.Build())
|
||||
.Build())
|
||||
.Build());
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings);
|
||||
|
||||
var result = await _seriesService.UpdateRating(user, new UpdateSeriesRatingDto
|
||||
{
|
||||
SeriesId = 1,
|
||||
UserRating = 10,
|
||||
});
|
||||
|
||||
Assert.True(result);
|
||||
|
||||
JobStorage.Current = new InMemoryStorage();
|
||||
var ratings = (await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007",
|
||||
AppUserIncludes.Ratings)!)
|
||||
.Ratings;
|
||||
Assert.NotEmpty(ratings);
|
||||
Assert.Equal(5, ratings.First().Rating);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateRating_ShouldReturnFalseWhenSeriesDoesntExist()
|
||||
{
|
||||
await ResetDb();
|
||||
|
||||
_context.Library.Add(new LibraryBuilder("Test LIb", LibraryType.Book)
|
||||
.WithAppUser(new AppUserBuilder("majora2007", string.Empty).Build())
|
||||
.WithSeries(new SeriesBuilder("Test")
|
||||
|
||||
.WithVolume(new VolumeBuilder("1")
|
||||
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
|
||||
.Build())
|
||||
.Build())
|
||||
.Build());
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Ratings);
|
||||
|
||||
var result = await _seriesService.UpdateRating(user, new UpdateSeriesRatingDto
|
||||
{
|
||||
SeriesId = 2,
|
||||
UserRating = 5,
|
||||
});
|
||||
|
||||
Assert.False(result);
|
||||
|
||||
var ratings = user.Ratings;
|
||||
Assert.Empty(ratings);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UpdateSeriesMetadata
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue