Implements tests for commit 525ac1348d

Covers the favorites feature and the playlist and favorite pagination changes with unit, integration and security tests, and fixtures for the new request, response, DTO and entity types.

Also fixes the issues found while covering the commit: declares FavoriteMediaKind.None as the default value and rejects it in every favorite operation; queues the favorite added domain event only after the persisted favorite is read back; and preserves the private, no-store cache header on view pages after the antiforgery and session middlewares overwrite it.
This commit is contained in:
BinaryAlley committed 2026-10-29 10:13:57 +02:00
1 parent 468f1846f1
commit 394f6b510c
135 files changed
+19167 -13

No files matched your search

@@ -10,6 +10,11 @@ namespace Lumina.Presentation.Web.Common.Enums.Favorites;
[DebuggerDisplay("{ToString()}")]
public enum FavoriteMediaKind
{
/// <summary>
/// No media kind. Used as the default value; it is not a kind that can be marked as a favorite.
/// </summary>
None = 0,
/// <summary>
/// A favorite that references an artist of a music library.
/// </summary>
@@ -8,4 +8,9 @@ public static class HttpContextItemKeys
public const string ERRORS = "errors";
public const string PENDING_SUPER_ADMIN_SETUP = "PendingSuperAdminSetup";
public const string LAST_DISPLAYED_VIEW = "LastViewUrl";
/// <summary>
/// The <c>Cache-Control</c> value chosen by the endpoint, restored when the response starts.
/// </summary>
public const string CACHE_CONTROL = "CacheControl";
}
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Http;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Web.Common.Middlewares;
/// <summary>
/// Middleware that restores the <c>Cache-Control</c> header chosen by an endpoint after any middleware that overwrites it.
/// </summary>
/// <remarks>
/// The session middleware sets <c>Cache-Control: no-cache,no-store</c>, <c>Pragma: no-cache</c> and <c>Expires: -1</c> when it establishes
/// a new session, and it registers that write before the endpoint runs. Response-start callbacks run in reverse registration order, so a
/// callback registered here, before the session middleware, runs after the session middleware and can restore the endpoint's value.
/// </remarks>
public class CacheControlHeaderMiddleware
{
private readonly RequestDelegate _next;
/// <summary>
/// Initializes a new instance of the <see cref="CacheControlHeaderMiddleware"/> class.
/// </summary>
/// <param name="next">The next middleware in the request pipeline.</param>
public CacheControlHeaderMiddleware(RequestDelegate next)
{
_next = next;
}
/// <summary>
/// Restores the endpoint's <c>Cache-Control</c> value when the response starts, after the response-start callbacks registered later, such as the session middleware's, have run.
/// </summary>
/// <param name="context">The <see cref="HttpContext"/> for the current request.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public async Task InvokeAsync(HttpContext context)
{
context.Response.OnStarting(() =>
{
if (context.Items.TryGetValue(HttpContextItemKeys.CACHE_CONTROL, out object? value) && value is string cacheControl && !string.IsNullOrEmpty(cacheControl))
context.Response.Headers.CacheControl = cacheControl;
return Task.CompletedTask;
});
await _next(context);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Middlewares;
using Microsoft.AspNetCore.Builder;
#endregion
namespace Lumina.Presentation.Web.Common.Utilities;
/// <summary>
/// Extension methods for adding the <see cref="CacheControlHeaderMiddleware"/> to the request pipeline.
/// </summary>
public static class CacheControlHeaderMiddlewareUtilities
{
/// <summary>
/// Adds the <see cref="CacheControlHeaderMiddleware"/> to the application's request pipeline.
/// </summary>
/// <remarks>
/// It must be registered before the session middleware, so that its response-start callback runs after the one of the session middleware.
/// </remarks>
/// <param name="builder">The <see cref="IApplicationBuilder"/> used to configure the application's request pipeline.</param>
/// <returns>The <see cref="IApplicationBuilder"/> for further configuration.</returns>
public static IApplicationBuilder UseCacheControlHeader(this IApplicationBuilder builder)
{
return builder.UseMiddleware<CacheControlHeaderMiddleware>();
}
}