## 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
91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using Big.Domain;
|
|
|
|
namespace Big.Tests;
|
|
|
|
// S-17 (#18): a BIG inscription is valid for a fixed term; before it lapses the zorgprofessional must
|
|
// herregistreren. The aggregate records when it was inscribed, derives the herregistratie deadline, and
|
|
// answers whether a reminder is due as of a given moment — the single rule the Quartz sweep and the
|
|
// store query both build on. All arithmetic is against an explicit "now" so it is wall-clock-free.
|
|
public class RegistrationHerregistratieTests
|
|
{
|
|
private static readonly DateTimeOffset Now = new(2026, 7, 23, 0, 0, 0, TimeSpan.Zero);
|
|
|
|
// The moment the reminder window opens: inscribed exactly (geldigheid - herinneringstermijn) ago.
|
|
private static DateTimeOffset InscribedSoDueAt(DateTimeOffset asOf)
|
|
=> asOf - Registration.HerregistratieGeldigheid + Registration.Herinneringstermijn;
|
|
|
|
private static Registration Inscribed(DateTimeOffset ingeschrevenOp)
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
registration.AttachZaak(FakeAclClient.DefaultZaakUrl);
|
|
registration.Approve(ingeschrevenOp);
|
|
return registration;
|
|
}
|
|
|
|
[Fact]
|
|
public void Approving_records_the_inscription_moment_and_the_herregistratie_deadline()
|
|
{
|
|
var registration = Inscribed(Now);
|
|
|
|
Assert.Equal(Now, registration.IngeschrevenOp);
|
|
Assert.Equal(Now + Registration.HerregistratieGeldigheid, registration.HerregistratieVoor);
|
|
}
|
|
|
|
[Fact]
|
|
public void A_reminder_is_due_the_moment_the_window_before_the_deadline_opens()
|
|
{
|
|
var registration = Inscribed(InscribedSoDueAt(Now));
|
|
|
|
Assert.True(registration.HerregistratieReminderDue(Now));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_reminder_is_not_yet_due_one_day_before_the_window_opens()
|
|
{
|
|
var registration = Inscribed(InscribedSoDueAt(Now) + TimeSpan.FromDays(1));
|
|
|
|
Assert.False(registration.HerregistratieReminderDue(Now));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_registration_that_is_not_ingeschreven_is_never_due_and_has_no_deadline()
|
|
{
|
|
var registration = Registration.Submit("123456782"); // INGEDIEND, never inscribed
|
|
|
|
Assert.Null(registration.IngeschrevenOp);
|
|
Assert.Null(registration.HerregistratieVoor);
|
|
Assert.False(registration.HerregistratieReminderDue(Now));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_reminded_registration_is_no_longer_due()
|
|
{
|
|
var registration = Inscribed(InscribedSoDueAt(Now));
|
|
|
|
registration.MarkHerregistratieReminderVerstuurd();
|
|
|
|
Assert.True(registration.HerregistratieReminderVerstuurd);
|
|
Assert.False(registration.HerregistratieReminderDue(Now));
|
|
}
|
|
|
|
[Fact]
|
|
public void Marking_the_reminder_sent_twice_is_idempotent()
|
|
{
|
|
var registration = Inscribed(InscribedSoDueAt(Now));
|
|
|
|
registration.MarkHerregistratieReminderVerstuurd();
|
|
registration.MarkHerregistratieReminderVerstuurd();
|
|
|
|
Assert.True(registration.HerregistratieReminderVerstuurd);
|
|
}
|
|
|
|
[Fact]
|
|
public void Marking_a_reminder_on_a_registration_that_is_not_ingeschreven_is_rejected()
|
|
{
|
|
var registration = Registration.Submit("123456782");
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.MarkHerregistratieReminderVerstuurd());
|
|
Assert.Contains("INGESCHREVEN", ex.Message);
|
|
}
|
|
}
|