From d72b8e4a0da7db24ea98a81db6c11290dc69e207 Mon Sep 17 00:00:00 2001 From: jvandaal Date: Wed, 6 Nov 2024 10:41:04 +0100 Subject: [PATCH] feat: allow correction of empty name --- .../Municipality/MunicipalityStreetName.cs | 8 ++- .../GivenMunicipality.cs | 58 ++++++++++++++++--- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/StreetNameRegistry/Municipality/MunicipalityStreetName.cs b/src/StreetNameRegistry/Municipality/MunicipalityStreetName.cs index bab1b96b6..04939c63d 100644 --- a/src/StreetNameRegistry/Municipality/MunicipalityStreetName.cs +++ b/src/StreetNameRegistry/Municipality/MunicipalityStreetName.cs @@ -109,9 +109,11 @@ public void CorrectNames(Names namesToCorrect, Action x.Language == correctedName.Language); - // This should never happen in the normal flow, but with CRAB migration there are streetnames without names in supported every language - if(originalName is null) - throw new StreetNameNameCorrectionExceededCharacterChangeLimitException(correctedName.Name); + // This should never happen in the normal flow, but with CRAB migration there are streetnames without names in supported languages + if (originalName is null) + { + continue; + } var changeDifference = LevenshteinDistanceCalculator.CalculatePercentage(correctedName.Name, originalName.Name); diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs index d6273d519..e365fad0e 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs @@ -330,14 +330,53 @@ public void WithInvalidLanguage_ThenThrowsStreetNameNameLanguageNotSupportedExce } [Fact] - public void WithFacilityLanguageNotInProposedStreetName_ThenThrowsStreetNameNameLanguageNotSupportedException() + public void WithOfficialLanguageNotInProposedStreetName_ThenStreetNameNameWasCorrected() { - var invalidStreetName = new StreetNameName("Rue de la Chapelle", Language.French); - var streetNameNames = new Names(new[] - { + var previousEmptyName = new StreetNameName("Rue de la Chapelle", Language.French); + var streetNameNames = new Names([ new StreetNameName("Kapelstraat", Language.Dutch), - invalidStreetName - }); + previousEmptyName + ]); + + var command = Fixture.Create() + .WithStreetNameNames(streetNameNames); + + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.Dutch) + .Build(); + + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); + + var streetNameWasProposedV2 = Fixture.Create() + .WithNames(new Names([new StreetNameName("Kapestraat", Language.Dutch)])); + + // Act, assert + Assert(new Scenario() + .Given(_streamId, + Fixture.Create(), + Fixture.Create(), + dutchLanguageWasAdded, + frenchLanguageWasAdded, + streetNameWasProposedV2) + .When(command) + .Then(new Fact(_streamId, + new StreetNameNamesWereCorrected( + _municipalityId, + command.PersistentLocalId, + command.StreetNameNames)) + )); + } + + [Fact] + public void WithFacilityLanguageNotInProposedStreetName_ThenStreetNameNameWasCorrected() + { + var previousEmptyName = new StreetNameName("Rue de la Chapelle", Language.French); + var streetNameNames = new Names([ + new StreetNameName("Kapelstraat", Language.Dutch), + previousEmptyName + ]); var command = Fixture.Create() .WithStreetNameNames(streetNameNames); @@ -362,7 +401,12 @@ public void WithFacilityLanguageNotInProposedStreetName_ThenThrowsStreetNameName facilityLanguageWasAdded, streetNameWasProposedV2) .When(command) - .Throws(new StreetNameNameCorrectionExceededCharacterChangeLimitException(invalidStreetName.Name))); + .Then(new Fact(_streamId, + new StreetNameNamesWereCorrected( + _municipalityId, + command.PersistentLocalId, + command.StreetNameNames)) + )); } [Fact]