mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-21 06:20:33 -04:00
* Cleanup some messaging in the scan loop to be more context bearing * Added Response Caching to Series Detail for 1 min, due to the heavy nature of the call. * Refactored code to make it so that processing of series runs sync correctly. Added a log to inform the user of corrupted volume from buggy code in v0.5.6. * Moved folder watching out of experimental * Fixed an issue where empty folders could break the scan loop * Another fix for when dates aren't valid, the scanner wouldn't get the proper min and would throw an exception (develop) * Implemented the ability to edit release year from the UI for a series. * Added a unit test for some new logic * Code smells * Rewrote the handler for suspending watching to be more resilient and ensure no two threads have a race condition. * More error handling for when a ScanFolder is invoked but multiple series belong to that folder, log it to the user and default to a library scan. * ScanSeries now will check for kavitaignores higher than it's own folder and respect library level. * Fixed an issue where image series with a folder name containing the word "folder" could get ignored as it thought the image was a cover image. When a series folder is moved or deleted, skip parent ignore finding. * Removed some old files, added in scanFolder a check if the series found for a folder is in a book library and if so to always do a library scan (as books are often nested into one folder with multiple series). Added some unit tests * Refactored some scan loop logic into ComicInfo, wrote tests and updated some documentation to make the fields more clear. * Added a test for GetLastWriteTime based on recent bug * Cleaned up some redundant code * Fixed a bad merge * Code smells * Removed a package that's no longer used. * Ensure we check against ScanQueue on ScanFolder enqueuing * Documentation and more bullet proofing to ensure Hangfire checks work more as expected
187 lines
5.7 KiB
C#
187 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using API.Entities;
|
|
using API.Entities.Enums;
|
|
using API.Extensions;
|
|
using API.Parser;
|
|
using Xunit;
|
|
|
|
namespace API.Tests.Extensions;
|
|
|
|
public class ChapterListExtensionsTests
|
|
{
|
|
private static Chapter CreateChapter(string range, string number, MangaFile file, bool isSpecial)
|
|
{
|
|
return new Chapter()
|
|
{
|
|
Range = range,
|
|
Number = number,
|
|
Files = new List<MangaFile>() {file},
|
|
IsSpecial = isSpecial
|
|
};
|
|
}
|
|
|
|
private static MangaFile CreateFile(string file, MangaFormat format)
|
|
{
|
|
return new MangaFile()
|
|
{
|
|
FilePath = file,
|
|
Format = format
|
|
};
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAnyChapterByRange_Test_ShouldBeNull()
|
|
{
|
|
var info = new ParserInfo()
|
|
{
|
|
Chapters = "0",
|
|
Edition = "",
|
|
Format = MangaFormat.Archive,
|
|
FullFilePath = "/manga/darker than black.cbz",
|
|
Filename = "darker than black.cbz",
|
|
IsSpecial = false,
|
|
Series = "darker than black",
|
|
Title = "darker than black",
|
|
Volumes = "0"
|
|
};
|
|
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("darker than black - Some special", "0", CreateFile("/manga/darker than black - special.cbz", MangaFormat.Archive), true)
|
|
};
|
|
|
|
var actualChapter = chapterList.GetChapterByRange(info);
|
|
|
|
Assert.NotEqual(chapterList[0], actualChapter);
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public void GetAnyChapterByRange_Test_ShouldBeNotNull()
|
|
{
|
|
var info = new ParserInfo()
|
|
{
|
|
Chapters = "0",
|
|
Edition = "",
|
|
Format = MangaFormat.Archive,
|
|
FullFilePath = "/manga/darker than black.cbz",
|
|
Filename = "darker than black.cbz",
|
|
IsSpecial = true,
|
|
Series = "darker than black",
|
|
Title = "darker than black",
|
|
Volumes = "0"
|
|
};
|
|
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("darker than black", "0", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true)
|
|
};
|
|
|
|
var actualChapter = chapterList.GetChapterByRange(info);
|
|
|
|
Assert.Equal(chapterList[0], actualChapter);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetChapterByRange_On_Duplicate_Files_Test_Should_Not_Error()
|
|
{
|
|
var info = new ParserInfo()
|
|
{
|
|
Chapters = "0",
|
|
Edition = "",
|
|
Format = MangaFormat.Archive,
|
|
FullFilePath = "/manga/detective comics #001.cbz",
|
|
Filename = "detective comics #001.cbz",
|
|
IsSpecial = true,
|
|
Series = "detective comics",
|
|
Title = "detective comics",
|
|
Volumes = "0"
|
|
};
|
|
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true),
|
|
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
|
};
|
|
|
|
var actualChapter = chapterList.GetChapterByRange(info);
|
|
|
|
Assert.Equal(chapterList[0], actualChapter);
|
|
}
|
|
|
|
#region GetFirstChapterWithFiles
|
|
|
|
[Fact]
|
|
public void GetFirstChapterWithFiles_ShouldReturnAllChapters()
|
|
{
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("darker than black", "0", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true),
|
|
CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),
|
|
};
|
|
|
|
Assert.Equal(chapterList.First(), chapterList.GetFirstChapterWithFiles());
|
|
}
|
|
|
|
[Fact]
|
|
public void GetFirstChapterWithFiles_ShouldReturnSecondChapter()
|
|
{
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("darker than black", "0", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true),
|
|
CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),
|
|
};
|
|
|
|
chapterList.First().Files = new List<MangaFile>();
|
|
|
|
Assert.Equal(chapterList.Last(), chapterList.GetFirstChapterWithFiles());
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region MinimumReleaseYear
|
|
|
|
[Fact]
|
|
public void MinimumReleaseYear_ZeroIfNoChapters()
|
|
{
|
|
var chapterList = new List<Chapter>();
|
|
|
|
Assert.Equal(0, chapterList.MinimumReleaseYear());
|
|
}
|
|
|
|
[Fact]
|
|
public void MinimumReleaseYear_ZeroIfNoValidDates()
|
|
{
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true),
|
|
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
|
};
|
|
|
|
chapterList[0].ReleaseDate = new DateTime(10, 1, 1);
|
|
chapterList[1].ReleaseDate = DateTime.MinValue;
|
|
|
|
Assert.Equal(0, chapterList.MinimumReleaseYear());
|
|
}
|
|
|
|
[Fact]
|
|
public void MinimumReleaseYear_MinValidReleaseYear()
|
|
{
|
|
var chapterList = new List<Chapter>()
|
|
{
|
|
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true),
|
|
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
|
};
|
|
|
|
chapterList[0].ReleaseDate = new DateTime(2002, 1, 1);
|
|
chapterList[1].ReleaseDate = new DateTime(2012, 2, 1);
|
|
|
|
Assert.Equal(2002, chapterList.MinimumReleaseYear());
|
|
}
|
|
|
|
#endregion
|
|
}
|