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 d72b8e4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 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 @@ -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

0 comments on commit d72b8e4

Please sign in to comment.