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