using System.Text.Json; using BigRegister.Api.Zgw; namespace BigRegister.Tests; /// /// The anti-corruption map is where ZGW's URL-as-identity + cross-service zaaktype join get /// flattened into the FE's existing DTO. Feeds a captured ZGW Zaak shape and asserts the /// mapping — the guarantee that the FE never sees a ZGW shape. /// public class ZgwZaakMapperTests { private const string OpenZaakJson = """ { "url": "https://open-zaak.example/zaken/api/v1/zaken/6f2c5f6e-1b1a-4b7e-9c3d-000000000001", "identificatie": "ZAAK-2026-0000000001", "zaaktype": "https://open-zaak.example/catalogi/api/v1/zaaktypen/aaaaaaaa-0000-0000-0000-000000000001", "startdatum": "2026-03-01", "einddatum": null, "registratiedatum": "2026-03-02" } """; private const string ClosedZaakJson = """ { "url": "https://open-zaak.example/zaken/api/v1/zaken/6f2c5f6e-1b1a-4b7e-9c3d-000000000002", "identificatie": "ZAAK-2026-0000000002", "zaaktype": "https://open-zaak.example/catalogi/api/v1/zaaktypen/aaaaaaaa-0000-0000-0000-000000000001", "startdatum": "2026-01-05", "einddatum": "2026-02-10", "registratiedatum": "2026-01-06" } """; [Fact] public void Maps_url_identity_zaaktype_and_open_status() { var zaak = JsonSerializer.Deserialize(OpenZaakJson)!; var dto = ZgwZaakMapper.ToSummaryDto(zaak, "Herregistratie arts"); // URL as identity → the trailing uuid, not the whole URL. Assert.Equal("6f2c5f6e-1b1a-4b7e-9c3d-000000000001", dto.Id); // zaaktype URL resolved to its human label (the cross-service join). Assert.Equal("Herregistratie arts", dto.Type); Assert.Equal("ZAAK-2026-0000000001", dto.Status.Referentie); Assert.Equal("InBehandeling", dto.Status.Tag); // no einddatum → open Assert.True(dto.Status.Manual); Assert.Empty(dto.DocumentIds); // Wire shape matches the local source: round-trip datetime at midnight UTC. Assert.Equal("2026-03-02T00:00:00.0000000Z", dto.CreatedAt); } [Fact] public void Closed_zaak_maps_to_goedgekeurd() { var zaak = JsonSerializer.Deserialize(ClosedZaakJson)!; var dto = ZgwZaakMapper.ToSummaryDto(zaak, "Herregistratie arts"); Assert.Equal("Goedgekeurd", dto.Status.Tag); Assert.Equal("2026-02-10T00:00:00.0000000Z", dto.UpdatedAt); // einddatum drives UpdatedAt } [Fact] public void Uuid_extracts_trailing_segment_ignoring_trailing_slash() { Assert.Equal("abc", ZgwZaakMapper.Uuid("https://host/zaken/api/v1/zaken/abc")); Assert.Equal("abc", ZgwZaakMapper.Uuid("https://host/zaken/api/v1/zaken/abc/")); } }