Files
novelly/tests/Novelly.Api.Tests/LoggingTests.cs
T
James Wampler 4313c8f206 Rename Project concept to Novel across the stack
Renames the domain concept from Project to Novel throughout the backend
(entities, DTOs, services, endpoints, ProjectAccessService/Permission,
ProjectId foreign keys), MCP server (tool names and routes), and the
React/Vite frontend (types, hooks, routes, components). Adds a new EF
Core migration (RenameProjectToNovel) using RenameTable/RenameColumn to
preserve existing data instead of dropping/recreating tables. Updates
CLAUDE.md's structure section to reference Novels/ instead of Projects/.
2026-08-17 23:03:09 -07:00

90 lines
3.2 KiB
C#

using Microsoft.Extensions.Logging;
using Novelly.Api.Beats;
using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Common;
using Novelly.Api.Novels;
namespace Novelly.Api.Tests;
[TestFixture]
public class LoggingTests : ServiceTestFixture
{
[Test]
public async Task Fetching_a_missing_chapter_returns_null_and_logs_a_warning()
{
var missingId = Guid.NewGuid();
var result = await Chapters.GetAsync(missingId);
Assert.Multiple(() =>
{
Assert.That(result, Is.Null);
Assert.That(
ChapterLogs.Entries,
Has.Some.Matches<CapturedLogEntry>(e => e.Level == LogLevel.Warning && e.Message.Contains(missingId.ToString())));
});
}
[Test]
public async Task Creating_a_chapter_logs_the_novel_and_title_at_information()
{
var novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
ChapterLogs.Entries.Clear();
await Chapters.CreateAsync(novel.Id, new CreateChapterRequest("Landfall"));
var info = ChapterLogs.Entries.Single(e => e.Level == LogLevel.Information);
Assert.Multiple(() =>
{
Assert.That(info.Message, Does.Contain("Landfall"));
Assert.That(info.Message, Does.Contain(novel.Id.ToString()));
});
}
[Test]
public async Task Logged_values_never_include_a_chapter_summary_body()
{
var novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
const string secretSummary = "A very specific plot twist nobody should see in a log line.";
ChapterLogs.Entries.Clear();
await Chapters.CreateAsync(novel.Id, new CreateChapterRequest("Landfall", Summary: secretSummary));
Assert.That(ChapterLogs.Entries.Select(e => e.Message), Has.None.Contain(secretSummary));
}
[Test]
public async Task Deleting_a_novel_logs_information_before_the_lookup()
{
var novel = await Novels.CreateAsync(new CreateNovelRequest("The Salt Road"));
NovelLogs.Entries.Clear();
await Novels.DeleteAsync(novel.Id);
Assert.That(
NovelLogs.Entries,
Has.Some.Matches<CapturedLogEntry>(e => e.Level == LogLevel.Information && e.Message.Contains(novel.Id.ToString())));
}
[Test]
public async Task Rejecting_a_beat_with_a_foreign_character_logs_a_warning_not_an_error()
{
var novelA = await Novels.CreateAsync(new CreateNovelRequest("Novel A"));
var novelB = await Novels.CreateAsync(new CreateNovelRequest("Novel B"));
var chapter = await Chapters.CreateAsync(novelA.Id, new CreateChapterRequest("Landfall"));
var foreignCharacter = await Characters.CreateAsync(novelB.Id, new CreateCharacterRequest("Ines"));
BeatLogs.Entries.Clear();
Assert.That(
() => Beats.CreateAsync(chapter.Id, new CreateBeatRequest("Arrival", CharacterIds: [foreignCharacter.Id])),
Throws.TypeOf<InvalidOperationException>());
Assert.Multiple(() =>
{
Assert.That(BeatLogs.Entries.Where(e => e.Level == LogLevel.Error), Is.Empty);
Assert.That(BeatLogs.Entries.Any(e => e.Level == LogLevel.Warning), Is.True);
});
}
}