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