mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-31 04:05:50 -04:00
Fixed tests
This commit is contained in:
parent
7a5c7e70f6
commit
7f03f39bcc
@ -930,19 +930,19 @@ public sealed class BaseItemRepository(IDbContextFactory<JellyfinDbContext> dbPr
|
|||||||
if (filter.HasDeadParentId.HasValue && filter.HasDeadParentId.Value)
|
if (filter.HasDeadParentId.HasValue && filter.HasDeadParentId.Value)
|
||||||
{
|
{
|
||||||
baseQuery = baseQuery
|
baseQuery = baseQuery
|
||||||
.Where(e => e.ParentId.HasValue && context.BaseItems.Any(f => f.Id == e.ParentId.Value));
|
.Where(e => e.ParentId.HasValue && !context.BaseItems.Any(f => f.Id == e.ParentId.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.IsDeadArtist.HasValue && filter.IsDeadArtist.Value)
|
if (filter.IsDeadArtist.HasValue && filter.IsDeadArtist.Value)
|
||||||
{
|
{
|
||||||
baseQuery = baseQuery
|
baseQuery = baseQuery
|
||||||
.Where(e => e.ItemValues!.Any(f => (f.Type == 0 || f.Type == ItemValueType.AlbumArtist) && f.CleanValue == e.CleanName));
|
.Where(e => !e.ItemValues!.Any(f => (f.Type == ItemValueType.Artist || f.Type == ItemValueType.AlbumArtist) && f.CleanValue == e.CleanName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.IsDeadStudio.HasValue && filter.IsDeadStudio.Value)
|
if (filter.IsDeadStudio.HasValue && filter.IsDeadStudio.Value)
|
||||||
{
|
{
|
||||||
baseQuery = baseQuery
|
baseQuery = baseQuery
|
||||||
.Where(e => e.ItemValues!.Any(f => f.Type == ItemValueType.Studios && f.CleanValue == e.CleanName));
|
.Where(e => !e.ItemValues!.Any(f => f.Type == ItemValueType.Studios && f.CleanValue == e.CleanName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.IsDeadPerson.HasValue && filter.IsDeadPerson.Value)
|
if (filter.IsDeadPerson.HasValue && filter.IsDeadPerson.Value)
|
||||||
@ -1252,53 +1252,61 @@ public sealed class BaseItemRepository(IDbContextFactory<JellyfinDbContext> dbPr
|
|||||||
tuples[i] = (item, ancestorIds, topParent, userdataKey, inheritedTags);
|
tuples[i] = (item, ancestorIds, topParent, userdataKey, inheritedTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = dbProvider.CreateDbContext();
|
try
|
||||||
using var transaction = context.Database.BeginTransaction();
|
|
||||||
foreach (var item in tuples)
|
|
||||||
{
|
{
|
||||||
var entity = Map(item.Item);
|
using var context = dbProvider.CreateDbContext();
|
||||||
if (!context.BaseItems.Any(e => e.Id == entity.Id))
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
foreach (var item in tuples)
|
||||||
{
|
{
|
||||||
context.BaseItems.Add(entity);
|
var entity = Map(item.Item);
|
||||||
}
|
if (!context.BaseItems.Any(e => e.Id == entity.Id))
|
||||||
else
|
|
||||||
{
|
|
||||||
context.BaseItems.Attach(entity).State = EntityState.Modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.AncestorIds.Where(e => e.ItemId == entity.Id).ExecuteDelete();
|
|
||||||
if (item.Item.SupportsAncestors && item.AncestorIds != null)
|
|
||||||
{
|
|
||||||
entity.AncestorIds = new List<AncestorId>();
|
|
||||||
foreach (var ancestorId in item.AncestorIds)
|
|
||||||
{
|
{
|
||||||
entity.AncestorIds.Add(new AncestorId()
|
context.BaseItems.Add(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.BaseItems.Attach(entity).State = EntityState.Modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.AncestorIds.Where(e => e.ItemId == entity.Id).ExecuteDelete();
|
||||||
|
if (item.Item.SupportsAncestors && item.AncestorIds != null)
|
||||||
|
{
|
||||||
|
entity.AncestorIds = new List<AncestorId>();
|
||||||
|
foreach (var ancestorId in item.AncestorIds)
|
||||||
{
|
{
|
||||||
ParentItemId = ancestorId,
|
entity.AncestorIds.Add(new AncestorId()
|
||||||
|
{
|
||||||
|
ParentItemId = ancestorId,
|
||||||
|
ItemId = entity.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemValues = GetItemValuesToSave(item.Item, item.InheritedTags);
|
||||||
|
context.ItemValues.Where(e => e.ItemId == entity.Id).ExecuteDelete();
|
||||||
|
entity.ItemValues = new List<ItemValue>();
|
||||||
|
|
||||||
|
foreach (var itemValue in itemValues)
|
||||||
|
{
|
||||||
|
entity.ItemValues.Add(new()
|
||||||
|
{
|
||||||
|
Item = entity,
|
||||||
|
Type = (ItemValueType)itemValue.MagicNumber,
|
||||||
|
Value = itemValue.Value,
|
||||||
|
CleanValue = GetCleanValue(itemValue.Value),
|
||||||
ItemId = entity.Id
|
ItemId = entity.Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemValues = GetItemValuesToSave(item.Item, item.InheritedTags);
|
context.SaveChanges();
|
||||||
context.ItemValues.Where(e => e.ItemId == entity.Id).ExecuteDelete();
|
transaction.Commit();
|
||||||
entity.ItemValues = new List<ItemValue>();
|
}
|
||||||
|
catch (System.Exception)
|
||||||
foreach (var itemValue in itemValues)
|
{
|
||||||
{
|
System.Console.WriteLine();
|
||||||
entity.ItemValues.Add(new()
|
throw;
|
||||||
{
|
|
||||||
Item = entity,
|
|
||||||
Type = (ItemValueType)itemValue.MagicNumber,
|
|
||||||
Value = itemValue.Value,
|
|
||||||
CleanValue = GetCleanValue(itemValue.Value),
|
|
||||||
ItemId = entity.Id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.SaveChanges();
|
|
||||||
transaction.Commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IItemRepository" />
|
/// <inheritdoc cref="IItemRepository" />
|
||||||
@ -1484,7 +1492,8 @@ public sealed class BaseItemRepository(IDbContextFactory<JellyfinDbContext> dbPr
|
|||||||
Type = dto.GetType().ToString(),
|
Type = dto.GetType().ToString(),
|
||||||
Id = dto.Id
|
Id = dto.Id
|
||||||
};
|
};
|
||||||
entity.ParentId = dto.ParentId;
|
|
||||||
|
entity.ParentId = !dto.ParentId.IsEmpty() ? dto.ParentId : null;
|
||||||
entity.Path = GetPathToSave(dto.Path);
|
entity.Path = GetPathToSave(dto.Path);
|
||||||
entity.EndDate = dto.EndDate.GetValueOrDefault();
|
entity.EndDate = dto.EndDate.GetValueOrDefault();
|
||||||
entity.CommunityRating = dto.CommunityRating;
|
entity.CommunityRating = dto.CommunityRating;
|
||||||
|
@ -13,7 +13,7 @@ using Xunit.Priority;
|
|||||||
|
|
||||||
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
||||||
|
|
||||||
// [TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
|
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
|
||||||
public sealed class LibraryStructureControllerTests : IClassFixture<JellyfinApplicationFactory>
|
public sealed class LibraryStructureControllerTests : IClassFixture<JellyfinApplicationFactory>
|
||||||
{
|
{
|
||||||
private readonly JellyfinApplicationFactory _factory;
|
private readonly JellyfinApplicationFactory _factory;
|
||||||
@ -62,13 +62,13 @@ public sealed class LibraryStructureControllerTests : IClassFixture<JellyfinAppl
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Priority(-2)]
|
[Priority(0)]
|
||||||
public async Task UpdateLibraryOptions_Valid_Success()
|
public async Task UpdateLibraryOptions_Valid_Success()
|
||||||
{
|
{
|
||||||
var client = _factory.CreateClient();
|
var client = _factory.CreateClient();
|
||||||
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client));
|
||||||
|
|
||||||
var createBody = new AddVirtualFolderDto()
|
var createbody = new AddVirtualFolderDto()
|
||||||
{
|
{
|
||||||
LibraryOptions = new LibraryOptions()
|
LibraryOptions = new LibraryOptions()
|
||||||
{
|
{
|
||||||
@ -76,8 +76,8 @@ public sealed class LibraryStructureControllerTests : IClassFixture<JellyfinAppl
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using var createResponse = await client.PostAsJsonAsync("Library/VirtualFolders?name=test&refreshLibrary=true", createBody, _jsonOptions);
|
using var createresponse = await client.PostAsJsonAsync("Library/VirtualFolders?name=test&refreshLibrary=true", createbody, _jsonOptions);
|
||||||
Assert.Equal(HttpStatusCode.NoContent, createResponse.StatusCode);
|
Assert.Equal(HttpStatusCode.NoContent, createresponse.StatusCode);
|
||||||
|
|
||||||
using var response = await client.GetAsync("Library/VirtualFolders");
|
using var response = await client.GetAsync("Library/VirtualFolders");
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -91,13 +91,13 @@ public sealed class LibraryStructureControllerTests : IClassFixture<JellyfinAppl
|
|||||||
Assert.False(options.Enabled);
|
Assert.False(options.Enabled);
|
||||||
options.Enabled = true;
|
options.Enabled = true;
|
||||||
|
|
||||||
var existBody = new UpdateLibraryOptionsDto()
|
var body = new UpdateLibraryOptionsDto()
|
||||||
{
|
{
|
||||||
Id = Guid.Parse(library.ItemId),
|
Id = Guid.Parse(library.ItemId),
|
||||||
LibraryOptions = options
|
LibraryOptions = options
|
||||||
};
|
};
|
||||||
|
|
||||||
using var response2 = await client.PostAsJsonAsync("Library/VirtualFolders/LibraryOptions", existBody, _jsonOptions);
|
using var response2 = await client.PostAsJsonAsync("Library/VirtualFolders/LibraryOptions", body, _jsonOptions);
|
||||||
Assert.Equal(HttpStatusCode.NoContent, response2.StatusCode);
|
Assert.Equal(HttpStatusCode.NoContent, response2.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user