- Endpoints POST api/settings/{email,ntfy,ai}/test (Admin) :
- email : envoi réel via EmailService vers l'expéditeur configuré
- ntfy : SendTestAsync (nouvelle méthode INtfyService, retour HTTP 2xx)
- ai : ping CodeProject.AI/Ollama via AiHealthCheck
- Client API : TestEmailAsync/TestNtfyAsync/TestAiAsync + record TestActionResult
- UI : boutons Tester dans NotificationSettingsSection (ntfy + email) et
AiSettingsSection (moteurs IA) avec résultat inline
- AgentDetail : la clé brute n'est plus affichée (libellé global/surchargé)
- Tests bUnit : 3 nouveaux (POST par endpoint + affichage résultat) — 224 verts
81 lines
2.9 KiB
C#
81 lines
2.9 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 AiSettingsSectionTests : PageTestBase
|
|
{
|
|
private static AppSettingItem Setting(string key, string value) =>
|
|
new(Guid.NewGuid(), key, value, key, "ai", "string", null, DateTime.UtcNow.AddDays(-1));
|
|
|
|
[Fact]
|
|
public void AiSection_AfficheChampsIA()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>
|
|
{
|
|
Setting("ai.cpaiurl", "http://cpai:32168"),
|
|
Setting("ai.ollamaUrl", "http://ollama:11434"),
|
|
Setting("ai.detection.enabled", "true"),
|
|
});
|
|
LoginAs();
|
|
|
|
var cut = Render<AiSettingsSection>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("URL CodeProject.AI");
|
|
cut.Markup.ShouldContain("URL Ollama");
|
|
cut.Markup.ShouldContain("http://cpai:32168");
|
|
cut.Markup.ShouldContain("http://ollama:11434");
|
|
cut.Markup.ShouldContain("Détection IA activée");
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void AiSection_ModifieCpaiUrl_AppellePutAvecBonneCle()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ai.cpaiurl", "http://cpai:32168") });
|
|
Handler.On(HttpMethod.Put, "api/settings/ai.cpaiurl", System.Net.HttpStatusCode.OK);
|
|
LoginAs();
|
|
|
|
var cut = Render<AiSettingsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("http://cpai:32168"));
|
|
|
|
cut.FindAll("input")[0].Change("http://cpai:32169");
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Put &&
|
|
r.RequestUri!.AbsolutePath.Contains("ai.cpaiurl", StringComparison.OrdinalIgnoreCase));
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void AiSection_TestMoteurs_AppelleEndpointEtAfficheStatut()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ai.cpaiurl", "http://cpai:32168") });
|
|
Handler.On(HttpMethod.Post, "api/settings/ai/test",
|
|
new { success = true, status = "Healthy", message = "CodeProject.AI reachable" });
|
|
LoginAs();
|
|
|
|
var cut = Render<AiSettingsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester les moteurs IA"));
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester les moteurs IA")).Click();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Post &&
|
|
r.RequestUri!.AbsolutePath.Contains("ai/test", StringComparison.OrdinalIgnoreCase));
|
|
cut.Markup.ShouldContain("CodeProject.AI reachable");
|
|
});
|
|
}
|
|
}
|