Skip to content

Commit

Permalink
fix: check duplicate merger streetnames in api
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal committed Oct 21, 2024
1 parent 04a3ff5 commit d062159
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public async Task<IActionResult> ProposeForMunicipalityMerger(
oldMunicipalities.Add(oldMunicipality);
}

errorMessages.AddRange(records
.GroupBy(x => new
{
x.OldStreetNamePersistentLocalId,
StreetName = x.StreetName.ToLowerInvariant()
})
.Where(x => x.Count() > 1)
.Select(x =>
$"Duplicate record for streetName with persistent local id {x.Key.OldStreetNamePersistentLocalId}"));

if (errorMessages.Any())
{
return BadRequest(errorMessages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ public void WithNoStreetName_ThenReturnsBadRequest()
((BadRequestObjectResult)result).Value.Should().BeEquivalentTo(new[] { "StreetName is required at record number 1" });
}

[Theory]
[InlineData("Kerkstraat", "Kerkstraat", "", "")]
[InlineData("Kerkstraat", "KERKSTRAAT", "", "")]
[InlineData("Kerkstraat", "Kerkstraat", "HO", "ho")]
public void WithDuplicateStreetName_ThenReturnsBadRequest(
string streetNameNameOne, string streetNameNameTwo,
string homonymAdditionOne, string homonymAdditionTwo)
{
const string oldNisCode = "11000";
var oldMunicipalityId = Guid.NewGuid();
_municipalityConsumerContext.Add(new MunicipalityConsumerItem
{
MunicipalityId = oldMunicipalityId,
NisCode = oldNisCode
});
_municipalityConsumerContext.SaveChanges();

var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
$"11000;123;NisCode;{streetNameNameOne};{homonymAdditionOne}\n" +
$"11000;123;NisCode;{streetNameNameTwo};{homonymAdditionTwo}"),
"NisCode",
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
CancellationToken.None).GetAwaiter().GetResult();

result.Should().BeOfType<BadRequestObjectResult>();
((BadRequestObjectResult)result).Value.Should().BeEquivalentTo(new[] { "Duplicate record for streetName with persistent local id 123" });
}

[Fact]
public void WithValidCsv_ThenReturnsOk()
{
Expand Down

0 comments on commit d062159

Please sign in to comment.