using System.Net.Http.Json; using BigRegister.Api.Contracts; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; namespace BigRegister.Tests; /// /// 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 /// HttpMessageHandler every other Zgw test (, /// ) uses. Requires the harness in backend/openzaak/ /// to be up and seeded first (see its README); tagged Category=Integration so it's excluded /// from the default `dotnet test` run and from CI (`ci.yml`, `scripts/ci-local.sh` both filter /// it out) — nobody without a live OpenZaak should see it fail. /// /// Not an off : /// that fixture hardcodes Zgw:Enabled=false (offline default) for every other test class, /// so this one builds its own layering the /// harness's URLs/credentials (matching backend/openzaak/setup_configuration/data.yaml /// and bootstrap-catalogus.sh) on top. /// [Trait("Category", "Integration")] public class OpenZaakIntegrationTests { private static WebApplicationFactory Factory() { var dbPath = Path.Combine(Path.GetTempPath(), $"bigregister-oz-integration-{Guid.NewGuid():N}.db"); return new WebApplicationFactory().WithWebHostBuilder(builder => builder .UseSetting("ConnectionStrings:AppDb", $"Data Source={dbPath}") .UseSetting("Zgw:Enabled", "true") .UseSetting("Zgw:ZrcBaseUrl", "http://localhost:8000/zaken/api/v1") .UseSetting("Zgw:ZtcBaseUrl", "http://localhost:8000/catalogi/api/v1") .UseSetting("Zgw:ClientId", "bigregister-test") .UseSetting("Zgw:Secret", "bigregister-test-secret") .UseSetting("Zgw:UserId", "bigregister-test") .UseSetting("Zgw:UserRepresentation", "WP-54 integration test")); } [Fact] public async Task Admin_cases_returns_the_seeded_zaak_mapped_through_real_HTTP_and_JWT() { using var factory = Factory(); using var client = factory.CreateClient(); client.DefaultRequestHeaders.Add("X-Role", "admin"); // CasesAdmin gate (cases:manage) var cases = await client.GetFromJsonAsync>("/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. var seeded = Assert.Single(cases!, c => c.Status.Referentie == "BIG-2026-000123"); Assert.Equal("Herregistratie arts", seeded.Type); Assert.Equal("InBehandeling", seeded.Status.Tag); } }