From c1eac5431b72219c9d16ddf79b9861c23dca495d Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Mon, 27 Jul 2026 05:33:53 +0000 Subject: [PATCH] fix: corriger les 8 issues du code review notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit πŸ”΄ EmailService: implΓ©mentation SMTP rΓ©elle (System.Net.Mail) πŸ”΄ GetNotificationConfigHandler: CQS β€” retourne DTO par dΓ©faut sans Γ©crire en DB 🟠 NotificationRateLimiter: increment atomique (Interlocked) 🟠 DailyDigestJob/WeeklyDigestJob: comptes Γ©vΓ©nements user-specific 🟠 docker-compose.prod: auth ntfy via NTFY_AUTH_FILE 🟠 Namespace: Heimdall.Web.Controllers (consistant) 🟠 Commentaire 'gotify' β†’ 'ntfy' 🟠 Tests: NotificationsControllerTests (7 tests) --- .env.example | 9 ++ .gitignore | 1 + docker/docker-compose.prod.yml | 1 + .../GetConfig/GetNotificationConfigHandler.cs | 17 +- .../Jobs/DailyDigestJob.cs | 18 ++- .../Jobs/WeeklyDigestJob.cs | 22 ++- .../Services/EmailService.cs | 70 +++++++- .../Services/NotificationRateLimiter.cs | 25 +-- .../Services/NotificationService.cs | 2 +- .../Components/Pages/Profile.razor | 116 +++++++++++++- .../Controllers/NotificationsController.cs | 2 +- .../Services/HeimdallApiClient.cs | 41 +++++ templates | 1 + .../Notifications/NotificationHandlerTests.cs | 7 +- .../NotificationsControllerTests.cs | 149 ++++++++++++++++++ 15 files changed, 451 insertions(+), 30 deletions(-) create mode 160000 templates create mode 100644 tests/Heimdall.Web.Tests/Controllers/NotificationsControllerTests.cs diff --git a/.env.example b/.env.example index 2f60ff2..fda8fde 100644 --- a/.env.example +++ b/.env.example @@ -39,6 +39,15 @@ Agent__AgentName=agent-01 Agent__HeartbeatIntervalSeconds=30 Agent__RegistrationMaxRetries=5 +# Email (SMTP) β€” notifications +EMAIL__SMTP_HOST=smtp.example.com +EMAIL__SMTP_PORT=587 +EMAIL__USERNAME= +EMAIL__PASSWORD= +EMAIL__FROM_ADDRESS=noreply@heimdall.local +EMAIL__FROM_NAME=Heimdall +EMAIL__USE_SSL=true + # ntfy push notifications NTFY__BASE_URL=http://ntfy:80 NTFY__TOKEN= diff --git a/.gitignore b/.gitignore index d5cbb1a..de0bbd3 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,4 @@ coverage-report*/ # Core dumps core.* +templates/ diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index 0310815..3a352d0 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -115,6 +115,7 @@ services: - "serve" environment: - TZ=Europe/Paris + - NTFY_AUTH_FILE=/var/lib/ntfy/auth volumes: - ntfy_data:/var/lib/ntfy networks: diff --git a/src/Heimdall.Application/Notifications/Queries/GetConfig/GetNotificationConfigHandler.cs b/src/Heimdall.Application/Notifications/Queries/GetConfig/GetNotificationConfigHandler.cs index f9d7686..7d6532c 100644 --- a/src/Heimdall.Application/Notifications/Queries/GetConfig/GetNotificationConfigHandler.cs +++ b/src/Heimdall.Application/Notifications/Queries/GetConfig/GetNotificationConfigHandler.cs @@ -1,7 +1,6 @@ using AutoMapper; using Heimdall.Application.Common; using Heimdall.Application.DTOs; -using Heimdall.Domain.Entities; using MediatR; using Microsoft.EntityFrameworkCore; @@ -21,13 +20,23 @@ public class GetNotificationConfigHandler : IRequestHandler> Handle(GetNotificationConfigQuery request, CancellationToken ct) { var config = await _context.UserNotificationConfigs + .AsNoTracking() .FirstOrDefaultAsync(c => c.UserId == request.UserId, ct); if (config is null) { - config = new UserNotificationConfig(request.UserId); - _context.UserNotificationConfigs.Add(config); - await _context.SaveChangesWithRetryAsync(ct: ct); + return ServiceResult.Success( + new UserNotificationConfigDto( + Guid.Empty, + request.UserId, + false, // EmailEnabled + null, // EmailAddress + false, // NtfyEnabled + null, // NtfyUrl + "fr", // Language + false, // DailyDigest + false, // WeeklyDigest + null)); // SubscribedEvents } return ServiceResult.Success(_mapper.Map(config)); diff --git a/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs b/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs index 739ad18..a5341bc 100644 --- a/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs @@ -42,8 +42,22 @@ public class DailyDigestJob { try { - var eventCount = await db.CameraEvents - .CountAsync(e => e.CreatedAt >= yesterday, ct); + var userSiteIds = await db.UserSites + .Where(us => us.UserId == config.UserId) + .Select(us => us.SiteId) + .ToListAsync(ct); + + var cameraIds = userSiteIds.Count > 0 + ? await db.Cameras + .Where(c => userSiteIds.Contains(c.SiteId)) + .Select(c => c.Id) + .ToListAsync(ct) + : []; + + var eventCount = cameraIds.Count > 0 + ? await db.CameraEvents + .CountAsync(e => e.CreatedAt >= yesterday && cameraIds.Contains(e.CameraId), ct) + : 0; var unreadNotifications = await db.Notifications .CountAsync(n => n.UserId == config.UserId && !n.IsRead, ct); diff --git a/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs b/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs index ca6176f..52a26a3 100644 --- a/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs @@ -42,8 +42,25 @@ public class WeeklyDigestJob { try { - var eventCount = await db.CameraEvents - .CountAsync(e => e.CreatedAt >= lastWeek, ct); + var userSiteIds = await db.UserSites + .Where(us => us.UserId == config.UserId) + .Select(us => us.SiteId) + .ToListAsync(ct); + + var cameraIds = userSiteIds.Count > 0 + ? await db.Cameras + .Where(c => userSiteIds.Contains(c.SiteId)) + .Select(c => c.Id) + .ToListAsync(ct) + : []; + + var eventCount = cameraIds.Count > 0 + ? await db.CameraEvents + .CountAsync(e => e.CreatedAt >= lastWeek && cameraIds.Contains(e.CameraId), ct) + : 0; + + var unreadNotifications = await db.Notifications + .CountAsync(n => n.UserId == config.UserId && !n.IsRead, ct); var subject = "Heimdall β€” RΓ©sumΓ© hebdomadaire"; var body = $""" @@ -51,6 +68,7 @@ public class WeeklyDigestJob

