Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static IServiceCollection AddApiServices(
services.AddCustomAntiforgery();
services.AddMemoryCache();

// Configurar Geographic Restriction options para o middleware
services.Configure<GeographicRestrictionOptions>(
configuration.GetSection(GeographicRestrictionOptions.SectionName));

// Configura ForwardedHeaders para suporte a proxy reverso (load balancers, nginx, etc.)
services.Configure<ForwardedHeadersOptions>(options =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ public async Task GetProviders_WhenBlockedCity_ShouldReturn451()

var json = JsonSerializer.Deserialize<JsonElement>(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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Text.Json.JsonElement>(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);
}
Expand Down