mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Replaces the custom EmptyRequest with explicit API client operations
Removes the Web-specific EmptyRequest record struct and keeps FastEndpoints.EmptyRequest only as an endpoint request DTO. Adds bodyless and response-ignoring client overloads, centralizes request construction and response disposal, and separates stale-session failures from generic 404 responses. Updates the API client stub and tests, including regression coverage for non-empty response bodies, overload selection, and crafted theme asset paths.
This commit is contained in:
1 parent
c1dd08706c
commit
0a86f1a70b
70 files changed
+679
-384
No files matched your search
+2
-2
@@ -47,9 +47,9 @@ public class FireScheduledJobEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.ScheduledJobs.FIRE_SCHEDULED_JOB.Replace("{scheduledJobId}", request.ScheduledJobId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<FireScheduledJobRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Any<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Is<FireScheduledJobRequest>(forwardedRequest => forwardedRequest.ScheduledJobId == request.ScheduledJobId),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ public class StartScheduledJobEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.ScheduledJobs.START_SCHEDULED_JOB.Replace("{scheduledJobId}", request.ScheduledJobId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<StartScheduledJobRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Any<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Is<StartScheduledJobRequest>(forwardedRequest => forwardedRequest.ScheduledJobId == request.ScheduledJobId),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ public class StopScheduledJobEndpointTests
|
||||
|
||||
// Assert
|
||||
string expectedEndpoint = ApiRoutes.ScheduledJobs.STOP_SCHEDULED_JOB.Replace("{scheduledJobId}", request.ScheduledJobId.ToString());
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Web.Common.Requests.Common.EmptyRequest, Web.Common.Requests.Common.EmptyRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<StopScheduledJobRequest>(
|
||||
expectedEndpoint,
|
||||
Arg.Any<Web.Common.Requests.Common.EmptyRequest>(),
|
||||
Arg.Is<StopScheduledJobRequest>(forwardedRequest => forwardedRequest.ScheduledJobId == request.ScheduledJobId),
|
||||
Arg.Any<CancellationToken>());
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(body);
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class UpdateSchedulerDisplayPreferencesEndpointTests
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PutAsync<Lumina.Presentation.Web.Common.Requests.Common.EmptyRequest, UpdateSchedulerDisplayPreferencesRequest>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<UpdateSchedulerDisplayPreferencesRequest>(
|
||||
ApiRoutes.ScheduledJobs.UPDATE_DISPLAY_PREFERENCES,
|
||||
Arg.Is<UpdateSchedulerDisplayPreferencesRequest>(forwardedRequest =>
|
||||
forwardedRequest.JobTypeFilter == request.JobTypeFilter &&
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.RestoreTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
@@ -65,7 +64,7 @@ public class RestoreThemeEndpointTests
|
||||
await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ThemeResponseDto, object>(expectedEndpoint, Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.Received(1).PostIgnoringResponseAsync(expectedEndpoint, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -80,6 +79,6 @@ public class RestoreThemeEndpointTests
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, problemResult.StatusCode);
|
||||
await _mockApiHttpClient.DidNotReceive().PostAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.DidNotReceive().PostIgnoringResponseAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,11 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -26,7 +25,6 @@ public class SetCurrentThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly SetCurrentThemeEndpoint _sut;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -44,8 +42,8 @@ public class SetCurrentThemeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
string themeId = "editorial-paper";
|
||||
_mockApiHttpClient.PutAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_themeResponseDtoFixture.Create());
|
||||
_mockApiHttpClient.PutIgnoringResponseAsync<SetCurrentThemeRequest>(Arg.Any<string>(), Arg.Any<SetCurrentThemeRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(_setCurrentThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
@@ -55,9 +53,9 @@ public class SetCurrentThemeEndpointTests
|
||||
using (System.Text.Json.JsonDocument jsonDocument = System.Text.Json.JsonDocument.Parse(body))
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
|
||||
await _mockApiHttpClient.Received(1).PutAsync<ThemeResponseDto, object>(
|
||||
await _mockApiHttpClient.Received(1).PutIgnoringResponseAsync<SetCurrentThemeRequest>(
|
||||
ApiRoutes.Themes.SET_CURRENT_THEME,
|
||||
Arg.Is<object>(payload => (payload.GetType().GetProperty("ThemeId")!.GetValue(payload) as string) == themeId),
|
||||
Arg.Is<SetCurrentThemeRequest>(payload => payload.ThemeId == themeId),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -73,6 +71,6 @@ public class SetCurrentThemeEndpointTests
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, problemResult.StatusCode);
|
||||
await _mockApiHttpClient.DidNotReceive().PutAsync<ThemeResponseDto, object>(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
await _mockApiHttpClient.DidNotReceive().PutIgnoringResponseAsync<SetCurrentThemeRequest>(Arg.Any<string>(), Arg.Any<SetCurrentThemeRequest>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user