All checks were successful
## What & why First sub-slice of **S-11 · Withdrawal (Flow 3)** (#12). A zorgprofessional can withdraw a still-open registration ("trek aanvraag in"); this sub-slice delivers the **domain transition + endpoint**, mirroring how S-12a shipped the beoordeling decision model on its own (#82). - `RegistrationStatus.Ingetrokken` (terminal). - `Registration.Withdraw()` — allowed from INGEDIEND or IN_BEHANDELING, needs no zaak, idempotent, and rejected once the registration has been decided (INGESCHREVEN/AFGEWEZEN). - `WithdrawRegistration` application handler (load → withdraw → persist; repeated withdrawal is a no-op). - `POST /registrations/{id}/withdraw` on the domain API. Demoable: `POST /registrations/{id}/withdraw` → `GET /registrations/{id}` shows `INGETROKKEN`. Refs #12 (not closing — see below). ## Scope / follow-ups S-11 is bigger than one slice, so it is split (CLAUDE.md §13), like S-12 was: - **S-11a (this PR)** — domain withdrawal transition + endpoint. - **S-11b** — cancel the running Flowable process via a BPMN message event, so a withdrawn case leaves the behandelaar's werkbak. - **S-11c** — owner-scoped BFF self-service withdraw endpoint + "trek aanvraag in" button + e2e. Cancelling the Flowable process is deliberately deferred (documented in `WithdrawRegistration`), exactly as the beoordeling's rejection deferred its zaak propagation. #12 stays open until S-11c. ## Definition of Done - [x] Linked Gitea issue (#12). - [x] Failing test committed before the implementation. - [x] Implementation makes the test pass. - [x] Conventional Commits referencing the issue (`refs #12`). - [ ] CI green — all Gitea Actions jobs. - [x] `docker compose up` unaffected (no infra/contract change). - [x] Docs — none needed for this backend sub-slice; the user-visible demo note lands with S-11c. - [x] No ADR needed — mirrors existing aggregate/handler/endpoint patterns; no boundary change. ## Notes for reviewers - Verified locally: `Big.Tests` 89/89 pass; `Big.Api` builds clean. - The domain trusts its callers (§8.3); owner-scoping by the caller's bsn is enforced at the BFF in S-11c. Reviewed-on: #88
289 lines
9.3 KiB
C#
289 lines
9.3 KiB
C#
using Big.Domain;
|
|
|
|
namespace Big.Tests;
|
|
|
|
public class RegistrationTests
|
|
{
|
|
[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);
|
|
}
|
|
|
|
[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();
|
|
|
|
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());
|
|
|
|
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();
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => registration.Approve());
|
|
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();
|
|
|
|
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();
|
|
|
|
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();
|
|
});
|
|
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();
|
|
|
|
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);
|
|
}
|
|
}
|