using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Moq; using Oms.Application.Dtos.Orders; using Oms.Application.Messaging; using SimpleAdmin.Api.IntegrationTests.Support; namespace SimpleAdmin.Api.IntegrationTests; public class OrderBatchJobApiIntegrationTests { [Fact] public async Task BatchGovernanceRoutes_ShouldBeRegistered() { await using var host = await SimpleAdminApiTestHost.CreateAsync(configureServices: ConfigureDisabledQueueInspector); host.RoutePatterns.Should().Contain("order/batch/dlx/stats"); host.RoutePatterns.Should().Contain("order/batch/jobs/{id:int}/retry-failed"); host.RoutePatterns.Should().Contain("order/batch/jobs/{id:int}/cancel"); host.RoutePatterns.Should().Contain("order/batch/jobs"); host.GetHttpMethods("order/batch/dlx/stats").Should().Contain("GET"); host.GetHttpMethods("order/batch/jobs/{id:int}/retry-failed").Should().Contain("POST"); host.GetHttpMethods("order/batch/jobs/{id:int}/cancel").Should().Contain("POST"); } [Fact] public async Task GetBatchDlxStats_ShouldReturnDisabledPayloadWhenQueueDisabled() { var inspector = new Mock(MockBehavior.Strict); inspector.SetupGet(x => x.IsEnabled).Returns(false); inspector .Setup(x => x.GetStatsAsync(It.IsAny())) .ReturnsAsync(new OrderBatchDlxStatsOutput { Enabled = false, DlxAlertThreshold = 100, }); await using var host = await SimpleAdminApiTestHost.CreateAsync(configureServices: services => { services.RemoveAll(); services.AddSingleton(inspector.Object); }); var response = await host.Client.GetAsync("/order/batch/dlx/stats"); response.IsSuccessStatusCode.Should().BeTrue(); var payload = await IntegrationTestJson.ReadAsync(response); payload.Should().NotBeNull(); payload!.Enabled.Should().BeFalse(); payload.DlxAlertThreshold.Should().Be(100); } private static void ConfigureDisabledQueueInspector(IServiceCollection services) { var inspector = new Mock(MockBehavior.Strict); inspector.SetupGet(x => x.IsEnabled).Returns(false); inspector .Setup(x => x.GetStatsAsync(It.IsAny())) .ReturnsAsync(new OrderBatchDlxStatsOutput { Enabled = false }); services.RemoveAll(); services.AddSingleton(inspector.Object); } }