Files
novelly/tests/Novelly.Api.Tests/ListingTests.cs
T
James Wampler c620ddd626 Replace chapter setting with multi-select locations; add chapter character summary
Chapters now carry many Locations (new Tags-style entity with cross-referencing)
instead of a single free-text Setting field, with a Locations tab on the novel
for browsing them and seeing every chapter set at each one. Also surfaces the
distinct characters appearing in a chapter's beats, linked, under the beat/word
count on the outline tab.
2026-08-18 11:36:13 -07:00

119 lines
4.7 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.Novels;
namespace Novelly.Api.Tests;
[TestFixture]
public class ListingTests : ServiceTestFixture
{
[Test]
public async Task Novels_are_listed_most_recently_updated_first()
{
var older = await Novels.CreateAsync(new CreateNovelRequest("Older Book"));
var newer = await Novels.CreateAsync(new CreateNovelRequest("Newer Book"));
await Novels.UpdateAsync(older.Id, new UpdateNovelRequest(Logline: "Revised."));
var listed = await Novels.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 Novel_summaries_aggregate_counts_and_words_across_chapters()
{
var novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
await Characters.CreateAsync(novel.Id, new CreateCharacterRequest("Ines"));
await Characters.CreateAsync(novel.Id, new CreateCharacterRequest("Mara"));
await Chapters.CreateAsync(novel.Id, new CreateChapterRequest("Landfall", Prose: "One two three"));
await Chapters.CreateAsync(novel.Id, new CreateChapterRequest("The Harbour", Prose: "Four five"));
var summary = (await Novels.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_novel_with_no_chapters_reports_zero_words_rather_than_failing()
{
await Novels.CreateAsync(new CreateNovelRequest("Empty"));
var summary = (await Novels.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 novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
var second = await Chapters.CreateAsync(novel.Id, new CreateChapterRequest("Second", Number: 2, Prose: "One two three"));
var first = await Chapters.CreateAsync(novel.Id, new CreateChapterRequest("First", Number: 1));
var listed = await Chapters.ListAsync(novel.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 novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
var agent = new NovelAgentService(
Db.Context,
new ScriptedModelClient([[new AgentTextBlock("Reply.")]]),
new NovelAgentToolset(Novels, Characters, Arcs, Chapters, Beats, Tags, Locations, Questions, NullLogger<NovelAgentToolset>.Instance),
Options.Create(new AgentOptions()),
NullLogger<NovelAgentService>.Instance,
new SendAgentMessageRequestValidator());
await agent.SendMessageAsync(novel.Id, new SendAgentMessageRequest("First question."));
await agent.SendMessageAsync(novel.Id, new SendAgentMessageRequest("Second question."));
var listed = await agent.ListConversationsAsync(novel.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 novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
await Characters.CreateAsync(novel.Id, new CreateCharacterRequest("Zeno", CharacterRole.Supporting));
await Characters.CreateAsync(novel.Id, new CreateCharacterRequest("Ines", CharacterRole.Protagonist));
await Characters.CreateAsync(novel.Id, new CreateCharacterRequest("Anders", CharacterRole.Supporting));
var listed = await Characters.ListAsync(novel.Id);
Assert.That(listed.Select(c => c.Name), Is.EqualTo(new[] { "Ines", "Anders", "Zeno" }));
}
}