Skip to content

Commit

Permalink
fix: correct streetname when language is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Oct 25, 2024
1 parent b0630da commit bef70f9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ public void CorrectNames(Names namesToCorrect, Action<Names, HomonymAdditions, P

foreach (var correctedName in namesToCorrect)
{
var originalName = Names.Single(x => x.Language == correctedName.Language);
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);

var changeDifference = LevenshteinDistanceCalculator.CalculatePercentage(correctedName.Name, originalName.Name);

if (changeDifference > CorrectionChangeLimitPercentage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,42 @@ public void WithNoChanges_ThenNothing()
.ThenNone());
}

[Fact]
public void WithOneAdded_ThenOnlyOneStreetNameNameWasChanged()
{
var command = Fixture.Create<ChangeStreetNameNames>()
.WithStreetNameNames(new Names())
//.WithStreetNameName(new StreetNameName("Kapelstraat", Language.Dutch))
.WithStreetNameName(new StreetNameName("Rue de la Chapelle", Language.French));

var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture)
.Build();

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

var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture)
.WithNisCode(new NisCode("abc"))
.WithNames(new Names(new[]
{
new StreetNameName("Kapelstraat", Language.Dutch),
}))
.Build();

// Act, assert
Assert(new Scenario()
.Given(_streamId,
Fixture.Create<MunicipalityWasImported>(),
Fixture.Create<MunicipalityBecameCurrent>(),
dutchLanguageWasAdded,
frenchLanguageWasAdded,
streetNameWasProposedV2)
.When(command)
.Then(new Fact(_streamId, new StreetNameNamesWereChanged(
_municipalityId, command.PersistentLocalId, new Names(new[] { new StreetNameName("Rue de la Chapelle", Language.French) })))));
}

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

[Fact]
public void WithFacilityLanguageNotInProposedStreetName_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 languageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture)
.WithLanguage(Language.Dutch)
.Build();

var facilityLanguageWasAdded = Fixture.Create<AddFacilityLanguageToMunicipality>()
.WithLanguage(Language.French)
.ToEvent();

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>(),
languageWasAdded,
facilityLanguageWasAdded,
streetNameWasProposedV2)
.When(command)
.Throws(new StreetNameNameCorrectionExceededCharacterChangeLimitException(invalidStreetName.Name)));
}

[Fact]
public void WithNoChanges_ThenNothing()
{
Expand Down

0 comments on commit bef70f9

Please sign in to comment.