Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Omika.Diagnostics.Models;
|
||||
using Omika.Diagnostics.Tests.Fakes;
|
||||
using Omika.Diagnostics.Web.Pages;
|
||||
|
||||
namespace Omika.Diagnostics.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// T24-A — handlers serveur du prompt IA (OnGetPromptAsync) : vérifie que le clic renvoie
|
||||
/// bien le texte du prompt (text/plain), et 404 pour un id inconnu. Ne teste pas la
|
||||
/// génération (déjà couverte par DiagnosticPromptBuilderTests) mais le contrat HTTP.
|
||||
/// </summary>
|
||||
public class DiagnosticPromptHandlerTests
|
||||
{
|
||||
private static DiagnosticEventRecord Ev(long id, string eventCode = "ERR") => new()
|
||||
{
|
||||
Id = id,
|
||||
EventId = Guid.NewGuid(),
|
||||
EventCode = eventCode,
|
||||
TimestampUtc = new DateTimeOffset(2025, 1, 1, 12, 0, 0, TimeSpan.Zero),
|
||||
Level = "Error",
|
||||
Priority = "P2",
|
||||
ExceptionType = "System.InvalidOperationException",
|
||||
Source = DiagnosticSources.Api,
|
||||
IngestedAtUtc = DateTimeOffset.UtcNow
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public async Task DiagnosticsDetail_Prompt_ReturnsTextPrompt()
|
||||
{
|
||||
var repo = new FakeDiagnosticEventRepository();
|
||||
await repo.InsertBatchAsync(new[] { Ev(42) });
|
||||
var model = new DiagnosticsDetailModel(repo);
|
||||
|
||||
IActionResult result = await model.OnGetPromptAsync(42);
|
||||
|
||||
ContentResult content = Assert.IsType<ContentResult>(result);
|
||||
Assert.StartsWith("Analyse cette erreur Omika", content.Content, StringComparison.Ordinal);
|
||||
Assert.Contains("ERR", content.Content, StringComparison.Ordinal);
|
||||
Assert.Equal("text/plain; charset=utf-8", content.ContentType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DiagnosticsDetail_Prompt_UnknownId_ReturnsNotFound()
|
||||
{
|
||||
var repo = new FakeDiagnosticEventRepository();
|
||||
var model = new DiagnosticsDetailModel(repo);
|
||||
|
||||
IActionResult result = await model.OnGetPromptAsync(999);
|
||||
|
||||
Assert.IsType<NotFoundResult>(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user