Bookmark Refactor (#1049)
* Tweaked how the migration to change users with ChangePassword role happens. It will now only run once. * Refactored bookmarks into it's own service with unit tests. Bookmark management happens in real time and we no longer delete bookmarks on a schedule. This means once you bookmark something, even if you delete the entity, the files will remain. * Commented out a test that no longer is needed
This commit is contained in:
parent
9c9a5f92a1
commit
05c35a1cb6
8 changed files with 685 additions and 230 deletions
|
@ -364,142 +364,142 @@ public class CleanupServiceTests
|
|||
|
||||
#endregion
|
||||
|
||||
#region CleanupBookmarks
|
||||
|
||||
[Fact]
|
||||
public async Task CleanupBookmarks_LeaveAllFiles()
|
||||
{
|
||||
var filesystem = CreateFileSystem();
|
||||
filesystem.AddFile($"{BookmarkDirectory}1/1/1/0001.jpg", new MockFileData(""));
|
||||
filesystem.AddFile($"{BookmarkDirectory}1/1/1/0002.jpg", new MockFileData(""));
|
||||
|
||||
// Delete all Series to reset state
|
||||
await ResetDB();
|
||||
|
||||
_context.Series.Add(new Series()
|
||||
{
|
||||
Name = "Test",
|
||||
Library = new Library() {
|
||||
Name = "Test LIb",
|
||||
Type = LibraryType.Manga,
|
||||
},
|
||||
Volumes = new List<Volume>()
|
||||
{
|
||||
new Volume()
|
||||
{
|
||||
Chapters = new List<Chapter>()
|
||||
{
|
||||
new Chapter()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_context.AppUser.Add(new AppUser()
|
||||
{
|
||||
Bookmarks = new List<AppUserBookmark>()
|
||||
{
|
||||
new AppUserBookmark()
|
||||
{
|
||||
AppUserId = 1,
|
||||
ChapterId = 1,
|
||||
Page = 1,
|
||||
FileName = "1/1/1/0001.jpg",
|
||||
SeriesId = 1,
|
||||
VolumeId = 1
|
||||
},
|
||||
new AppUserBookmark()
|
||||
{
|
||||
AppUserId = 1,
|
||||
ChapterId = 1,
|
||||
Page = 2,
|
||||
FileName = "1/1/1/0002.jpg",
|
||||
SeriesId = 1,
|
||||
VolumeId = 1
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);
|
||||
var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,
|
||||
ds);
|
||||
|
||||
await cleanupService.CleanupBookmarks();
|
||||
|
||||
Assert.Equal(2, ds.GetFiles(BookmarkDirectory, searchOption:SearchOption.AllDirectories).Count());
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CleanupBookmarks_LeavesOneFiles()
|
||||
{
|
||||
var filesystem = CreateFileSystem();
|
||||
filesystem.AddFile($"{BookmarkDirectory}1/1/1/0001.jpg", new MockFileData(""));
|
||||
filesystem.AddFile($"{BookmarkDirectory}1/1/2/0002.jpg", new MockFileData(""));
|
||||
|
||||
// Delete all Series to reset state
|
||||
await ResetDB();
|
||||
|
||||
_context.Series.Add(new Series()
|
||||
{
|
||||
Name = "Test",
|
||||
Library = new Library() {
|
||||
Name = "Test LIb",
|
||||
Type = LibraryType.Manga,
|
||||
},
|
||||
Volumes = new List<Volume>()
|
||||
{
|
||||
new Volume()
|
||||
{
|
||||
Chapters = new List<Chapter>()
|
||||
{
|
||||
new Chapter()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_context.AppUser.Add(new AppUser()
|
||||
{
|
||||
Bookmarks = new List<AppUserBookmark>()
|
||||
{
|
||||
new AppUserBookmark()
|
||||
{
|
||||
AppUserId = 1,
|
||||
ChapterId = 1,
|
||||
Page = 1,
|
||||
FileName = "1/1/1/0001.jpg",
|
||||
SeriesId = 1,
|
||||
VolumeId = 1
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);
|
||||
var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,
|
||||
ds);
|
||||
|
||||
await cleanupService.CleanupBookmarks();
|
||||
|
||||
Assert.Equal(1, ds.GetFiles(BookmarkDirectory, searchOption:SearchOption.AllDirectories).Count());
|
||||
Assert.Equal(1, ds.FileSystem.Directory.GetDirectories($"{BookmarkDirectory}1/1/").Length);
|
||||
}
|
||||
|
||||
#endregion
|
||||
// #region CleanupBookmarks
|
||||
//
|
||||
// [Fact]
|
||||
// public async Task CleanupBookmarks_LeaveAllFiles()
|
||||
// {
|
||||
// var filesystem = CreateFileSystem();
|
||||
// filesystem.AddFile($"{BookmarkDirectory}1/1/1/0001.jpg", new MockFileData(""));
|
||||
// filesystem.AddFile($"{BookmarkDirectory}1/1/1/0002.jpg", new MockFileData(""));
|
||||
//
|
||||
// // Delete all Series to reset state
|
||||
// await ResetDB();
|
||||
//
|
||||
// _context.Series.Add(new Series()
|
||||
// {
|
||||
// Name = "Test",
|
||||
// Library = new Library() {
|
||||
// Name = "Test LIb",
|
||||
// Type = LibraryType.Manga,
|
||||
// },
|
||||
// Volumes = new List<Volume>()
|
||||
// {
|
||||
// new Volume()
|
||||
// {
|
||||
// Chapters = new List<Chapter>()
|
||||
// {
|
||||
// new Chapter()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// await _context.SaveChangesAsync();
|
||||
//
|
||||
// _context.AppUser.Add(new AppUser()
|
||||
// {
|
||||
// Bookmarks = new List<AppUserBookmark>()
|
||||
// {
|
||||
// new AppUserBookmark()
|
||||
// {
|
||||
// AppUserId = 1,
|
||||
// ChapterId = 1,
|
||||
// Page = 1,
|
||||
// FileName = "1/1/1/0001.jpg",
|
||||
// SeriesId = 1,
|
||||
// VolumeId = 1
|
||||
// },
|
||||
// new AppUserBookmark()
|
||||
// {
|
||||
// AppUserId = 1,
|
||||
// ChapterId = 1,
|
||||
// Page = 2,
|
||||
// FileName = "1/1/1/0002.jpg",
|
||||
// SeriesId = 1,
|
||||
// VolumeId = 1
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// await _context.SaveChangesAsync();
|
||||
//
|
||||
//
|
||||
// var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);
|
||||
// var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,
|
||||
// ds);
|
||||
//
|
||||
// await cleanupService.CleanupBookmarks();
|
||||
//
|
||||
// Assert.Equal(2, ds.GetFiles(BookmarkDirectory, searchOption:SearchOption.AllDirectories).Count());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// [Fact]
|
||||
// public async Task CleanupBookmarks_LeavesOneFiles()
|
||||
// {
|
||||
// var filesystem = CreateFileSystem();
|
||||
// filesystem.AddFile($"{BookmarkDirectory}1/1/1/0001.jpg", new MockFileData(""));
|
||||
// filesystem.AddFile($"{BookmarkDirectory}1/1/2/0002.jpg", new MockFileData(""));
|
||||
//
|
||||
// // Delete all Series to reset state
|
||||
// await ResetDB();
|
||||
//
|
||||
// _context.Series.Add(new Series()
|
||||
// {
|
||||
// Name = "Test",
|
||||
// Library = new Library() {
|
||||
// Name = "Test LIb",
|
||||
// Type = LibraryType.Manga,
|
||||
// },
|
||||
// Volumes = new List<Volume>()
|
||||
// {
|
||||
// new Volume()
|
||||
// {
|
||||
// Chapters = new List<Chapter>()
|
||||
// {
|
||||
// new Chapter()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// await _context.SaveChangesAsync();
|
||||
//
|
||||
// _context.AppUser.Add(new AppUser()
|
||||
// {
|
||||
// Bookmarks = new List<AppUserBookmark>()
|
||||
// {
|
||||
// new AppUserBookmark()
|
||||
// {
|
||||
// AppUserId = 1,
|
||||
// ChapterId = 1,
|
||||
// Page = 1,
|
||||
// FileName = "1/1/1/0001.jpg",
|
||||
// SeriesId = 1,
|
||||
// VolumeId = 1
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// await _context.SaveChangesAsync();
|
||||
//
|
||||
//
|
||||
// var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), filesystem);
|
||||
// var cleanupService = new CleanupService(_logger, _unitOfWork, _messageHub,
|
||||
// ds);
|
||||
//
|
||||
// await cleanupService.CleanupBookmarks();
|
||||
//
|
||||
// Assert.Equal(1, ds.GetFiles(BookmarkDirectory, searchOption:SearchOption.AllDirectories).Count());
|
||||
// Assert.Equal(1, ds.FileSystem.Directory.GetDirectories($"{BookmarkDirectory}1/1/").Length);
|
||||
// }
|
||||
//
|
||||
// #endregion
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue