2026-08-12 10:46:09 +02:00
|
|
|
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"),
|
2026-08-12 11:12:28 +02:00
|
|
|
Setting("log.retentiondays", "7"),
|
2026-08-12 10:46:09 +02:00
|
|
|
Setting("heartbeat.interval.seconds", "30"),
|
2026-08-12 12:18:52 +02:00
|
|
|
Setting("sentry.enabled", "true"),
|
2026-08-12 10:46:09 +02:00
|
|
|
});
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
var cut = Render<AgentDefaultsSection>();
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
{
|
2026-10-25 06:17:43 +01:00
|
|
|
cut.Markup.ShouldContain("Niveau de journalisation global");
|
|
|
|
|
cut.Markup.ShouldContain("Rétention des journaux des agents");
|
2026-10-25 06:35:00 +01:00
|
|
|
cut.Markup.ShouldContain("Intervalle du heartbeat");
|
2026-10-25 06:19:40 +01:00
|
|
|
cut.Markup.ShouldContain("Envoyer les erreurs à GlitchTip");
|
2026-08-12 10:46:09 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AgentDefaults_ModifieRetention_AppellePutAvecBonneCle()
|
|
|
|
|
{
|
2026-08-12 11:12:28 +02:00
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("log.retentiondays", "7") });
|
|
|
|
|
Handler.On(HttpMethod.Put, "api/settings/log.retentiondays", System.Net.HttpStatusCode.OK);
|
2026-08-12 10:46:09 +02:00
|
|
|
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 &&
|
2026-08-12 11:12:28 +02:00
|
|
|
r.RequestUri!.AbsolutePath.Contains("log.retentiondays", StringComparison.OrdinalIgnoreCase));
|
2026-08-12 10:46:09 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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));
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-08-12 12:18:52 +02:00
|
|
|
|
|
|
|
|
[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>();
|
2026-10-25 06:19:40 +01:00
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Envoyer les erreurs à GlitchTip"));
|
2026-08-12 12:18:52 +02:00
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-08-12 10:46:09 +02:00
|
|
|
}
|