From 0617d71d6b75fdae1a7592d3bd1f090a9f77b4a4 Mon Sep 17 00:00:00 2001 From: Joe Milazzo Date: Tue, 14 Mar 2023 13:31:00 -0500 Subject: [PATCH] Fixed an issue where docker installs were trying to update wwwroot, when docker doesn't do reverse proxy stuff. (#1880) Fixed a bug in reading list date calculations. --- API.Tests/Services/ReadingListServiceTests.cs | 122 ++++++++++++++++++ API/Helpers/Builders/ChapterBuilder.cs | 9 +- API/Services/ReadingListService.cs | 2 +- API/Startup.cs | 1 + openapi.json | 4 +- 5 files changed, 134 insertions(+), 4 deletions(-) diff --git a/API.Tests/Services/ReadingListServiceTests.cs b/API.Tests/Services/ReadingListServiceTests.cs index d9f582719..b76aee059 100644 --- a/API.Tests/Services/ReadingListServiceTests.cs +++ b/API.Tests/Services/ReadingListServiceTests.cs @@ -631,6 +631,128 @@ public class ReadingListServiceTests #endregion + #region CalculateStartAndEndDates + + [Fact] + public async Task CalculateStartAndEndDates_ShouldBeNothing_IfNothing() + { + await ResetDb(); + var s = new SeriesBuilder("Test") + .WithMetadata(DbFactory.SeriesMetadata(new List())) + .WithVolumes(new List() + { + new VolumeBuilder("0") + .WithChapter(new ChapterBuilder("1") + .Build() + ) + .WithChapter(new ChapterBuilder("2") + .Build() + ) + .Build() + }) + .Build(); + _context.AppUser.Add(new AppUser() + { + UserName = "majora2007", + ReadingLists = new List(), + Libraries = new List() + { + new Library() + { + Name = "Test LIb", + Type = LibraryType.Book, + Series = new List() + { + s + } + }, + } + }); + + await _context.SaveChangesAsync(); + + var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.ReadingLists); + var readingList = DbFactory.ReadingList("Test"); + user.ReadingLists = new List() + { + readingList + }; + + await _readingListService.AddChaptersToReadingList(1, new List() {1, 2}, readingList); + + + _unitOfWork.UserRepository.Update(user); + await _unitOfWork.CommitAsync(); + + await _readingListService.CalculateStartAndEndDates(readingList); + Assert.Equal(0, readingList.StartingMonth); + Assert.Equal(0, readingList.StartingYear); + Assert.Equal(0, readingList.EndingMonth); + Assert.Equal(0, readingList.EndingYear); + } + + [Fact] + public async Task CalculateStartAndEndDates_ShouldBeSomething_IfChapterHasSet() + { + await ResetDb(); + var s = new SeriesBuilder("Test") + .WithMetadata(DbFactory.SeriesMetadata(new List())) + .WithVolumes(new List() + { + new VolumeBuilder("0") + .WithChapter(new ChapterBuilder("1") + .WithReleaseDate(new DateTime(2005, 03, 01)) + .Build() + ) + .WithChapter(new ChapterBuilder("2") + .WithReleaseDate(new DateTime(2002, 03, 01)) + .Build() + ) + .Build() + }) + .Build(); + _context.AppUser.Add(new AppUser() + { + UserName = "majora2007", + ReadingLists = new List(), + Libraries = new List() + { + new Library() + { + Name = "Test LIb", + Type = LibraryType.Book, + Series = new List() + { + s + } + }, + } + }); + + await _context.SaveChangesAsync(); + + var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.ReadingLists); + var readingList = DbFactory.ReadingList("Test"); + user.ReadingLists = new List() + { + readingList + }; + + await _readingListService.AddChaptersToReadingList(1, new List() {1, 2}, readingList); + + + _unitOfWork.UserRepository.Update(user); + await _unitOfWork.CommitAsync(); + + await _readingListService.CalculateStartAndEndDates(readingList); + Assert.Equal(3, readingList.StartingMonth); + Assert.Equal(2002, readingList.StartingYear); + Assert.Equal(3, readingList.EndingMonth); + Assert.Equal(2005, readingList.EndingYear); + } + + #endregion + #region FormatTitle [Fact] diff --git a/API/Helpers/Builders/ChapterBuilder.cs b/API/Helpers/Builders/ChapterBuilder.cs index ae4253a60..19e6aa40c 100644 --- a/API/Helpers/Builders/ChapterBuilder.cs +++ b/API/Helpers/Builders/ChapterBuilder.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using API.Entities; using API.Entities.Enums; @@ -21,6 +22,12 @@ public class ChapterBuilder : IEntityBuilder }; } + public ChapterBuilder WithReleaseDate(DateTime time) + { + _chapter.ReleaseDate = time; + return this; + } + public ChapterBuilder WithAgeRating(AgeRating rating) { _chapter.AgeRating = rating; diff --git a/API/Services/ReadingListService.cs b/API/Services/ReadingListService.cs index f6f0ffc3b..f2c4f6893 100644 --- a/API/Services/ReadingListService.cs +++ b/API/Services/ReadingListService.cs @@ -299,7 +299,7 @@ public class ReadingListService : IReadingListService return; } var maxReleaseDate = items.Max(item => item.Chapter.ReleaseDate); - var minReleaseDate = items.Max(item => item.Chapter.ReleaseDate); + var minReleaseDate = items.Min(item => item.Chapter.ReleaseDate); if (maxReleaseDate != DateTime.MinValue) { readingListWithItems.EndingMonth = maxReleaseDate.Month; diff --git a/API/Startup.cs b/API/Startup.cs index 81e88510c..6f65e3a05 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -364,6 +364,7 @@ public class Startup private static void UpdateBaseUrlInIndex(string baseUrl) { + if (new OsInfo(Array.Empty()).IsDocker) return; var htmlDoc = new HtmlDocument(); var indexHtmlPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html"); htmlDoc.Load(indexHtmlPath); diff --git a/openapi.json b/openapi.json index 87b756e25..1b8e479d6 100644 --- a/openapi.json +++ b/openapi.json @@ -7,7 +7,7 @@ "name": "GPL-3.0", "url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE" }, - "version": "0.7.1.19" + "version": "0.7.1.20" }, "servers": [ { @@ -15361,4 +15361,4 @@ "description": "Responsible for all things Want To Read" } ] -} +} \ No newline at end of file