Files
Heimdall/tests/Heimdall.Web.Tests/Components/Settings/NotificationSettingsSectionTests.cs
T
Arnaud Dartois db49a07440
Heimdall Gitea / Build and tests (pull_request) Failing after 7m50s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
test(i18n): align SMTP label assertion
2026-10-25 06:41:02 +01:00

130 lines
4.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Bunit;
using Heimdall.Web.Components.Settings;
using Heimdall.Web.Services;
using Heimdall.Web.Tests.Components.Pages;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor;
using Shouldly;
namespace Heimdall.Web.Tests.Components.Settings;
public class NotificationSettingsSectionTests : PageTestBase
{
private static AppSettingItem Setting(string key, string value) =>
new(Guid.NewGuid(), key, value, key, "integrations", "string", null, DateTime.UtcNow.AddDays(-1));
[Fact]
public void NotificationSection_AfficheChampsNtfyEtEmail()
{
Handler.OnGet("api/settings", new List<AppSettingItem>
{
Setting("ntfy.baseurl", "https://ntfy.sh"),
Setting("ntfy.token", "tok123"),
Setting("email.fromaddress", "alertes@heimdall.local"),
Setting("email.smtphost", "smtp.gmail.com"),
Setting("email.usessl", "true"),
});
LoginAs();
var cut = Render<NotificationSettingsSection>();
cut.WaitForAssertion(() =>
{
cut.Markup.ShouldContain("Serveur ntfy");
cut.Markup.ShouldContain("Jeton d’accès");
cut.Markup.ShouldContain("Adresse d’expédition");
cut.Markup.ShouldContain("Serveur SMTP");
cut.Markup.ShouldContain("https://ntfy.sh");
cut.Markup.ShouldContain("smtp.gmail.com");
cut.Markup.ShouldContain("Utiliser SSL/TLS");
});
}
[Fact]
public async Task NotificationSection_ModifieBaseUrl_AppellePutAvecBonneCle()
{
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ntfy.baseurl", "https://ntfy.sh") });
Handler.On(HttpMethod.Put, "api/settings/ntfy.baseurl", System.Net.HttpStatusCode.OK);
LoginAs();
var cut = Render<NotificationSettingsSection>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("https://ntfy.sh"));
// Inputs texte : [0]=ntfy.baseurl (les 8 champs texte viennent avant le switch)
cut.FindAll("input")[0].Change("https://ntfy.tordais.cc");
cut.WaitForAssertion(() =>
{
Handler.Requests.ShouldContain(r =>
r.Method == HttpMethod.Put &&
r.RequestUri!.AbsolutePath.Contains("ntfy.baseurl", StringComparison.OrdinalIgnoreCase));
});
}
[Fact]
public void NotificationSection_SecretRedacte_ChampVideAvecPlaceholder()
{
Handler.OnGet("api/settings", new List<AppSettingItem>
{
Setting("ntfy.baseurl", "https://ntfy.sh"),
Setting("ntfy.token", "***REDACTED***"),
Setting("email.password", "***REDACTED***"),
});
LoginAs();
var cut = Render<NotificationSettingsSection>();
cut.WaitForAssertion(() =>
{
// Le champ token ne doit PAS exposer la valeur redactée
cut.FindAll("input")[1].GetAttribute("value").ShouldBe(string.Empty);
// Le champ mot de passe SMTP non plus (7e champ texte)
cut.FindAll("input")[7].GetAttribute("value").ShouldBe(string.Empty);
});
}
[Fact]
public void NotificationSection_TestNtfy_AppelleEndpointEtAfficheSucces()
{
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ntfy.baseurl", "https://ntfy.sh") });
Handler.On(HttpMethod.Post, "api/settings/ntfy/test",
new { success = true, message = "Notification test envoyée sur le topic « heimdall-test »" });
LoginAs();
var cut = Render<NotificationSettingsSection>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester ntfy"));
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester ntfy")).Click();
cut.WaitForAssertion(() =>
{
Handler.Requests.ShouldContain(r =>
r.Method == HttpMethod.Post &&
r.RequestUri!.AbsolutePath.Contains("ntfy/test", StringComparison.OrdinalIgnoreCase));
cut.Markup.ShouldContain("Notification test envoyée");
});
}
[Fact]
public void NotificationSection_TestEmail_AppelleEndpointEtAfficheErreur()
{
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("email.fromaddress", "a@b.c") });
Handler.On(HttpMethod.Post, "api/settings/email/test",
new { success = false, message = "Échec de l'envoi : SMTP injoignable" });
LoginAs();
var cut = Render<NotificationSettingsSection>();
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester l’envoi de courriel"));
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester l’envoi de courriel")).Click();
cut.WaitForAssertion(() =>
{
Handler.Requests.ShouldContain(r =>
r.Method == HttpMethod.Post &&
r.RequestUri!.AbsolutePath.Contains("email/test", StringComparison.OrdinalIgnoreCase));
cut.Markup.ShouldContain("SMTP injoignable");
});
}
}