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

feat: allow correction of empty name #427

Merged
merged 1 commit into from
Dec 2, 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 @@ -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 @@ -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<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_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<CorrectStreetNameNames>()
.WithStreetNameNames(streetNameNames);
Expand All @@ -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]
Expand Down
Loading