## What & why
S-17: a BIG inscription is valid for a fixed term; before it lapses the zorgprofessional must herregistreren. This adds a **daily herregistratie reminder sweep**.
- **Domain:** `Approve(ingeschrevenOp)` now stamps the inscription moment; `HerregistratieVoor` derives the deadline (inscription + 5-year validity); `HerregistratieReminderDue(asOf)` is the single rule (inside the 90-day window, inscribed, not yet reminded); `MarkHerregistratieReminderVerstuurd()` is idempotent.
- **Store:** `FindDueForHerregistratieReminderAsync(asOf)` — the sweep's candidate set, filtered on the aggregate's own rule (no duplicated policy).
- **Application:** `HerregistratieReminderSweep` — pure over the store + an injected `TimeProvider`; flags + persists each due inscription, returns the reminded ids.
- **Infra/API:** `HerregistratieReminderJob` (Quartz `IJob`) fires the sweep on a daily cron (03:00, overridable via `Quartz__Cron`) and logs the count. `GET /registrations/{id}` surfaces `herregistratieVoor` + `herregistratieReminderVerstuurd`.
**Decisions (both raised with you before coding):** use Quartz.NET as the PRD names it — a genuine cron concern, distinct from the queue-draining pumps, which stay as-is (**ADR-0022**, proposal #120); and the reminder's observable effect is a flag on the aggregate + a log line (no outbound notification infra in v1). No coupling rule (§8) is touched — Quartz is internal to the Domain Service.
Closes #18
Closes #120
## Definition of Done
- [x] Linked Gitea issue (above).
- [x] Failing test committed before the implementation (red→green per layer: domain rule, store query, sweep).
- [x] Implementation makes the test pass; refactor commit for the 90-day knob.
- [x] Conventional Commits referencing the issue (`refs #18`).
- [ ] CI green — awaiting Gitea Actions.
- [ ] `docker compose up` reaches green health checks within 3 minutes — API boots locally with Quartz initialised; verified in CI compose smoke.
- [x] Docs updated — ADR-0022, demo-script, BACKLOG.
- [x] ADR added — `docs/architecture/adr-0022-quartz-scheduler.md`.
- [x] Demo note in `docs/demo-script.md`.
## Notes for reviewers
- **Ripple:** `Approve()` gained the inscription moment, so the two approving handlers (`ApproveRegistration`, `BeoordeelRegistratie`) now take an injected `TimeProvider`; existing tests pass a fixed clock. All three `IRegistrationStore` implementers (prod, unit fake, acceptance) got the new query.
- **Calibration knobs:** validity (5y) and reminder lead time (90d) are domain constants marked with `ponytail:` comments; promotion path to beheer config (S-15) noted in the ADR.
- **Mutation:** the Quartz job shell is excluded from Stryker, mirroring the pumps; all rule/sweep/query logic is covered.
- Local: 152 domain unit tests green; API boots with the Quartz scheduler and `/health` green.
Reviewed-on: #121
360 lines
12 KiB
C#
360 lines
12 KiB
C#
using Big.Domain;
|
|
|
|
namespace Big.Tests;
|
|
|
|
public class RegistrationTests
|
|
{
|
|
// A fixed inscription moment for the approval tests; its exact value is irrelevant to them.
|
|
private static readonly DateTimeOffset Ingeschreven = new(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
|
[Fact]
|
|
public void Submitting_a_registration_starts_in_ingediend()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
Assert.Equal(RegistrationStatus.Ingediend, registration.Status);
|
|
Assert.Equal("123456782", registration.Bsn);
|
|
Assert.NotEqual(Guid.Empty, registration.Id.Value);
|
|
Assert.Null(registration.ZaakUrl);
|
|
Assert.Null(registration.ProcessInstanceId);
|
|
}
|
|
|
|
[Fact]
|
|
public void A_registration_defaults_to_a_domestic_diploma()
|
|
=> Assert.Equal(DiplomaOrigin.Binnenlands, Registration.Submit("123456782").DiplomaOrigin);
|
|
|
|
[Fact]
|
|
public void A_foreign_diploma_submission_records_its_origin()
|
|
=> Assert.Equal(DiplomaOrigin.Buitenlands,
|
|
Registration.Submit("123456782", DiplomaOrigin.Buitenlands).DiplomaOrigin);
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
[InlineData(null)]
|
|
public void Submitting_without_a_bsn_is_rejected(string? bsn)
|
|
=> Assert.ThrowsAny<ArgumentException>(() => Registration.Submit(bsn!));
|
|
|
|
[Fact]
|
|
public void Recording_the_started_process_keeps_its_instance_id()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.RecordProcessStarted("proc-42");
|
|
|
|
Assert.Equal("proc-42", registration.ProcessInstanceId);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
[InlineData(null)]
|
|
public void Recording_an_empty_process_instance_id_is_rejected(string? processInstanceId)
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
Assert.ThrowsAny<ArgumentException>(() => registration.RecordProcessStarted(processInstanceId!));
|
|
}
|
|
|
|
[Fact]
|
|
public void Attaching_a_zaak_records_its_url_and_keeps_the_status_ingediend()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
var zaak = new Uri("http://openzaak/zaken/api/v1/zaken/abc");
|
|
|
|
registration.AttachZaak(zaak);
|
|
|
|
Assert.Equal(zaak, registration.ZaakUrl);
|
|
Assert.Equal(RegistrationStatus.Ingediend, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Attaching_a_null_zaak_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
Assert.Throws<ArgumentNullException>(() => registration.AttachZaak(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void Re_attaching_the_same_zaak_is_idempotent()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
var zaak = new Uri("http://openzaak/zaken/api/v1/zaken/abc");
|
|
|
|
registration.AttachZaak(zaak);
|
|
registration.AttachZaak(zaak);
|
|
|
|
Assert.Equal(zaak, registration.ZaakUrl);
|
|
}
|
|
|
|
[Fact]
|
|
public void Attaching_a_conflicting_zaak_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(
|
|
() => registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/other")));
|
|
Assert.Contains("/zaken/abc", ex.Message);
|
|
Assert.Contains("/zaken/other", ex.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void Approving_a_registration_with_a_zaak_sets_it_ingeschreven()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
|
|
registration.Approve(Ingeschreven);
|
|
|
|
Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Approving_before_the_zaak_is_opened_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Approve(Ingeschreven));
|
|
|
|
Assert.Contains("no zaak", ex.Message, StringComparison.OrdinalIgnoreCase);
|
|
Assert.Equal(RegistrationStatus.Ingediend, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Approving_an_already_ingeschreven_registration_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
registration.Approve(Ingeschreven);
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Approve(Ingeschreven));
|
|
Assert.Contains("only an INGEDIEND", ex.Message);
|
|
Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Taking_a_registration_into_behandeling_moves_it_to_in_behandeling()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.TakeIntoBehandeling();
|
|
|
|
Assert.Equal(RegistrationStatus.InBehandeling, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Re_taking_an_in_behandeling_registration_is_idempotent()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.TakeIntoBehandeling();
|
|
|
|
registration.TakeIntoBehandeling();
|
|
|
|
Assert.Equal(RegistrationStatus.InBehandeling, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Taking_a_decided_registration_into_behandeling_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
registration.Approve(Ingeschreven);
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.TakeIntoBehandeling());
|
|
Assert.Contains("only an INGEDIEND", ex.Message);
|
|
Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Approving_an_in_behandeling_registration_with_a_zaak_sets_it_ingeschreven()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
registration.TakeIntoBehandeling();
|
|
|
|
registration.Approve(Ingeschreven);
|
|
|
|
Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Rejecting_a_registration_sets_it_afgewezen()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.Reject();
|
|
|
|
Assert.Equal(RegistrationStatus.Afgewezen, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Rejecting_needs_no_zaak()
|
|
{
|
|
// A registration can be turned down before its zaak is ever opened, so Reject must not require one.
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.Reject();
|
|
|
|
Assert.Equal(RegistrationStatus.Afgewezen, registration.Status);
|
|
Assert.Null(registration.ZaakUrl);
|
|
}
|
|
|
|
[Fact]
|
|
public void Rejecting_an_in_behandeling_registration_sets_it_afgewezen()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.TakeIntoBehandeling();
|
|
|
|
registration.Reject();
|
|
|
|
Assert.Equal(RegistrationStatus.Afgewezen, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Deciding_an_already_decided_registration_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.Reject();
|
|
|
|
var approveEx = Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
registration.Approve(Ingeschreven);
|
|
});
|
|
Assert.Contains("IN_BEHANDELING", approveEx.Message);
|
|
|
|
var rejectEx = Assert.Throws<InvalidOperationException>(() => registration.Reject());
|
|
Assert.Contains("Afgewezen", rejectEx.Message);
|
|
Assert.Equal(RegistrationStatus.Afgewezen, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Withdrawing_an_ingediend_registration_sets_it_ingetrokken()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.Withdraw();
|
|
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Withdrawing_an_in_behandeling_registration_sets_it_ingetrokken()
|
|
{
|
|
// A citizen can still pull a registration back while a behandelaar has it in behandeling.
|
|
var registration = Registration.Submit("123456782");
|
|
registration.TakeIntoBehandeling();
|
|
|
|
registration.Withdraw();
|
|
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Withdrawing_needs_no_zaak()
|
|
{
|
|
// Withdrawal is the citizen's own action and does not depend on the zaak having been opened.
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.Withdraw();
|
|
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, registration.Status);
|
|
Assert.Null(registration.ZaakUrl);
|
|
}
|
|
|
|
[Fact]
|
|
public void Re_withdrawing_an_already_ingetrokken_registration_is_idempotent()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.Withdraw();
|
|
|
|
registration.Withdraw();
|
|
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Withdrawing_an_approved_registration_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
registration.Approve(Ingeschreven);
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Withdraw());
|
|
Assert.Contains("only an INGEDIEND", ex.Message);
|
|
Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Withdrawing_a_rejected_registration_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.Reject();
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Withdraw());
|
|
Assert.Contains("only an INGEDIEND", ex.Message);
|
|
Assert.Equal(RegistrationStatus.Afgewezen, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Expiring_an_ingediend_registration_sets_it_verlopen()
|
|
{
|
|
// The 30-day document-wait timer fired before the documents arrived (S-10a): the case is
|
|
// cancelled and the aggregate becomes terminal VERLOPEN.
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.Expire();
|
|
|
|
Assert.Equal(RegistrationStatus.Verlopen, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Expiring_needs_no_zaak()
|
|
{
|
|
// The timer fires on a purely time-based boundary; expiry does not depend on the zaak.
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
registration.Expire();
|
|
|
|
Assert.Equal(RegistrationStatus.Verlopen, registration.Status);
|
|
Assert.Null(registration.ZaakUrl);
|
|
}
|
|
|
|
[Fact]
|
|
public void Re_expiring_an_already_verlopen_registration_is_idempotent()
|
|
{
|
|
// The RegistratieVerlopen worker job may be redelivered (§8.6); re-expiring is a no-op.
|
|
var registration = Registration.Submit("123456782");
|
|
registration.Expire();
|
|
|
|
registration.Expire();
|
|
|
|
Assert.Equal(RegistrationStatus.Verlopen, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Expiring_an_approved_registration_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc"));
|
|
registration.Approve(Ingeschreven);
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Expire());
|
|
Assert.Contains("only an INGEDIEND", ex.Message);
|
|
Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public void Expiring_a_withdrawn_registration_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.Withdraw();
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Expire());
|
|
Assert.Contains("only an INGEDIEND", ex.Message);
|
|
Assert.Equal(RegistrationStatus.Ingetrokken, registration.Status);
|
|
}
|
|
}
|