#105 — Topic ntfy cible par site : - Site.NtfyTopic (migration AddSiteNtfyTopic), UI création/édition SitesPage - NotificationService.ResolveNtfyTopicAsync : topic du site sinon heimdall_{userId} #106 — Paramètres SMTP/ntfy/S3 GLOBAUX : - Seed + sections UI : agentScoped=false pour ntfy.*/email.*/storage.*/sentry.* - Migration douce au démarrage : UPDATE des clés existantes en base #107 — GlitchTip : DSN fixes (central projet 6, agent projet 7) dans appsettings, - plus de champ DSN éditable en UI → switch sentry.enabled (nécessite redémarrage) - Init Sentry déplacé après AddInfrastructure, lit sentry.enabled en base (fallback true) #108 — Composants typés : MudNumericField borné (port SMTP, rétention, heartbeat), - switch pour booléens, select pour log.level — pas de saisie libre
102 lines
3.7 KiB
C#
102 lines
3.7 KiB
C#
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 AgentDefaultsSectionTests : PageTestBase
|
|
{
|
|
private static AppSettingItem Setting(string key, string value) =>
|
|
new(Guid.NewGuid(), key, value, key, "agent", "string", null, DateTime.UtcNow.AddDays(-1));
|
|
|
|
[Fact]
|
|
public void AgentDefaults_AfficheChampsLogsHeartbeatEtDiagnostic()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>
|
|
{
|
|
Setting("log.level", "info"),
|
|
Setting("log.retentiondays", "7"),
|
|
Setting("heartbeat.interval.seconds", "30"),
|
|
Setting("sentry.enabled", "true"),
|
|
});
|
|
LoginAs();
|
|
|
|
var cut = Render<AgentDefaultsSection>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Niveau de log global");
|
|
cut.Markup.ShouldContain("Rétention des logs agents");
|
|
cut.Markup.ShouldContain("Intervalle de heartbeat");
|
|
cut.Markup.ShouldContain("Envoyer les erreurs vers GlitchTip");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void AgentDefaults_ModifieRetention_AppellePutAvecBonneCle()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("log.retentiondays", "7") });
|
|
Handler.On(HttpMethod.Put, "api/settings/log.retentiondays", System.Net.HttpStatusCode.OK);
|
|
LoginAs();
|
|
|
|
var cut = Render<AgentDefaultsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("7"));
|
|
|
|
// Inputs : [0]=select log.level (readonly), [1]=rétention
|
|
cut.FindAll("input")[1].Change("14");
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Put &&
|
|
r.RequestUri!.AbsolutePath.Contains("log.retentiondays", StringComparison.OrdinalIgnoreCase));
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void AgentDefaults_ModifieHeartbeat_AppellePutAvecBonneCle()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("heartbeat.interval.seconds", "30") });
|
|
Handler.On(HttpMethod.Put, "api/settings/heartbeat.interval.seconds", System.Net.HttpStatusCode.OK);
|
|
LoginAs();
|
|
|
|
var cut = Render<AgentDefaultsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("30"));
|
|
|
|
cut.FindAll("input")[2].Change("45");
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Put &&
|
|
r.RequestUri!.AbsolutePath.Contains("heartbeat.interval.seconds", StringComparison.OrdinalIgnoreCase));
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void AgentDefaults_ToggleSentry_AppellePutAvecBonneCle()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("sentry.enabled", "false") });
|
|
Handler.On(HttpMethod.Put, "api/settings/sentry.enabled", System.Net.HttpStatusCode.OK);
|
|
LoginAs();
|
|
|
|
var cut = Render<AgentDefaultsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Envoyer les erreurs vers GlitchTip"));
|
|
|
|
// Le switch sentry.enabled est le seul input[type=checkbox] de la section
|
|
// (MudSwitch déclenche onchange, pas onclick)
|
|
cut.FindAll("input[type=checkbox]")[0].Change(true);
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Put &&
|
|
r.RequestUri!.AbsolutePath.Contains("sentry.enabled", StringComparison.OrdinalIgnoreCase));
|
|
});
|
|
}
|
|
}
|