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.
This commit is contained in:
2026-11-05 12:03:40 +01:00
parent 85104511fd
commit ee7d01ed7f

View File

@@ -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;
/// <summary>
/// Sends envelope notifications, optionally with randomly generated payloads.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="NotificationController"/> class.
/// </remarks>
[ApiController]
[Route("api/[controller]")]
public class NotificationController(IEnvelopeNotificationService notificationService) : ControllerBase
{
private const string FallbackEmail = "htek0100@gmail.com";
/// <summary>
/// Sends the supplied document signed notification.
/// </summary>
[HttpPost("signed")]
public async Task<IActionResult> SendSigned(
[FromBody] DocumentSignedNotification notification,
[FromQuery] string? email,
CancellationToken cancel)
{
await notificationService.Notify(NormalizeEmail(email), notification, cancel);
return Ok();
}
/// <summary>
/// Sends a randomly generated document signed notification.
/// </summary>
[HttpPost("signed/random")]
public async Task<IActionResult> 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();
}
/// <summary>
/// Sends the supplied document received notification.
/// </summary>
[HttpPost("received")]
public async Task<IActionResult> SendReceived(
[FromBody] DocumentReceivedNotification notification,
[FromQuery] string? email,
CancellationToken cancel)
{
await notificationService.Notify(NormalizeEmail(email), notification, cancel);
return Ok();
}
/// <summary>
/// Sends a randomly generated document received notification.
/// </summary>
[HttpPost("received/random")]
public async Task<IActionResult> 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;
}