diff --git a/tests/SIGCM2.Api.Tests/Auth/AuthControllerTests.cs b/tests/SIGCM2.Api.Tests/Auth/AuthControllerTests.cs index 13c6faf..5649e52 100644 --- a/tests/SIGCM2.Api.Tests/Auth/AuthControllerTests.cs +++ b/tests/SIGCM2.Api.Tests/Auth/AuthControllerTests.cs @@ -49,8 +49,9 @@ public class AuthControllerTests Assert.Equal(JsonValueKind.Array, permisos.ValueKind); // V011 (ADM-001) adds 'administracion:secciones:gestionar' → 22 // V013 (ADM-008) adds 'administracion:puntos_de_venta:gestionar' → 23 - // V014 (ADM-009) adds 'administracion:fiscal:gestionar' → 24 total - Assert.Equal(24, permisos.GetArrayLength()); + // V014 (ADM-009) adds 'administracion:fiscal:gestionar' → 24 + // V016 (CAT-001) adds 'catalogo:rubros:gestionar' → 25 total + Assert.Equal(25, permisos.GetArrayLength()); } // Scenario: invalid credentials return 401 with opaque error diff --git a/tests/SIGCM2.Api.Tests/Permisos/PermisosEndpointTests.cs b/tests/SIGCM2.Api.Tests/Permisos/PermisosEndpointTests.cs index 2936a27..4e6dcb3 100644 --- a/tests/SIGCM2.Api.Tests/Permisos/PermisosEndpointTests.cs +++ b/tests/SIGCM2.Api.Tests/Permisos/PermisosEndpointTests.cs @@ -130,7 +130,7 @@ public sealed class PermisosEndpointTests : IAsyncLifetime // ── GET /api/v1/permisos — catalog ─────────────────────────────────────── [Fact] - public async Task GetPermisos_WithAdmin_Returns200With24Items() + public async Task GetPermisos_WithAdmin_Returns200With25Items() { var token = await GetBearerTokenAsync(AdminUsername, AdminPassword); using var req = BuildRequest(HttpMethod.Get, "/api/v1/permisos", bearerToken: token); @@ -140,8 +140,9 @@ public sealed class PermisosEndpointTests : IAsyncLifetime var list = await resp.Content.ReadFromJsonAsync(); // V011 (ADM-001) adds 'administracion:secciones:gestionar' → 22 // V013 (ADM-008) adds 'administracion:puntos_de_venta:gestionar' → 23 - // V014 (ADM-009) adds 'administracion:fiscal:gestionar' → 24 total - Assert.Equal(24, list.GetArrayLength()); + // V014 (ADM-009) adds 'administracion:fiscal:gestionar' → 24 + // V016 (CAT-001) adds 'catalogo:rubros:gestionar' → 25 total + Assert.Equal(25, list.GetArrayLength()); } [Fact] @@ -184,7 +185,7 @@ public sealed class PermisosEndpointTests : IAsyncLifetime // ── GET /api/v1/roles/{codigo}/permisos ────────────────────────────────── [Fact] - public async Task GetRolPermisos_AdminRol_Returns200With24Items() + public async Task GetRolPermisos_AdminRol_Returns200With25Items() { var token = await GetBearerTokenAsync(AdminUsername, AdminPassword); using var req = BuildRequest(HttpMethod.Get, "/api/v1/roles/admin/permisos", bearerToken: token); @@ -194,8 +195,9 @@ public sealed class PermisosEndpointTests : IAsyncLifetime var list = await resp.Content.ReadFromJsonAsync(); // V011 (ADM-001) adds 'administracion:secciones:gestionar' → 22 // V013 (ADM-008) adds 'administracion:puntos_de_venta:gestionar' → 23 - // V014 (ADM-009) adds 'administracion:fiscal:gestionar' → 24 total - Assert.Equal(24, list.GetArrayLength()); + // V014 (ADM-009) adds 'administracion:fiscal:gestionar' → 24 + // V016 (CAT-001) adds 'catalogo:rubros:gestionar' → 25 total + Assert.Equal(25, list.GetArrayLength()); } [Fact] diff --git a/tests/SIGCM2.Application.Tests/Infrastructure/RefreshTokenRepositoryTests.cs b/tests/SIGCM2.Application.Tests/Infrastructure/RefreshTokenRepositoryTests.cs index ad6b299..541d1c2 100644 --- a/tests/SIGCM2.Application.Tests/Infrastructure/RefreshTokenRepositoryTests.cs +++ b/tests/SIGCM2.Application.Tests/Infrastructure/RefreshTokenRepositoryTests.cs @@ -51,6 +51,8 @@ public class RefreshTokenRepositoryTests : IAsyncLifetime new Respawn.Graph.Table("dbo", "IngresosBrutos_History"), new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es temporal — history no puede deletearse directo. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); diff --git a/tests/SIGCM2.Application.Tests/Integration/PermisoRepositoryTests.cs b/tests/SIGCM2.Application.Tests/Integration/PermisoRepositoryTests.cs index 9d64583..867919f 100644 --- a/tests/SIGCM2.Application.Tests/Integration/PermisoRepositoryTests.cs +++ b/tests/SIGCM2.Application.Tests/Integration/PermisoRepositoryTests.cs @@ -74,15 +74,16 @@ public class PermisoRepositoryTests : IAsyncLifetime // ── ListAsync ──────────────────────────────────────────────────────────── [Fact] - public async Task ListAsync_Returns23CanonicalSeeds() + public async Task ListAsync_Returns25CanonicalSeeds() { var list = await _repository.ListAsync(); // V005 seeds 18 canonical permisos + V007 (UDT-006) adds 3 admin permisos // + V011 (ADM-001) adds 'administracion:secciones:gestionar' // + V013 (ADM-008) adds 'administracion:puntos_de_venta:gestionar' - // + V014 (ADM-009) adds 'administracion:fiscal:gestionar' = 24 total - Assert.Equal(24, list.Count); + // + V014 (ADM-009) adds 'administracion:fiscal:gestionar' + // + V016 (CAT-001) adds 'catalogo:rubros:gestionar' = 25 total + Assert.Equal(25, list.Count); } [Fact] diff --git a/tests/SIGCM2.Application.Tests/Integration/RolPermisoRepositoryTests.cs b/tests/SIGCM2.Application.Tests/Integration/RolPermisoRepositoryTests.cs index 0a90f50..18674a4 100644 --- a/tests/SIGCM2.Application.Tests/Integration/RolPermisoRepositoryTests.cs +++ b/tests/SIGCM2.Application.Tests/Integration/RolPermisoRepositoryTests.cs @@ -174,15 +174,16 @@ public class RolPermisoRepositoryTests : IAsyncLifetime // ── GetByRolCodigoAsync ────────────────────────────────────────────────── [Fact] - public async Task GetByRolCodigoAsync_Admin_Returns23Permisos() + public async Task GetByRolCodigoAsync_Admin_Returns25Permisos() { // admin has 18 permisos from V006 + 3 new admin permisos from V007 (UDT-006) // + 1 from V011 (ADM-001): 'administracion:secciones:gestionar' // + 1 from V013 (ADM-008): 'administracion:puntos_de_venta:gestionar' - // + 1 from V014 (ADM-009): 'administracion:fiscal:gestionar' = 24 total + // + 1 from V014 (ADM-009): 'administracion:fiscal:gestionar' + // + 1 from V016 (CAT-001): 'catalogo:rubros:gestionar' = 25 total var permisos = await _repository.GetByRolCodigoAsync("admin"); - Assert.Equal(24, permisos.Count); + Assert.Equal(25, permisos.Count); } [Fact] diff --git a/tests/SIGCM2.Application.Tests/Integration/UsuarioRepositoryTests.cs b/tests/SIGCM2.Application.Tests/Integration/UsuarioRepositoryTests.cs index bb35e14..26d8f41 100644 --- a/tests/SIGCM2.Application.Tests/Integration/UsuarioRepositoryTests.cs +++ b/tests/SIGCM2.Application.Tests/Integration/UsuarioRepositoryTests.cs @@ -43,6 +43,8 @@ public class UsuarioRepositoryTests : IAsyncLifetime new Respawn.Graph.Table("dbo", "IngresosBrutos_History"), new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es temporal — history no puede deletearse directo. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); diff --git a/tests/SIGCM2.Application.Tests/Integration/UsuarioRepository_PermisosTests.cs b/tests/SIGCM2.Application.Tests/Integration/UsuarioRepository_PermisosTests.cs index ed0186d..aada4e2 100644 --- a/tests/SIGCM2.Application.Tests/Integration/UsuarioRepository_PermisosTests.cs +++ b/tests/SIGCM2.Application.Tests/Integration/UsuarioRepository_PermisosTests.cs @@ -47,6 +47,8 @@ public sealed class UsuarioRepository_PermisosTests : IAsyncLifetime new Respawn.Graph.Table("dbo", "IngresosBrutos_History"), new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es temporal — history no puede deletearse directo. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); diff --git a/tests/SIGCM2.Application.Tests/Integration/V009MigrationTests.cs b/tests/SIGCM2.Application.Tests/Integration/V009MigrationTests.cs index 530e4e2..6de0294 100644 --- a/tests/SIGCM2.Application.Tests/Integration/V009MigrationTests.cs +++ b/tests/SIGCM2.Application.Tests/Integration/V009MigrationTests.cs @@ -46,6 +46,8 @@ public sealed class V009MigrationTests : IAsyncLifetime new Respawn.Graph.Table("dbo", "IngresosBrutos_History"), new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es temporal — history no puede deletearse directo. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); diff --git a/tests/SIGCM2.Application.Tests/Medios/MedioRepositoryTests.cs b/tests/SIGCM2.Application.Tests/Medios/MedioRepositoryTests.cs index 80c9fdf..2323f04 100644 --- a/tests/SIGCM2.Application.Tests/Medios/MedioRepositoryTests.cs +++ b/tests/SIGCM2.Application.Tests/Medios/MedioRepositoryTests.cs @@ -49,6 +49,8 @@ public class MedioRepositoryTests : IAsyncLifetime new Respawn.Graph.Table("dbo", "IngresosBrutos_History"), new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es temporal — history no puede deletearse directo. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); diff --git a/tests/SIGCM2.Application.Tests/Secciones/SeccionRepositoryTests.cs b/tests/SIGCM2.Application.Tests/Secciones/SeccionRepositoryTests.cs index 541fb13..dd04e62 100644 --- a/tests/SIGCM2.Application.Tests/Secciones/SeccionRepositoryTests.cs +++ b/tests/SIGCM2.Application.Tests/Secciones/SeccionRepositoryTests.cs @@ -50,6 +50,8 @@ public class SeccionRepositoryTests : IAsyncLifetime new Respawn.Graph.Table("dbo", "IngresosBrutos_History"), new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es temporal — history no puede deletearse directo. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); diff --git a/tests/SIGCM2.TestSupport/SqlTestFixture.cs b/tests/SIGCM2.TestSupport/SqlTestFixture.cs index 828bd42..ab479bd 100644 --- a/tests/SIGCM2.TestSupport/SqlTestFixture.cs +++ b/tests/SIGCM2.TestSupport/SqlTestFixture.cs @@ -50,6 +50,9 @@ public sealed class SqlTestFixture : IAsyncLifetime // V015 (UDT-011): ensure dbo.v_AuditEvent_Local + dbo.v_SecurityEvent_Local views exist. await EnsureV015SchemaAsync(); + // V016 (CAT-001): ensure dbo.Rubro + temporal + permiso 'catalogo:rubros:gestionar'. + await EnsureV016SchemaAsync(); + _respawner = await Respawner.CreateAsync(_connection, new RespawnerOptions { DbAdapter = DbAdapter.SqlServer, @@ -74,6 +77,8 @@ public sealed class SqlTestFixture : IAsyncLifetime // Seed de TipoDeIva e IngresosBrutos son datos de referencia — no limpiar con Respawn. new Respawn.Graph.Table("dbo", "TipoDeIva"), new Respawn.Graph.Table("dbo", "IngresosBrutos"), + // CAT-001 (V016): Rubro es system-versioned — Respawn no puede DELETE su history. + new Respawn.Graph.Table("dbo", "Rubro_History"), ] }); @@ -187,7 +192,9 @@ public sealed class SqlTestFixture : IAsyncLifetime -- V013 (ADM-008): permiso para CRUD de Puntos de Venta ('administracion:puntos_de_venta:gestionar', N'Gestionar puntos de venta', N'Crear, editar y desactivar puntos de venta AFIP','administracion'), -- V014 (ADM-009): permiso para tablas fiscales - ('administracion:fiscal:gestionar', N'Gestionar tablas fiscales', N'Gestionar tablas fiscales (IVA, IIBB)', 'administracion') + ('administracion:fiscal:gestionar', N'Gestionar tablas fiscales', N'Gestionar tablas fiscales (IVA, IIBB)', 'administracion'), + -- V016 (CAT-001): permiso para gestionar árbol de rubros + ('catalogo:rubros:gestionar', N'Gestionar rubros del catálogo', N'Crear, editar, mover y desactivar rubros del árbol de catálogo comercial', 'catalogo') ) AS s (Codigo, Nombre, Descripcion, Modulo) ON t.Codigo = s.Codigo WHEN NOT MATCHED BY TARGET THEN @@ -233,6 +240,8 @@ public sealed class SqlTestFixture : IAsyncLifetime ('admin', 'administracion:puntos_de_venta:gestionar'), -- V014 (ADM-009) ('admin', 'administracion:fiscal:gestionar'), + -- V016 (CAT-001) + ('admin', 'catalogo:rubros:gestionar'), ('cajero', 'ventas:contado:crear'), ('cajero', 'ventas:contado:modificar'), ('cajero', 'ventas:contado:cobrar'), @@ -778,6 +787,82 @@ public sealed class SqlTestFixture : IAsyncLifetime // desde SeedPermisosCanonicalAsync / SeedRolPermisosCanonicalAsync (post-respawn). } + /// + /// CAT-001 (V016): applies dbo.Rubro schema + temporal + filtered unique index + covering index + /// + permiso 'catalogo:rubros:gestionar' idempotentemente. Mirrors V016__create_rubro.sql. + /// Nota: COLLATE debe ir ANTES de NOT NULL — parser de SQL Server 2019 es estricto con ese orden. + /// Permiso y asignación a admin se siembran desde SeedPermisosCanonicalAsync / SeedRolPermisosCanonicalAsync. + /// + private async Task EnsureV016SchemaAsync() + { + const string createRubro = """ + IF OBJECT_ID(N'dbo.Rubro', N'U') IS NULL + BEGIN + CREATE TABLE dbo.Rubro ( + Id INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_Rubro PRIMARY KEY, + ParentId INT NULL, + Nombre NVARCHAR(200) COLLATE SQL_Latin1_General_CP1_CI_AI NOT NULL, + Orden INT NOT NULL CONSTRAINT DF_Rubro_Orden DEFAULT(0), + Activo BIT NOT NULL CONSTRAINT DF_Rubro_Activo DEFAULT(1), + TarifarioBaseId INT NULL, + FechaCreacion DATETIME2(3) NOT NULL CONSTRAINT DF_Rubro_FechaCreacion DEFAULT(SYSUTCDATETIME()), + FechaModificacion DATETIME2(3) NULL, + CONSTRAINT FK_Rubro_Parent FOREIGN KEY (ParentId) REFERENCES dbo.Rubro(Id) ON DELETE NO ACTION + ); + END + """; + + const string addRubroPeriod = """ + IF COL_LENGTH('dbo.Rubro', 'ValidFrom') IS NULL + BEGIN + ALTER TABLE dbo.Rubro + ADD + ValidFrom DATETIME2(3) GENERATED ALWAYS AS ROW START HIDDEN NOT NULL + CONSTRAINT DF_Rubro_ValidFrom DEFAULT(SYSUTCDATETIME()), + ValidTo DATETIME2(3) GENERATED ALWAYS AS ROW END HIDDEN NOT NULL + CONSTRAINT DF_Rubro_ValidTo DEFAULT(CONVERT(DATETIME2(3), '9999-12-31 23:59:59.999')), + PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo); + END + """; + + const string setRubroVersioning = """ + IF NOT EXISTS (SELECT 1 FROM sys.tables WHERE object_id = OBJECT_ID('dbo.Rubro') AND temporal_type = 2) + BEGIN + ALTER TABLE dbo.Rubro + SET (SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = dbo.Rubro_History, + HISTORY_RETENTION_PERIOD = 10 YEARS + )); + END + """; + + const string createUqIndex = """ + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'UQ_Rubro_ParentId_Nombre_Activo' AND object_id = OBJECT_ID('dbo.Rubro')) + BEGIN + CREATE UNIQUE INDEX UQ_Rubro_ParentId_Nombre_Activo + ON dbo.Rubro(ParentId, Nombre) + WHERE Activo = 1 AND ParentId IS NOT NULL; + END + """; + + const string createCoveringIndex = """ + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'IX_Rubro_ParentId_Activo' AND object_id = OBJECT_ID('dbo.Rubro')) + BEGIN + CREATE INDEX IX_Rubro_ParentId_Activo + ON dbo.Rubro(ParentId, Activo) + INCLUDE (Nombre, Orden); + END + """; + + await _connection.ExecuteAsync(createRubro); + await _connection.ExecuteAsync(addRubroPeriod); + await _connection.ExecuteAsync(setRubroVersioning); + await _connection.ExecuteAsync(createUqIndex); + await _connection.ExecuteAsync(createCoveringIndex); + // Permiso 'catalogo:rubros:gestionar' y asignación a admin se siembran + // desde SeedPermisosCanonicalAsync / SeedRolPermisosCanonicalAsync (post-respawn). + } + /// /// UDT-011 (V015): applies dbo.v_AuditEvent_Local + dbo.v_SecurityEvent_Local views /// idempotently to the test database. Mirrors V015__create_local_timezone_views.sql.