Files
KArtSell.Aegis/tests/KArtSell.Integration.Tests/ApprovalWorkflowPolicyTests.cs
T
kjh2064 14e2cedc4f fix: resolve DEBT-017 duplicate ApprovalWorkflow implementation
Adopt Features/ApprovalWorkflow/ (wired into Program.cs, reachable over
HTTP) as the sole VS-26 (formerly VS-03) maker-checker approval slice.
Delete the dead, [DontRegister]'d duplicate under
ApprovalWorkflow/ (Workstream H) and its dedicated test file, which had
been misleadingly credited with "20/20 tests PASS" while being
unreachable at runtime.

- Sql.cs: fix the same Dapper DateOnly-parameter-binding bug that was
  already found and fixed in the now-deleted implementation
  (commit 2ccf74c) but had not been ported to this one; InsertProposalAsync
  would have failed 100% of the time against a real database.
- tests/.../ApprovalWorkflow/ApprovalWorkflowTests.cs: new Handler+Sql+
  real-Postgres integration coverage (create/approve/activate role
  gating, maker!=checker separation of duties, evidence attachment,
  DateOnly round-trip, list filtering) replacing the deleted dead-code
  suite at the same path.
- ApprovalWorkflowPolicyTests.cs: extended (5->10 cases) rather than
  replaced, since it already tested the kept implementation's Policy.
- Program.cs: drop the reference comment to the deleted namespace.
- TECH_DEBT_REGISTER.md: DEBT-017 marked Completed (DB verification
  pending); corrected stale DEBT-023 to point at this resolution;
  registered two residual gaps discovered (not introduced) by this
  cleanup as DEBT-025 (no GET /approvals/{id}, evidence unreachable via
  HTTP) and DEBT-026 (no wired Draft->Proposed transition, so the
  approve/activate path is currently unreachable end-to-end via HTTP).
- WBS_PROGRESS_TRACKER.csv / CURRENT_ROADMAP.md: AEG-VS-26-01 kept
  BLOCKED, not COMPLETED — no PostgreSQL was reachable in this session
  (127.0.0.1:5432 connection refused), so the 8 new integration tests
  are unverified; only the 10 pure-Policy tests were confirmed passing.

Cherry-picked cedc8d7/8c777df from docs/wbs-tracker-current-state onto
this worktree branch first, to bring in the VS-26 renumbering and
ADR-WBS-001 that this task's brief assumed already existed.

dotnet build -c Release: 0 errors/0 warnings.
dotnet test --filter "FullyQualifiedName~ApprovalWorkflow" -c Release:
10 passed (Policy, no DB), 15 failed (DB connection refused - includes
6 unrelated pre-existing tests matched by the filter substring).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-08 13:05:03 +09:00

84 lines
3.1 KiB
C#

namespace KArtSell.Integration.Tests;
using KArtSell.Modules.ModelOperations.Domain.ApprovalWorkflow;
using KArtSell.Modules.ModelOperations.Features.ApprovalWorkflow;
using Xunit;
public class ApprovalWorkflowPolicyTests
{
[Fact]
public void CanCreateProposal_MakerRole_ReturnsTrue()
{
var result = ApprovalWorkflowPolicy.CanCreateProposal("maker@test.com", "Maker");
Assert.True(result);
}
[Fact]
public void CanCreateProposal_NonMakerRole_ReturnsFalse()
{
var result = ApprovalWorkflowPolicy.CanCreateProposal("user@test.com", "Viewer");
Assert.False(result);
}
[Fact]
public void CanApprove_CheckerDifferentFromMaker_ReturnsTrue()
{
var proposal = new ApprovalProposal { CreatedBy = "maker@test.com", Justification = "test", Status = ApprovalStatus.Proposed };
var result = ApprovalWorkflowPolicy.CanApprove(proposal, "checker@test.com", "Checker");
Assert.True(result);
}
[Fact]
public void CanApprove_SeparationOfDuties_Enforced()
{
var proposal = new ApprovalProposal { CreatedBy = "user@test.com", Justification = "test", Status = ApprovalStatus.Proposed };
var result = ApprovalWorkflowPolicy.CanApprove(proposal, "user@test.com", "Checker");
Assert.False(result);
}
[Fact]
public void CanApprove_NonCheckerRole_ReturnsFalse()
{
var proposal = new ApprovalProposal { CreatedBy = "maker@test.com", Justification = "test", Status = ApprovalStatus.Proposed };
var result = ApprovalWorkflowPolicy.CanApprove(proposal, "other@test.com", "Maker");
Assert.False(result);
}
[Fact]
public void CanActivate_SreRoleWithApprovedStatus_ReturnsTrue()
{
var proposal = new ApprovalProposal { CreatedBy = "maker@test.com", Justification = "test", Status = ApprovalStatus.Approved };
var result = ApprovalWorkflowPolicy.CanActivate(proposal, "sre@test.com", "SRE");
Assert.True(result);
}
[Fact]
public void CanActivate_NonSreRole_ReturnsFalse()
{
var proposal = new ApprovalProposal { CreatedBy = "maker@test.com", Justification = "test", Status = ApprovalStatus.Approved };
var result = ApprovalWorkflowPolicy.CanActivate(proposal, "maker@test.com", "Maker");
Assert.False(result);
}
[Fact]
public void CanActivate_ApprovedRequired_NonApprovedStatus_ReturnsFalse()
{
var proposal = new ApprovalProposal { CreatedBy = "maker@test.com", Justification = "test", Status = ApprovalStatus.Proposed };
var result = ApprovalWorkflowPolicy.CanActivate(proposal, "sre@test.com", "SRE");
Assert.False(result);
}
[Fact]
public void ValidateProposalState_ValidTransition_Succeeds()
{
ApprovalWorkflowPolicy.ValidateProposalState(ApprovalStatus.Draft, ApprovalStatus.Proposed);
}
[Fact]
public void ValidateProposalState_InvalidTransition_Throws()
{
Assert.Throws<InvalidOperationException>(() =>
ApprovalWorkflowPolicy.ValidateProposalState(ApprovalStatus.Draft, ApprovalStatus.Active));
}
}