Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
Joe Milazzo 2025-02-19 15:06:54 -06:00 committed by GitHub
parent b858729c9e
commit 9565fe7360
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 777 additions and 314 deletions

View file

@ -521,6 +521,71 @@ public class CleanupServiceTests : AbstractDbTest
}
#endregion
#region ConsolidateProgress
[Fact]
public async Task ConsolidateProgress_ShouldRemoveDuplicates()
{
await ResetDb();
var s = new SeriesBuilder("Test ConsolidateProgress_ShouldRemoveDuplicates")
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("1")
.WithPages(3)
.Build())
.Build())
.Build();
s.Library = new LibraryBuilder("Test Lib").Build();
_context.Series.Add(s);
var user = new AppUser()
{
UserName = "ConsolidateProgress_ShouldRemoveDuplicates",
};
_context.AppUser.Add(user);
await _unitOfWork.CommitAsync();
// Add 2 progress events
user.Progresses ??= [];
user.Progresses.Add(new AppUserProgress()
{
ChapterId = 1,
VolumeId = 1,
SeriesId = 1,
LibraryId = s.LibraryId,
PagesRead = 1,
});
await _unitOfWork.CommitAsync();
// Add a duplicate with higher page number
user.Progresses.Add(new AppUserProgress()
{
ChapterId = 1,
VolumeId = 1,
SeriesId = 1,
LibraryId = s.LibraryId,
PagesRead = 3,
});
await _unitOfWork.CommitAsync();
Assert.Equal(2, (await _unitOfWork.AppUserProgressRepository.GetAllProgress()).Count());
var cleanupService = new CleanupService(Substitute.For<ILogger<CleanupService>>(), _unitOfWork,
Substitute.For<IEventHub>(),
new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new MockFileSystem()));
await cleanupService.ConsolidateProgress();
var progress = await _unitOfWork.AppUserProgressRepository.GetAllProgress();
Assert.Single(progress);
Assert.True(progress.First().PagesRead == 3);
}
#endregion
#region EnsureChapterProgressIsCapped
@ -587,7 +652,7 @@ public class CleanupServiceTests : AbstractDbTest
}
#endregion
// #region CleanupBookmarks
#region CleanupBookmarks
//
// [Fact]
// public async Task CleanupBookmarks_LeaveAllFiles()
@ -724,5 +789,5 @@ public class CleanupServiceTests : AbstractDbTest
// Assert.Equal(1, ds.FileSystem.Directory.GetDirectories($"{BookmarkDirectory}1/1/").Length);
// }
//
// #endregion
#endregion
}

View file

@ -562,4 +562,73 @@ public class ScannerServiceTests : AbstractDbTest
s2 = postLib.Series.First(s => s.Name == "Accel");
Assert.Single(s2.Volumes);
}
//[Fact]
public async Task ScanLibrary_AlternatingRemoval_IssueReplication()
{
// https://github.com/Kareadita/Kavita/issues/3476#issuecomment-2661635558
// TODO: Come back to this, it's complicated
const string testcase = "Alternating Removal - Manga.json";
// Setup: Generate test library
var infos = new Dictionary<string, ComicInfo>();
var library = await _scannerHelper.GenerateScannerData(testcase, infos);
var testDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(),
"../../../Services/Test Data/ScannerService/ScanTests",
testcase.Replace(".json", string.Empty));
library.Folders =
[
new FolderPath() { Path = Path.Combine(testDirectoryPath, "Root 1") },
new FolderPath() { Path = Path.Combine(testDirectoryPath, "Root 2") }
];
_unitOfWork.LibraryRepository.Update(library);
await _unitOfWork.CommitAsync();
var scanner = _scannerHelper.CreateServices();
// First Scan: Everything should be added
await scanner.ScanLibrary(library.Id);
var postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
Assert.NotNull(postLib);
Assert.Contains(postLib.Series, s => s.Name == "Accel");
Assert.Contains(postLib.Series, s => s.Name == "Plush");
// Second Scan: Remove Root 2, expect Accel to be removed
library.Folders = [new FolderPath() { Path = Path.Combine(testDirectoryPath, "Root 1") }];
_unitOfWork.LibraryRepository.Update(library);
await _unitOfWork.CommitAsync();
await scanner.ScanLibrary(library.Id);
postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
Assert.DoesNotContain(postLib.Series, s => s.Name == "Accel"); // Ensure Accel is gone
Assert.Contains(postLib.Series, s => s.Name == "Plush");
// Third Scan: Re-add Root 2, Accel should come back
library.Folders =
[
new FolderPath() { Path = Path.Combine(testDirectoryPath, "Root 1") },
new FolderPath() { Path = Path.Combine(testDirectoryPath, "Root 2") }
];
_unitOfWork.LibraryRepository.Update(library);
await _unitOfWork.CommitAsync();
await scanner.ScanLibrary(library.Id);
postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
Assert.Contains(postLib.Series, s => s.Name == "Accel"); // Accel should be back
Assert.Contains(postLib.Series, s => s.Name == "Plush");
// Fourth Scan: Run again to check stability (should not remove Accel)
await scanner.ScanLibrary(library.Id);
postLib = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(library.Id, LibraryIncludes.Series);
Assert.Contains(postLib.Series, s => s.Name == "Accel");
Assert.Contains(postLib.Series, s => s.Name == "Plush");
}
}

View file

@ -0,0 +1,5 @@
[
"Root 1/Antarctic Press/Plush/Plush v01.cbz",
"Root 1/Antarctic Press/Plush/Plush v02.cbz",
"Root 2/Accel/Accel v01.cbz"
]