Ingestion et indexation
- IIngestionService/IngestionService : chargement des collections filles par
sous-type, un jeu de morceaux par langue, ChunkIndex continu.
- SectionIndexingInterceptor retenu comme unique déclencheur : les 5
sous-contrôleurs totalisaient 30 SaveChanges et 0 Enqueue, donc ajouter des
points d'intérêt à une carte ne réindexait rien.
- HTML retiré avant l'embedding et lignes trop longues recoupées : sans cela un
article dépassait l'entrée max du modèle et emportait son lot de 50 morceaux.
- Gabarits de LanguageInit filtrés, DistinctBy(Text) avant le Take : ils
occupaient les cinq premiers résultats d'une recherche en néerlandais.
Endpoints du guide IA
- GET /api/Ai/knowledge/{id} : agrégats sur ContentEmbedding, donc sur ce qui
est réellement indexé — compter les sections publiées serait plus flatteur et faux.
- GET /api/Ai/insights/{id} : miroir de GuideIaInsights côté manager-app, c'est
l'écran qui a fixé la forme pour que le job de thèmes la remplisse.
RGPD
- VisitorQuestion journalisée dans AiController.Chat. HasAnswer se déduit des
sources du retrieval, pas du texte : un repli poli ressemble à une réponse.
L'écriture n'échoue jamais la réponse au visiteur.
- VisitorQuestionPurgeService, 90 jours, actif sans condition de configuration :
une durée écrite dans les CGU n'est pas un réglage commercial.
Corrections
- Updateinstance ne recopiait pas les quotas du nouveau plan.
- CheckQuota ne bloquait ni ne comptait à quota 0 — IA gratuite non comptée.
- StoragePath et SizeBytes renseignés à Create, types URL exclus.
dotnet build 0 erreur, dotnet test 130/130.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
126 lines
4.6 KiB
C#
126 lines
4.6 KiB
C#
using Manager.Services;
|
|
using ManagerService.Controllers;
|
|
using ManagerService.Data;
|
|
using ManagerService.DTOs;
|
|
using ManagerService.Services;
|
|
using ManagerService.Tests.Infrastructure;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Xunit;
|
|
|
|
namespace ManagerService.Tests.Controllers
|
|
{
|
|
public class SectionControllerTests
|
|
{
|
|
private static IConfiguration BuildConfig() =>
|
|
new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ConnectionStrings:TabletDb"] = "mongodb://localhost:27017",
|
|
["SupportedLanguages:0"] = "FR",
|
|
["SupportedLanguages:1"] = "EN"
|
|
})
|
|
.Build();
|
|
|
|
private static SectionController BuildController(MyInfoMateDbContext db)
|
|
{
|
|
var cfg = FakeMongoConfig.Create();
|
|
var controller = new SectionController(
|
|
BuildConfig(),
|
|
NullLogger<SectionController>.Instance,
|
|
new SectionDatabaseService(cfg),
|
|
new ConfigurationDatabaseService(cfg),
|
|
db);
|
|
FakeUser.SetUser(controller, FakeUser.Create("Manager.contenteditor", "inst-test"));
|
|
return controller;
|
|
}
|
|
|
|
// ── GET ──────────────────────────────────────────────────────────────
|
|
|
|
[Fact]
|
|
public void Get_FiltersToInstance()
|
|
{
|
|
using var db = DbContextFactory.Create();
|
|
db.Sections.AddRange(
|
|
TestSection.Article("s1", "inst-test", "A", "c1"),
|
|
TestSection.Article("s2", "other-inst", "B", "c2")
|
|
);
|
|
db.SaveChanges();
|
|
|
|
var result = BuildController(db).Get("inst-test");
|
|
|
|
var ok = Assert.IsType<OkObjectResult>(result);
|
|
var sections = (ok.Value as System.Collections.IEnumerable)!.Cast<object>().ToList();
|
|
Assert.Single(sections);
|
|
}
|
|
|
|
// ── CREATE ───────────────────────────────────────────────────────────
|
|
|
|
[Fact]
|
|
public void Create_ValidDto_Persists()
|
|
{
|
|
using var db = DbContextFactory.Create();
|
|
db.Configurations.Add(new Configuration { Id = "c1", InstanceId = "inst-test", Label = "Conf", Title = new List<TranslationDTO>() });
|
|
db.SaveChanges();
|
|
|
|
var result = BuildController(db).Create(new SectionDTO
|
|
{
|
|
instanceId = "inst-test",
|
|
configurationId = "c1",
|
|
label = "Section 1",
|
|
type = SectionType.Video
|
|
});
|
|
|
|
Assert.IsType<OkObjectResult>(result);
|
|
Assert.Equal(1, db.Sections.Count());
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_UnknownConfiguration_ReturnsError()
|
|
{
|
|
using var db = DbContextFactory.Create();
|
|
|
|
// KeyNotFoundException → caught by catch(Exception) → 500
|
|
var result = BuildController(db).Create(new SectionDTO
|
|
{
|
|
instanceId = "inst-test",
|
|
configurationId = "nonexistent",
|
|
label = "Section 1",
|
|
type = SectionType.Video
|
|
});
|
|
|
|
var obj = Assert.IsType<ObjectResult>(result);
|
|
Assert.Equal(500, obj.StatusCode);
|
|
}
|
|
|
|
// ── DELETE ───────────────────────────────────────────────────────────
|
|
|
|
[Fact]
|
|
public void Delete_ExistingSection_Returns202()
|
|
{
|
|
using var db = DbContextFactory.Create();
|
|
db.Sections.Add(TestSection.Article("s1", "inst-test", "A", "c1"));
|
|
db.SaveChanges();
|
|
|
|
var result = BuildController(db).Delete("s1");
|
|
|
|
var obj = Assert.IsType<ObjectResult>(result);
|
|
Assert.Equal(202, obj.StatusCode);
|
|
Assert.Equal(0, db.Sections.Count());
|
|
}
|
|
|
|
[Fact]
|
|
public void Delete_UnknownSection_Returns404()
|
|
{
|
|
using var db = DbContextFactory.Create();
|
|
|
|
var result = BuildController(db).Delete("unknown");
|
|
|
|
Assert.IsType<NotFoundObjectResult>(result);
|
|
}
|
|
}
|
|
}
|