Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Fixing duplicate chapter issue and adding unit test (#1221)

Robbie Davis03ab44d50a6e
diff --git a/API.Tests/Extensions/ChapterListExtensionsTests.cs b/API.Tests/Extensions/ChapterListExtensionsTests.cs
index 845b1387b..a1beddf09 100644
--- a/API.Tests/Extensions/ChapterListExtensionsTests.cs
+++ b/API.Tests/Extensions/ChapterListExtensionsTests.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using API.Entities;
using API.Entities.Enums;
@@ -83,9 +83,37 @@ namespace API.Tests.Extensions
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]
+ [Fact]
public void GetFirstChapterWithFiles_ShouldReturnAllChapters()
{
var chapterList = new List<Chapter>()
diff --git a/API/Extensions/ChapterListExtensions.cs b/API/Extensions/ChapterListExtensions.cs
index 6362c0571..a5d80bb92 100644
--- a/API/Extensions/ChapterListExtensions.cs
+++ b/API/Extensions/ChapterListExtensions.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using API.Entities;
using API.Parser;
@@ -28,8 +28,8 @@ namespace API.Extensions
{
var specialTreatment = info.IsSpecialInfo();
return specialTreatment
- ? chapters.SingleOrDefault(c => c.Range == info.Filename || (c.Files.Select(f => f.FilePath).Contains(info.FullFilePath)))
- : chapters.SingleOrDefault(c => c.Range == info.Chapters);
+ ? chapters.FirstOrDefault(c => c.Range == info.Filename || (c.Files.Select(f => f.FilePath).Contains(info.FullFilePath)))
+ : chapters.FirstOrDefault(c => c.Range == info.Chapters);
}
}
-}
\ No newline at end of file
+}