fix(sms): S2 review — add DeleteSmsConfigurationAsync + schema/repo tests + doc nit

This commit is contained in:
Joseph Doherty
2026-06-19 10:06:44 -04:00
parent b46691747c
commit 3827b98484
6 changed files with 47 additions and 2 deletions
@@ -124,6 +124,12 @@ public interface INotificationRepository
/// <returns>A task representing the asynchronous operation.</returns>
Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default);
/// <summary>Deletes an SMS configuration by ID.</summary>
/// <param name="id">The SMS configuration ID.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task representing the asynchronous operation.</returns>
Task DeleteSmsConfigurationAsync(int id, CancellationToken cancellationToken = default);
/// <summary>Saves pending changes to the repository.</summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The number of entities saved.</returns>
@@ -57,8 +57,7 @@ public class NotificationRecipientConfiguration : IEntityTypeConfiguration<Notif
public class SmsConfigurationConfiguration : IEntityTypeConfiguration<SmsConfiguration>
{
/// <summary>Configures the EF Core mapping for <see cref="SmsConfiguration"/>.</summary>
/// <param name="builder">The entity type builder.</param>
/// <inheritdoc />
public void Configure(EntityTypeBuilder<SmsConfiguration> builder)
{
builder.HasKey(s => s.Id);
@@ -104,6 +104,13 @@ public class NotificationRepository : INotificationRepository
public Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default)
{ _context.Set<SmsConfiguration>().Update(smsConfiguration); return Task.CompletedTask; }
/// <inheritdoc />
public async Task DeleteSmsConfigurationAsync(int id, CancellationToken cancellationToken = default)
{
var entity = await _context.Set<SmsConfiguration>().FindAsync(new object[] { id }, cancellationToken);
if (entity != null) _context.Set<SmsConfiguration>().Remove(entity);
}
/// <inheritdoc />
public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
=> await _context.SaveChangesAsync(cancellationToken);
@@ -211,6 +211,10 @@ public class SiteNotificationRepository : INotificationRepository
public Task UpdateSmsConfigurationAsync(SmsConfiguration smsConfiguration, CancellationToken cancellationToken = default)
=> throw new NotSupportedException("Managed via artifact deployment from Central");
/// <inheritdoc />
public Task DeleteSmsConfigurationAsync(int id, CancellationToken cancellationToken = default)
=> throw new NotSupportedException("Managed via artifact deployment from Central");
/// <inheritdoc />
public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
=> throw new NotSupportedException("Managed via artifact deployment from Central");
@@ -226,6 +226,34 @@ public class NotificationRepositoryTests : IDisposable
Assert.Null(await _repository.GetNotificationListByIdAsync(list.Id));
}
[Fact]
public async Task AddSmsConfiguration_RoundTrips()
{
var sms = new SmsConfiguration("ACtest123", "+14155550100");
await _repository.AddSmsConfigurationAsync(sms);
await _repository.SaveChangesAsync();
var loaded = await _repository.GetSmsConfigurationAsync();
Assert.NotNull(loaded);
Assert.Equal("ACtest123", loaded!.AccountSid);
Assert.Equal("+14155550100", loaded.FromNumber);
// Update a field and verify GetAllSmsConfigurationsAsync reflects it.
loaded.FromNumber = "+14155550199";
await _repository.UpdateSmsConfigurationAsync(loaded);
await _repository.SaveChangesAsync();
var all = await _repository.GetAllSmsConfigurationsAsync();
Assert.Single(all);
Assert.Equal("+14155550199", all[0].FromNumber);
// Delete and verify removal.
await _repository.DeleteSmsConfigurationAsync(loaded.Id);
await _repository.SaveChangesAsync();
Assert.Null(await _repository.GetSmsConfigurationAsync());
}
[Fact]
public async Task NotificationList_PersistsType()
{
@@ -53,6 +53,7 @@ public class DbContextTests : IDisposable
Assert.NotNull(_context.NotificationLists);
Assert.NotNull(_context.NotificationRecipients);
Assert.NotNull(_context.SmtpConfigurations);
Assert.NotNull(_context.SmsConfigurations);
Assert.NotNull(_context.SharedScripts);
Assert.NotNull(_context.LdapGroupMappings);
Assert.NotNull(_context.SiteScopeRules);