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

fix: create streetname snapshot sqs handler #1284

Merged
merged 1 commit into from
Jan 7, 2025
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 @@ -28,7 +28,8 @@ public CreateStreetNameSnapshotSqsHandler(
{
return _backOfficeContext
.AddressPersistentIdStreetNamePersistentIds
.SingleOrDefault(x => x.StreetNamePersistentLocalId == request.Request.StreetNamePersistentLocalId)
.FirstOrDefault(x =>
x.StreetNamePersistentLocalId == request.Request.StreetNamePersistentLocalId)
?.StreetNamePersistentLocalId.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
namespace AddressRegistry.Tests.BackOffice.Sqs
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AddressRegistry.Api.BackOffice.Abstractions.Requests;
using AddressRegistry.Api.BackOffice.Abstractions.SqsRequests;
using AddressRegistry.Api.BackOffice.Handlers;
using AutoFixture;
using Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple;
using Be.Vlaanderen.Basisregisters.Sqs;
using Be.Vlaanderen.Basisregisters.Sqs.Exceptions;
using FluentAssertions;
using global::AutoFixture;
using Infrastructure;
using Moq;
using StreetName;
using TicketingService.Abstractions;
using Xunit;
using Xunit.Abstractions;

public sealed class GivenAddressBackOfficeCreateSnapshotRequest : AddressRegistryTest
{
private readonly TestBackOfficeContext _backOfficeContext;

public GivenAddressBackOfficeCreateSnapshotRequest(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
Fixture.Customize(new WithFixedStreetNamePersistentLocalId());

_backOfficeContext = new FakeBackOfficeContextFactory().CreateDbContext();
}

[Fact]
public async Task ThenTicketWithLocationIsCreated()
{
// Arrange
await _backOfficeContext.AddAddressPersistentIdStreetNamePersistentId(
Fixture.Create<AddressPersistentLocalId>(),
Fixture.Create<StreetNamePersistentLocalId>());
await _backOfficeContext.AddAddressPersistentIdStreetNamePersistentId(
Fixture.Create<AddressPersistentLocalId>(),
Fixture.Create<StreetNamePersistentLocalId>());

var ticketId = Fixture.Create<Guid>();
var ticketingMock = new Mock<ITicketing>();
ticketingMock
.Setup(x => x.CreateTicket(It.IsAny<IDictionary<string, string>>(), CancellationToken.None))
.ReturnsAsync(ticketId);

var ticketingUrl = new TicketingUrl(Fixture.Create<Uri>().ToString());

var sqsQueue = new Mock<ISqsQueue>();

var sut = new CreateStreetNameSnapshotSqsHandler(
sqsQueue.Object,
ticketingMock.Object,
ticketingUrl,
_backOfficeContext);

var sqsRequest = new CreateStreetNameSnapshotSqsRequest
{
Request = new CreateStreetNameSnapshotRequest
{
StreetNamePersistentLocalId = Fixture.Create<StreetNamePersistentLocalId>()
}
};

// Act
var result = await sut.Handle(sqsRequest, CancellationToken.None);

// Assert
sqsRequest.TicketId.Should().Be(ticketId);
sqsQueue.Verify(x => x.Copy(
sqsRequest,
It.Is<SqsQueueOptions>(y => y.MessageGroupId == sqsRequest.Request.StreetNamePersistentLocalId.ToString("D")),
CancellationToken.None));
result.Location.Should().Be(ticketingUrl.For(ticketId));
}

[Fact]
public void WithNoStreetNameFoundByAddressPersistentLocalId_ThrowsAggregateIdNotFound()
{
// Arrange
var sut = new CreateStreetNameSnapshotSqsHandler(
Mock.Of<ISqsQueue>(),
Mock.Of<ITicketing>(),
Mock.Of<ITicketingUrl>(),
_backOfficeContext);

// Act
var act = async () => await sut.Handle(
new CreateStreetNameSnapshotSqsRequest
{
Request = Fixture.Create<CreateStreetNameSnapshotRequest>()
}, CancellationToken.None);

// Assert
act
.Should()
.ThrowAsync<AggregateIdIsNotFoundException>();
}
}
}
Loading