79 lines
2.8 KiB
C#
79 lines
2.8 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.dsn", "***REDACTED***"),
|
||
|
|
});
|
||
|
|
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("DSN Sentry / 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));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|