Drop the Scene entity/grouping in favor of chapters carrying prose directly and beats belonging to many characters. Add markdown editor + character multi-select components to the web client. Remove all XML doc and inline comments across the touched C#/TS/CSS files in favor of self-documenting names, and record that convention in CLAUDE.md. Add .mcp.json (local MCP server config, no secrets) and ignore .idea/.
119 lines
4.8 KiB
C#
119 lines
4.8 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Options;
|
|
using Novelly.Api.Agent;
|
|
using Novelly.Api.Chapters;
|
|
using Novelly.Api.Characters;
|
|
using Novelly.Api.Projects;
|
|
|
|
namespace Novelly.Api.Tests;
|
|
|
|
[TestFixture]
|
|
public class ListingTests : ServiceTestFixture
|
|
{
|
|
[Test]
|
|
public async Task Projects_are_listed_most_recently_updated_first()
|
|
{
|
|
var older = await Projects.CreateAsync(new CreateProjectRequest("Older Book"));
|
|
var newer = await Projects.CreateAsync(new CreateProjectRequest("Newer Book"));
|
|
|
|
await Projects.UpdateAsync(older.Id, new UpdateProjectRequest(Logline: "Revised."));
|
|
|
|
var listed = await Projects.ListAsync();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(listed.Select(p => p.Title), Is.EqualTo(new[] { "Older Book", "Newer Book" }));
|
|
Assert.That(listed.Select(p => p.Id), Does.Contain(newer.Id));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Project_summaries_aggregate_counts_and_words_across_chapters()
|
|
{
|
|
var project = await Projects.CreateAsync(new CreateProjectRequest("The Salt Road"));
|
|
await Characters.CreateAsync(project.Id, new CreateCharacterRequest("Ines"));
|
|
await Characters.CreateAsync(project.Id, new CreateCharacterRequest("Mara"));
|
|
|
|
await Chapters.CreateAsync(project.Id, new CreateChapterRequest("Landfall", Prose: "One two three"));
|
|
await Chapters.CreateAsync(project.Id, new CreateChapterRequest("The Harbour", Prose: "Four five"));
|
|
|
|
var summary = (await Projects.ListAsync()).Single();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(summary.CharacterCount, Is.EqualTo(2));
|
|
Assert.That(summary.ChapterCount, Is.EqualTo(2));
|
|
Assert.That(summary.WordCount, Is.EqualTo(5));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task A_project_with_no_chapters_reports_zero_words_rather_than_failing()
|
|
{
|
|
await Projects.CreateAsync(new CreateProjectRequest("Empty"));
|
|
|
|
var summary = (await Projects.ListAsync()).Single();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(summary.WordCount, Is.EqualTo(0));
|
|
Assert.That(summary.ChapterCount, Is.EqualTo(0));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Chapters_are_listed_in_manuscript_order_with_word_counts()
|
|
{
|
|
var project = await Projects.CreateAsync(new CreateProjectRequest("The Salt Road"));
|
|
var second = await Chapters.CreateAsync(project.Id, new CreateChapterRequest("Second", Number: 2, Prose: "One two three"));
|
|
var first = await Chapters.CreateAsync(project.Id, new CreateChapterRequest("First", Number: 1));
|
|
|
|
var listed = await Chapters.ListAsync(project.Id);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(listed.Select(c => c.Title), Is.EqualTo(new[] { "First", "Second" }));
|
|
Assert.That(listed.Single(c => c.Id == second.Id).WordCount, Is.EqualTo(3));
|
|
Assert.That(listed.Single(c => c.Id == first.Id).WordCount, Is.EqualTo(0));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Conversations_are_listed_most_recently_updated_first()
|
|
{
|
|
var project = await Projects.CreateAsync(new CreateProjectRequest("The Salt Road"));
|
|
var agent = new NovelAgentService(
|
|
Db.Context,
|
|
new ScriptedModelClient([[new AgentTextBlock("Reply.")]]),
|
|
new NovelAgentToolset(Projects, Characters, Arcs, Chapters, Beats, Tags, Questions, NullLogger<NovelAgentToolset>.Instance),
|
|
Options.Create(new AgentOptions()),
|
|
NullLogger<NovelAgentService>.Instance,
|
|
new SendAgentMessageRequestValidator());
|
|
|
|
await agent.SendMessageAsync(project.Id, new SendAgentMessageRequest("First question."));
|
|
await agent.SendMessageAsync(project.Id, new SendAgentMessageRequest("Second question."));
|
|
|
|
var listed = await agent.ListConversationsAsync(project.Id);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(listed, Has.Count.EqualTo(2));
|
|
Assert.That(listed[0].Title, Is.EqualTo("Second question."));
|
|
Assert.That(listed[0].MessageCount, Is.EqualTo(2));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Characters_are_listed_by_role_then_name()
|
|
{
|
|
var project = await Projects.CreateAsync(new CreateProjectRequest("The Salt Road"));
|
|
await Characters.CreateAsync(project.Id, new CreateCharacterRequest("Zeno", CharacterRole.Supporting));
|
|
await Characters.CreateAsync(project.Id, new CreateCharacterRequest("Ines", CharacterRole.Protagonist));
|
|
await Characters.CreateAsync(project.Id, new CreateCharacterRequest("Anders", CharacterRole.Supporting));
|
|
|
|
var listed = await Characters.ListAsync(project.Id);
|
|
|
|
Assert.That(listed.Select(c => c.Name), Is.EqualTo(new[] { "Ines", "Anders", "Zeno" }));
|
|
}
|
|
}
|