fix(backend): resolve besluit endpoint's id via Referentie, not local PK

POST /beoordeling/{id}/besluit always 404'd against a real OpenZaak: {id} is the
FE-facing case id from IZaakSource.ListCases, which under OpenZaakZaakSource is the
ZGW zaak's own uuid, not ApplicationStore's primary key. Resolve the case through
ListCases first (same seam the GET sibling already uses), then to the local Aanvraag
via its Referentie — the one identifier stable across both sources.

Adds ApplicationStore.GetByReferentie and a regression test that reproduces the
divergence with a decorating IZaakSource test double instead of a live OpenZaak.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
eho
2026-08-05 15:20:36 +02:00
co-authored by Claude Opus 5
parent d2c2cffc1f
commit 6cfd70eeeb
12 changed files with 310 additions and 63 deletions
@@ -1,5 +1,7 @@
using System.Net.Http.Headers;
using System.Net.Http.Json;
using BigRegister.Api.Contracts;
using BigRegister.Api.Zgw;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
@@ -7,7 +9,7 @@ namespace BigRegister.Tests;
/// <summary>
/// WP-54: the one test that proves the BFF actually talks to a REAL OpenZaak — auth accepted,
/// real response shapes, real pagination/zaaktype resolution — rather than the stub
/// real response shapes, real pagination/zaaktype→aanvraag-type mapping — rather than the stub
/// HttpMessageHandler every other Zgw test (<see cref="ZgwZaakMapperTests"/>,
/// <see cref="OpenZaakZaakSourceTests"/>) uses. Requires the harness in <c>backend/openzaak/</c>
/// to be up and seeded first (see its README); tagged Category=Integration so it's excluded
@@ -23,7 +25,7 @@ namespace BigRegister.Tests;
[Trait("Category", "Integration")]
public class OpenZaakIntegrationTests
{
private static WebApplicationFactory<Program> Factory()
private static WebApplicationFactory<Program> Factory(string zaaktypeUrl)
{
var dbPath = Path.Combine(Path.GetTempPath(), $"bigregister-oz-integration-{Guid.NewGuid():N}.db");
return new WebApplicationFactory<Program>().WithWebHostBuilder(builder => builder
@@ -34,23 +36,39 @@ public class OpenZaakIntegrationTests
.UseSetting("Zgw:ClientId", "bigregister-test")
.UseSetting("Zgw:Secret", "bigregister-test-secret")
.UseSetting("Zgw:UserId", "bigregister-test")
.UseSetting("Zgw:UserRepresentation", "WP-54 integration test"));
.UseSetting("Zgw:UserRepresentation", "WP-54 integration test")
.UseSetting("Zgw:ZaaktypeUrls:herregistratie", zaaktypeUrl));
}
/// <summary>bootstrap-catalogus.sh mints the seeded zaaktype's uuid fresh per harness
/// instance, so unlike every other setting <c>Factory</c> hardcodes, this one has to be
/// discovered live — the same real HTTP + JWT this test is meant to exercise, done once up
/// front to learn the URL <c>Zgw:ZaaktypeUrls</c> needs (see <see cref="OpenZaakZaakSource.AanvraagTypeFor"/>).</summary>
private static async Task<string> SeededZaaktypeUrlAsync()
{
var tokenOptions = new ZgwOptions { ClientId = "bigregister-test", Secret = "bigregister-test-secret" };
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", new ZgwTokenProvider(tokenOptions).Mint());
client.DefaultRequestHeaders.Add("Accept-Crs", "EPSG:4326"); // else OpenZaak 412s
var page = await client.GetFromJsonAsync<ZgwPage<ZgwZaak>>(
"http://localhost:8000/zaken/api/v1/zaken?identificatie=BIG-2026-000123");
return Assert.Single(page!.Results).Zaaktype;
}
[Fact]
public async Task Admin_cases_returns_the_seeded_zaak_mapped_through_real_HTTP_and_JWT()
{
using var factory = Factory();
using var factory = Factory(await SeededZaaktypeUrlAsync());
using var client = factory.CreateClient();
client.DefaultRequestHeaders.Add("X-Role", "admin"); // CasesAdmin gate (cases:manage)
var cases = await client.GetFromJsonAsync<List<ApplicationSummaryDto>>("/api/v1/admin/cases");
Assert.NotNull(cases);
// bootstrap-catalogus.sh seeds exactly one zaak, identificatie BIG-2026-000123, under a
// zaaktype whose omschrijving is "Herregistratie arts" — see backend/openzaak/README.md.
// bootstrap-catalogus.sh seeds exactly one zaak, identificatie BIG-2026-000123.
var seeded = Assert.Single(cases!, c => c.Status.Referentie == "BIG-2026-000123");
Assert.Equal("Herregistratie arts", seeded.Type);
Assert.Equal("herregistratie", seeded.Type);
Assert.Equal("InBehandeling", seeded.Status.Tag);
}
}