mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-03 13:44:22 -04:00
Add more tests
This commit is contained in:
parent
52230d1c30
commit
eb7fee9590
@ -6,6 +6,7 @@ using Jellyfin.Api.Extensions;
|
|||||||
using Jellyfin.Api.Helpers;
|
using Jellyfin.Api.Helpers;
|
||||||
using Jellyfin.Api.ModelBinders;
|
using Jellyfin.Api.ModelBinders;
|
||||||
using Jellyfin.Data.Enums;
|
using Jellyfin.Data.Enums;
|
||||||
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Controller.Dto;
|
using MediaBrowser.Controller.Dto;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
@ -241,7 +242,7 @@ public class ItemsController : BaseJellyfinApiController
|
|||||||
var isApiKey = User.GetIsApiKey();
|
var isApiKey = User.GetIsApiKey();
|
||||||
// if api key is used (auth.IsApiKey == true), then `user` will be null throughout this method
|
// if api key is used (auth.IsApiKey == true), then `user` will be null throughout this method
|
||||||
var user = !isApiKey && userId.HasValue && !userId.Value.Equals(default)
|
var user = !isApiKey && userId.HasValue && !userId.Value.Equals(default)
|
||||||
? _userManager.GetUserById(userId.Value)
|
? _userManager.GetUserById(userId.Value) ?? throw new ResourceNotFoundException()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// beyond this point, we're either using an api key or we have a valid user
|
// beyond this point, we're either using an api key or we have a valid user
|
||||||
|
@ -283,6 +283,11 @@ public class LibraryController : BaseJellyfinApiController
|
|||||||
userId,
|
userId,
|
||||||
inheritFromParent);
|
inheritFromParent);
|
||||||
|
|
||||||
|
if (themeSongs.Result is NotFoundObjectResult || themeVideos.Result is NotFoundObjectResult)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
return new AllThemeMediaResult
|
return new AllThemeMediaResult
|
||||||
{
|
{
|
||||||
ThemeSongsResult = themeSongs?.Value,
|
ThemeSongsResult = themeSongs?.Value,
|
||||||
@ -676,6 +681,11 @@ public class LibraryController : BaseJellyfinApiController
|
|||||||
: _libraryManager.GetUserRootFolder())
|
: _libraryManager.GetUserRootFolder())
|
||||||
: _libraryManager.GetItemById(itemId);
|
: _libraryManager.GetItemById(itemId);
|
||||||
|
|
||||||
|
if (item is null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
if (item is Episode || (item is IItemByName && item is not MusicArtist))
|
if (item is Episode || (item is IItemByName && item is not MusicArtist))
|
||||||
{
|
{
|
||||||
return new QueryResult<BaseItemDto>();
|
return new QueryResult<BaseItemDto>();
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Extensions.Json;
|
||||||
|
using MediaBrowser.Model.Dto;
|
||||||
|
using MediaBrowser.Model.Querying;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
||||||
|
|
||||||
|
public sealed class ItemsControllerTests : IClassFixture<JellyfinApplicationFactory>
|
||||||
|
{
|
||||||
|
private readonly JellyfinApplicationFactory _factory;
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
||||||
|
private static string? _accessToken;
|
||||||
|
|
||||||
|
public ItemsControllerTests(JellyfinApplicationFactory factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetItems_NoApiKeyOrUserId_BadRequest()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
var response = await client.GetAsync("Items").ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Users/{0}/Items")]
|
||||||
|
[InlineData("Users/{0}/Items/Resume")]
|
||||||
|
public async Task GetUserItems_NonExistentUserId_NotFound(string format)
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
var response = await client.GetAsync(string.Format(CultureInfo.InvariantCulture, format, Guid.NewGuid())).ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Items?userId={0}")]
|
||||||
|
[InlineData("Users/{0}/Items")]
|
||||||
|
[InlineData("Users/{0}/Items/Resume")]
|
||||||
|
public async Task GetItems_UserId_Ok(string format)
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
var userDto = await AuthHelper.GetUserDtoAsync(client).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var response = await client.GetAsync(string.Format(CultureInfo.InvariantCulture, format, userDto.Id)).ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
var items = await JsonSerializer.DeserializeAsync<QueryResult<BaseItemDto>>(
|
||||||
|
await response.Content.ReadAsStreamAsync().ConfigureAwait(false),
|
||||||
|
_jsonOptions).ConfigureAwait(false);
|
||||||
|
Assert.NotNull(items);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
||||||
|
|
||||||
|
public sealed class LibraryControllerTests : IClassFixture<JellyfinApplicationFactory>
|
||||||
|
{
|
||||||
|
private readonly JellyfinApplicationFactory _factory;
|
||||||
|
private static string? _accessToken;
|
||||||
|
|
||||||
|
public LibraryControllerTests(JellyfinApplicationFactory factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Items/{0}/File")]
|
||||||
|
[InlineData("Items/{0}/ThemeSongs")]
|
||||||
|
[InlineData("Items/{0}/ThemeVideos")]
|
||||||
|
[InlineData("Items/{0}/ThemeMedia")]
|
||||||
|
[InlineData("Items/{0}/Ancestors")]
|
||||||
|
[InlineData("Items/{0}/Download")]
|
||||||
|
[InlineData("Artists/{0}/Similar")]
|
||||||
|
[InlineData("Items/{0}/Similar")]
|
||||||
|
[InlineData("Albums/{0}/Similar")]
|
||||||
|
[InlineData("Shows/{0}/Similar")]
|
||||||
|
[InlineData("Movies/{0}/Similar")]
|
||||||
|
[InlineData("Trailers/{0}/Similar")]
|
||||||
|
public async Task Get_NonExistentItemId_NotFound(string format)
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
var response = await client.GetAsync(string.Format(CultureInfo.InvariantCulture, format, Guid.NewGuid())).ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
}
|
@ -1,18 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Priority;
|
|
||||||
|
|
||||||
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
||||||
|
|
||||||
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
|
|
||||||
public class PlaystateControllerTests : IClassFixture<JellyfinApplicationFactory>
|
public class PlaystateControllerTests : IClassFixture<JellyfinApplicationFactory>
|
||||||
{
|
{
|
||||||
private readonly JellyfinApplicationFactory _factory;
|
private readonly JellyfinApplicationFactory _factory;
|
||||||
private static readonly Guid _testUserId = Guid.NewGuid();
|
|
||||||
private static readonly Guid _testItemId = Guid.NewGuid();
|
|
||||||
private static string? _accessToken;
|
private static string? _accessToken;
|
||||||
|
|
||||||
public PlaystateControllerTests(JellyfinApplicationFactory factory)
|
public PlaystateControllerTests(JellyfinApplicationFactory factory)
|
||||||
@ -20,31 +15,47 @@ public class PlaystateControllerTests : IClassFixture<JellyfinApplicationFactory
|
|||||||
_factory = factory;
|
_factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<HttpResponseMessage> DeleteUserPlayedItems(HttpClient httpClient, Guid userId, Guid itemId)
|
|
||||||
=> httpClient.DeleteAsync($"Users/{userId}/PlayedItems/{itemId}");
|
|
||||||
|
|
||||||
private Task<HttpResponseMessage> PostUserPlayedItems(HttpClient httpClient, Guid userId, Guid itemId)
|
|
||||||
=> httpClient.PostAsync($"Users/{userId}/PlayedItems/{itemId}", null);
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Priority(0)]
|
public async Task DeleteMarkUnplayedItem_NonExistentUserId_NotFound()
|
||||||
public async Task DeleteMarkUnplayedItem_DoesNotExist_NotFound()
|
|
||||||
{
|
{
|
||||||
var client = _factory.CreateClient();
|
var client = _factory.CreateClient();
|
||||||
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
using var response = await DeleteUserPlayedItems(client, _testUserId, _testItemId).ConfigureAwait(false);
|
using var response = await client.DeleteAsync($"Users/{Guid.NewGuid()}/PlayedItems/{Guid.NewGuid()}").ConfigureAwait(false);
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Priority(0)]
|
public async Task PostMarkPlayedItem_NonExistentUserId_NotFound()
|
||||||
public async Task PostMarkPlayedItem_DoesNotExist_NotFound()
|
|
||||||
{
|
{
|
||||||
var client = _factory.CreateClient();
|
var client = _factory.CreateClient();
|
||||||
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
using var response = await PostUserPlayedItems(client, _testUserId, _testItemId).ConfigureAwait(false);
|
using var response = await client.PostAsync($"Users/{Guid.NewGuid()}/PlayedItems/{Guid.NewGuid()}", null).ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task DeleteMarkUnplayedItem_NonExistentItemId_NotFound()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
var userDto = await AuthHelper.GetUserDtoAsync(client).ConfigureAwait(false);
|
||||||
|
|
||||||
|
using var response = await client.DeleteAsync($"Users/{userDto.Id}/PlayedItems/{Guid.NewGuid()}").ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PostMarkPlayedItem_NonExistentItemId_NotFound()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
var userDto = await AuthHelper.GetUserDtoAsync(client).ConfigureAwait(false);
|
||||||
|
|
||||||
|
using var response = await client.PostAsync($"Users/{userDto.Id}/PlayedItems/{Guid.NewGuid()}", null).ConfigureAwait(false);
|
||||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Integration.Tests.Controllers;
|
||||||
|
|
||||||
|
public class SessionControllerTests : IClassFixture<JellyfinApplicationFactory>
|
||||||
|
{
|
||||||
|
private readonly JellyfinApplicationFactory _factory;
|
||||||
|
private static string? _accessToken;
|
||||||
|
|
||||||
|
public SessionControllerTests(JellyfinApplicationFactory factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetSessions_NonExistentUserId_NotFound()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||||
|
|
||||||
|
using var response = await client.GetAsync($"Session/Sessions?userId={Guid.NewGuid()}").ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
}
|
@ -125,6 +125,19 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
|
|||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Priority(0)]
|
||||||
|
public async Task Delete_DoesntExist_NotFound()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
// access token can't be null here as the previous test populated it
|
||||||
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken!);
|
||||||
|
|
||||||
|
using var response = await client.DeleteAsync($"User/{Guid.NewGuid()}").ConfigureAwait(false);
|
||||||
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Priority(1)]
|
[Priority(1)]
|
||||||
public async Task UpdateUserPassword_Valid_Success()
|
public async Task UpdateUserPassword_Valid_Success()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user