Use Ollama rewrite path for CV generation
This commit is contained in:
@@ -11,7 +11,7 @@ namespace JobTrackerApi.Tests;
|
||||
public sealed class SummarizerServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Summarize_section_clamps_lengths_to_ai_service_limits()
|
||||
public async Task Summarize_section_uses_cv_rewrite_endpoint()
|
||||
{
|
||||
var handler = new CapturingHandler();
|
||||
var httpClient = new HttpClient(handler)
|
||||
@@ -27,7 +27,31 @@ public sealed class SummarizerServiceTests
|
||||
|
||||
var result = await service.SummarizeSectionAsync("Rewrite this CV", "Professional Summary\nBuilt backend systems.", 1800, 400);
|
||||
|
||||
Assert.Equal("ok", result);
|
||||
Assert.Equal("rewritten cv", result);
|
||||
Assert.Equal("/cv/rewrite", handler.LastPath);
|
||||
Assert.NotNull(handler.LastBody);
|
||||
Assert.Contains("\"instruction\":\"Rewrite this CV\"", handler.LastBody);
|
||||
Assert.Contains("\"max_length\":256", handler.LastBody);
|
||||
Assert.Contains("\"min_length\":180", handler.LastBody);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Summarize_section_clamps_lengths_to_ai_service_limits()
|
||||
{
|
||||
var handler = new CapturingHandler();
|
||||
var httpClient = new HttpClient(handler)
|
||||
{
|
||||
BaseAddress = new Uri("http://localhost:8001")
|
||||
};
|
||||
|
||||
var httpFactory = new Mock<IHttpClientFactory>();
|
||||
httpFactory.Setup(x => x.CreateClient("ai-service")).Returns(httpClient);
|
||||
|
||||
using var memoryCache = new MemoryCache(new MemoryCacheOptions());
|
||||
var service = new SummarizerService(httpFactory.Object, memoryCache);
|
||||
|
||||
await service.SummarizeSectionAsync("Rewrite this CV", "Professional Summary\nBuilt backend systems.", 1800, 400);
|
||||
|
||||
Assert.NotNull(handler.LastBody);
|
||||
Assert.Contains("\"max_length\":256", handler.LastBody);
|
||||
Assert.Contains("\"min_length\":180", handler.LastBody);
|
||||
@@ -36,13 +60,18 @@ public sealed class SummarizerServiceTests
|
||||
private sealed class CapturingHandler : HttpMessageHandler
|
||||
{
|
||||
public string? LastBody { get; private set; }
|
||||
public string? LastPath { get; private set; }
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
LastPath = request.RequestUri?.AbsolutePath;
|
||||
LastBody = request.Content is null ? null : await request.Content.ReadAsStringAsync(cancellationToken);
|
||||
var responseBody = LastPath == "/cv/rewrite"
|
||||
? "{\"rewritten_text\":\"rewritten cv\"}"
|
||||
: "{\"summary\":\"ok\"}";
|
||||
return new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent("{\"summary\":\"ok\"}", Encoding.UTF8, "application/json")
|
||||
Content = new StringContent(responseBody, Encoding.UTF8, "application/json")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user