Adds artwork provider management to the library edit page

Adds the artwork providers list to the library edit page, mirroring the
metadata providers list, so that the artwork providers of a library can be
enabled, disabled and reordered. Adds the web routes, request types, DTO and
endpoints that proxy the artwork provider operations to the API.
This commit is contained in:
BinaryAlley committed 2026-08-26 21:49:49 +03:00
1 parent 4b861d8323
commit 4ee2976806
30 files changed
+905 -1

No files matched your search

@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Plugins;
/// <summary>
/// Fixture class for generating <see cref="LibraryArtworkProviderDto"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryArtworkProviderDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="LibraryArtworkProviderDto"/> instance with randomized test data.
/// </summary>
/// <param name="pluginId">Optional unique identifier of the plugin providing the artwork.</param>
/// <param name="name">Optional display name of the artwork provider.</param>
/// <param name="isEnabled">Whether the artwork provider is enabled for the media library or not.</param>
/// <param name="rank">Optional rank of the artwork provider, determining the order in which providers are tried.</param>
/// <returns>A configured <see cref="LibraryArtworkProviderDto"/> instance.</returns>
public LibraryArtworkProviderDto Create(
Guid? pluginId = null,
string? name = null,
bool? isEnabled = null,
int? rank = null)
{
return new LibraryArtworkProviderDto
{
PluginId = pluginId ?? Guid.NewGuid(),
Name = name ?? _faker.Company.CompanyName(),
IsEnabled = isEnabled ?? _faker.Random.Bool(),
Rank = rank ?? _faker.Random.Int(0, 100)
};
}
/// <summary>
/// Creates multiple <see cref="LibraryArtworkProviderDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryArtworkProviderDto"/> instances.</returns>
public List<LibraryArtworkProviderDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for generating <see cref="ReorderLibraryArtworkProvidersRequest"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryArtworkProvidersRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="ReorderLibraryArtworkProvidersRequest"/> instance with randomized test data.
/// </summary>
/// <param name="libraryId">Optional identifier of the media library.</param>
/// <param name="pluginIds">Optional plugin Ids in the new order.</param>
/// <returns>A configured <see cref="ReorderLibraryArtworkProvidersRequest"/> instance.</returns>
public ReorderLibraryArtworkProvidersRequest Create(
Guid? libraryId = null,
List<Guid>? pluginIds = null)
{
return new ReorderLibraryArtworkProvidersRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginIds = pluginIds ?? [_faker.Random.Guid(), _faker.Random.Guid()]
};
}
/// <summary>
/// Creates multiple <see cref="ReorderLibraryArtworkProvidersRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ReorderLibraryArtworkProvidersRequest"/> instances.</returns>
public List<ReorderLibraryArtworkProvidersRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
/// <summary>
/// Fixture class for generating <see cref="SetLibraryArtworkProviderEnabledRequest"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryArtworkProviderEnabledRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="SetLibraryArtworkProviderEnabledRequest"/> instance with randomized test data.
/// </summary>
/// <param name="libraryId">Optional identifier of the media library.</param>
/// <param name="pluginId">Optional identifier of the plugin.</param>
/// <param name="isEnabled">Optional value indicating whether the artwork provider is enabled.</param>
/// <returns>A configured <see cref="SetLibraryArtworkProviderEnabledRequest"/> instance.</returns>
public SetLibraryArtworkProviderEnabledRequest Create(
Guid? libraryId = null,
Guid? pluginId = null,
bool? isEnabled = null)
{
return new SetLibraryArtworkProviderEnabledRequest
{
LibraryId = libraryId ?? Guid.NewGuid(),
PluginId = pluginId ?? Guid.NewGuid(),
IsEnabled = isEnabled ?? _faker.Random.Bool()
};
}
/// <summary>
/// Creates multiple <see cref="SetLibraryArtworkProviderEnabledRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="SetLibraryArtworkProviderEnabledRequest"/> instances.</returns>
public List<SetLibraryArtworkProviderEnabledRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,84 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.DTO.Plugins;
using Lumina.Presentation.Web.Core.Endpoints.Library.Management.GetArtworkProviders;
using Lumina.Presentation.Web.Fixtures.Common.DTO.Plugins;
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
using Lumina.Presentation.Web.IntegrationTests.Common.Setup;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.IntegrationTests.Core.Endpoints.Library.Management.GetArtworkProviders;
/// <summary>
/// Contains integration tests for the <c>/{culture}/libraries/manage/api-get-artwork-providers/{{libraryId}}</c> route served by the <see cref="GetArtworkProvidersEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetArtworkProvidersEndpointTests : IClassFixture<LuminaWebFactory>
{
private readonly LuminaWebFactory _apiFactory;
private readonly LibraryArtworkProviderDtoFixture _libraryArtworkProviderDtoFixture = new();
/// <summary>
/// Initializes a new instance of the <see cref="GetArtworkProvidersEndpointTests"/> class.
/// </summary>
/// <param name="apiFactory">Injected Web application factory.</param>
public GetArtworkProvidersEndpointTests(LuminaWebFactory apiFactory)
{
_apiFactory = apiFactory;
}
[Fact]
public async Task GetArtworkProviders_WhenCalledByAuthenticatedUser_ShouldReturnArtworkProvidersJson()
{
// Arrange
_apiFactory.ApiClientStub.Reset();
Guid libraryId = Guid.NewGuid();
LibraryArtworkProviderDto[] expectedProviders =
[
_libraryArtworkProviderDtoFixture.Create(name: "Artwork Provider One", isEnabled: true, rank: 1),
_libraryArtworkProviderDtoFixture.Create(name: "Artwork Provider Two", isEnabled: false, rank: 2)
];
_apiFactory.ApiClientStub.RegisterGetResponse($"libraries/{libraryId}/artwork-providers", expectedProviders);
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
HttpRequestMessage getRequest = new(HttpMethod.Get, $"/en-us/libraries/manage/api-get-artwork-providers/{libraryId}");
getRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Act
HttpResponseMessage response = await webClient.Client.SendAsync(getRequest);
string content = await response.Content.ReadAsStringAsync();
// Assert
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
using JsonDocument json = JsonDocument.Parse(content);
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
JsonElement data = json.RootElement.GetProperty("data");
Assert.Equal(2, data.GetArrayLength());
Assert.Equal("Artwork Provider One", data[0].GetProperty("name").GetString());
}
[Fact]
public async Task GetArtworkProviders_WhenCalled_ShouldRequestArtworkProvidersFromApi()
{
// Arrange
_apiFactory.ApiClientStub.Reset();
Guid libraryId = Guid.NewGuid();
_apiFactory.ApiClientStub.RegisterGetResponse($"libraries/{libraryId}/artwork-providers", Array.Empty<LibraryArtworkProviderDto>());
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
HttpRequestMessage getRequest = new(HttpMethod.Get, $"/en-us/libraries/manage/api-get-artwork-providers/{libraryId}");
getRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Act
HttpResponseMessage response = await webClient.Client.SendAsync(getRequest);
// Assert
response.EnsureSuccessStatusCode();
Assert.Contains($"libraries/{libraryId}/artwork-providers", _apiFactory.ApiClientStub.GetEndpointsCalled);
}
}
@@ -0,0 +1,71 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Requests.Plugins;
using Lumina.Presentation.Web.Core.Endpoints.Library.Management.ReorderArtworkProviders;
using Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
using Lumina.Presentation.Web.IntegrationTests.Common.Setup;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.IntegrationTests.Core.Endpoints.Library.Management.ReorderArtworkProviders;
/// <summary>
/// Contains integration tests for the <c>/{culture}/libraries/manage/api-reorder-artwork-providers</c> route served by the <see cref="ReorderArtworkProvidersEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderArtworkProvidersEndpointTests : IClassFixture<LuminaWebFactory>
{
private readonly LuminaWebFactory _apiFactory;
private readonly ReorderLibraryArtworkProvidersRequestFixture _reorderLibraryArtworkProvidersRequestFixture = new();
/// <summary>
/// Initializes a new instance of the <see cref="ReorderArtworkProvidersEndpointTests"/> class.
/// </summary>
/// <param name="apiFactory">Injected Web application factory.</param>
public ReorderArtworkProvidersEndpointTests(LuminaWebFactory apiFactory)
{
_apiFactory = apiFactory;
}
[Fact]
public async Task ReorderArtworkProviders_WhenCalledByAuthenticatedUserWithAntiforgeryToken_ShouldReorderProvidersAndReturnSuccess()
{
// Arrange
_apiFactory.ApiClientStub.Reset();
Guid libraryId = Guid.NewGuid();
Guid firstPluginId = Guid.NewGuid();
Guid secondPluginId = Guid.NewGuid();
ReorderLibraryArtworkProvidersRequest request = _reorderLibraryArtworkProvidersRequestFixture.Create(
libraryId: libraryId,
pluginIds: [firstPluginId, secondPluginId]
);
string expectedEndpoint = $"libraries/{libraryId}/artwork-providers/reorder";
_apiFactory.ApiClientStub.RegisterPutResponseFactory(expectedEndpoint, _ => new Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest());
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
HttpRequestMessage updateRequest = new(HttpMethod.Put, "/en-us/libraries/manage/api-reorder-artwork-providers")
{
Content = JsonContent.Create(request)
};
updateRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
updateRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
updateRequest.Headers.Add("RequestVerificationToken", webClient.AntiforgeryToken);
// Act
HttpResponseMessage response = await webClient.Client.SendAsync(updateRequest);
string content = await response.Content.ReadAsStringAsync();
// Assert
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
using JsonDocument json = JsonDocument.Parse(content);
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
Assert.Contains(_apiFactory.ApiClientStub.PutRequests, putRequest => putRequest.Endpoint == expectedEndpoint);
}
}
@@ -0,0 +1,71 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Requests.Plugins;
using Lumina.Presentation.Web.Core.Endpoints.Library.Management.SetArtworkProviderEnabled;
using Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
using Lumina.Presentation.Web.IntegrationTests.Common.Setup;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.IntegrationTests.Core.Endpoints.Library.Management.SetArtworkProviderEnabled;
/// <summary>
/// Contains integration tests for the <c>/{culture}/libraries/manage/api-set-artwork-provider-enabled</c> route served by the <see cref="SetArtworkProviderEnabledEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetArtworkProviderEnabledEndpointTests : IClassFixture<LuminaWebFactory>
{
private readonly LuminaWebFactory _apiFactory;
private readonly SetLibraryArtworkProviderEnabledRequestFixture _setLibraryArtworkProviderEnabledRequestFixture = new();
/// <summary>
/// Initializes a new instance of the <see cref="SetArtworkProviderEnabledEndpointTests"/> class.
/// </summary>
/// <param name="apiFactory">Injected Web application factory.</param>
public SetArtworkProviderEnabledEndpointTests(LuminaWebFactory apiFactory)
{
_apiFactory = apiFactory;
}
[Fact]
public async Task SetArtworkProviderEnabled_WhenCalledByAuthenticatedUserWithAntiforgeryToken_ShouldEnableProviderAndReturnSuccess()
{
// Arrange
_apiFactory.ApiClientStub.Reset();
Guid libraryId = Guid.NewGuid();
Guid pluginId = Guid.NewGuid();
SetLibraryArtworkProviderEnabledRequest request = _setLibraryArtworkProviderEnabledRequestFixture.Create(
libraryId: libraryId,
pluginId: pluginId,
isEnabled: true
);
string expectedEndpoint = $"libraries/{libraryId}/artwork-providers/{pluginId}/enabled";
_apiFactory.ApiClientStub.RegisterPutResponseFactory(expectedEndpoint, _ => new Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest());
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
HttpRequestMessage updateRequest = new(HttpMethod.Put, "/en-us/libraries/manage/api-set-artwork-provider-enabled")
{
Content = JsonContent.Create(request)
};
updateRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
updateRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
updateRequest.Headers.Add("RequestVerificationToken", webClient.AntiforgeryToken);
// Act
HttpResponseMessage response = await webClient.Client.SendAsync(updateRequest);
string content = await response.Content.ReadAsStringAsync();
// Assert
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
using JsonDocument json = JsonDocument.Parse(content);
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
Assert.Contains(_apiFactory.ApiClientStub.PutRequests, putRequest => putRequest.Endpoint == expectedEndpoint);
}
}