feat(api): UDT-004 dominio + repositorio + application roles (tdd)
- Migraciones V003 (tabla Rol + 8 seeds canonicos) y V004 (drop CK + FK Usuario.Rol) - Dominio: Rol entity + 3 excepciones (RolNotFound/AlreadyExists/InUse) - Infraestructura: RolRepository (Dapper) con List/Get/ExistsActive/Add/Update/HasActiveUsuarios - Application: CRUD queries y commands (List, Get, Create, Update, Deactivate) + validators (codigo regex ^[a-z][a-z0-9_]*$) - Validator UDT-003: whitelist alineada a codigos canonicos (full IRolRepository lookup diferido a Phase 5.1) - Tests: 169 application + 15 api (todos verdes). Respawn configurado para re-seedear Rol canonical post-reset. - Estricto TDD: RED/GREEN/TRIANGULATE en todos los handlers nuevos.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using FluentValidation.TestHelper;
|
||||
using SIGCM2.Application.Roles.Create;
|
||||
|
||||
namespace SIGCM2.Application.Tests.Roles.Create;
|
||||
|
||||
public class CreateRolCommandValidatorTests
|
||||
{
|
||||
private static CreateRolCommandValidator BuildValidator() => new();
|
||||
private static CreateRolCommand Valid() => new("cajero_senior", "Cajero Senior", "Cajero con permisos extendidos");
|
||||
|
||||
// ── Happy path ─────────────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Validate_Valid_NoErrors()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid()).ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_NullDescripcion_IsValid()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Descripcion = null }).ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
// ── Codigo ─────────────────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Validate_EmptyCodigo_HasError()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Codigo = "" })
|
||||
.ShouldHaveValidationErrorFor(c => c.Codigo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_CodigoTooShort_HasError()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Codigo = "ab" })
|
||||
.ShouldHaveValidationErrorFor(c => c.Codigo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_CodigoTooLong_HasError()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Codigo = new string('a', 31) })
|
||||
.ShouldHaveValidationErrorFor(c => c.Codigo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("abc")] // boundary short
|
||||
[InlineData("cajero")]
|
||||
[InlineData("operador_ctacte")]
|
||||
[InlineData("jefe_publicidad")]
|
||||
[InlineData("a1b2")]
|
||||
public void Validate_CodigoValidFormats_NoError(string codigo)
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Codigo = codigo })
|
||||
.ShouldNotHaveValidationErrorFor(c => c.Codigo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Cajero")] // uppercase
|
||||
[InlineData("1cajero")] // starts with digit
|
||||
[InlineData("_cajero")] // starts with underscore
|
||||
[InlineData("cajero senior")] // space
|
||||
[InlineData("cajero-senior")] // dash
|
||||
[InlineData("cajero.senior")] // dot
|
||||
public void Validate_CodigoInvalidFormats_HasError(string codigo)
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Codigo = codigo })
|
||||
.ShouldHaveValidationErrorFor(c => c.Codigo);
|
||||
}
|
||||
|
||||
// ── Nombre ─────────────────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Validate_EmptyNombre_HasError()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Nombre = "" })
|
||||
.ShouldHaveValidationErrorFor(c => c.Nombre);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_NombreTooLong_HasError()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Nombre = new string('a', 61) })
|
||||
.ShouldHaveValidationErrorFor(c => c.Nombre);
|
||||
}
|
||||
|
||||
// ── Descripcion ────────────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Validate_DescripcionTooLong_HasError()
|
||||
{
|
||||
BuildValidator().TestValidate(Valid() with { Descripcion = new string('a', 251) })
|
||||
.ShouldHaveValidationErrorFor(c => c.Descripcion);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user