feat(smtp): UpdateSmtpConfigCommand carries TlsMode + Credentials
Add two optional nullable fields (TlsMode, Credentials) to the UpdateSmtpConfigCommand record. The handler applies preserve-if-null semantics: an update that omits a field leaves the existing value intact, so existing 5-arg callers remain non-breaking.
This commit is contained in:
@@ -1002,6 +1002,72 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
Assert.Contains(envelope.CorrelationId, response.Error);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// UpdateSmtpConfig — TlsMode + Credentials plumbing (preserve-if-null)
|
||||
// ========================================================================
|
||||
|
||||
[Fact]
|
||||
public void UpdateSmtpConfig_WithTlsModeAndCredentials_PersistsThem()
|
||||
{
|
||||
var notifRepo = Substitute.For<INotificationRepository>();
|
||||
var existing = new Commons.Entities.Notifications.SmtpConfiguration(
|
||||
"old.example.com", "OAuth2", "old@example.com")
|
||||
{
|
||||
Id = 1,
|
||||
Port = 25,
|
||||
TlsMode = "StartTLS",
|
||||
Credentials = "old-secret",
|
||||
};
|
||||
notifRepo.GetSmtpConfigurationByIdAsync(1, Arg.Any<CancellationToken>()).Returns(existing);
|
||||
_services.AddScoped(_ => notifRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
var envelope = Envelope(
|
||||
new UpdateSmtpConfigCommand(1, "new.example.com", 465, "Basic", "new@example.com", "SSL", "user:pass"),
|
||||
"Design");
|
||||
|
||||
actor.Tell(envelope);
|
||||
|
||||
var response = ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal(envelope.CorrelationId, response.CorrelationId);
|
||||
Assert.Equal("SSL", existing.TlsMode);
|
||||
Assert.Equal("user:pass", existing.Credentials);
|
||||
Assert.Equal("new.example.com", existing.Host);
|
||||
Assert.Equal("Basic", existing.AuthType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateSmtpConfig_WithNullTlsModeAndCredentials_PreservesExistingValues()
|
||||
{
|
||||
var notifRepo = Substitute.For<INotificationRepository>();
|
||||
var existing = new Commons.Entities.Notifications.SmtpConfiguration(
|
||||
"old.example.com", "OAuth2", "old@example.com")
|
||||
{
|
||||
Id = 1,
|
||||
Port = 25,
|
||||
TlsMode = "StartTLS",
|
||||
Credentials = "old-secret",
|
||||
};
|
||||
notifRepo.GetSmtpConfigurationByIdAsync(1, Arg.Any<CancellationToken>()).Returns(existing);
|
||||
_services.AddScoped(_ => notifRepo);
|
||||
|
||||
var actor = CreateActor();
|
||||
var envelope = Envelope(
|
||||
new UpdateSmtpConfigCommand(1, "new.example.com", 465, "Basic", "new@example.com"),
|
||||
"Design");
|
||||
|
||||
actor.Tell(envelope);
|
||||
|
||||
var response = ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal(envelope.CorrelationId, response.CorrelationId);
|
||||
// Omitted fields are preserved, not nulled.
|
||||
Assert.Equal("StartTLS", existing.TlsMode);
|
||||
Assert.Equal("old-secret", existing.Credentials);
|
||||
// Provided fields are still updated.
|
||||
Assert.Equal("new.example.com", existing.Host);
|
||||
Assert.Equal("Basic", existing.AuthType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CuratedHandlerFailure_SurfacesTheCuratedMessage()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user