[FA-misc] Saga seems to work, fixed a UserNovelDataService bug

This commit is contained in:
gamer147
2026-01-28 12:11:06 -05:00
parent 579e05b853
commit ec967770d3
34 changed files with 1341 additions and 97 deletions

View File

@@ -14,6 +14,7 @@ using MassTransit;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using NodaTime;
using NSubstitute;
using Xunit;
@@ -80,7 +81,10 @@ public class NovelUpdateServiceTests
PendingImageUrl = pendingImageUrl
});
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, publishEndpoint, options);
var clock = Substitute.For<IClock>();
clock.GetCurrentInstant().Returns(Instant.FromUnixTimeSeconds(0));
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, publishEndpoint, options, clock);
}
[Fact]
@@ -110,8 +114,10 @@ public class NovelUpdateServiceTests
var pendingImageUrl = "https://pending/placeholder.jpg";
var service = CreateService(dbContext, adapter, publishEndpoint, pendingImageUrl);
var updatedChapter = await service.PullChapterContents(novel.Id, volume.Id, chapter.Order);
var importId = Guid.NewGuid();
var (updatedChapter, imageCount) = await service.PullChapterContents(importId, novel.Id, volume.Id, chapter.Order);
imageCount.Should().Be(2);
updatedChapter.Images.Should().HaveCount(2);
updatedChapter.Images.Select(i => i.OriginalPath).Should().BeEquivalentTo(new[] { image1.Url, image2.Url });
updatedChapter.Images.All(i => i.Id != Guid.Empty).Should().BeTrue();
@@ -128,9 +134,10 @@ public class NovelUpdateServiceTests
.BeEquivalentTo(updatedChapter.Images.Select(img => img.Id.ToString()));
publishedEvents.Should().HaveCount(2);
publishedEvents.Should().OnlyContain(e => e.ImportId == importId);
publishedEvents.Select(e => e.RequestId).Should().BeEquivalentTo(updatedChapter.Images.Select(i => i.Id));
publishedEvents.Select(e => e.FileData).Should().BeEquivalentTo(new[] { image1.Data, image2.Data });
publishedEvents.Should().OnlyContain(e => e.FilePath.StartsWith($"{novel.Id}/Images/Chapter-{updatedChapter.Id}/"));
publishedEvents.Should().OnlyContain(e => e.FilePath.StartsWith($"Novels/{novel.Id}/Images/Chapter-{updatedChapter.Id}/"));
}
[Fact]
@@ -155,8 +162,10 @@ public class NovelUpdateServiceTests
var service = CreateService(dbContext, adapter, publishEndpoint);
var updatedChapter = await service.PullChapterContents(novel.Id, volume.Id, chapter.Order);
var importId = Guid.NewGuid();
var (updatedChapter, imageCount) = await service.PullChapterContents(importId, novel.Id, volume.Id, chapter.Order);
imageCount.Should().Be(1);
var storedHtml = updatedChapter.Body.Texts.Single().Text;
var doc = new HtmlDocument();
doc.LoadHtml(storedHtml);