Ensure we set the correct MaxCount & TotalCount when matching on modifiedMinVolumeCount

This commit is contained in:
Amelia 2025-06-25 08:55:38 +02:00
parent b5e1e7eddd
commit 7c910ce090
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
2 changed files with 39 additions and 4 deletions

View file

@ -928,6 +928,36 @@ public class ExternalMetadataServiceTests : AbstractDbTest
Assert.Equal(3, series.Metadata.TotalCount); Assert.Equal(3, series.Metadata.TotalCount);
} }
/// <summary>
/// This is validating that we get a completed even though we have a special chapter and AL doesn't count it
/// </summary>
[Fact]
public void IsSeriesCompleted_Volumes_HasSpecialAndDecimal_ExternalNoSpecial()
{
const string seriesName = "Test - Volume Complete";
var series = new SeriesBuilder(seriesName)
.WithLibraryId(1)
.WithMetadata(new SeriesMetadataBuilder()
.WithMaxCount(2)
.WithTotalCount(3)
.Build())
.WithVolume(new VolumeBuilder("1").WithNumber(1).Build())
.WithVolume(new VolumeBuilder("1.5").WithNumber(1.5f).Build())
.WithVolume(new VolumeBuilder("2").WithNumber(2).Build())
.WithVolume(new VolumeBuilder(Parser.SpecialVolume).Build())
.Build();
var chapters = new List<Chapter>();
// External metadata includes volume 1.5, but not the special
var externalMetadata = new ExternalSeriesDetailDto { Chapters = 0, Volumes = 3 };
var result = ExternalMetadataService.IsSeriesCompleted(series, chapters, externalMetadata, 2);
Assert.True(result);
Assert.Equal(3, series.Metadata.MaxCount);
Assert.Equal(3, series.Metadata.TotalCount);
}
[Fact] [Fact]
public void IsSeriesCompleted_Volumes_TooManySpecials() public void IsSeriesCompleted_Volumes_TooManySpecials()
{ {

View file

@ -1653,15 +1653,20 @@ public class ExternalMetadataService : IExternalMetadataService
// Note: I've currently opted to keep this an equals to prevent the above bug from happening // Note: I've currently opted to keep this an equals to prevent the above bug from happening
// We *could* change this to >= in the future in case this is reported by users // We *could* change this to >= in the future in case this is reported by users
// If we do; test IsSeriesCompleted_Volumes_TooManySpecials needs to be updated // If we do; test IsSeriesCompleted_Volumes_TooManySpecials needs to be updated
if (maxVolumes != Parser.DefaultChapterNumber && externalMetadata.Volumes == series.Volumes.Count)
{
series.Metadata.MaxCount = series.Volumes.Count;
series.Metadata.TotalCount = series.Volumes.Count;
return true;
}
// Note: If Kavita has specials, we should be lenient and ignore for the volume check // Note: If Kavita has specials, we should be lenient and ignore for the volume check
var volumeModifier = series.Volumes.Any(v => v.Name == Parser.SpecialVolume) ? 1 : 0; var volumeModifier = series.Volumes.Any(v => v.Name == Parser.SpecialVolume) ? 1 : 0;
var modifiedMinVolumeCount = series.Volumes.Count - volumeModifier; var modifiedMinVolumeCount = series.Volumes.Count - volumeModifier;
if (maxVolumes != Parser.DefaultChapterNumber && if (maxVolumes != Parser.DefaultChapterNumber && externalMetadata.Volumes == modifiedMinVolumeCount)
(externalMetadata.Volumes == series.Volumes.Count || externalMetadata.Volumes == modifiedMinVolumeCount))
{ {
series.Metadata.MaxCount = series.Volumes.Count; series.Metadata.MaxCount = modifiedMinVolumeCount;
series.Metadata.TotalCount = series.Volumes.Count; series.Metadata.TotalCount = modifiedMinVolumeCount;
return true; return true;
} }