S-09b: Approval flow — temp admin endpoint + status transition to projection (#77)
All checks were successful
All checks were successful
## What & why S-09b (#75, split from #10) — the **approval flow** that completes the walking skeleton. A behandelaar can now approve a submitted registration; the entry flips from `INGEDIEND` to `INGESCHREVEN` in the public register. Flow: `POST /registrations/{id}/approve` (domain) → ACL sets the zaak eindstatus (ZGW `/statussen`) → OpenZaak → NRC → event-subscriber → projection → openbaar. ## Changes (bottom-up, each red→green TDD) - **Domain** — `RegistrationStatus.Ingeschreven` + `Registration.Approve()` (guards: opened zaak, only from INGEDIEND); `ApproveRegistration` use case (idempotent) + temp `POST /registrations/{id}/approve` endpoint; `IAclClient.ApproveZaakAsync`. - **ACL** — resolves the zaaktype's **eindstatus** from the catalogus (`isEindstatus` / highest volgnummer) and POSTs a ZGW status; exposed as `POST /statussen`. Unit + real-OpenZaak integration test. - **Event-subscriber** — binds NRC `hoofdObject`, projects a `status`/`create` as `INGESCHREVEN` keyed on the zaak (updates the existing row), **without reading OpenZaak** (§8.1). Retains the ZGW `resource` in the log (new column + EF migration) so a rebuild reproduces the status. - **e2e** — extended: submit → public INGEDIEND → approve → public INGESCHREVEN. - **Docs** — ADR-0011 (the two non-obvious decisions + the walking-skeleton assumption) + demo note. ## Key decisions (see ADR-0011) - **ACL discovers the eindstatus** (chosen over injecting a statustype URL): no new config/seed plumbing, domain stays ZGW-ignorant. - **Any post-creation status-set ⇒ INGESCHREVEN**: in the walking skeleton the only status ever set after creation is the approval, and the subscriber may not read ZGW — documented to tighten when more transitions arrive (S-12+). ## Verification - All .NET unit suites green locally (domain 47, acl 11, event-subscriber 14, bff 16, acceptance 7); Release build + `dotnet format` clean. - No new compose config (the eindstatus-discovery approach avoided it). - The real-OpenZaak integration test (ACL status-set) and the full submit→approve→visible e2e run in CI `verify-stack` (live NRC→projection + selectielijst egress, not reproducible locally). closes #75 Reviewed-on: #77
This commit was merged in pull request #77.
This commit is contained in:
@@ -9,13 +9,29 @@ public class AclServiceTests
|
||||
public ZaakRequest? Captured;
|
||||
public Uri Result { get; } = new("http://openzaak/zaken/api/v1/zaken/abc");
|
||||
|
||||
public (Uri Zaak, Uri Zaaktype, DateOnly Datum)? Approved;
|
||||
|
||||
public Task<Uri> OpenZaakAsync(ZaakRequest request, CancellationToken ct = default)
|
||||
{
|
||||
Captured = request;
|
||||
return Task.FromResult(Result);
|
||||
}
|
||||
|
||||
public Task SetZaakToEindstatusAsync(Uri zaakUrl, Uri zaaktypeUrl, DateOnly datumStatusGezet, CancellationToken ct = default)
|
||||
{
|
||||
Approved = (zaakUrl, zaaktypeUrl, datumStatusGezet);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
private static AclDefaults Defaults() => new()
|
||||
{
|
||||
Bronorganisatie = "517439943",
|
||||
VerantwoordelijkeOrganisatie = "517439943",
|
||||
Vertrouwelijkheidaanduiding = "openbaar",
|
||||
ZaaktypeUrl = new("http://openzaak/catalogi/api/v1/zaaktypen/big"),
|
||||
};
|
||||
|
||||
private sealed class FixedClock(DateOnly today) : IClock
|
||||
{
|
||||
public DateOnly Today { get; } = today;
|
||||
@@ -61,4 +77,30 @@ public class AclServiceTests
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => service.OpenZaakAsync(null!));
|
||||
Assert.Null(gateway.Captured);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_a_zaak_sets_it_to_its_zaaktypes_eindstatus_dated_today()
|
||||
{
|
||||
var gateway = new FakeGateway();
|
||||
var defaults = Defaults();
|
||||
var service = new AclService(gateway, defaults, new FixedClock(new DateOnly(2026, 6, 4)));
|
||||
var zaak = new Uri("http://openzaak/zaken/api/v1/zaken/abc");
|
||||
|
||||
await service.ApproveZaakAsync(zaak);
|
||||
|
||||
Assert.NotNull(gateway.Approved);
|
||||
Assert.Equal(zaak, gateway.Approved!.Value.Zaak);
|
||||
Assert.Equal(defaults.ZaaktypeUrl, gateway.Approved.Value.Zaaktype);
|
||||
Assert.Equal(new DateOnly(2026, 6, 4), gateway.Approved.Value.Datum);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_a_null_zaak_is_rejected_without_touching_the_gateway()
|
||||
{
|
||||
var gateway = new FakeGateway();
|
||||
var service = new AclService(gateway, Defaults(), new FixedClock(new DateOnly(2026, 6, 4)));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => service.ApproveZaakAsync(null!));
|
||||
Assert.Null(gateway.Approved);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +131,9 @@ public class OpenZaakGatewayTests
|
||||
Content = new StringContent("null", Encoding.UTF8, "application/json"),
|
||||
}));
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => Gateway(handler).OpenZaakAsync(SampleRequest()));
|
||||
Assert.Contains("empty zaak response", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -144,6 +145,229 @@ public class OpenZaakGatewayTests
|
||||
() => Gateway(handler).OpenZaakAsync(null!));
|
||||
}
|
||||
|
||||
// --- SetZaakToEindstatusAsync (approval / S-09b) ---
|
||||
|
||||
private const string ZaakUrl = "http://openzaak/zaken/api/v1/zaken/xyz";
|
||||
private static readonly Uri Zaaktype = new("http://openzaak/catalogi/api/v1/zaaktypen/big");
|
||||
|
||||
private sealed class Recorder
|
||||
{
|
||||
public List<HttpRequestMessage> Requests { get; } = [];
|
||||
public List<string?> Bodies { get; } = [];
|
||||
public List<long?> ContentLengths { get; } = [];
|
||||
|
||||
public int IndexOf(string pathContains) =>
|
||||
Requests.FindIndex(r => r.RequestUri!.ToString().Contains(pathContains));
|
||||
|
||||
// The (body, content-length, request) of the single request whose URL contains the segment.
|
||||
public (string? Body, long? Length, HttpRequestMessage Request) Sent(string pathContains)
|
||||
{
|
||||
var i = IndexOf(pathContains);
|
||||
return (Bodies[i], ContentLengths[i], Requests[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Per-route response config for the four calls the approval makes.
|
||||
private sealed class OzRoutes
|
||||
{
|
||||
public string StatustypenJson { get; init; } = StatustypenPage(withEindstatusFlag: true);
|
||||
public string ResultaattypenJson { get; init; } = """{"results":[{"url":"http://openzaak/catalogi/api/v1/resultaattypen/1"}]}""";
|
||||
public HttpStatusCode StatustypenStatus { get; init; } = HttpStatusCode.OK;
|
||||
public HttpStatusCode ResultaattypenStatus { get; init; } = HttpStatusCode.OK;
|
||||
public HttpStatusCode ResultaatPostStatus { get; init; } = HttpStatusCode.Created;
|
||||
public HttpStatusCode StatusPostStatus { get; init; } = HttpStatusCode.Created;
|
||||
}
|
||||
|
||||
// Routes the approval's four calls by URL: GET /statustypen, GET /resultaattypen (catalogus),
|
||||
// then POST /resultaten and POST /statussen (zaken).
|
||||
private static StubHandler ApprovalStub(Recorder rec, OzRoutes routes) => new(async req =>
|
||||
{
|
||||
rec.Requests.Add(req);
|
||||
// Capture the length BEFORE reading the body (ReadAsStringAsync buffers as a side effect).
|
||||
rec.ContentLengths.Add(req.Content?.Headers.ContentLength);
|
||||
rec.Bodies.Add(req.Content is null ? null : await req.Content.ReadAsStringAsync());
|
||||
|
||||
var url = req.RequestUri!.ToString();
|
||||
if (req.Method == HttpMethod.Get && url.Contains("/statustypen"))
|
||||
return Json(routes.StatustypenStatus, routes.StatustypenJson);
|
||||
if (req.Method == HttpMethod.Get && url.Contains("/resultaattypen"))
|
||||
return Json(routes.ResultaattypenStatus, routes.ResultaattypenJson);
|
||||
if (url.Contains("/resultaten"))
|
||||
return Json(routes.ResultaatPostStatus, """{"url":"http://openzaak/zaken/api/v1/resultaten/new"}""");
|
||||
return Json(routes.StatusPostStatus, """{"url":"http://openzaak/zaken/api/v1/statussen/new"}""");
|
||||
});
|
||||
|
||||
private static HttpResponseMessage Json(HttpStatusCode status, string body) =>
|
||||
new(status) { Content = new StringContent(body, Encoding.UTF8, "application/json") };
|
||||
|
||||
// Two statustypen; the eindstatus is flagged on the *lower* volgnummer so the tests prove the
|
||||
// isEindstatus flag is preferred over "highest volgnummer", not coincidentally equal to it.
|
||||
private static string StatustypenPage(bool withEindstatusFlag) => JsonSerializer.Serialize(new
|
||||
{
|
||||
results = new object[]
|
||||
{
|
||||
new { url = "http://openzaak/catalogi/api/v1/statustypen/1", volgnummer = 1, isEindstatus = withEindstatusFlag },
|
||||
new { url = "http://openzaak/catalogi/api/v1/statustypen/2", volgnummer = 2, isEindstatus = false },
|
||||
},
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_sets_a_resultaat_then_posts_the_flagged_eindstatus_against_the_zaak()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
await Gateway(ApprovalStub(rec, new OzRoutes()))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4));
|
||||
|
||||
Assert.Equal(4, rec.Requests.Count);
|
||||
|
||||
// Both catalogus queries filter by the zaaktype and carry the bearer.
|
||||
var statustypenGet = rec.Sent("/statustypen").Request;
|
||||
Assert.Equal(HttpMethod.Get, statustypenGet.Method);
|
||||
Assert.Contains(Uri.EscapeDataString(Zaaktype.ToString()), statustypenGet.RequestUri!.ToString());
|
||||
Assert.Equal("Bearer", statustypenGet.Headers.Authorization!.Scheme);
|
||||
Assert.Contains(Uri.EscapeDataString(Zaaktype.ToString()), rec.Sent("/resultaattypen").Request.RequestUri!.ToString());
|
||||
|
||||
// OpenZaak requires a resultaat before the eindstatus, so /resultaten precedes /statussen.
|
||||
Assert.True(rec.IndexOf("/resultaten") < rec.IndexOf("/statussen"));
|
||||
|
||||
var resultaat = rec.Sent("/resultaten");
|
||||
Assert.Equal("http://openzaak/zaken/api/v1/resultaten", resultaat.Request.RequestUri!.ToString());
|
||||
Assert.Equal("Bearer", resultaat.Request.Headers.Authorization!.Scheme);
|
||||
Assert.Contains("\"zaak\":\"" + ZaakUrl + "\"", resultaat.Body);
|
||||
Assert.Contains("\"resultaattype\":\"http://openzaak/catalogi/api/v1/resultaattypen/1\"", resultaat.Body);
|
||||
Assert.True(resultaat.Length > 0);
|
||||
|
||||
var status = rec.Sent("/statussen");
|
||||
Assert.Equal("http://openzaak/zaken/api/v1/statussen", status.Request.RequestUri!.ToString());
|
||||
Assert.Equal("Bearer", status.Request.Headers.Authorization!.Scheme);
|
||||
Assert.Contains("\"zaak\":\"" + ZaakUrl + "\"", status.Body);
|
||||
// The isEindstatus-flagged statustype (/1) is chosen — even though /2 has a higher volgnummer.
|
||||
Assert.Contains("\"statustype\":\"http://openzaak/catalogi/api/v1/statustypen/1\"", status.Body);
|
||||
Assert.Contains("\"datumStatusGezet\":\"2026-06-04T00:00:00Z\"", status.Body);
|
||||
// Bodies are buffered (Content-Length set), so uwsgi doesn't get a chunked body.
|
||||
Assert.True(status.Length > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_falls_back_to_the_highest_volgnummer_when_no_eindstatus_is_flagged()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
await Gateway(ApprovalStub(rec, new OzRoutes { StatustypenJson = StatustypenPage(withEindstatusFlag: false) }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4));
|
||||
|
||||
// No isEindstatus flag → the highest volgnummer (/2) is chosen.
|
||||
Assert.Contains("\"statustype\":\"http://openzaak/catalogi/api/v1/statustypen/2\"", rec.Sent("/statussen").Body);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_the_zaaktype_has_no_statustypen()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
// A page with no `results` property (Results is null) — the eindstatus cannot be resolved.
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { StatustypenJson = "{}" }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("No statustypen found", ex.Message);
|
||||
// It never posts anything when it cannot resolve the eindstatus.
|
||||
Assert.Single(rec.Requests);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_the_statustypen_response_is_empty()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { StatustypenJson = "null" }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("empty statustypen", ex.Message);
|
||||
Assert.Single(rec.Requests);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_the_statustypen_query_fails()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HttpRequestException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { StatustypenStatus = HttpStatusCode.InternalServerError }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("Querying statustypen", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_the_resultaattypen_query_fails()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HttpRequestException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { ResultaattypenStatus = HttpStatusCode.InternalServerError }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("Querying resultaattypen", ex.Message);
|
||||
Assert.Equal(-1, rec.IndexOf("/resultaten"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_the_zaaktype_has_no_resultaattype()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { ResultaattypenJson = "{}" }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("No resultaattypen found", ex.Message);
|
||||
// Resolved the eindstatus + queried resultaattypen, but posted nothing.
|
||||
Assert.Equal(-1, rec.IndexOf("/resultaten"));
|
||||
Assert.Equal(-1, rec.IndexOf("/statussen"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_posting_the_resultaat_fails()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HttpRequestException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { ResultaatPostStatus = HttpStatusCode.BadRequest }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("Setting the zaak resultaat", ex.Message);
|
||||
// The status is never posted if the resultaat could not be recorded.
|
||||
Assert.Equal(-1, rec.IndexOf("/statussen"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_throws_when_posting_the_status_fails()
|
||||
{
|
||||
var rec = new Recorder();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HttpRequestException>(() =>
|
||||
Gateway(ApprovalStub(rec, new OzRoutes { StatusPostStatus = HttpStatusCode.BadRequest }))
|
||||
.SetZaakToEindstatusAsync(new Uri(ZaakUrl), Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
|
||||
Assert.Contains("Setting the zaak status", ex.Message);
|
||||
// It got as far as the resultaat + the status POST (4 calls) before failing.
|
||||
Assert.Equal(4, rec.Requests.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Approving_rejects_a_null_zaak_or_zaaktype()
|
||||
{
|
||||
var handler = new StubHandler(_ => throw new InvalidOperationException("should not be sent"));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
Gateway(handler).SetZaakToEindstatusAsync(null!, Zaaktype, new DateOnly(2026, 6, 4)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
Gateway(handler).SetZaakToEindstatusAsync(new Uri(ZaakUrl), null!, new DateOnly(2026, 6, 4)));
|
||||
}
|
||||
|
||||
// ZGW tokens are base64url with padding stripped (ZgwToken.B64Url); restore it to decode.
|
||||
private static string DecodeSegment(string segment)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user