fix(api): ExceptionFilter 409 para ProductTypeInactivo y RubroInactivo (PRD-002 W1)

This commit is contained in:
2026-04-19 13:31:38 -03:00
parent 08a4738daf
commit d262454b28
2 changed files with 30 additions and 2 deletions

View File

@@ -508,7 +508,7 @@ public sealed class ExceptionFilter : IExceptionFilter
message = productTypeInactivoEx.Message message = productTypeInactivoEx.Message
}) })
{ {
StatusCode = StatusCodes.Status422UnprocessableEntity StatusCode = StatusCodes.Status409Conflict
}; };
context.ExceptionHandled = true; context.ExceptionHandled = true;
break; break;
@@ -520,7 +520,7 @@ public sealed class ExceptionFilter : IExceptionFilter
message = rubroInactivoEx.Message message = rubroInactivoEx.Message
}) })
{ {
StatusCode = StatusCodes.Status422UnprocessableEntity StatusCode = StatusCodes.Status409Conflict
}; };
context.ExceptionHandled = true; context.ExceptionHandled = true;
break; break;

View File

@@ -336,4 +336,32 @@ public sealed class ProductsControllerTests : IAsyncLifetime
var resp = await _client.SendAsync(req); var resp = await _client.SendAsync(req);
Assert.Equal(HttpStatusCode.NotFound, resp.StatusCode); Assert.Equal(HttpStatusCode.NotFound, resp.StatusCode);
} }
// ── PRD-002 W1: ExceptionFilter 409 for ProductTypeInactivo ──────────────
[Fact]
public async Task Create_WithInactiveProductType_Returns409()
{
var token = await GetAdminTokenAsync();
var (medioId, productTypeId) = await EnsureMedioAndProductTypeAsync(token);
// Deactivate the ProductType first
using var deactivatePtReq = BuildRequest(HttpMethod.Delete, $"/api/v1/admin/product-types/{productTypeId}", bearerToken: token);
var deactivatePtResp = await _client.SendAsync(deactivatePtReq);
Assert.Equal(HttpStatusCode.NoContent, deactivatePtResp.StatusCode);
// Now attempt to create a product with the inactive ProductType
using var createReq = BuildRequest(HttpMethod.Post, AdminEndpoint, new
{
nombre = $"Prod_{Guid.NewGuid():N}"[..28],
medioId,
productTypeId,
basePrice = 50m
}, token);
var createResp = await _client.SendAsync(createReq);
Assert.Equal(HttpStatusCode.Conflict, createResp.StatusCode);
var body = await createResp.Content.ReadFromJsonAsync<JsonElement>();
Assert.Equal("product_type_inactivo", body.GetProperty("error").GetString());
}
} }