fix(notification): enable web smtp test with saved password
Allow Web SMTP egress on TCP 587 and reuse the saved channel password only when connection settings match. Ref: IT-1601
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Reflection;
|
||||
using HrynCo.NotificationService.DAL.Abstract.Providers;
|
||||
using HrynCo.NotificationService.Services.Core;
|
||||
using HrynCo.NotificationService.Services.EmailChannels.Get;
|
||||
using HrynCo.NotificationService.Services.EmailChannels.TestSmtp;
|
||||
using MediatR;
|
||||
using ServiceUnit = HrynCo.NotificationService.Services.Core.Unit;
|
||||
|
||||
namespace HrynCo.NotificationService.Web.IntegrationTests;
|
||||
|
||||
public class RecordingAdminSmtpMediator : DispatchProxy
|
||||
{
|
||||
public EmailChannel? Channel { get; set; }
|
||||
public TestSmtpCommand? SentCommand { get; private set; }
|
||||
public int LookupCount { get; private set; }
|
||||
|
||||
protected override object Invoke(MethodInfo? targetMethod, object?[]? args)
|
||||
{
|
||||
if (targetMethod?.Name != nameof(IMediator.Send) || args?.Length is null or 0)
|
||||
throw new NotSupportedException();
|
||||
|
||||
return args[0] switch
|
||||
{
|
||||
GetEmailChannelQuery => RecordLookup(),
|
||||
TestSmtpCommand command => RecordSend(command),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
}
|
||||
|
||||
private Task<ServiceResult<EmailChannel>> RecordLookup()
|
||||
{
|
||||
LookupCount++;
|
||||
return Task.FromResult(Channel is null
|
||||
? ServiceResult<EmailChannel>.Failure("Channel not found.")
|
||||
: ServiceResult<EmailChannel>.Success(Channel));
|
||||
}
|
||||
|
||||
private Task<ServiceResult<ServiceUnit>> RecordSend(TestSmtpCommand command)
|
||||
{
|
||||
SentCommand = command;
|
||||
return Task.FromResult(ServiceResult<ServiceUnit>.Success(ServiceUnit.Value));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user