You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/tests/Jellyfin.Server.Integration.../Controllers/StartupControllerTests.cs

116 lines
4.7 KiB

using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Net.Mime;
using System.Text.Json;
using System.Threading.Tasks;
using Jellyfin.Api.Models.StartupDtos;
using Jellyfin.Extensions.Json;
using Xunit;
using Xunit.Priority;
namespace Jellyfin.Server.Integration.Tests.Controllers
{
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public sealed class StartupControllerTests : IClassFixture<JellyfinApplicationFactory>
{
private readonly JellyfinApplicationFactory _factory;
4 years ago
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
public StartupControllerTests(JellyfinApplicationFactory factory)
{
_factory = factory;
}
[Fact]
4 years ago
[Priority(-2)]
public async Task Configuration_EditConfig_Success()
{
var client = _factory.CreateClient();
4 years ago
var config = new StartupConfigurationDto()
{
UICulture = "NewCulture",
MetadataCountryCode = "be",
PreferredMetadataLanguage = "nl"
};
using var postResponse = await client.PostAsJsonAsync("/Startup/Configuration", config, _jsonOptions).ConfigureAwait(false);
4 years ago
Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
using var getResponse = await client.GetAsync("/Startup/Configuration").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
Assert.Equal(MediaTypeNames.Application.Json, getResponse.Content.Headers.ContentType?.MediaType);
using var responseStream = await getResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
var newConfig = await JsonSerializer.DeserializeAsync<StartupConfigurationDto>(responseStream, _jsonOptions).ConfigureAwait(false);
Assert.Equal(config.UICulture, newConfig!.UICulture);
Assert.Equal(config.MetadataCountryCode, newConfig.MetadataCountryCode);
Assert.Equal(config.PreferredMetadataLanguage, newConfig.PreferredMetadataLanguage);
}
[Fact]
4 years ago
[Priority(-2)]
public async Task User_DefaultUser_NameWithoutPassword()
{
var client = _factory.CreateClient();
4 years ago
using var response = await client.GetAsync("/Startup/User").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
using var contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var user = await JsonSerializer.DeserializeAsync<StartupUserDto>(contentStream, _jsonOptions).ConfigureAwait(false);
Assert.NotEmpty(user!.Name);
Assert.Null(user.Password);
}
4 years ago
[Fact]
[Priority(-1)]
public async Task User_EditUser_Success()
{
var client = _factory.CreateClient();
4 years ago
var user = new StartupUserDto()
{
Name = "NewName",
Password = "NewPassword"
};
var postResponse = await client.PostAsJsonAsync("/Startup/User", user, _jsonOptions).ConfigureAwait(false);
4 years ago
Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
4 years ago
var getResponse = await client.GetAsync("/Startup/User").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
Assert.Equal(MediaTypeNames.Application.Json, getResponse.Content.Headers.ContentType?.MediaType);
4 years ago
var contentStream = await getResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
var newUser = await JsonSerializer.DeserializeAsync<StartupUserDto>(contentStream, _jsonOptions).ConfigureAwait(false);
Assert.Equal(user.Name, newUser!.Name);
Assert.NotEmpty(newUser.Password);
Assert.NotEqual(user.Password, newUser.Password);
}
[Fact]
4 years ago
[Priority(0)]
public async Task CompleteWizard_Success()
{
var client = _factory.CreateClient();
4 years ago
var response = await client.PostAsync("/Startup/Complete", new ByteArrayContent(Array.Empty<byte>())).ConfigureAwait(false);
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
}
[Fact]
4 years ago
[Priority(1)]
public async Task GetFirstUser_CompleteWizard_Unauthorized()
{
var client = _factory.CreateClient();
4 years ago
using var response = await client.GetAsync("/Startup/User").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
}
}