diff --git a/src/api/SIGCM2.Api/Filters/ExceptionFilter.cs b/src/api/SIGCM2.Api/Filters/ExceptionFilter.cs index e5c8c73..decc84d 100644 --- a/src/api/SIGCM2.Api/Filters/ExceptionFilter.cs +++ b/src/api/SIGCM2.Api/Filters/ExceptionFilter.cs @@ -508,7 +508,7 @@ public sealed class ExceptionFilter : IExceptionFilter message = productTypeInactivoEx.Message }) { - StatusCode = StatusCodes.Status422UnprocessableEntity + StatusCode = StatusCodes.Status409Conflict }; context.ExceptionHandled = true; break; @@ -520,7 +520,7 @@ public sealed class ExceptionFilter : IExceptionFilter message = rubroInactivoEx.Message }) { - StatusCode = StatusCodes.Status422UnprocessableEntity + StatusCode = StatusCodes.Status409Conflict }; context.ExceptionHandled = true; break; diff --git a/tests/SIGCM2.Api.Tests/Products/ProductsControllerTests.cs b/tests/SIGCM2.Api.Tests/Products/ProductsControllerTests.cs index bfb795b..6b1f8ec 100644 --- a/tests/SIGCM2.Api.Tests/Products/ProductsControllerTests.cs +++ b/tests/SIGCM2.Api.Tests/Products/ProductsControllerTests.cs @@ -336,4 +336,32 @@ public sealed class ProductsControllerTests : IAsyncLifetime var resp = await _client.SendAsync(req); 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(); + Assert.Equal("product_type_inactivo", body.GetProperty("error").GetString()); + } }