feat: PRD-002 Product CRUD #40
@@ -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;
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user