Skip to content

Commit

Permalink
feat: allow correction of empty name
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal committed Nov 6, 2024
1 parent 4cca1bb commit 3b4a19f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/StreetNameRegistry/Municipality/MunicipalityStreetName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ public void CorrectNames(Names namesToCorrect, Action<Names, HomonymAdditions, P
{
var originalName = Names.SingleOrDefault(x => 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,47 @@ public void WithInvalidLanguage_ThenThrowsStreetNameNameLanguageNotSupportedExce
$"The language '{Language.Dutch}' is not an official or facility language of municipality '{_municipalityId}'.")));
}

[Fact]
public void WithOfficialLanguageNotInProposedStreetName_ThenThrowsStreetNameNameLanguageNotSupportedException()
{
var invalidStreetName = new StreetNameName("Rue de la Chapelle", Language.French);
var streetNameNames = new Names(new[]
{
new StreetNameName("Kapelstraat", Language.Dutch),
invalidStreetName
});

var command = Fixture.Create<CorrectStreetNameNames>()
.WithStreetNameNames(streetNameNames);

var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture)
.WithLanguage(Language.Dutch)
.Build();

var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture)
.WithLanguage(Language.French)
.Build();

var streetNameWasProposedV2 = Fixture.Create<StreetNameWasProposedV2>()
.WithNames(new Names([new StreetNameName("Kapestraat", Language.Dutch)]));

// Act, assert
Assert(new Scenario()
.Given(_streamId,
Fixture.Create<MunicipalityWasImported>(),
Fixture.Create<MunicipalityBecameCurrent>(),
dutchLanguageWasAdded,
frenchLanguageWasAdded,
streetNameWasProposedV2)
.When(command)
.Then(new Fact(_streamId,
new StreetNameNamesWereCorrected(
_municipalityId,
command.PersistentLocalId,
command.StreetNameNames))
));
}

[Fact]
public void WithFacilityLanguageNotInProposedStreetName_ThenThrowsStreetNameNameLanguageNotSupportedException()
{
Expand Down Expand Up @@ -362,7 +403,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]
Expand Down

0 comments on commit 3b4a19f

Please sign in to comment.