- Concurrent_besluiten_on_the_same_aanvraag_yield_exactly_one_success: races two besluiten on the same open aanvraag, asserts exactly one 200 and one 409 — the behavior F2's in-lock guard exists to guarantee. - Only_a_non_approval_requires_a_toelichting: unit test for BeoordelingRules.RequiresToelichting (F6). - A_terminal_decision_refuses_any_further_besluit / MeerInfoOpvragen_is_not_terminal_a_further_besluit_is_still_legal: the transition table at the aggregate level (T3) — an Aanvraag whose BesluitStatus already records a decision computes a terminal StatusAt, and CanDecide refuses a further besluit, independent of the endpoint-level equivalent. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
242 lines
8.3 KiB
C#
242 lines
8.3 KiB
C#
using BigRegister.Api.Data;
|
|
using BigRegister.Domain.Applications;
|
|
using BigRegister.Domain.Beoordeling;
|
|
using BigRegister.Domain.Diplomas;
|
|
using BigRegister.Domain.Documents;
|
|
using BigRegister.Domain.Registrations;
|
|
using BigRegister.Domain.Submissions;
|
|
|
|
namespace BigRegister.Tests;
|
|
|
|
public class DocumentRuleTests
|
|
{
|
|
[Fact]
|
|
public void Rejects_unknown_category() =>
|
|
Assert.NotNull(DocumentRules.RejectUpload(null, "application/pdf", 1));
|
|
|
|
[Fact]
|
|
public void Rejects_disallowed_type()
|
|
{
|
|
var c = DocumentRules.Find("registratie", "diploma");
|
|
Assert.NotNull(DocumentRules.RejectUpload(c, "text/plain", 1));
|
|
}
|
|
|
|
[Fact]
|
|
public void Rejects_oversized_file()
|
|
{
|
|
var c = DocumentRules.Find("registratie", "diploma");
|
|
Assert.NotNull(DocumentRules.RejectUpload(c, "application/pdf", 11L * 1024 * 1024));
|
|
}
|
|
|
|
[Fact]
|
|
public void Accepts_valid_file()
|
|
{
|
|
var c = DocumentRules.Find("registratie", "diploma");
|
|
Assert.Null(DocumentRules.RejectUpload(c, "application/pdf", 5L * 1024 * 1024));
|
|
}
|
|
|
|
private static IReadOnlyList<string> Ids(string? herkomst, string? taalvaardigheid) =>
|
|
DocumentRules.CategoriesFor("registratie", herkomst, taalvaardigheid).Select(c => c.CategoryId).ToList();
|
|
|
|
[Fact]
|
|
public void First_load_has_no_diploma_upload() => // no diploma chosen yet
|
|
Assert.Equal(new[] { "identiteit" }, Ids(null, null));
|
|
|
|
[Fact]
|
|
public void Manual_diploma_needs_a_diploma_upload() =>
|
|
Assert.Equal(new[] { "diploma", "identiteit" }, Ids("handmatig", null));
|
|
|
|
[Fact]
|
|
public void Duo_diploma_skips_diploma_upload() =>
|
|
Assert.DoesNotContain("diploma", Ids("duo", null));
|
|
|
|
[Fact]
|
|
public void Confirmed_dutch_proficiency_requires_taalvaardigheid_proof() =>
|
|
Assert.Contains("taalvaardigheid", Ids("handmatig", "ja"));
|
|
|
|
[Fact]
|
|
public void Unconfirmed_proficiency_requires_no_taalvaardigheid_proof() =>
|
|
Assert.DoesNotContain("taalvaardigheid", Ids("handmatig", "nee"));
|
|
|
|
[Fact]
|
|
public void Find_resolves_taalvaardigheid_for_upload_validation() =>
|
|
Assert.NotNull(DocumentRules.Find("registratie", "taalvaardigheid"));
|
|
}
|
|
|
|
public class HerregistratieRuleTests
|
|
{
|
|
private static Registration Active(DateOnly deadline) => new(
|
|
"19012345601", "Test", "Arts",
|
|
new DateOnly(2012, 9, 1), new DateOnly(1985, 3, 14),
|
|
new RegistrationStatus(StatusTag.Geregistreerd, HerregistratieDatum: deadline));
|
|
|
|
[Fact]
|
|
public void Eligible_within_window()
|
|
{
|
|
var (eligible, reason) = HerregistratieRule.Evaluate(
|
|
Active(new DateOnly(2027, 3, 1)), today: new DateOnly(2026, 6, 26));
|
|
Assert.True(eligible);
|
|
Assert.Contains("12 maanden", reason);
|
|
}
|
|
|
|
[Fact]
|
|
public void Not_eligible_before_window()
|
|
{
|
|
var (eligible, _) = HerregistratieRule.Evaluate(
|
|
Active(new DateOnly(2027, 3, 1)), today: new DateOnly(2025, 1, 1));
|
|
Assert.False(eligible);
|
|
}
|
|
|
|
[Fact]
|
|
public void Eligible_on_window_boundary()
|
|
{
|
|
// window opens exactly 12 months before the deadline
|
|
var (eligible, _) = HerregistratieRule.Evaluate(
|
|
Active(new DateOnly(2027, 3, 1)), today: new DateOnly(2026, 3, 1));
|
|
Assert.True(eligible);
|
|
}
|
|
|
|
[Fact]
|
|
public void Suspended_is_not_eligible()
|
|
{
|
|
var reg = Active(new DateOnly(2027, 3, 1)) with
|
|
{
|
|
Status = new RegistrationStatus(StatusTag.Geschorst, GeschorstTot: new DateOnly(2027, 1, 1), Reden: "x"),
|
|
};
|
|
var (eligible, _) = HerregistratieRule.Evaluate(reg, today: new DateOnly(2026, 6, 26));
|
|
Assert.False(eligible);
|
|
}
|
|
|
|
[Fact]
|
|
public void Status_consistency_invariant()
|
|
{
|
|
Assert.True(HerregistratieRule.IsStatusConsistent(
|
|
new RegistrationStatus(StatusTag.Geregistreerd, HerregistratieDatum: new DateOnly(2027, 3, 1))));
|
|
Assert.False(HerregistratieRule.IsStatusConsistent(
|
|
new RegistrationStatus(StatusTag.Geregistreerd)));
|
|
}
|
|
}
|
|
|
|
public class DiplomaRuleTests
|
|
{
|
|
private static Diploma Diploma(string opleiding, bool engelstalig) =>
|
|
new("x", "naam", "instelling", 2011, opleiding, engelstalig);
|
|
|
|
[Theory]
|
|
[InlineData("geneeskunde", "Arts")]
|
|
[InlineData("verpleegkunde", "Verpleegkundige")]
|
|
[InlineData("onbekend-programma", "Onbekend")]
|
|
public void Profession_is_derived_from_program(string opleiding, string expected) =>
|
|
Assert.Equal(expected, DiplomaRules.ProfessionFor(Diploma(opleiding, false)));
|
|
|
|
[Fact]
|
|
public void English_diploma_requires_dutch_proficiency()
|
|
{
|
|
var questions = DiplomaRules.QuestionsFor(Diploma("geneeskunde", engelstalig: true));
|
|
Assert.Single(questions);
|
|
Assert.Equal("nl-taalvaardigheid", questions[0].Id);
|
|
}
|
|
|
|
[Fact]
|
|
public void Dutch_diploma_has_no_policy_questions() =>
|
|
Assert.Empty(DiplomaRules.QuestionsFor(Diploma("geneeskunde", engelstalig: false)));
|
|
|
|
[Fact]
|
|
public void Manual_diploma_gets_maximal_set()
|
|
{
|
|
var questions = DiplomaRules.ManualQuestions();
|
|
Assert.Equal(3, questions.Count);
|
|
Assert.Equal(new[] { "nl-taalvaardigheid", "diploma-erkend", "toelichting" },
|
|
questions.Select(q => q.Id));
|
|
}
|
|
|
|
[Fact]
|
|
public void Manual_professions_match_known_programs() =>
|
|
Assert.Equal(new[] { "Arts", "Verpleegkundige", "Fysiotherapeut", "Apotheker", "Tandarts" },
|
|
DiplomaRules.ManualProfessions());
|
|
}
|
|
|
|
public class SubmissionRuleTests
|
|
{
|
|
[Fact]
|
|
public void Manual_diploma_is_rejected() =>
|
|
Assert.NotNull(SubmissionRules.RejectRegistratie("handmatig"));
|
|
|
|
[Fact]
|
|
public void Duo_diploma_is_accepted() =>
|
|
Assert.Null(SubmissionRules.RejectRegistratie("duo"));
|
|
|
|
[Fact]
|
|
public void Zero_hours_is_rejected() =>
|
|
Assert.NotNull(SubmissionRules.RejectZeroUren(0));
|
|
|
|
[Fact]
|
|
public void Worked_hours_are_accepted() =>
|
|
Assert.Null(SubmissionRules.RejectZeroUren(40));
|
|
|
|
[Theory]
|
|
[InlineData("0612345678", null)] // valid mobile
|
|
[InlineData("070 123 45 67", null)] // valid landline, formatting stripped
|
|
[InlineData("nope", "Voer een geldig telefoonnummer in, bijv. 0612345678.")]
|
|
[InlineData("12345", "Voer een geldig telefoonnummer in, bijv. 0612345678.")]
|
|
public void Phone_change_is_validated(string telefoon, string? expected) =>
|
|
Assert.Equal(expected, SubmissionRules.RejectPhoneChange(telefoon));
|
|
}
|
|
|
|
public class BeoordelingRuleTests
|
|
{
|
|
[Theory]
|
|
[InlineData(AanvraagStatusTag.Ingediend, true)]
|
|
[InlineData(AanvraagStatusTag.InBehandeling, true)]
|
|
[InlineData(AanvraagStatusTag.MeerInfoGevraagd, true)]
|
|
[InlineData(AanvraagStatusTag.Goedgekeurd, false)]
|
|
[InlineData(AanvraagStatusTag.Afgewezen, false)]
|
|
public void Only_open_statuses_are_decidable(AanvraagStatusTag tag, bool expected) =>
|
|
Assert.Equal(expected, BeoordelingRules.CanDecide(tag));
|
|
|
|
// WP-68 (F6): the toelichting rule, moved here from an inline endpoint check.
|
|
[Theory]
|
|
[InlineData(Besluit.Goedkeuren, false)]
|
|
[InlineData(Besluit.Afwijzen, true)]
|
|
[InlineData(Besluit.MeerInfoOpvragen, true)]
|
|
public void Only_a_non_approval_requires_a_toelichting(Besluit besluit, bool expected) =>
|
|
Assert.Equal(expected, BeoordelingRules.RequiresToelichting(besluit));
|
|
|
|
// WP-68 (T3): the transition table at the AGGREGATE level, not just against a bare tag —
|
|
// an Aanvraag whose BesluitStatus already records a terminal decision computes a terminal
|
|
// StatusAt, and CanDecide refuses a further besluit regardless of which one. Pins the
|
|
// domain statement "Afgewezen/Goedgekeurd → no further besluit" independent of the
|
|
// endpoint's own (integration-level) Already_decided_case_rejects_a_further_besluit.
|
|
private static Aanvraag Decided(Besluit besluit) => new()
|
|
{
|
|
Id = "x",
|
|
Type = "registratie",
|
|
Owner = "test",
|
|
Submitted = true,
|
|
Referentie = "BIG-2026-1",
|
|
SubmittedAt = DateTimeOffset.UtcNow,
|
|
CreatedAt = DateTimeOffset.UtcNow,
|
|
UpdatedAt = DateTimeOffset.UtcNow,
|
|
BesluitStatus = besluit,
|
|
BesluitToelichting = besluit == Besluit.Goedkeuren ? null : "toelichting",
|
|
};
|
|
|
|
[Theory]
|
|
[InlineData(Besluit.Goedkeuren)]
|
|
[InlineData(Besluit.Afwijzen)]
|
|
public void A_terminal_decision_refuses_any_further_besluit(Besluit recorded)
|
|
{
|
|
var now = DateTimeOffset.UtcNow;
|
|
var tag = Decided(recorded).StatusAt(now).Tag!.Value;
|
|
Assert.False(BeoordelingRules.CanDecide(tag));
|
|
}
|
|
|
|
[Fact]
|
|
public void MeerInfoOpvragen_is_not_terminal_a_further_besluit_is_still_legal()
|
|
{
|
|
var now = DateTimeOffset.UtcNow;
|
|
var tag = Decided(Besluit.MeerInfoOpvragen).StatusAt(now).Tag!.Value;
|
|
Assert.True(BeoordelingRules.CanDecide(tag));
|
|
}
|
|
}
|