Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use persistentlocalids for propose streetnames for municipality merger #416

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,19 @@ public async Task<IActionResult> ProposeForMunicipalityMerger(
recordNr++;

var oldNisCode = csv.GetField<string>("OUD NIS code");
var oldStreetNamePuri = csv.GetField<string>("OUD straatnaamid");
var oldStreetNamePersistentLocalIdAsString = csv.GetField<string>("OUD straatnaamid");
var newNisCode = csv.GetField<string>("NIEUW NIS code");
var streetName = csv.GetField<string>("NIEUW straatnaam");
var homonymAddition = csv.GetField<string>("NIEUW homoniemtoevoeging");

if (string.IsNullOrWhiteSpace(oldNisCode))
return BadRequest($"OldNisCode is required at record number {recordNr}");

if (string.IsNullOrWhiteSpace(oldStreetNamePuri))
return BadRequest($"OldStreetNamePuri is required at record number {recordNr}");

if (!OsloPuriValidator.TryParseIdentifier(oldStreetNamePuri, out var oldStreetNamePersistentLocalIdAsString)
|| !int.TryParse(oldStreetNamePersistentLocalIdAsString, out var oldStreetNamePersistentLocalId))
return BadRequest($"OldStreetNamePuri is NaN at record number {recordNr}");
if (string.IsNullOrWhiteSpace(oldStreetNamePersistentLocalIdAsString))
return BadRequest($"OldStreetNamePersistentLocalId is required at record number {recordNr}");

if (!int.TryParse(oldStreetNamePersistentLocalIdAsString, out var oldStreetNamePersistentLocalId))
return BadRequest($"OldStreetNamePersistentLocalId is NaN at record number {recordNr}");

if (string.IsNullOrWhiteSpace(newNisCode))
return BadRequest($"NisCode is required at record number {recordNr}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void WithNoNisCode_ThenReturnsBadRequest()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
"11001;http://b/123;;Name;HO"),
"11001;123;;Name;HO"),
"bla",
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
Expand All @@ -79,7 +79,7 @@ public void WithDifferentNisCodeThanRoute_ThenReturnsBadRequest()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
"11000;http://b/123;11001;Name;HO"),
"11000;123;11001;Name;HO"),
nisCode,
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
Expand All @@ -95,7 +95,7 @@ public void WithNoStreetName_ThenReturnsBadRequest()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
"11000;http://b/123;NisCode;;HO"),
"11000;123;NisCode;;HO"),
"NisCode",
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
Expand Down Expand Up @@ -128,7 +128,7 @@ public void WithValidCsv_ThenReturnsOk()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString($"OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
$"{oldNisCode};http://a/123;11001;Street;HO\n{oldNisCode};http://a/456;11001;Name;NYM\n{oldNisCode};http://a/789;11001;Street;HO"),
$"{oldNisCode};123;11001;Street;HO\n{oldNisCode};456;11001;Name;NYM\n{oldNisCode};789;11001;Street;HO"),
"11001",
mockPersistentLocalIdGenerator.Object,
_municipalityConsumerContext,
Expand Down
2 changes: 1 addition & 1 deletion test/StreetNameRegistry.Tests/CsvHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public sealed class CsvHelpers
{
public const string OldNisCode = "11000";
public const string Example = $"OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n{OldNisCode};http://v/a/123;11001;naam;BB";
public const string Example = $"OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n{OldNisCode};123;11001;naam;BB";
//Convert the string to be able to passed as IFormFile

public static IFormFile CreateFormFileFromString(string content, string fileName = "file.csv")
Expand Down
Loading