aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs
diff options
context:
space:
mode:
authorShadowghost <Shadowghost@users.noreply.github.com>2026-09-15 11:13:48 -0400
committerCody Robibero <cody@robibe.ro>2026-09-15 11:13:48 -0400
commit8150ee2484dabed61718ef43d5c98cdd2c0fa01c (patch)
treecb81b848e8931122d4771de780746be51a0e1d94 /tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs
parent7baca5f2b891cbc92e48145e633e1417d9bf2de3 (diff)
Backport pull request #17842 from jellyfin/release-12.z
Fix versions of a video still listing separately from their group and preserve manual merges Original-merge: cabec7ec28df671e3bb1c360c32db60b085f4084 Merged-by: crobibero <cody@robibe.ro> Backported-by: Cody Robibero <cody@robibe.ro>
Diffstat (limited to 'tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs')
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs
new file mode 100644
index 0000000000..5e045e9f83
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/Item/BaseItemRepositoryChildrenTests.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Linq;
+using Emby.Server.Implementations.Data;
+using Jellyfin.Database.Implementations.Entities;
+using Jellyfin.Server.Implementations.Item;
+using MediaBrowser.Controller.Entities;
+using Xunit;
+using BaseItemKind = Jellyfin.Data.Enums.BaseItemKind;
+
+namespace Jellyfin.Server.Implementations.Tests.Item;
+
+/// <summary>
+/// Covers the children query the library scan runs against a folder: a version merged by hand is
+/// hidden from ordinary queries, but the scan has to see it or it takes the row for a new item and
+/// recreates it, splitting the version group apart again.
+/// </summary>
+public sealed class BaseItemRepositoryChildrenTests : SqliteDbTestFixture
+{
+ private static readonly Guid _folderId = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
+ private static readonly Guid _primaryId = Guid.Parse("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb");
+ private static readonly Guid _mergedVersionId = Guid.Parse("cccccccc-cccc-cccc-cccc-cccccccccccc");
+ private static readonly Guid _ownedVersionId = Guid.Parse("dddddddd-dddd-dddd-dddd-dddddddddddd");
+
+ private readonly BaseItemRepository _repository;
+
+ public BaseItemRepositoryChildrenTests()
+ {
+ var itemTypeLookup = new ItemTypeLookup();
+ _repository = CreateBaseItemRepository(itemTypeLookup);
+
+ var movieTypeName = itemTypeLookup.BaseItemKindNames[BaseItemKind.Movie];
+ using var ctx = CreateDbContext();
+ ctx.BaseItems.Add(new BaseItemEntity
+ {
+ Id = _folderId,
+ Type = itemTypeLookup.BaseItemKindNames[BaseItemKind.Folder]!,
+ Name = "Movies",
+ Path = "/movies",
+ IsFolder = true
+ });
+ ctx.BaseItems.Add(CreateMovie(_primaryId, movieTypeName!, "Big Buck Bunny", "/media1/Big Buck Bunny/bbb-1080p.mp4", null, null));
+ ctx.BaseItems.Add(CreateMovie(_mergedVersionId, movieTypeName!, "Big Buck Bunny", "/media2/Big Buck Bunny/bbb-2160p.mp4", _primaryId, null));
+ ctx.BaseItems.Add(CreateMovie(_ownedVersionId, movieTypeName!, "Big Buck Bunny - 720p", "/media1/Big Buck Bunny/bbb-720p.mp4", _primaryId, _primaryId));
+ ctx.SaveChanges();
+ }
+
+ [Fact]
+ public void GetItemList_ChildrenOfFolder_ExcludesAlternateVersionsByDefault()
+ {
+ var result = _repository.GetItemList(new InternalItemsQuery { ParentId = _folderId });
+
+ var item = Assert.Single(result);
+ Assert.Equal(_primaryId, item.Id);
+ }
+
+ [Fact]
+ public void GetItemList_ChildrenOfFolderIncludingAlternateVersions_KeepsMergedVersion()
+ {
+ var result = _repository.GetItemList(new InternalItemsQuery
+ {
+ ParentId = _folderId,
+ IncludeAlternateVersions = true
+ });
+
+ Assert.Equal(2, result.Count);
+ Assert.Contains(result, i => i.Id.Equals(_primaryId));
+ Assert.Contains(result, i => i.Id.Equals(_mergedVersionId));
+ }
+
+ [Fact]
+ public void GetItemList_ChildrenOfFolderIncludingAlternateVersions_StillExcludesOwnedVersion()
+ {
+ // A version stored next to the file it belongs to is owned by its primary and is never
+ // resolved on its own, so the scan must not see it as a child of the folder either.
+ var result = _repository.GetItemList(new InternalItemsQuery
+ {
+ ParentId = _folderId,
+ IncludeAlternateVersions = true
+ });
+
+ Assert.DoesNotContain(result, i => i.Id.Equals(_ownedVersionId));
+ }
+
+ private static BaseItemEntity CreateMovie(Guid id, string typeName, string name, string path, Guid? primaryVersionId, Guid? ownerId)
+ {
+ return new BaseItemEntity
+ {
+ Id = id,
+ Type = typeName,
+ Name = name,
+ Path = path,
+ ParentId = _folderId,
+ TopParentId = _folderId,
+ PresentationUniqueKey = (primaryVersionId ?? id).ToString("N"),
+ PrimaryVersionId = primaryVersionId,
+ OwnerId = ownerId,
+ MediaType = "Video",
+ IsMovie = true,
+ IsFolder = false,
+ IsVirtualItem = false
+ };
+ }
+}