Adds a theme caching toggle to the user settings

This commit is contained in:
BinaryAlley committed 2026-08-21 04:04:54 -07:00
1 parent 60b551558f
commit 3da7167538
43 files changed
+1611 -56

No files matched your search

@@ -23,13 +23,15 @@ public class UserSettingsEntityFixture
/// <param name="isPaginationEnabled">Optional. Whether pagination is enabled for the user, or not.</param>
/// <param name="itemsPerPage">Optional. The number of library items displayed per page when pagination is enabled.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the "The" prefix is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Optional. Whether the theme data served to this user is cached, or not.</param>
/// <returns>The created user settings entity.</returns>
public UserSettingsEntity Create(
Guid? id = null,
Guid? userId = null,
bool? isPaginationEnabled = null,
int? itemsPerPage = null,
bool? ignoreThePrefixForAlphaPicker = null)
bool? ignoreThePrefixForAlphaPicker = null,
bool? isThemeCachingEnabled = null)
{
return new Faker<UserSettingsEntity>()
.CustomInstantiator(f => new UserSettingsEntity
@@ -38,7 +40,8 @@ public class UserSettingsEntityFixture
UserId = userId ?? Guid.NewGuid(),
IsPaginationEnabled = isPaginationEnabled ?? f.Random.Bool(),
ItemsPerPage = itemsPerPage ?? f.Random.Int(1, 100),
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker ?? f.Random.Bool()
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker ?? f.Random.Bool(),
IsThemeCachingEnabled = isThemeCachingEnabled ?? f.Random.Bool()
})
.Generate();
}
@@ -20,17 +20,20 @@ public class UpdateUserSettingsCommandFixture
/// <param name="isPaginationEnabled">Optional. Whether pagination is enabled for the user, or not.</param>
/// <param name="itemsPerPage">Optional. The number of library items displayed per page when pagination is enabled.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the "The" prefix is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Optional. Whether the theme data served to this user is cached, or not.</param>
/// <returns>The created command.</returns>
public UpdateUserSettingsCommand Create(
bool? isPaginationEnabled = null,
int? itemsPerPage = null,
bool? ignoreThePrefixForAlphaPicker = null)
bool? ignoreThePrefixForAlphaPicker = null,
bool? isThemeCachingEnabled = null)
{
return new Faker<UpdateUserSettingsCommand>()
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default))
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default, default))
.RuleFor(x => x.IsPaginationEnabled, f => isPaginationEnabled ?? f.Random.Bool())
.RuleFor(x => x.ItemsPerPage, f => itemsPerPage ?? f.Random.Int(1, 100))
.RuleFor(x => x.IgnoreThePrefixForAlphaPicker, f => ignoreThePrefixForAlphaPicker ?? f.Random.Bool())
.RuleFor(x => x.IsThemeCachingEnabled, f => isThemeCachingEnabled ?? f.Random.Bool())
.Generate();
}
@@ -23,18 +23,21 @@ public class UserSettingsFixture
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user.</param>
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached.</param>
/// <returns>The created <see cref="UserSettings"/>.</returns>
public UserSettings Create(
Guid? userId = null,
bool isPaginationEnabled = true,
int itemsPerPage = 48,
bool ignoreThePrefixForAlphaPicker = false)
bool ignoreThePrefixForAlphaPicker = false,
bool isThemeCachingEnabled = true)
{
Result<UserSettings> settings = UserSettings.Create(
userId is null ? UserId.CreateUnique() : UserId.Create(userId.Value),
isPaginationEnabled,
itemsPerPage,
ignoreThePrefixForAlphaPicker);
ignoreThePrefixForAlphaPicker,
isThemeCachingEnabled);
return settings.Value;
}
@@ -59,7 +59,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
UpdateUserSettingsRequest request = new(
IsPaginationEnabled: false,
ItemsPerPage: 24,
IgnoreThePrefixForAlphaPicker: true
IgnoreThePrefixForAlphaPicker: true,
IsThemeCachingEnabled: false
);
// Act
@@ -77,6 +78,7 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
Assert.False(storedSettings.IsPaginationEnabled);
Assert.Equal(24, storedSettings.ItemsPerPage);
Assert.True(storedSettings.IgnoreThePrefixForAlphaPicker);
Assert.False(storedSettings.IsThemeCachingEnabled);
}
[Fact]
@@ -86,7 +88,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
UpdateUserSettingsRequest request = new(
IsPaginationEnabled: true,
ItemsPerPage: 0,
IgnoreThePrefixForAlphaPicker: false
IgnoreThePrefixForAlphaPicker: false,
IsThemeCachingEnabled: true
);
// Act
@@ -118,7 +121,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
UpdateUserSettingsRequest request = new(
IsPaginationEnabled: true,
ItemsPerPage: 48,
IgnoreThePrefixForAlphaPicker: false
IgnoreThePrefixForAlphaPicker: false,
IsThemeCachingEnabled: true
);
// Act
@@ -50,7 +50,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<LuminaApiFactory>
UpdateUserSettingsRequest request = new(
IsPaginationEnabled: true,
ItemsPerPage: 48,
IgnoreThePrefixForAlphaPicker: false
IgnoreThePrefixForAlphaPicker: false,
IsThemeCachingEnabled: true
);
// Act
@@ -79,7 +80,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<LuminaApiFactory>
UpdateUserSettingsRequest request = new(
IsPaginationEnabled: true,
ItemsPerPage: int.MaxValue,
IgnoreThePrefixForAlphaPicker: false
IgnoreThePrefixForAlphaPicker: false,
IsThemeCachingEnabled: true
);
// Act
@@ -101,7 +103,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<LuminaApiFactory>
UpdateUserSettingsRequest request = new(
IsPaginationEnabled: true,
ItemsPerPage: int.MinValue,
IgnoreThePrefixForAlphaPicker: false
IgnoreThePrefixForAlphaPicker: false,
IsThemeCachingEnabled: true
);
// Act
@@ -17,7 +17,7 @@ public class UpdateUserSettingsRequestMappingTests
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
UpdateUserSettingsRequest request = new(IsPaginationEnabled: true, ItemsPerPage: 48, IgnoreThePrefixForAlphaPicker: false);
UpdateUserSettingsRequest request = new(IsPaginationEnabled: true, ItemsPerPage: 48, IgnoreThePrefixForAlphaPicker: false, IsThemeCachingEnabled: true);
// Act
UpdateUserSettingsCommand result = request.ToCommand();
@@ -27,5 +27,6 @@ public class UpdateUserSettingsRequestMappingTests
Assert.Equal(request.IsPaginationEnabled, result.IsPaginationEnabled);
Assert.Equal(request.ItemsPerPage, result.ItemsPerPage);
Assert.Equal(request.IgnoreThePrefixForAlphaPicker, result.IgnoreThePrefixForAlphaPicker);
Assert.Equal(request.IsThemeCachingEnabled, result.IsThemeCachingEnabled);
}
}
@@ -34,6 +34,7 @@ public class UserSettingsEntityMappingTests
Assert.Equal(entity.IsPaginationEnabled, result.Value.IsPaginationEnabled);
Assert.Equal(entity.ItemsPerPage, result.Value.ItemsPerPage);
Assert.Equal(entity.IgnoreThePrefixForAlphaPicker, result.Value.IgnoreThePrefixForAlphaPicker);
Assert.Equal(entity.IsThemeCachingEnabled, result.Value.IsThemeCachingEnabled);
}
[Fact]
@@ -51,5 +52,6 @@ public class UserSettingsEntityMappingTests
Assert.Equal(entity.IsPaginationEnabled, result.IsPaginationEnabled);
Assert.Equal(entity.ItemsPerPage, result.ItemsPerPage);
Assert.Equal(entity.IgnoreThePrefixForAlphaPicker, result.IgnoreThePrefixForAlphaPicker);
Assert.Equal(entity.IsThemeCachingEnabled, result.IsThemeCachingEnabled);
}
}
@@ -21,7 +21,7 @@ public class UpdateUserSettingsRequestTests
public void RoundTrip_WhenSerializingUpdateUserSettingsRequest_ShouldPreserveValues()
{
// Arrange
UpdateUserSettingsRequest expected = new(true, 50, true);
UpdateUserSettingsRequest expected = new(true, 50, true, true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
@@ -36,14 +36,15 @@ public class UpdateUserSettingsRequestTests
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
{
// Arrange
UpdateUserSettingsRequest sut = new(false, 25, false);
UpdateUserSettingsRequest sut = new(false, 25, false, false);
// Act
(bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker) = sut;
(bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker, bool isThemeCachingEnabled) = sut;
// Assert
Assert.Equal(sut.IsPaginationEnabled, isPaginationEnabled);
Assert.Equal(sut.ItemsPerPage, itemsPerPage);
Assert.Equal(sut.IgnoreThePrefixForAlphaPicker, ignoreThePrefixForAlphaPicker);
Assert.Equal(sut.IsThemeCachingEnabled, isThemeCachingEnabled);
}
}
@@ -23,7 +23,7 @@ public class UserSettingsResponseTests
{
// Arrange
Guid userId = Guid.NewGuid();
UserSettingsResponse expected = new(userId, true, 50, true);
UserSettingsResponse expected = new(userId, true, 50, true, true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
@@ -39,15 +39,16 @@ public class UserSettingsResponseTests
{
// Arrange
Guid userId = Guid.NewGuid();
UserSettingsResponse sut = new(userId, false, 25, false);
UserSettingsResponse sut = new(userId, false, 25, false, false);
// Act
(Guid sutUserId, bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker) = sut;
(Guid sutUserId, bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker, bool isThemeCachingEnabled) = sut;
// Assert
Assert.Equal(sut.UserId, sutUserId);
Assert.Equal(sut.IsPaginationEnabled, isPaginationEnabled);
Assert.Equal(sut.ItemsPerPage, itemsPerPage);
Assert.Equal(sut.IgnoreThePrefixForAlphaPicker, ignoreThePrefixForAlphaPicker);
Assert.Equal(sut.IsThemeCachingEnabled, isThemeCachingEnabled);
}
}
@@ -72,7 +72,7 @@ public class UserSettingsTests
UserId userId = _userIdFixture.Create();
// Act
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, ignoreThePrefixForAlphaPicker: true);
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, ignoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: true);
// Assert
Assert.False(result.IsFailure);
@@ -80,6 +80,7 @@ public class UserSettingsTests
Assert.False(result.Value.IsPaginationEnabled);
Assert.Equal(24, result.Value.ItemsPerPage);
Assert.True(result.Value.IgnoreThePrefixForAlphaPicker);
Assert.True(result.Value.IsThemeCachingEnabled);
}
[Fact]
@@ -105,7 +106,7 @@ public class UserSettingsTests
UserId userId = _userIdFixture.Create();
// Act
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true);
// Assert
Assert.True(result.IsFailure);
@@ -119,13 +120,14 @@ public class UserSettingsTests
UserSettings userSettings = _userSettingsFixture.Create();
// Act
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, ignoreThePrefixForAlphaPicker: true);
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, ignoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: false);
// Assert
Assert.False(result.IsFailure);
Assert.False(userSettings.IsPaginationEnabled);
Assert.Equal(12, userSettings.ItemsPerPage);
Assert.True(userSettings.IgnoreThePrefixForAlphaPicker);
Assert.False(userSettings.IsThemeCachingEnabled);
}
[Theory]
@@ -137,7 +139,7 @@ public class UserSettingsTests
UserSettings userSettings = _userSettingsFixture.Create();
// Act
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true);
// Assert
Assert.True(result.IsFailure);
@@ -39,7 +39,7 @@ public class GetUserSettingsEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
UserSettingsResponse expectedResponse = new(Guid.NewGuid(), true, 48, false);
UserSettingsResponse expectedResponse = new(Guid.NewGuid(), true, 48, false, true);
_mockHandler.HandleAsync(Arg.Any<GetUserSettingsQuery>(), Arg.Any<CancellationToken>())
.Returns(Result.From(expectedResponse));
@@ -79,7 +79,7 @@ public class GetUserSettingsEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockHandler.HandleAsync(Arg.Any<GetUserSettingsQuery>(), Arg.Any<CancellationToken>())
.Returns(Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false)));
.Returns(Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false, true)));
// Act
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
@@ -104,7 +104,7 @@ public class GetUserSettingsEndpointTests
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false));
return Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false, true));
}, info.Arg<CancellationToken>()));
// Act
@@ -37,7 +37,7 @@ public class UpdateUserSettingsEndpointTests
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithUpdatedMarker()
{
// Arrange
UpdateUserSettingsRequest request = new(true, 48, false);
UpdateUserSettingsRequest request = new(true, 48, false, true);
CancellationToken cancellationToken = CancellationToken.None;
_mockHandler.HandleAsync(Arg.Any<UpdateUserSettingsCommand>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
@@ -54,7 +54,7 @@ public class UpdateUserSettingsEndpointTests
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
{
// Arrange
UpdateUserSettingsRequest request = new(true, 0, false);
UpdateUserSettingsRequest request = new(true, 0, false, true);
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("UserSettings.ItemsPerPageMustBeGreaterThanZero", "ItemsPerPage must be greater than zero.");
_mockHandler.HandleAsync(Arg.Any<UpdateUserSettingsCommand>(), Arg.Any<CancellationToken>())
@@ -76,7 +76,7 @@ public class UpdateUserSettingsEndpointTests
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateUserSettingsCommandToHandler()
{
// Arrange
UpdateUserSettingsRequest request = new(true, 24, true);
UpdateUserSettingsRequest request = new(true, 24, true, true);
CancellationToken cancellationToken = CancellationToken.None;
_mockHandler.HandleAsync(Arg.Any<UpdateUserSettingsCommand>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
@@ -89,7 +89,8 @@ public class UpdateUserSettingsEndpointTests
Arg.Is<UpdateUserSettingsCommand>(command =>
command.IsPaginationEnabled == request.IsPaginationEnabled &&
command.ItemsPerPage == request.ItemsPerPage &&
command.IgnoreThePrefixForAlphaPicker == request.IgnoreThePrefixForAlphaPicker),
command.IgnoreThePrefixForAlphaPicker == request.IgnoreThePrefixForAlphaPicker &&
command.IsThemeCachingEnabled == request.IsThemeCachingEnabled),
Arg.Is(cancellationToken));
}
@@ -111,7 +112,7 @@ public class UpdateUserSettingsEndpointTests
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new UpdateUserSettingsRequest(true, 48, false), cts.Token);
Task<IResult> operationTask = _sut.ExecuteAsync(new UpdateUserSettingsRequest(true, 48, false, true), cts.Token);
await operationStarted.Task;
cts.Cancel();
cancellationRequested.SetResult(true);
@@ -3,10 +3,13 @@ using FastEndpoints;
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
using Lumina.Presentation.Web.Common.Routes;
using Lumina.Presentation.Web.Common.Services;
using Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.GetUserSettings;
using Lumina.Presentation.Web.Fixtures.Common.DTO.UsersManagement;
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
@@ -32,7 +35,14 @@ public class GetUserSettingsEndpointTests
public GetUserSettingsEndpointTests()
{
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
_sut = Factory.Create<GetUserSettingsEndpoint>(_mockApiHttpClient);
_sut = Factory.Create<GetUserSettingsEndpoint>(_mockApiHttpClient, CreateThemeCachePreferenceService());
}
private static ThemeCachePreferenceService CreateThemeCachePreferenceService()
{
ServiceCollection services = new();
services.AddHybridCache();
return new ThemeCachePreferenceService(services.BuildServiceProvider().GetRequiredService<HybridCache>());
}
[Fact]
@@ -3,10 +3,13 @@ using FastEndpoints;
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
using Lumina.Presentation.Web.Common.Routes;
using Lumina.Presentation.Web.Common.Services;
using Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.UpdateUserSettings;
using Lumina.Presentation.Web.Fixtures.Common.DTO.UsersManagement;
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
@@ -32,7 +35,14 @@ public class UpdateUserSettingsEndpointTests
public UpdateUserSettingsEndpointTests()
{
_mockApiHttpClient = Substitute.For<IApiHttpClient>();
_sut = Factory.Create<UpdateUserSettingsEndpoint>(_mockApiHttpClient);
_sut = Factory.Create<UpdateUserSettingsEndpoint>(_mockApiHttpClient, CreateThemeCachePreferenceService());
}
private static ThemeCachePreferenceService CreateThemeCachePreferenceService()
{
ServiceCollection services = new();
services.AddHybridCache();
return new ThemeCachePreferenceService(services.BuildServiceProvider().GetRequiredService<HybridCache>());
}
[Fact]