Files
atomic-design-poc/backend/tests/BigRegister.Tests/OpenZaakIntegrationTests.cs
T
ehoandClaude Sonnet 5 8560746d15 refactor: strip WP-/RB- ticket refs from backend (RD-19)
The backend half of the sweep RD-18 did for the front end. git blame
holds the provenance and stays correct when the code moves; the
comment names a closed ticket and tells the reader nothing the
sentence around it does not.

public/letter.css and LetterHtml.golden.html change together, because
the renderer inlines the CSS and the golden file snapshots the
result.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 21:48:08 +02:00

75 lines
3.9 KiB
C#

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;
namespace BigRegister.Tests;
/// <summary>
/// The one test that proves the BFF actually talks to a REAL OpenZaak — auth accepted,
/// 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
/// 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 <see cref="IClassFixture{TFixture}"/> off <see cref="TestWebApplicationFactory"/>:
/// that fixture hardcodes <c>Zgw:Enabled=false</c> (offline default) for every other test class,
/// so this one builds its own <see cref="WebApplicationFactory{TEntryPoint}"/> layering the
/// harness's URLs/credentials (matching <c>backend/openzaak/setup_configuration/data.yaml</c>
/// and <c>bootstrap-catalogus.sh</c>) on top.
/// </summary>
[Trait("Category", "Integration")]
public class OpenZaakIntegrationTests
{
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
.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", "OpenZaak 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(await SeededZaaktypeUrlAsync());
using var client = factory.CreateClient();
client.DefaultRequestHeaders.Add("X-Role", "admin"); // CasesAdmin gate (cases:manage)
var cases = await client.GetFromJsonAsync<List<AanvraagSummaryDto>>("/api/v1/admin/cases");
Assert.NotNull(cases);
// 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", seeded.Type);
Assert.Equal("InBehandeling", seeded.Status.Tag);
}
}