Files
novelly/tests/Novelly.Api.Tests/BeatServiceTests.cs
T
James Wampler 23348327a9 Remove Scenes, group beats by multiple characters; strip comments repo-wide
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/.
2026-08-11 21:05:13 -07:00

146 lines
5.7 KiB
C#

using Novelly.Api.Beats;
using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Projects;
namespace Novelly.Api.Tests;
[TestFixture]
public class BeatServiceTests : ServiceTestFixture
{
private Guid _projectId;
private Guid _chapterId;
protected override void OnSetUp()
{
_projectId = Projects.CreateAsync(new CreateProjectRequest("The Salt Road")).Result.Id;
_chapterId = Chapters.CreateAsync(_projectId, new CreateChapterRequest("Landfall")).Result.Id;
}
[Test]
public async Task Beats_are_appended_in_order_and_listed_that_way()
{
await Beats.CreateAsync(_chapterId, new CreateBeatRequest("She finds the map"));
await Beats.CreateAsync(_chapterId, new CreateBeatRequest("The harbour burns"));
await Beats.CreateAsync(_chapterId, new CreateBeatRequest("She boards anyway"));
var listed = await Beats.ListAsync(_chapterId);
Assert.Multiple(() =>
{
Assert.That(
listed.Select(b => b.Title),
Is.EqualTo(new[] { "She finds the map", "The harbour burns", "She boards anyway" }));
Assert.That(listed.Select(b => b.SortOrder), Is.EqualTo(new[] { 1, 2, 3 }));
});
}
[Test]
public async Task Reordering_renumbers_to_match_the_order_given()
{
var first = await Beats.CreateAsync(_chapterId, new CreateBeatRequest("First"));
var second = await Beats.CreateAsync(_chapterId, new CreateBeatRequest("Second"));
var third = await Beats.CreateAsync(_chapterId, new CreateBeatRequest("Third"));
var reordered = await Beats.ReorderAsync(
_chapterId, new ReorderBeatsRequest([third.Id, first.Id, second.Id]));
Assert.That(
reordered.Select(b => b.Title),
Is.EqualTo(new[] { "Third", "First", "Second" }));
}
[Test]
public async Task Beats_left_out_of_a_reorder_keep_their_relative_position_at_the_end()
{
var first = await Beats.CreateAsync(_chapterId, new CreateBeatRequest("First"));
await Beats.CreateAsync(_chapterId, new CreateBeatRequest("Second"));
var third = await Beats.CreateAsync(_chapterId, new CreateBeatRequest("Third"));
var reordered = await Beats.ReorderAsync(_chapterId, new ReorderBeatsRequest([third.Id, first.Id]));
Assert.That(
reordered.Select(b => b.Title),
Is.EqualTo(new[] { "Third", "First", "Second" }));
}
[Test]
public async Task Reordering_with_an_unknown_beat_returns_null_rather_than_throwing()
{
await Beats.CreateAsync(_chapterId, new CreateBeatRequest("First"));
Assert.That(await Beats.ReorderAsync(_chapterId, new ReorderBeatsRequest([Guid.NewGuid()])), Is.Null);
}
[Test]
public async Task A_beat_can_carry_several_characters()
{
var ines = await Characters.CreateAsync(_projectId, new CreateCharacterRequest("Ines"));
var mara = await Characters.CreateAsync(_projectId, new CreateCharacterRequest("Mara"));
var beat = await Beats.CreateAsync(_chapterId, new CreateBeatRequest(
"She burns the atlas",
CharacterIds: [ines.Id, mara.Id],
WhatHappened: "The pages go up faster than she expected.",
WhatsNext: "Nothing to navigate by but memory."));
Assert.Multiple(() =>
{
Assert.That(beat.Characters.Select(c => c.Name), Is.EquivalentTo(new[] { "Ines", "Mara" }));
Assert.That(beat.WhatHappened, Does.Contain("faster than she expected"));
});
}
[Test]
public async Task A_beat_cannot_borrow_a_character_from_another_project()
{
var other = await Projects.CreateAsync(new CreateProjectRequest("Other Book"));
var stranger = await Characters.CreateAsync(other.Id, new CreateCharacterRequest("Stranger"));
Assert.That(
async () => await Beats.CreateAsync(
_chapterId, new CreateBeatRequest("A beat", CharacterIds: [stranger.Id])),
Throws.TypeOf<InvalidOperationException>().With.Message.Contains("same project"));
}
[Test]
public async Task Updating_leaves_omitted_fields_alone_and_clears_on_empty_string()
{
var beat = await Beats.CreateAsync(_chapterId, new CreateBeatRequest(
"She finds the map",
WhatHappened: "Behind the lining of the case.",
WhatsNext: "She books passage."));
var renamed = (await Beats.UpdateAsync(beat.Id, new UpdateBeatRequest(Title: "She finds it")))!;
Assert.Multiple(() =>
{
Assert.That(renamed.WhatHappened, Is.EqualTo("Behind the lining of the case."));
Assert.That(renamed.WhatsNext, Is.EqualTo("She books passage."));
});
var cleared = (await Beats.UpdateAsync(beat.Id, new UpdateBeatRequest(WhatsNext: "")))!;
Assert.Multiple(() =>
{
Assert.That(cleared.WhatsNext, Is.Null);
Assert.That(cleared.WhatHappened, Is.EqualTo("Behind the lining of the case."));
});
}
[Test]
public async Task An_empty_CharacterIds_list_clears_a_beats_characters_since_null_means_leave_it_alone()
{
var ines = await Characters.CreateAsync(_projectId, new CreateCharacterRequest("Ines"));
var beat = await Beats.CreateAsync(_chapterId, new CreateBeatRequest(
"She burns the atlas", CharacterIds: [ines.Id]));
var untouched = (await Beats.UpdateAsync(beat.Id, new UpdateBeatRequest(Title: "She burns it")))!;
Assert.That(untouched.Characters.Select(c => c.Name), Is.EqualTo(new[] { "Ines" }));
var cleared = (await Beats.UpdateAsync(beat.Id, new UpdateBeatRequest(CharacterIds: [])))!;
Assert.That(cleared.Characters, Is.Empty);
}
}