1631786ce2
Add push contracts, provider delivery and channel diagnostics. Link email channels to services and document migration and validation. Ref: IT-1074
93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
namespace HrynCo.NotificationService.Services.Tests.EmailProcessing;
|
|
|
|
using HrynCo.NotificationService.Contracts.Messages;
|
|
using HrynCo.NotificationService.Worker;
|
|
using Hrynco.RabbitMq;
|
|
|
|
public sealed class SendEmailDeliveryValidatorTests
|
|
{
|
|
[Fact]
|
|
public void ValidItemTrackerDelivery_IsAccepted()
|
|
{
|
|
string? error = SendEmailDeliveryValidator.GetValidationError(
|
|
CreateMessage(),
|
|
CreateContext(),
|
|
SupportedMessageType.SendEmailV1);
|
|
|
|
Assert.Null(error);
|
|
}
|
|
|
|
[Fact]
|
|
public void MissingMessageId_IsRejected()
|
|
{
|
|
RabbitMqMessageContext context = CreateContext() with { MessageId = null };
|
|
|
|
string? error = SendEmailDeliveryValidator.GetValidationError(
|
|
CreateMessage(),
|
|
context,
|
|
SupportedMessageType.SendEmailV1);
|
|
|
|
Assert.Equal("AMQP MessageId is required.", error);
|
|
}
|
|
|
|
[Fact]
|
|
public void UnsupportedContractVersion_IsRejected()
|
|
{
|
|
RabbitMqMessageContext context = CreateContext() with
|
|
{
|
|
MessageType = "Notification.SendEmail.v2"
|
|
};
|
|
|
|
string? error = SendEmailDeliveryValidator.GetValidationError(
|
|
CreateMessage(),
|
|
context,
|
|
SupportedMessageType.SendEmailV1);
|
|
|
|
Assert.Equal("Unsupported AMQP message type 'Notification.SendEmail.v2'.", error);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Notification.SendPush.v1")]
|
|
[InlineData("notification.sendemail.v1")]
|
|
[InlineData("SendEmailV1")]
|
|
[InlineData("0")]
|
|
[InlineData("")]
|
|
[InlineData(null)]
|
|
public void OtherOrMissingWireType_IsRejected(string? wireType)
|
|
{
|
|
string? error = SendEmailDeliveryValidator.GetValidationError(CreateMessage(),
|
|
CreateContext() with { MessageType = wireType }, SupportedMessageType.SendEmailV1);
|
|
|
|
Assert.Equal($"Unsupported AMQP message type '{wireType ?? "<missing>"}'.", error);
|
|
}
|
|
|
|
private static RabbitMqMessageContext CreateContext() => new()
|
|
{
|
|
QueueName = SendEmailConsumer.IncomingQueue,
|
|
Exchange = string.Empty,
|
|
RoutingKey = SendEmailConsumer.IncomingQueue,
|
|
MessageId = Guid.NewGuid().ToString("D"),
|
|
MessageType = "Notification.SendEmail.v1",
|
|
CorrelationId = "correlation-id",
|
|
ContentType = "application/json"
|
|
};
|
|
|
|
private static SendEmailMessage CreateMessage() => new()
|
|
{
|
|
CorrelationContext = new CorrelationContext
|
|
{
|
|
CorrelationId = "correlation-id",
|
|
ReplyTo = "item-tracker.notifications.result"
|
|
},
|
|
Data = new SendEmailMessageData
|
|
{
|
|
ServiceName = "StoreMate-Prod",
|
|
TemplateKey = "EmailVerification",
|
|
RecipientEmail = "owner@example.com",
|
|
RecipientName = "Owner",
|
|
LanguageCode = "uk",
|
|
Variables = new Dictionary<string, string> { ["AppName"] = "StoreMate" }
|
|
}
|
|
};
|
|
}
|