U1 mail-foundation (backend): verzender, opties, sjabloon, SiteSettings met toegestane afzenderlijst
IEmailSender met MailKit-implementatie (StartTls, timeout, fouten als waarde), opties met startvalidatie, nl/en sjabloon, taalkeuze, tabel SiteSettings (additieve migratie), SiteSettings-API (Beheerder leest, Eigenaar wijzigt) en emailEnabled/defaultLanguage in de capabilities. Zonder SMTP-host verandert er niets. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System.Reflection;
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NSubstitute;
|
||||
using SlpModularCms.Core.SiteSettings;
|
||||
using SlpModularCms.Modules.Identity.Controllers;
|
||||
|
||||
namespace SlpModularCms.Modules.Identity.Tests.Controllers;
|
||||
|
||||
public class SiteSettingsControllerTests
|
||||
{
|
||||
private readonly ISiteSettingsService _settings = Substitute.For<ISiteSettingsService>();
|
||||
|
||||
private SiteSettingsController Controller() => new(_settings)
|
||||
{
|
||||
ControllerContext = new ControllerContext { HttpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext() }
|
||||
};
|
||||
|
||||
private static string PolicyOf(string method) =>
|
||||
typeof(SiteSettingsController).GetMethod(method)!.GetCustomAttribute<AuthorizeAttribute>()!.Policy!;
|
||||
|
||||
[Fact]
|
||||
public void AnAdministratorReads_OnlyAnOwnerChanges()
|
||||
{
|
||||
PolicyOf(nameof(SiteSettingsController.GetMail)).Should().Be("AdminOnly");
|
||||
PolicyOf(nameof(SiteSettingsController.SetMail)).Should().Be("OwnerOnly");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Set_ReturnsTheNewView_OnSuccess()
|
||||
{
|
||||
var view = new MailSettingsView(true, "a@b.nl", "N", "d@b.nl", "D", ["a@b.nl"], true);
|
||||
_settings.SetMailAsync("a@b.nl", "N", Arg.Any<string?>(), Arg.Any<CancellationToken>()).Returns(SetMailResult.Success);
|
||||
_settings.GetMailAsync(Arg.Any<CancellationToken>()).Returns(view);
|
||||
|
||||
var result = await Controller().SetMail(new UpdateMailSettingsRequest("a@b.nl", "N"), default);
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.Value.Should().Be(view);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(SetMailResult.InvalidAddress, 400)]
|
||||
[InlineData(SetMailResult.AddressNotAllowed, 400)]
|
||||
[InlineData(SetMailResult.InvalidName, 400)]
|
||||
[InlineData(SetMailResult.MailDisabled, 409)]
|
||||
public async Task Set_MapsFailuresToStatusCodes(string error, int status)
|
||||
{
|
||||
_settings.SetMailAsync(Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(SetMailResult.Fail(error));
|
||||
|
||||
var result = await Controller().SetMail(new UpdateMailSettingsRequest("x", "y"), default);
|
||||
|
||||
result.Should().BeAssignableTo<ObjectResult>().Which.StatusCode.Should().Be(status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user