Skip to content

Commit

Permalink
fix: or-1821 fix identificator nullref on get address adresmatch
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy authored and koenmetsu committed Apr 25, 2024
1 parent ad39d8b commit ead2f25
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AssociationRegistry/Grar/GrarClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<IReadOnlyCollection<AddressMatchResponse>> GetAddress(

return JsonConvert.DeserializeObject<AddressMatchOsloCollection>(await response.Content.ReadAsStringAsync())
.AdresMatches
.Where(w => !string.IsNullOrEmpty(w.Identificator.ObjectId))
.Where(w => !string.IsNullOrEmpty(w.Identificator?.ObjectId))
.Where(w => w.AdresStatus != AdresStatus.Gehistoreerd)
.Select(s => new AddressMatchResponse(
Score: s.Score,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AdresMatchOsloItem

[DataMember(Name = "Identificator", Order = 1, EmitDefaultValue = false)]
[JsonProperty(Required = Required.Default)]
public AdresIdentificator Identificator { get; set; }
public AdresIdentificator? Identificator { get; set; }

[DataMember(Name = "Detail", Order = 2, EmitDefaultValue = false)]
[JsonProperty(Required = Required.Default)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace AssociationRegistry.Test.Admin.Api.Grar.When_Address_Match.Fixtures;

using AssociationRegistry.Grar;
using AssociationRegistry.Grar.Models;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;

public class WithNoIdInMatchDestelbergenFixture : IAsyncLifetime
{
private readonly GrarClient _client;
public string Straatnaam = "Dendermondsesteenweg";
public string Huisnummer = "32747";
public string Gemeentenaam = "Destelbergen";
public string Postcode = "9070";

public WithNoIdInMatchDestelbergenFixture()
{
_client = new GrarClient(new GrarHttpClient(new HttpClient()
{
BaseAddress = new Uri("http://localhost:8080/")
}), NullLogger<GrarClient>.Instance);
}

public IReadOnlyCollection<AddressMatchResponse> Result { get; private set; }

public async Task InitializeAsync()
{
Result = await _client.GetAddress(Straatnaam, Huisnummer, null, Postcode, Gemeentenaam);
}

public Task DisposeAsync() => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace AssociationRegistry.Test.Admin.Api.Grar.When_Address_Match;

using Fixtures;
using FluentAssertions;
using Xunit;
using Xunit.Categories;

[UnitTest]
public class With_No_Id_In_Match_Destelbergen : IClassFixture<WithNoIdInMatchDestelbergenFixture>
{
private readonly WithNoIdInMatchDestelbergenFixture _fixture;

public With_No_Id_In_Match_Destelbergen(WithNoIdInMatchDestelbergenFixture fixture)
{
_fixture = fixture;
}

[Fact]
public void Then_It_Returns_No_Matches()
{
_fixture.Result.Should().BeEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace AssociationRegistry.Test.When_ProbeerAdresTeMatchen;

using AutoFixture;
using Events;
using FluentAssertions;
using Framework.Customizations;
using Grar;
using Grar.Models;
using Moq;
using Vereniging;
using Xunit;

public class Given_GrarClient_Returned_No_Matches
{
[Fact]
public async Task Then_AdresWerdNietGevondenInAdressenregister()
{
var fixture = new Fixture().CustomizeDomain();

var grarClient = new Mock<IGrarClient>();
var vereniging = new Vereniging();

var feitelijkeVerenigingWerdGeregistreerd = fixture.Create<FeitelijkeVerenigingWerdGeregistreerd>();

grarClient.Setup(x => x.GetAddress(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<string>()))
.ReturnsAsync(new List<AddressMatchResponse>());

vereniging.Hydrate(
new VerenigingState()
.Apply(feitelijkeVerenigingWerdGeregistreerd));

await vereniging.ProbeerAdresTeMatchen(grarClient.Object, feitelijkeVerenigingWerdGeregistreerd.Locaties.First().LocatieId);

var @event = vereniging.UncommittedEvents.OfType<AdresWerdNietGevondenInAdressenregister>().SingleOrDefault();

@event.Should().NotBeNull();
}

}
31 changes: 31 additions & 0 deletions wiremock/__files/AdresMatch/No_Id_In_Match_Destelbergen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"@context": "https://docs.basisregisters.staging-vlaanderen.be/context/adresmatch/2023-03-13/adresmatch.jsonld",
"adresMatches": [
{
"@type": "Adres",
"gemeente": {
"objectId": "44013",
"detail": "https://api.basisregisters.staging-vlaanderen.be/v2/gemeenten/44013",
"gemeentenaam": {
"geografischeNaam": {
"spelling": "Destelbergen",
"taal": "nl"
}
}
},
"straatnaam": {
"objectId": "68713",
"detail": "https://api.basisregisters.staging-vlaanderen.be/v2/straatnamen/68713",
"straatnaam": {
"geografischeNaam": {
"spelling": "Dendermondesteenweg",
"taal": "nl"
}
}
},
"score": 87.9911986967736,
"links": []
}
],
"warnings": []
}
19 changes: 19 additions & 0 deletions wiremock/mappings/AdresMatch.no-id-in-match-Destelbergen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"priority": 2,
"request": {
"method": "GET",
"urlPath": "/v2/adresmatch",
"queryParameters": {
"Gemeentenaam": {
"equalTo": "Destelbergen"
}
}
},
"response": {
"status": 200,
"bodyFileName": "AdresMatch/No_Id_In_Match_Destelbergen.json",
"headers": {
"Content-Type": "application/json"
}
}
}

0 comments on commit ead2f25

Please sign in to comment.