The backend half of the sweep RD-18 did for the front end. git blame holds the provenance and stays correct when the code moves; the comment names a closed ticket and tells the reader nothing the sentence around it does not. public/letter.css and LetterHtml.golden.html change together, because the renderer inlines the CSS and the golden file snapshots the result. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using BigRegister.Domain.Authorization;
|
|
using Xunit;
|
|
|
|
namespace BigRegister.Tests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for the single authorization helper (PRD-0002 phase P1) that both
|
|
/// computes the brief screen's decision flags and gates the mutation endpoints.
|
|
/// </summary>
|
|
public class AuthzTests
|
|
{
|
|
private static readonly Principal Drafter = new(PrincipalRole.Drafter);
|
|
private static readonly Principal Approver = new(PrincipalRole.Approver);
|
|
private const string DrafterId = "demo-drafter";
|
|
|
|
[Fact]
|
|
public void Drafter_may_not_approve_or_reject_even_when_submitted()
|
|
{
|
|
Assert.False(Authz.CanActOn(BriefAction.Approve, Drafter, DrafterId));
|
|
Assert.False(Authz.CanActOn(BriefAction.Reject, Drafter, DrafterId));
|
|
}
|
|
|
|
[Fact]
|
|
public void Approver_may_approve_and_reject_a_different_drafters_letter()
|
|
{
|
|
Assert.True(Authz.CanActOn(BriefAction.Approve, Approver, DrafterId));
|
|
Assert.True(Authz.CanActOn(BriefAction.Reject, Approver, DrafterId));
|
|
}
|
|
|
|
[Fact]
|
|
public void Send_is_not_role_gated()
|
|
{
|
|
Assert.True(Authz.CanActOn(BriefAction.Send, Drafter, DrafterId));
|
|
Assert.True(Authz.CanActOn(BriefAction.Send, Approver, DrafterId));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("draft")]
|
|
[InlineData("rejected")]
|
|
public void Decisions_CanEdit_true_for_drafter_in_editable_statuses(string status)
|
|
{
|
|
Assert.True(Authz.Decisions(Drafter, status, DrafterId).CanEdit);
|
|
Assert.False(Authz.Decisions(Approver, status, DrafterId).CanEdit);
|
|
}
|
|
|
|
[Fact]
|
|
public void Decisions_CanApprove_requires_submitted_status_and_approver_role()
|
|
{
|
|
Assert.True(Authz.Decisions(Approver, "submitted", DrafterId).CanApprove);
|
|
Assert.False(Authz.Decisions(Approver, "draft", DrafterId).CanApprove);
|
|
Assert.False(Authz.Decisions(Drafter, "submitted", DrafterId).CanApprove);
|
|
}
|
|
|
|
[Fact]
|
|
public void Decisions_CanSend_requires_approved_status_only()
|
|
{
|
|
Assert.True(Authz.Decisions(Drafter, "approved", DrafterId).CanSend);
|
|
Assert.True(Authz.Decisions(Approver, "approved", DrafterId).CanSend);
|
|
Assert.False(Authz.Decisions(Approver, "submitted", DrafterId).CanSend);
|
|
}
|
|
|
|
[Fact]
|
|
public void RoleCapabilities_are_empty_for_drafter_and_the_three_brief_capabilities_for_approver()
|
|
{
|
|
Assert.Empty(Authz.RoleCapabilities(Drafter));
|
|
Assert.Equal(new[] { "brief:approve", "brief:reject", "brief:send" }, Authz.RoleCapabilities(Approver));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanRevealBigNummer_only_for_the_case_drafter_behandelaar()
|
|
{
|
|
Assert.True(Authz.CanRevealBigNummer(Drafter));
|
|
Assert.False(Authz.CanRevealBigNummer(Approver));
|
|
}
|
|
|
|
[Fact]
|
|
public void Decisions_CanRevealBigNummer_is_status_independent()
|
|
{
|
|
// Unlike the action gates, PII reveal does not depend on the brief's status.
|
|
Assert.True(Authz.Decisions(Drafter, "draft", DrafterId).CanRevealBigNummer);
|
|
Assert.True(Authz.Decisions(Drafter, "sent", DrafterId).CanRevealBigNummer);
|
|
Assert.False(Authz.Decisions(Approver, "draft", DrafterId).CanRevealBigNummer);
|
|
}
|
|
|
|
// --- CanBeoordelen --------------------------------------------------------------
|
|
|
|
[Fact]
|
|
public void CanBeoordelen_true_for_a_medewerker_with_the_behandelaar_rol()
|
|
{
|
|
var medewerker = new MedewerkerCaller("m.jansen", [MedewerkerRol.Behandelaar], "M. Jansen", PrincipalRole.Drafter);
|
|
Assert.True(Authz.CanBeoordelen(medewerker));
|
|
}
|
|
|
|
[Fact]
|
|
public void CanBeoordelen_false_for_a_medewerker_without_it()
|
|
{
|
|
var medewerker = new MedewerkerCaller("m.jansen", [], "M. Jansen", PrincipalRole.Drafter);
|
|
Assert.False(Authz.CanBeoordelen(medewerker));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(PrincipalRole.Drafter)]
|
|
[InlineData(PrincipalRole.Approver)]
|
|
[InlineData(PrincipalRole.Admin)]
|
|
public void CanBeoordelen_false_for_a_zorgverlener_regardless_of_role(PrincipalRole role)
|
|
{
|
|
var zorgverlener = new ZorgverlenerCaller("111222333", "Dr. Test", role);
|
|
Assert.False(Authz.CanBeoordelen(zorgverlener));
|
|
}
|
|
}
|