diff --git a/services/acl/Acl.Tests/OpenZaakGatewayTests.cs b/services/acl/Acl.Tests/OpenZaakGatewayTests.cs index fb750aa..081701c 100644 --- a/services/acl/Acl.Tests/OpenZaakGatewayTests.cs +++ b/services/acl/Acl.Tests/OpenZaakGatewayTests.cs @@ -721,24 +721,85 @@ public class OpenZaakGatewayTests [Fact] public async Task Resolves_the_informatieobjecttype_url_by_omschrijving() { - var handler = new StubHandler(_ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + HttpRequestMessage? seen = null; + var handler = new StubHandler(req => { - Content = JsonContent.Create(new + seen = req; + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { - results = new[] + Content = JsonContent.Create(new { - new { url = "http://openzaak/catalogi/api/v1/informatieobjecttypen/other", omschrijving = "Overig" }, - new { url = "http://openzaak/catalogi/api/v1/informatieobjecttypen/dip", omschrijving = "Diploma" }, - }, - }), - })); + results = new[] + { + new { url = "http://openzaak/catalogi/api/v1/informatieobjecttypen/other", omschrijving = "Overig" }, + new { url = "http://openzaak/catalogi/api/v1/informatieobjecttypen/dip", omschrijving = "Diploma" }, + }, + }), + }); + }); var url = await Gateway(handler).ResolveInformatieobjecttypeUrlAsync("Diploma"); - // Matches on omschrijving, not position. + // Queries the published informatieobjecttypen collection, and matches on omschrijving (not position). + Assert.Contains("/catalogi/api/v1/informatieobjecttypen", seen!.RequestUri!.ToString()); + Assert.Contains("status=definitief", seen.RequestUri!.Query); Assert.Equal("http://openzaak/catalogi/api/v1/informatieobjecttypen/dip", url.ToString()); } + [Fact] + public async Task Resolving_a_zaaktype_throws_when_the_response_carries_no_results() + { + // No "results" property → the page's Results is null; the gateway must treat that as "none + // found" (not dereference null). + var handler = new StubHandler(_ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = JsonContent.Create(new { count = 0 }), + })); + + await Assert.ThrowsAsync( + () => Gateway(handler).ResolveZaaktypeUrlAsync("BIG-REGISTRATIE")); + } + + [Fact] + public async Task Resolving_an_informatieobjecttype_throws_when_the_response_carries_no_results() + { + var handler = new StubHandler(_ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = JsonContent.Create(new { count = 0 }), + })); + + await Assert.ThrowsAsync( + () => Gateway(handler).ResolveInformatieobjecttypeUrlAsync("Diploma")); + } + + [Fact] + public async Task Resolving_a_zaaktype_surfaces_a_non_success_catalogi_response() + { + var handler = new StubHandler(_ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.InternalServerError) + { + Content = new StringContent("boom"), + })); + + var ex = await Assert.ThrowsAsync( + () => Gateway(handler).ResolveZaaktypeUrlAsync("BIG-REGISTRATIE")); + // The error names the resource being queried and includes OpenZaak's body. + Assert.Contains("zaaktypen", ex.Message); + Assert.Contains("boom", ex.Message); + } + + [Fact] + public async Task Resolving_an_informatieobjecttype_surfaces_a_non_success_catalogi_response() + { + var handler = new StubHandler(_ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.InternalServerError) + { + Content = new StringContent("boom"), + })); + + var ex = await Assert.ThrowsAsync( + () => Gateway(handler).ResolveInformatieobjecttypeUrlAsync("Diploma")); + Assert.Contains("informatieobjecttypen", ex.Message); + } + [Fact] public async Task Resolving_an_informatieobjecttype_throws_when_no_omschrijving_matches() {