fix(backend+tests): reactivate endpoint 500 + test schema mismatches (PRC-001)

Three bugs surfaced while user smoke-testing Reactivate:

1. ReactivateAsync opened a SECOND connection for GetByIdAsync after the SP
   call, inside the ambient TransactionScope. This promoted the tx to DTC
   (distributed) which requires MSDTC — typically not enabled on dev/prod
   servers. The API returned an opaque 500. Fix: run the post-SP SELECT on
   the SAME connection (local tx stays lightweight / LTM).

2. Agent 1's V023 test refactor wrote 'INSERT INTO dbo.ProductType (Nombre,
   Codigo, Activo)' in 2 test files — but dbo.ProductType has no 'Codigo' or
   'Activo' columns (schema is Nombre + IsActive + flags + multimedia limits).
   Fix: use '(Nombre, HasDuration, RequiresText, RequiresCategory, IsBundle,
   AllowImages)' matching the other test files (ProductQueryRepositoryTests,
   ProductRepositoryTests, ProductPriceRepositoryIntegrationTests).

3. SqlTestFixture.EnsureV021SchemaAsync unconditionally ALTERed the V021-era
   SPs with '@MedioId' body. On second fixture run after V023 had already
   refactored the table, ALTER PROCEDURE body referenced a MedioId column
   that no longer existed — 'Invalid column name MedioId'. Fix: guard the
   V021 SP ALTERs + seedV022 behind 'MedioId column exists' check. If V023
   already dropped MedioId, skip V021 re-install; EnsureV023SchemaAsync
   still recreates SPs with @ProductTypeId.

4. PricingExceptionTests still used 'medioId:' named-arg + '.MedioId' — Agent 2
   renamed the exception property but not these 6 test references.

Tests: 1297/1297 Application.Tests green.
This commit is contained in:
2026-04-21 11:32:23 -03:00
parent 40b5f3904a
commit d7c6cbd4ff
5 changed files with 58 additions and 25 deletions

View File

@@ -51,15 +51,15 @@ public sealed class ChargeableCharConfigHardeningTests : IAsyncLifetime
// Seed two dedicated ProductTypes for override/fallback resolution tests.
// V023: ChargeableCharConfig.ProductTypeId references dbo.ProductType(Id).
_productType1Id = await conn.ExecuteScalarAsync<int>("""
INSERT INTO dbo.ProductType (Nombre, Codigo, Activo)
INSERT INTO dbo.ProductType (Nombre, HasDuration, RequiresText, RequiresCategory, IsBundle, AllowImages)
OUTPUT INSERTED.Id
VALUES ('Hardening PT1 (override)', 'H_PT1', 1)
VALUES ('Hardening PT1 (override)', 0, 0, 0, 0, 0)
""");
_productType2Id = await conn.ExecuteScalarAsync<int>("""
INSERT INTO dbo.ProductType (Nombre, Codigo, Activo)
INSERT INTO dbo.ProductType (Nombre, HasDuration, RequiresText, RequiresCategory, IsBundle, AllowImages)
OUTPUT INSERTED.Id
VALUES ('Hardening PT2 (fallback)', 'H_PT2', 1)
VALUES ('Hardening PT2 (fallback)', 0, 0, 0, 0, 0)
""");
}

View File

@@ -58,9 +58,9 @@ public class ChargeableCharConfigRepositoryIntegrationTests : IAsyncLifetime
await conn.OpenAsync();
_productTypeId = await conn.ExecuteScalarAsync<int>("""
INSERT INTO dbo.ProductType (Nombre, Codigo, Activo)
INSERT INTO dbo.ProductType (Nombre, HasDuration, RequiresText, RequiresCategory, IsBundle, AllowImages)
OUTPUT INSERTED.Id
VALUES ('RepoIntegration PT1', 'RI_PT1', 1)
VALUES ('RepoIntegration PT1', 0, 0, 0, 0, 0)
""");
}
@@ -263,9 +263,9 @@ public class ChargeableCharConfigRepositoryIntegrationTests : IAsyncLifetime
await using var conn = new SqlConnection(TestConnectionStrings.AppTestDb);
await conn.OpenAsync();
var otherPTId = await conn.ExecuteScalarAsync<int>("""
INSERT INTO dbo.ProductType (Nombre, Codigo, Activo)
INSERT INTO dbo.ProductType (Nombre, HasDuration, RequiresText, RequiresCategory, IsBundle, AllowImages)
OUTPUT INSERTED.Id
VALUES ('RepoIntegration PT2 NoOverride', 'RI_PT2', 1)
VALUES ('RepoIntegration PT2 NoOverride', 0, 0, 0, 0, 0)
""");
var rows = await repo.GetActiveForProductTypeAsync((long)otherPTId, asOf);