2021-08-28 14:12:25 -04:00
|
|
|
using System;
|
2021-08-28 13:30:57 -04:00
|
|
|
using System.Net;
|
|
|
|
using System.Net.Http;
|
2021-11-30 18:13:02 -05:00
|
|
|
using System.Net.Http.Json;
|
2021-08-28 13:30:57 -04:00
|
|
|
using System.Text.Json;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Jellyfin.Api.Models.LibraryStructureDto;
|
|
|
|
using Jellyfin.Extensions.Json;
|
2021-08-28 14:34:04 -04:00
|
|
|
using MediaBrowser.Model.Configuration;
|
2021-08-28 13:30:57 -04:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Integration.Tests.Controllers
|
|
|
|
{
|
|
|
|
public sealed class MediaStructureControllerTests : IClassFixture<JellyfinApplicationFactory>
|
|
|
|
{
|
|
|
|
private readonly JellyfinApplicationFactory _factory;
|
|
|
|
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
|
|
|
private static string? _accessToken;
|
|
|
|
|
|
|
|
public MediaStructureControllerTests(JellyfinApplicationFactory factory)
|
|
|
|
{
|
|
|
|
_factory = factory;
|
|
|
|
}
|
|
|
|
|
2021-08-28 14:12:25 -04:00
|
|
|
[Fact]
|
|
|
|
public async Task RenameVirtualFolder_WhiteSpaceName_ReturnsBadRequest()
|
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
|
|
|
using var postContent = new ByteArrayContent(Array.Empty<byte>());
|
|
|
|
var response = await client.PostAsync("Library/VirtualFolders/Name?name=+&newName=test", postContent).ConfigureAwait(false);
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task RenameVirtualFolder_WhiteSpaceNewName_ReturnsBadRequest()
|
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
|
|
|
using var postContent = new ByteArrayContent(Array.Empty<byte>());
|
|
|
|
var response = await client.PostAsync("Library/VirtualFolders/Name?name=test&newName=+", postContent).ConfigureAwait(false);
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task RenameVirtualFolder_NameDoesntExist_ReturnsNotFound()
|
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
|
|
|
using var postContent = new ByteArrayContent(Array.Empty<byte>());
|
|
|
|
var response = await client.PostAsync("Library/VirtualFolders/Name?name=doesnt+exist&newName=test", postContent).ConfigureAwait(false);
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
2021-08-28 13:30:57 -04:00
|
|
|
[Fact]
|
|
|
|
public async Task AddMediaPath_PathDoesntExist_ReturnsNotFound()
|
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
|
|
|
var data = new MediaPathDto()
|
|
|
|
{
|
|
|
|
Name = "Test",
|
|
|
|
Path = "/this/path/doesnt/exist"
|
|
|
|
};
|
|
|
|
|
2021-12-01 09:58:23 -05:00
|
|
|
var response = await client.PostAsJsonAsync("Library/VirtualFolders/Paths", data, _jsonOptions).ConfigureAwait(false);
|
2021-08-28 13:30:57 -04:00
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2021-08-28 14:34:04 -04:00
|
|
|
public async Task UpdateMediaPath_WhiteSpaceName_ReturnsBadRequest()
|
2021-08-28 13:30:57 -04:00
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
|
|
|
var data = new UpdateMediaPathRequestDto()
|
|
|
|
{
|
2021-08-28 14:34:04 -04:00
|
|
|
Name = " ",
|
2021-09-01 08:00:06 -04:00
|
|
|
PathInfo = new MediaPathInfo("test")
|
2021-08-28 13:30:57 -04:00
|
|
|
};
|
|
|
|
|
2021-12-01 09:58:23 -05:00
|
|
|
var response = await client.PostAsJsonAsync("Library/VirtualFolders/Paths/Update", data, _jsonOptions).ConfigureAwait(false);
|
2021-08-28 13:30:57 -04:00
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2021-08-28 14:12:25 -04:00
|
|
|
public async Task RemoveMediaPath_WhiteSpaceName_ReturnsBadRequest()
|
2021-08-28 13:30:57 -04:00
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
2021-08-28 14:12:25 -04:00
|
|
|
var response = await client.DeleteAsync("Library/VirtualFolders/Paths?name=+").ConfigureAwait(false);
|
2021-08-28 13:30:57 -04:00
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task RemoveMediaPath_PathDoesntExist_ReturnsNotFound()
|
|
|
|
{
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
|
|
|
|
|
|
|
var response = await client.DeleteAsync("Library/VirtualFolders/Paths?name=none&path=%2Fthis%2Fpath%2Fdoesnt%2Fexist").ConfigureAwait(false);
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|