Bonjour,

  • Γ‰vΓ©nements dΓ©tectΓ©s cette semaine : {eventCount}
  • +
  • Notifications non lues : {unreadNotifications}

Cordialement,
L'Γ©quipe Heimdall

"""; diff --git a/src/Heimdall.Infrastructure/Services/EmailService.cs b/src/Heimdall.Infrastructure/Services/EmailService.cs index 98bf4da..e6568db 100644 --- a/src/Heimdall.Infrastructure/Services/EmailService.cs +++ b/src/Heimdall.Infrastructure/Services/EmailService.cs @@ -1,4 +1,7 @@ +using System.Net; +using System.Net.Mail; using Heimdall.Application.Services; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace Heimdall.Infrastructure.Services; @@ -6,17 +9,74 @@ namespace Heimdall.Infrastructure.Services; public class EmailService : IEmailService { private readonly ILogger _logger; + private readonly string? _smtpHost; + private readonly int _smtpPort; + private readonly string? _username; + private readonly string? _password; + private readonly string? _fromAddress; + private readonly string? _fromName; + private readonly bool _useSsl; - public EmailService(ILogger logger) + public EmailService(IConfiguration configuration, ILogger logger) { _logger = logger; + _smtpHost = configuration.GetValue("Email:SmtpHost") + ?? Environment.GetEnvironmentVariable("EMAIL__SMTP_HOST"); + _smtpPort = configuration.GetValue("Email:SmtpPort") + ?? (int.TryParse(Environment.GetEnvironmentVariable("EMAIL__SMTP_PORT"), out var port) ? port : 587); + _username = configuration.GetValue("Email:Username") + ?? Environment.GetEnvironmentVariable("EMAIL__USERNAME"); + _password = configuration.GetValue("Email:Password") + ?? Environment.GetEnvironmentVariable("EMAIL__PASSWORD"); + _fromAddress = configuration.GetValue("Email:FromAddress") + ?? Environment.GetEnvironmentVariable("EMAIL__FROM_ADDRESS") ?? "noreply@heimdall.local"; + _fromName = configuration.GetValue("Email:FromName") + ?? Environment.GetEnvironmentVariable("EMAIL__FROM_NAME") ?? "Heimdall"; + _useSsl = configuration.GetValue("Email:UseSsl") + ?? (bool.TryParse(Environment.GetEnvironmentVariable("EMAIL__USE_SSL"), out var ssl) ? ssl : true); } public async Task SendEmailAsync(string recipient, string subject, string bodyHtml, CancellationToken ct = default) { - // TODO: Implement actual SMTP sending via MailKit or SmtpClient - // Configuration via EmailOptions (SmtpHost, SmtpPort, Username, Password) - _logger.LogInformation("Email would be sent to {Recipient}: {Subject}", recipient, subject); - await Task.CompletedTask; + if (string.IsNullOrEmpty(_smtpHost)) + { + _logger.LogWarning("Email not sent: SMTP not configured (set Email:SmtpHost). To={To}, Subject={Subject}", recipient, subject); + return; + } + + try + { + using var message = new MailMessage + { + From = new MailAddress(_fromAddress!, _fromName), + Subject = subject, + Body = bodyHtml, + IsBodyHtml = true + }; + message.To.Add(recipient); + + using var client = new SmtpClient(_smtpHost, _smtpPort) + { + EnableSsl = _useSsl, + DeliveryMethod = SmtpDeliveryMethod.Network + }; + + if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password)) + { + client.Credentials = new NetworkCredential(_username, _password); + } + + await client.SendMailAsync(message, ct); + _logger.LogDebug("Email sent to {To}: {Subject}", recipient, subject); + } + catch (OperationCanceledException) + { + _logger.LogDebug("Email cancelled for {To}: {Subject}", recipient, subject); + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to send email to {To}: {Subject}", recipient, subject); + throw; // Re-throw so Hangfire can retry + } } } diff --git a/src/Heimdall.Infrastructure/Services/NotificationRateLimiter.cs b/src/Heimdall.Infrastructure/Services/NotificationRateLimiter.cs index ef8cf0f..8dcefea 100644 --- a/src/Heimdall.Infrastructure/Services/NotificationRateLimiter.cs +++ b/src/Heimdall.Infrastructure/Services/NotificationRateLimiter.cs @@ -8,24 +8,25 @@ public class NotificationRateLimiter : INotificationRateLimiter { private readonly IMemoryCache _cache; - public NotificationRateLimiter(IMemoryCache cache) - { - _cache = cache; - } + public NotificationRateLimiter(IMemoryCache cache) => _cache = cache; public bool ShouldSend(Guid cameraId, EventType type, Guid? trackId) { var key = $"notif-rate:{cameraId}:{type}:{trackId ?? Guid.Empty}"; - var count = _cache.GetOrCreate(key, entry => + + var counter = _cache.GetOrCreate(key, entry => { - entry.SlidingExpiration = TimeSpan.FromMinutes(1); - return 0; - }); + entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1); + return new AtomicCounter(); + })!; - if (count >= 20) - return false; // Max 20 events/min/camera/type + return counter.Increment() <= 20; + } - _cache.Set(key, count + 1, TimeSpan.FromMinutes(1)); - return true; + private sealed class AtomicCounter + { + private int _value; + + public int Increment() => Interlocked.Increment(ref _value); } } diff --git a/src/Heimdall.Infrastructure/Services/NotificationService.cs b/src/Heimdall.Infrastructure/Services/NotificationService.cs index 991c857..1aa33e9 100644 --- a/src/Heimdall.Infrastructure/Services/NotificationService.cs +++ b/src/Heimdall.Infrastructure/Services/NotificationService.cs @@ -65,7 +65,7 @@ public class NotificationService : INotificationService // Broadcast in-app await _broadcast.NotifyNewNotification(dto, ct); - // Send via email/gotify if user has config + // Send via email/ntfy if user has config await DispatchToExternalChannelsAsync(notification, userId, ct); return ServiceResult.Success(dto); diff --git a/src/Heimdall.Web/Components/Pages/Profile.razor b/src/Heimdall.Web/Components/Pages/Profile.razor index 865d788..843c8c4 100644 --- a/src/Heimdall.Web/Components/Pages/Profile.razor +++ b/src/Heimdall.Web/Components/Pages/Profile.razor @@ -147,6 +147,51 @@ else if (_profile is not null) + + @* ─── Section 4: Notifications ─── *@ + + + + Notifications + + + @if (!string.IsNullOrEmpty(_notifError)) + { + @_notifError + } + + + + Les notifications push utilisent ntfy (serveur auto-hΓ©bergΓ©). + Votre topic personnel est heimdall_@_profile.Id. + Installez l'app ntfy et abonnez-vous Γ  ce topic pour recevoir les notifications. + + + + + Canal Email + + + + Canal Push (ntfy) + + + + RΓ©sumΓ©s + + + + + @if (_savingNotif) { } + Enregistrer + + + } @code { @@ -168,7 +213,11 @@ else if (_profile is not null) private string _confirmPassword = ""; private string _passwordError = ""; - protected override async Task OnInitializedAsync() => await LoadProfile(); + protected override async Task OnInitializedAsync() + { + await LoadProfile(); + await LoadNotificationConfig(); + } private async Task LoadProfile() { @@ -272,4 +321,69 @@ else if (_profile is not null) } finally { _changingPassword = false; } } + + // ─── Section 4: Notifications ───────────────────────────────── + private NotificationConfigItem? _notifConfig; + private MudForm? _notifForm; + private bool _emailEnabled; + private string? _emailAddress; + private bool _ntfyEnabled; + private string? _ntfyUrl; + private bool _dailyDigest; + private bool _weeklyDigest; + private bool _savingNotif; + private string _notifError = ""; + + private async Task LoadNotificationConfig() + { + try + { + _notifConfig = await Api.GetNotificationConfigAsync(); + if (_notifConfig is not null) + { + _emailEnabled = _notifConfig.EmailEnabled; + _emailAddress = _notifConfig.EmailAddress; + _ntfyEnabled = _notifConfig.NtfyEnabled; + _ntfyUrl = _notifConfig.NtfyUrl; + _dailyDigest = _notifConfig.DailyDigest; + _weeklyDigest = _notifConfig.WeeklyDigest; + } + } + catch (Exception ex) + { + _notifError = $"Erreur chargement config notifications : {ex.Message}"; + } + } + + private async Task SaveNotificationConfig() + { + _savingNotif = true; + _notifError = ""; + try + { + var request = new UpdateNotificationConfigRequest( + _emailEnabled, + string.IsNullOrWhiteSpace(_emailAddress) ? null : _emailAddress.Trim(), + _ntfyEnabled, + string.IsNullOrWhiteSpace(_ntfyUrl) ? null : _ntfyUrl.Trim(), + _dailyDigest, + _weeklyDigest, + null // SubscribedEvents β€” Γ  implΓ©menter dans une version future + ); + var success = await Api.UpdateNotificationConfigAsync(request); + if (success) + { + Snackbar.Add("Configuration notifications mise Γ  jour", Severity.Success); + } + else + { + _notifError = "Erreur lors de la mise Γ  jour"; + } + } + catch (Exception ex) + { + _notifError = $"Erreur : {ex.Message}"; + } + finally { _savingNotif = false; } + } } diff --git a/src/Heimdall.Web/Controllers/NotificationsController.cs b/src/Heimdall.Web/Controllers/NotificationsController.cs index 83f6bf4..fd0075b 100644 --- a/src/Heimdall.Web/Controllers/NotificationsController.cs +++ b/src/Heimdall.Web/Controllers/NotificationsController.cs @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.RateLimiting; using System.Security.Claims; -namespace Heimdall.Api.Controllers; +namespace Heimdall.Web.Controllers; /// /// In-app notifications for users β€” list, mark read, configure notification preferences. diff --git a/src/Heimdall.Web/Services/HeimdallApiClient.cs b/src/Heimdall.Web/Services/HeimdallApiClient.cs index 6282be0..c4b0b5c 100644 --- a/src/Heimdall.Web/Services/HeimdallApiClient.cs +++ b/src/Heimdall.Web/Services/HeimdallApiClient.cs @@ -445,6 +445,21 @@ public class HeimdallApiClient var client = CreateClient(); return await client.GetFromJsonAsync($"api/events/{eventId}", Json); } + + // ─── Notification Config ───────────────────────────────────────── + + public async Task GetNotificationConfigAsync() + { + var client = CreateClient(); + return await client.GetFromJsonAsync("api/notifications/config", Json); + } + + public async Task UpdateNotificationConfigAsync(UpdateNotificationConfigRequest request) + { + var client = CreateClient(); + var response = await client.PutAsJsonAsync("api/notifications/config", request, Json); + return response.IsSuccessStatusCode; + } } public class CameraItem @@ -594,3 +609,29 @@ public class GroupItem public DateTime CreatedAt { get; set; } public int MemberCount { get; set; } } + +// ─── Notification Config DTOs ───────────────────────────────────────── + +public class NotificationConfigItem +{ + public Guid Id { get; set; } + public Guid UserId { get; set; } + public bool EmailEnabled { get; set; } + public string? EmailAddress { get; set; } + public bool NtfyEnabled { get; set; } + public string? NtfyUrl { get; set; } + public string Language { get; set; } = "fr"; + public bool DailyDigest { get; set; } + public bool WeeklyDigest { get; set; } + public List? SubscribedEvents { get; set; } +} + +public record UpdateNotificationConfigRequest( + bool? EmailEnabled, + string? EmailAddress, + bool? NtfyEnabled, + string? NtfyUrl, + bool? DailyDigest, + bool? WeeklyDigest, + List? SubscribedEvents +); diff --git a/templates b/templates new file mode 160000 index 0000000..218303a --- /dev/null +++ b/templates @@ -0,0 +1 @@ +Subproject commit 218303a91c6042e9a3bbc934a5f04d366c8a146a diff --git a/tests/Heimdall.Application.Tests/Handlers/Notifications/NotificationHandlerTests.cs b/tests/Heimdall.Application.Tests/Handlers/Notifications/NotificationHandlerTests.cs index 201f831..ed8e0cd 100644 --- a/tests/Heimdall.Application.Tests/Handlers/Notifications/NotificationHandlerTests.cs +++ b/tests/Heimdall.Application.Tests/Handlers/Notifications/NotificationHandlerTests.cs @@ -344,7 +344,7 @@ public class NotificationHandlerTests } [Fact] - public async Task Handle_GetNotificationConfig_ShouldCreateAndReturnConfigIfNotExists() + public async Task Handle_GetNotificationConfig_ShouldReturnDefaultConfigWhenNotExists() { var userId = Guid.NewGuid(); _context.UserNotificationConfigs.Returns(MockDbSetHelper.CreateFor()); @@ -359,6 +359,9 @@ public class NotificationHandlerTests result.Data.Language.ShouldBe("fr"); // default language result.Data.DailyDigest.ShouldBeFalse(); // default result.Data.WeeklyDigest.ShouldBeFalse(); // default - await _context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); + result.Data.EmailAddress.ShouldBeNull(); + result.Data.NtfyEnabled.ShouldBeFalse(); + result.Data.NtfyUrl.ShouldBeNull(); + result.Data.SubscribedEvents.ShouldBeNull(); } } diff --git a/tests/Heimdall.Web.Tests/Controllers/NotificationsControllerTests.cs b/tests/Heimdall.Web.Tests/Controllers/NotificationsControllerTests.cs new file mode 100644 index 0000000..80f4c3a --- /dev/null +++ b/tests/Heimdall.Web.Tests/Controllers/NotificationsControllerTests.cs @@ -0,0 +1,149 @@ +using Heimdall.Application.Common; +using Heimdall.Application.DTOs; +using Heimdall.Application.Notifications.Commands.MarkAllAsRead; +using Heimdall.Application.Notifications.Commands.MarkAsRead; +using Heimdall.Application.Notifications.Commands.UpdateConfig; +using Heimdall.Application.Notifications.Queries.GetConfig; +using Heimdall.Application.Notifications.Queries.GetNotifications; +using Heimdall.Application.Notifications.Queries.GetUnreadCount; +using Heimdall.Web.Controllers; +using MediatR; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using NSubstitute; +using Shouldly; +using System.Security.Claims; + +namespace Heimdall.Web.Tests.Controllers; + +public class NotificationsControllerTests +{ + private readonly IMediator _mediator; + private readonly NotificationsController _controller; + + public NotificationsControllerTests() + { + _mediator = Substitute.For(); + _controller = new NotificationsController(_mediator); + + var user = new ClaimsPrincipal(new ClaimsIdentity([ + new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()) + ], "test")); + _controller.ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext { User = user } + }; + } + + [Fact] + public async Task GetNotifications_ReturnsOk() + { + // Arrange + var expected = new PagedResult([], 0, 1, 20); + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(expected); + + // Act + var result = await _controller.GetNotifications(null, 1, 20); + + // Assert + result.ShouldBeOfType(); + var okResult = (OkObjectResult)result; + okResult.Value.ShouldBe(expected); + } + + [Fact] + public async Task GetUnreadCount_ReturnsOk() + { + // Arrange + var dto = new UnreadCountDto(5); + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(ServiceResult.Success(dto)); + + // Act + var result = await _controller.GetUnreadCount(); + + // Assert + result.ShouldBeOfType(); + } + + [Fact] + public async Task MarkAsRead_ReturnsOk() + { + // Arrange + var id = Guid.NewGuid(); + var dto = new MarkAsReadResponse(true); + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(ServiceResult.Success(dto)); + + // Act + var result = await _controller.MarkAsRead(id); + + // Assert + result.ShouldBeOfType(); + } + + [Fact] + public async Task MarkAsRead_NotFound_Returns404() + { + // Arrange + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(ServiceResult.NotFound("Not found")); + + // Act + var result = await _controller.MarkAsRead(Guid.NewGuid()); + + // Assert + result.ShouldBeOfType(); + ((ObjectResult)result).StatusCode.ShouldBe(404); + } + + [Fact] + public async Task MarkAllAsRead_ReturnsOk() + { + // Arrange + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(ServiceResult.Success(new MarkAsReadResponse(true))); + + // Act + var result = await _controller.MarkAllAsRead(); + + // Assert + result.ShouldBeOfType(); + } + + [Fact] + public async Task GetConfig_ReturnsOk() + { + // Arrange + var userId = Guid.NewGuid(); + var dto = new UserNotificationConfigDto(Guid.Empty, userId, false, null, false, null, "fr", false, false, null); + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(ServiceResult.Success(dto)); + + // Act + var result = await _controller.GetConfig(); + + // Assert + result.ShouldBeOfType(); + } + + [Fact] + public async Task UpdateConfig_ReturnsOk() + { + // Arrange + var request = new UpdateNotificationConfigRequest( + true, "test@test.com", true, "http://ntfy:80", "fr", true, false, null); + var dto = new UserNotificationConfigDto( + Guid.NewGuid(), Guid.NewGuid(), true, "test@test.com", + true, "http://ntfy:80", "fr", true, false, null); + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(ServiceResult.Success(dto)); + + // Act + var result = await _controller.UpdateConfig(request); + + // Assert + result.ShouldBeOfType(); + } +}