Skip to content

Commit

Permalink
fix(backoffice): remove address from merger relation
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD authored and jvandaal committed Dec 11, 2024
1 parent 6fe3b31 commit 056cd49
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ public async Task<AddressPersistentIdStreetNamePersistentId> AddIdempotentAddres
return relation;
}

public async Task RemoveIdempotentMunicipalityMergerAddress(int newAddressPersistentLocalId, CancellationToken cancellationToken)
{
var relation = await MunicipalityMergerAddresses.SingleOrDefaultAsync(
x => x.NewAddressPersistentLocalId == newAddressPersistentLocalId, cancellationToken: cancellationToken);
if (relation is null)
{
return;
}

MunicipalityMergerAddresses.Remove(relation);
await SaveChangesAsync(cancellationToken);
}

public async Task<MunicipalityMergerAddress> AddIdempotentMunicipalityMergerAddress(
int oldAddressPersistentLocalId,
int newStreetNamePersistentLocalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ await backOfficeContext.AddIdempotentAddressStreetNameIdRelation(
message.Message.AddressPersistentLocalId, message.Message.StreetNamePersistentLocalId, cancellationToken);
});

When<Envelope<AddressWasRemovedV2>>(async (_, message, cancellationToken) =>
{
await DelayProjection(message.CreatedUtc, delayInSeconds, cancellationToken);

await using var backOfficeContext = await backOfficeContextFactory.CreateDbContextAsync(cancellationToken);
await backOfficeContext.RemoveIdempotentMunicipalityMergerAddress(message.Message.AddressPersistentLocalId, cancellationToken);
});

When<Envelope<AddressWasProposedForMunicipalityMerger>>(async (_, message, cancellationToken) =>
{
await DelayProjection(message.CreatedUtc, delayInSeconds, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public async Task<IActionResult> Get(
sqlConsumerReadStreetNameLatestItemConnection.QueryFirstAsync<DateTimeOffset>(
$"SELECT TOP(1) [{nameof(StreetNameLatestItem.VersionTimestamp)}] FROM [{Schema.ConsumerReadStreetName}].[{StreetNameLatestItemConfiguration.TableName}] ORDER BY [{nameof(StreetNameLatestItem.VersionTimestamp)}] DESC");


await Task.WhenAll(consumerResult, municipalityLatestItemResult, streetNameLatestItemResult);

return Ok(new object[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ await Sut
});
}

[Fact]
public async Task GivenAddressWasRemovedV2_ThenRelationIsRemoved()
{
var addressWasRemovedV2 = _fixture.Create<AddressWasRemovedV2>();

var oldAddressPersistentLocalId = _fixture.Create<int>();
await _fakeBackOfficeContext.AddIdempotentAddressStreetNameIdRelation(
oldAddressPersistentLocalId,
_fixture.Create<int>(),
CancellationToken.None);

await _fakeBackOfficeContext.AddIdempotentMunicipalityMergerAddress(
oldAddressPersistentLocalId,
addressWasRemovedV2.StreetNamePersistentLocalId,
addressWasRemovedV2.AddressPersistentLocalId,
CancellationToken.None);

await Sut
.Given(new Envelope<AddressWasRemovedV2>(new Envelope(addressWasRemovedV2, new Dictionary<string, object>
{
{ Envelope.CreatedUtcMetadataKey, DateTime.UtcNow }
})))
.Then(async _ =>
{
await Task.Delay(TimeSpan.FromSeconds(DelayInSeconds + 1));

var result = await _fakeBackOfficeContext.MunicipalityMergerAddresses
.FindAsync(oldAddressPersistentLocalId);

result.Should().BeNull();
});
}

[Fact]
public async Task GivenAddressWasProposedForMunicipalityMerger_ThenRelationIsAdded()
{
Expand Down
1 change: 0 additions & 1 deletion test/AddressRegistry.Tests/ProjectionsHandlesEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public void BackOfficeProjectionHandlesEvents()
typeof(AddressWasRejectedBecauseStreetNameWasRetired),
typeof(AddressWasRemovedBecauseHouseNumberWasRemoved),
typeof(AddressWasRemovedBecauseStreetNameWasRemoved),
typeof(AddressWasRemovedV2),
typeof(AddressWasRetiredBecauseHouseNumberWasRetired),
typeof(AddressWasRetiredBecauseOfMunicipalityMerger),
typeof(AddressWasRetiredBecauseOfReaddress),
Expand Down

0 comments on commit 056cd49

Please sign in to comment.