Implements tests for commit 2e9f7d8496

This commit is contained in:
BinaryAlley committed 2026-10-28 23:50:00 +02:00
1 parent a75447062f
commit 468f1846f1
18 files changed
+1711 -48

No files matched your search

@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.UsersManagement.Settings;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@@ -72,6 +73,15 @@ public class GetUserSettingsEndpointTests : IClassFixture<AuthenticatedLuminaApi
Assert.Equal(storedSettings.IsPaginationEnabled, result.IsPaginationEnabled);
Assert.Equal(storedSettings.ItemsPerPage, result.ItemsPerPage);
Assert.Equal(storedSettings.ShouldIgnoreThePrefixForAlphaPicker, result.ShouldIgnoreThePrefixForAlphaPicker);
Assert.Equal(VuMeterOrientation.Horizontal, result.VuMeterOrientation);
Assert.Equal(20, result.VuMeterSegmentCount);
Assert.Equal(4, result.VuMeterSegmentGap);
Assert.Equal(0.35, result.VuMeterMediumThreshold);
Assert.Equal(0.9, result.VuMeterHighThreshold);
Assert.False(result.VuMeterShowPeak);
Assert.Equal(1200, result.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(7.5, result.VuMeterReleasePerSecond);
Assert.Equal(0.25, result.VuMeterPeakReleasePerSecond);
}
[Fact]
@@ -91,6 +101,15 @@ public class GetUserSettingsEndpointTests : IClassFixture<AuthenticatedLuminaApi
Assert.True(result!.IsPaginationEnabled);
Assert.Equal(48, result.ItemsPerPage);
Assert.False(result.ShouldIgnoreThePrefixForAlphaPicker);
Assert.Equal(VuMeterOrientation.Vertical, result.VuMeterOrientation);
Assert.Equal(12, result.VuMeterSegmentCount);
Assert.Equal(1, result.VuMeterSegmentGap);
Assert.Equal(0.6, result.VuMeterMediumThreshold);
Assert.Equal(0.8, result.VuMeterHighThreshold);
Assert.True(result.VuMeterShowPeak);
Assert.Equal(650, result.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(3.0, result.VuMeterReleasePerSecond);
Assert.Equal(0.65, result.VuMeterPeakReleasePerSecond);
}
[Fact]
@@ -116,7 +135,16 @@ public class GetUserSettingsEndpointTests : IClassFixture<AuthenticatedLuminaApi
userId: userId,
isPaginationEnabled: false,
itemsPerPage: 24,
shouldIgnoreThePrefixForAlphaPicker: true);
shouldIgnoreThePrefixForAlphaPicker: true,
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 20,
vuMeterSegmentGap: 4,
vuMeterMediumThreshold: 0.35,
vuMeterHighThreshold: 0.9,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 1200,
vuMeterReleasePerSecond: 7.5,
vuMeterPeakReleasePerSecond: 0.25);
dbContext.UserSettings.Add(settings);
await dbContext.SaveChangesAsync();
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Fixtures.Core.Requests.UsersManagement.Settings;
using Lumina.Contracts.Requests.UsersManagement.Settings;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
@@ -63,7 +64,16 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
itemsPerPage: 24,
shouldIgnoreThePrefixForAlphaPicker: true,
isThemeCachingEnabled: false,
shouldAggregateMetadataWhenMissing: false
shouldAggregateMetadataWhenMissing: false,
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 20,
vuMeterSegmentGap: 4,
vuMeterMediumThreshold: 0.35,
vuMeterHighThreshold: 0.9,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 1200,
vuMeterReleasePerSecond: 7.5,
vuMeterPeakReleasePerSecond: 0.25
);
// Act
@@ -82,6 +92,15 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
Assert.Equal(24, storedSettings.ItemsPerPage);
Assert.True(storedSettings.ShouldIgnoreThePrefixForAlphaPicker);
Assert.False(storedSettings.IsThemeCachingEnabled);
Assert.Equal(VuMeterOrientation.Horizontal, storedSettings.VuMeterOrientation);
Assert.Equal(20, storedSettings.VuMeterSegmentCount);
Assert.Equal(4, storedSettings.VuMeterSegmentGap);
Assert.Equal(0.35, storedSettings.VuMeterMediumThreshold);
Assert.Equal(0.9, storedSettings.VuMeterHighThreshold);
Assert.False(storedSettings.VuMeterShowPeak);
Assert.Equal(1200, storedSettings.VuMeterPeakHoldDurationInMilliseconds);
Assert.Equal(7.5, storedSettings.VuMeterReleasePerSecond);
Assert.Equal(0.25, storedSettings.VuMeterPeakReleasePerSecond);
}
[Fact]
@@ -100,21 +119,7 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/users/me/settings", problemDetails["instance"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("ItemsPerPageMustBeGreaterThanZero", errors["General.Validation"]);
await AssertValidationErrorAsync(response, "ItemsPerPageMustBeGreaterThanZero");
}
[Fact]
@@ -137,6 +142,352 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterOrientationIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterOrientation: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterOrientationCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterSegmentCountIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterSegmentCount: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterSegmentCountCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterSegmentGapIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterSegmentGap: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterSegmentGapCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterMediumThresholdIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterMediumThreshold: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterMediumThresholdCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterHighThresholdIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterHighThreshold: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterHighThresholdCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterShowPeakIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterShowPeak: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterShowPeakCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterPeakHoldDurationIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterPeakHoldDurationInMilliseconds: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterPeakHoldDurationCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterReleasePerSecondIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterReleasePerSecond: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterReleasePerSecondCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterPeakReleasePerSecondIsNull_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(includeVuMeterPeakReleasePerSecond: false);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterPeakReleasePerSecondCannotBeNull");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterOrientationIsNotDefined_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(vuMeterOrientation: (VuMeterOrientation)999);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "InvalidVuMeterOrientation");
}
[Theory]
[InlineData(0)] // below the minimum
[InlineData(129)] // above the maximum
public async Task UpdateUserSettings_WhenVuMeterSegmentCountIsOutOfRange_ShouldReturnValidationError(int vuMeterSegmentCount)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(vuMeterSegmentCount: vuMeterSegmentCount);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterSegmentCountMustBeBetweenOneAndOneHundredTwentyEight");
}
[Theory]
[InlineData(-1)] // below the minimum
[InlineData(33)] // above the maximum
public async Task UpdateUserSettings_WhenVuMeterSegmentGapIsOutOfRange_ShouldReturnValidationError(int vuMeterSegmentGap)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(vuMeterSegmentGap: vuMeterSegmentGap);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterSegmentGapMustBeBetweenZeroAndThirtyTwo");
}
[Theory]
[InlineData(-0.01)] // just below the minimum
[InlineData(1.01)] // just above the maximum
public async Task UpdateUserSettings_WhenVuMeterMediumThresholdIsOutOfRange_ShouldReturnValidationError(double vuMeterMediumThreshold)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterMediumThreshold: vuMeterMediumThreshold,
vuMeterHighThreshold: 1.0);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterMediumThresholdMustBeBetweenZeroAndOne");
}
[Theory]
[InlineData(-0.01)] // just below the minimum
[InlineData(1.01)] // just above the maximum
public async Task UpdateUserSettings_WhenVuMeterHighThresholdIsOutOfRange_ShouldReturnValidationError(double vuMeterHighThreshold)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterMediumThreshold: 0.0,
vuMeterHighThreshold: vuMeterHighThreshold);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterHighThresholdMustBeBetweenZeroAndOne");
}
[Fact]
public async Task UpdateUserSettings_WhenVuMeterHighThresholdIsLowerThanMediumThreshold_ShouldReturnValidationError()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterMediumThreshold: 0.9,
vuMeterHighThreshold: 0.1);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterHighThresholdMustBeGreaterThanOrEqualToMediumThreshold");
}
[Theory]
[InlineData(0.5, 0.5)] // the thresholds are equal
[InlineData(0.4, 0.9)] // the high threshold is greater than the medium one
public async Task UpdateUserSettings_WhenVuMeterHighThresholdIsGreaterThanOrEqualToMediumThreshold_ShouldUpdateSettings(
double vuMeterMediumThreshold,
double vuMeterHighThreshold)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterMediumThreshold: vuMeterMediumThreshold,
vuMeterHighThreshold: vuMeterHighThreshold);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[Theory]
[InlineData(-1)] // below the minimum
[InlineData(10001)] // above the maximum
public async Task UpdateUserSettings_WhenVuMeterPeakHoldDurationIsOutOfRange_ShouldReturnValidationError(int vuMeterPeakHoldDurationInMilliseconds)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterPeakHoldDurationInMilliseconds: vuMeterPeakHoldDurationInMilliseconds);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterPeakHoldDurationMustBeBetweenZeroAndTenThousandMilliseconds");
}
[Theory]
[InlineData(-0.01)] // just below the minimum
[InlineData(100.01)] // just above the maximum
public async Task UpdateUserSettings_WhenVuMeterReleasePerSecondIsOutOfRange_ShouldReturnValidationError(double vuMeterReleasePerSecond)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(vuMeterReleasePerSecond: vuMeterReleasePerSecond);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterReleasePerSecondMustBeBetweenZeroAndOneHundred");
}
[Theory]
[InlineData(-0.01)] // just below the minimum
[InlineData(100.01)] // just above the maximum
public async Task UpdateUserSettings_WhenVuMeterPeakReleasePerSecondIsOutOfRange_ShouldReturnValidationError(double vuMeterPeakReleasePerSecond)
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(vuMeterPeakReleasePerSecond: vuMeterPeakReleasePerSecond);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
await AssertValidationErrorAsync(response, "VuMeterPeakReleasePerSecondMustBeBetweenZeroAndOneHundred");
}
[Fact]
public async Task UpdateUserSettings_WhenAllVuMeterValuesAreAtTheirMinimums_ShouldUpdateSettings()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterOrientation: VuMeterOrientation.Vertical,
vuMeterSegmentCount: 1,
vuMeterSegmentGap: 0,
vuMeterMediumThreshold: 0.0,
vuMeterHighThreshold: 0.0,
vuMeterShowPeak: false,
vuMeterPeakHoldDurationInMilliseconds: 0,
vuMeterReleasePerSecond: 0.0,
vuMeterPeakReleasePerSecond: 0.0);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[Fact]
public async Task UpdateUserSettings_WhenAllVuMeterValuesAreAtTheirMaximums_ShouldUpdateSettings()
{
// Arrange
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
vuMeterOrientation: VuMeterOrientation.Horizontal,
vuMeterSegmentCount: 128,
vuMeterSegmentGap: 32,
vuMeterMediumThreshold: 1.0,
vuMeterHighThreshold: 1.0,
vuMeterShowPeak: true,
vuMeterPeakHoldDurationInMilliseconds: 10000,
vuMeterReleasePerSecond: 100.0,
vuMeterPeakReleasePerSecond: 100.0);
// Act
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/users/me/settings", request);
// Assert
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
/// <summary>
/// Asserts that <paramref name="response"/> is a validation problem response carrying the specified error.
/// </summary>
/// <param name="response">The response to assert.</param>
/// <param name="expectedError">The exact error description expected in the validation errors.</param>
/// <returns>A task representing the asynchronous operation.</returns>
private async Task AssertValidationErrorAsync(HttpResponseMessage response, string expectedError)
{
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/users/me/settings", problemDetails["instance"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains(expectedError, errors["General.Validation"]);
}
/// <summary>
/// Disposes API factory resources.
/// </summary>