jellyfin/tests/Jellyfin.Server.Integration.Tests/Controllers/DashboardControllerTests.cs

91 lines
3.7 KiB
C#
Raw Normal View History

2021-02-22 13:15:29 +01:00
using System.IO;
using System.Net;
2021-02-22 16:27:02 +01:00
using System.Net.Mime;
using System.Text;
2021-02-22 13:15:29 +01:00
using System.Text.Json;
using System.Threading.Tasks;
using Jellyfin.Api.Models;
using Jellyfin.Extensions.Json;
2021-02-22 13:15:29 +01:00
using Xunit;
namespace Jellyfin.Server.Integration.Tests.Controllers
2021-02-22 13:15:29 +01:00
{
public sealed class DashboardControllerTests : IClassFixture<JellyfinApplicationFactory>
{
private readonly JellyfinApplicationFactory _factory;
2021-03-09 05:57:38 +01:00
private readonly JsonSerializerOptions _jsonOpions = JsonDefaults.Options;
2022-03-18 22:21:08 +01:00
private static string? _accessToken;
2021-02-22 13:15:29 +01:00
public DashboardControllerTests(JellyfinApplicationFactory factory)
{
_factory = factory;
}
[Fact]
public async Task GetDashboardConfigurationPage_NonExistingPage_NotFound()
{
var client = _factory.CreateClient();
2021-02-22 16:27:02 +01:00
var response = await client.GetAsync("web/ConfigurationPage?name=ThisPageDoesntExists").ConfigureAwait(false);
2021-02-22 13:15:29 +01:00
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
[Fact]
public async Task GetDashboardConfigurationPage_ExistingPage_CorrectPage()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/web/ConfigurationPage?name=TestPlugin").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
2021-02-22 16:27:02 +01:00
Assert.Equal(MediaTypeNames.Text.Html, response.Content.Headers.ContentType?.MediaType);
StreamReader reader = new StreamReader(typeof(TestPlugin).Assembly.GetManifestResourceStream("Jellyfin.Server.Integration.Tests.TestPage.html")!);
2021-11-09 13:14:31 +01:00
Assert.Equal(await response.Content.ReadAsStringAsync().ConfigureAwait(false), await reader.ReadToEndAsync().ConfigureAwait(false));
2021-02-22 13:15:29 +01:00
}
[Fact]
public async Task GetDashboardConfigurationPage_BrokenPage_NotFound()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/web/ConfigurationPage?name=BrokenPage").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
[Fact]
public async Task GetConfigurationPages_NoParams_AllConfigurationPages()
{
var client = _factory.CreateClient();
2022-03-18 22:21:08 +01:00
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
2021-02-22 13:15:29 +01:00
var response = await client.GetAsync("/web/ConfigurationPages").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
2021-02-22 16:27:02 +01:00
var res = await response.Content.ReadAsStreamAsync();
_ = await JsonSerializer.DeserializeAsync<ConfigurationPageInfo[]>(res, _jsonOpions);
2021-02-22 13:15:29 +01:00
// TODO: check content
}
[Fact]
public async Task GetConfigurationPages_True_MainMenuConfigurationPages()
{
var client = _factory.CreateClient();
2022-03-18 22:21:08 +01:00
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
2021-02-22 13:15:29 +01:00
var response = await client.GetAsync("/web/ConfigurationPages?enableInMainMenu=true").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
2021-02-22 16:27:02 +01:00
Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet);
2021-02-22 13:46:40 +01:00
var res = await response.Content.ReadAsStreamAsync();
var data = await JsonSerializer.DeserializeAsync<ConfigurationPageInfo[]>(res, _jsonOpions);
2022-08-14 19:20:01 +02:00
Assert.NotNull(data);
2021-02-22 13:46:40 +01:00
Assert.Empty(data);
2021-02-22 13:15:29 +01:00
}
}
}