From ee7d01ed7f7104abe5daa1b1c06044511005d904 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 5 Nov 2026 12:03:40 +0100 Subject: [PATCH] test(notification): add email notification preview endpoints Expose signed and received notification endpoints, with reset random payload variants, to exercise rendering and delivery without running a full envelope workflow. Fall back to a fixed recipient when no email is supplied. --- .../Controllers/NotificationController.cs | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 EnvelopeGenerator.Server/EnvelopeGenerator.Server/Controllers/NotificationController.cs diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Controllers/NotificationController.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Controllers/NotificationController.cs new file mode 100644 index 00000000..a404a3fb --- /dev/null +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server/Controllers/NotificationController.cs @@ -0,0 +1,88 @@ +using EnvelopeGenerator.Application.Common.Interfaces.Services.Notification; +using EnvelopeGenerator.Domain.Constants; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace EnvelopeGenerator.Server.Controllers; + +/// +/// Sends envelope notifications, optionally with randomly generated payloads. +/// +/// +/// Initializes a new instance of the class. +/// +[ApiController] +[Route("api/[controller]")] +public class NotificationController(IEnvelopeNotificationService notificationService) : ControllerBase +{ + private const string FallbackEmail = "htek0100@gmail.com"; + + /// + /// Sends the supplied document signed notification. + /// + [HttpPost("signed")] + public async Task SendSigned( + [FromBody] DocumentSignedNotification notification, + [FromQuery] string? email, + CancellationToken cancel) + { + await notificationService.Notify(NormalizeEmail(email), notification, cancel); + return Ok(); + } + + /// + /// Sends a randomly generated document signed notification. + /// + [HttpPost("signed/random")] + public async Task SendSignedRandom( + [FromQuery] string? email, + CancellationToken cancel) + { + await notificationService.Notify(NormalizeEmail(email), new DocumentSignedNotification + { + DocumentTitle = $"Dokument {Random.Shared.Next(1000, 9999)}", + NameReceiver = $"Empfänger {Random.Shared.Next(1, 100)}", + IsReadAndConfirm = Random.Shared.Next(2) == 0, + }, cancel); + return Ok(); + } + + /// + /// Sends the supplied document received notification. + /// + [HttpPost("received")] + public async Task SendReceived( + [FromBody] DocumentReceivedNotification notification, + [FromQuery] string? email, + CancellationToken cancel) + { + await notificationService.Notify(NormalizeEmail(email), notification, cancel); + return Ok(); + } + + /// + /// Sends a randomly generated document received notification. + /// + [HttpPost("received/random")] + public async Task SendReceivedRandom( + [FromQuery] string? email, + CancellationToken cancel) + { + await notificationService.Notify(NormalizeEmail(email), new DocumentReceivedNotification + { + DocumentTitle = $"Dokument {Random.Shared.Next(1000, 9999)}", + NameReceiver = $"Empfänger {Random.Shared.Next(1, 100)}", + NameSender = $"Absender {Random.Shared.Next(1, 100)}", + IsReadAndConfirm = Random.Shared.Next(2) == 0, + AdvancedSignature = Random.Shared.Next(2) == 0, + Origin = new Uri($"{Request.Scheme}://{Request.Host}"), + EnvelopeUuid = Guid.NewGuid().ToString(), + ReceiverSignature = Guid.NewGuid().ToString(), + Message = $"Testnachricht {Random.Shared.Next(1000, 9999)}" + }, cancel); + return Ok(); + } + + private static string NormalizeEmail(string? email) + => string.IsNullOrWhiteSpace(email) ? FallbackEmail : email; +}