Skip to content

Commit

Permalink
fix: or-2409 adopt gemeentenaam from postnaam when component is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Lesage authored and janlesage committed Sep 12, 2024
1 parent 04e0b05 commit ada8fe4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/AssociationRegistry/Grar/GrarClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ public async Task<IReadOnlyCollection<AddressMatchResponse>> GetAddressMatches(
var jsonContent = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<PostalInformationOsloResponse>(jsonContent);

var postalInformationResponse = new PostalInformationResponse(postcode,
result.Gemeente.Gemeentenaam.GeografischeNaam.Spelling,
result.Postnamen.Select(s => s.GeografischeNaam.Spelling)
.ToArray());
var gemeentenaam = result.Gemeente?.Gemeentenaam?.GeografischeNaam?.Spelling;
var postnamen = result.Postnamen.Select(s => s.GeografischeNaam.Spelling).ToArray();

var postalInformationResponse = new PostalInformationResponse(postcode,
gemeentenaam ?? postnamen[0],
postnamen);
return postalInformationResponse;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace AssociationRegistry.Test.GrarClient.When_Getting_PostInfo;

using AssociationRegistry.Grar;
using FluentAssertions;
using Grar.Models;
using Microsoft.Extensions.Logging;
using Moq;
using System.Net;
using Xunit;

public class Given_Grar_Returns_No_Gemeente_Components
{
[Fact]
public async Task Then_Returns_Empty_Collection()
{
var grarHttpClient = new Mock<IGrarHttpClient>();

grarHttpClient.Setup(x => x.GetPostInfo(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(PostInfoResponseWithoutGemeenteComponents),
});

var sut = new GrarClient(grarHttpClient.Object, Mock.Of<ILogger<GrarClient>>());

var result = await sut.GetPostalInformation("0612");

result.Should().BeEquivalentTo(new PostalInformationResponse("0612", "Sinterklaas", new [] { "Sinterklaas" }));
}

private const string PostInfoResponseWithoutGemeenteComponents =
@"{
""@context"": ""https://docs.basisregisters.test-vlaanderen.be/context/postinfo/2023-10-16/postinfo_detail.jsonld"",
""@type"": ""PostInfo"",
""identificator"": {
""id"": ""https://data.vlaanderen.be/id/postinfo/0612"",
""naamruimte"": ""https://data.vlaanderen.be/id/postinfo"",
""objectId"": ""0612"",
""versieId"": ""2020-02-10T12:42:50+01:00""
},
""postnamen"": [
{
""geografischeNaam"": {
""spelling"": ""Sinterklaas"",
""taal"": ""nl""
}
}
],
""postInfoStatus"": ""gerealiseerd""
}";
}

0 comments on commit ada8fe4

Please sign in to comment.