diff --git a/src/Bootstrapper/MeAjudaAi.ApiService/Extensions/ServiceCollectionExtensions.cs b/src/Bootstrapper/MeAjudaAi.ApiService/Extensions/ServiceCollectionExtensions.cs index 6dcfc2f27..518c70dfb 100644 --- a/src/Bootstrapper/MeAjudaAi.ApiService/Extensions/ServiceCollectionExtensions.cs +++ b/src/Bootstrapper/MeAjudaAi.ApiService/Extensions/ServiceCollectionExtensions.cs @@ -31,6 +31,10 @@ public static IServiceCollection AddApiServices( services.AddCustomAntiforgery(); services.AddMemoryCache(); + // Configurar Geographic Restriction options para o middleware + services.Configure( + configuration.GetSection(GeographicRestrictionOptions.SectionName)); + // Configura ForwardedHeaders para suporte a proxy reverso (load balancers, nginx, etc.) services.Configure(options => { diff --git a/tests/MeAjudaAi.Integration.Tests/Middleware/GeographicRestrictionIntegrationTests.cs b/tests/MeAjudaAi.Integration.Tests/Middleware/GeographicRestrictionIntegrationTests.cs index 6112a940d..75d60a5c1 100644 --- a/tests/MeAjudaAi.Integration.Tests/Middleware/GeographicRestrictionIntegrationTests.cs +++ b/tests/MeAjudaAi.Integration.Tests/Middleware/GeographicRestrictionIntegrationTests.cs @@ -64,14 +64,12 @@ public async Task GetProviders_WhenBlockedCity_ShouldReturn451() var json = JsonSerializer.Deserialize(content); - // Verify all expected fields are present - json.TryGetProperty("error", out var errorProp).Should().BeTrue($"Missing 'error' property. JSON: {content}"); - json.TryGetProperty("detail", out var detailProp).Should().BeTrue($"Missing 'detail' property. JSON: {content}"); + // Verify all expected fields are present (new response format from GeographicRestrictionErrorResponse) + json.TryGetProperty("message", out var messageProp).Should().BeTrue($"Missing 'message' property. JSON: {content}"); json.TryGetProperty("allowedCities", out var citiesProp).Should().BeTrue($"Missing 'allowedCities' property. JSON: {content}"); - json.TryGetProperty("yourLocation", out var locationProp).Should().BeTrue($"Missing 'yourLocation' property. JSON: {content}"); + json.TryGetProperty("userLocation", out var locationProp).Should().BeTrue($"Missing 'userLocation' property. JSON: {content}"); - errorProp.GetString().Should().Be("geographic_restriction"); - detailProp.GetString().Should().Contain("Muriaé"); + messageProp.GetString().Should().Contain("Muriaé"); citiesProp.GetArrayLength().Should().BeGreaterThan(0, "should have at least one allowed city"); locationProp.TryGetProperty("city", out var cityProp).Should().BeTrue(); cityProp.GetString().Should().Be("São Paulo"); diff --git a/tests/MeAjudaAi.Integration.Tests/Modules/Locations/IbgeUnavailabilityTests.cs b/tests/MeAjudaAi.Integration.Tests/Modules/Locations/IbgeUnavailabilityTests.cs index 381da29e7..a74384dc3 100644 --- a/tests/MeAjudaAi.Integration.Tests/Modules/Locations/IbgeUnavailabilityTests.cs +++ b/tests/MeAjudaAi.Integration.Tests/Modules/Locations/IbgeUnavailabilityTests.cs @@ -99,12 +99,12 @@ public async Task GeographicRestriction_WhenIbgeUnavailableAndCityNotAllowed_Sho response.StatusCode.Should().Be(System.Net.HttpStatusCode.UnavailableForLegalReasons, $"Expected 451 but got {(int)response.StatusCode}. Response body: {content}"); - // Verify error payload structure + // Verify error payload structure (new response format from GeographicRestrictionErrorResponse) var json = System.Text.Json.JsonSerializer.Deserialize(content); - json.GetProperty("error").GetString().Should().Be("geographic_restriction"); - json.GetProperty("yourLocation").GetProperty("city").GetString().Should().Be("Rio de Janeiro"); - json.GetProperty("yourLocation").GetProperty("state").GetString().Should().Be("RJ"); + json.GetProperty("message").GetString().Should().NotBeNullOrEmpty(); + json.GetProperty("userLocation").GetProperty("city").GetString().Should().Be("Rio de Janeiro"); + json.GetProperty("userLocation").GetProperty("state").GetString().Should().Be("RJ"); json.GetProperty("allowedCities").GetArrayLength().Should().BeGreaterThan(0); json.GetProperty("allowedStates").GetArrayLength().Should().BeGreaterThan(0); }