diff --git a/SVSim.UnitTests/Controllers/GiftControllerTests.cs b/SVSim.UnitTests/Controllers/GiftControllerTests.cs index e9df66b..75952de 100644 --- a/SVSim.UnitTests/Controllers/GiftControllerTests.cs +++ b/SVSim.UnitTests/Controllers/GiftControllerTests.cs @@ -1,7 +1,12 @@ using System.Net; using System.Text; using System.Text.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using SVSim.Database; +using SVSim.Database.Models; +using SVSim.Database.Repositories.Viewer; using SVSim.UnitTests.Infrastructure; namespace SVSim.UnitTests.Controllers; @@ -336,4 +341,41 @@ public class GiftControllerTests // ... and present_list now has 4 remaining unclaimed gifts. Assert.That(root.GetProperty("present_list").GetArrayLength(), Is.EqualTo(4)); } + + [Test] + public async Task Signup_creates_viewer_with_five_unclaimed_tutorial_presents() + { + using var factory = new SVSimTestFactory(); + await factory.SeedGlobalsAsync(); + + // Drive the real /tool/signup path via RegisterAnonymousViewer. SeedTutorialPresentsAsync + // is NOT called here — the point of this test is that the production signup flow seeds + // the rows on its own. + var freshUdid = Guid.NewGuid(); + long viewerId; + using (var scope = factory.Services.CreateScope()) + { + var repo = scope.ServiceProvider.GetRequiredService(); + var v = await repo.RegisterAnonymousViewer(freshUdid); + viewerId = v.Id; + } + + // Verify five ViewerPresent rows exist for this viewer, all Unclaimed, all + // Source="tutorial", with the expected PresentIds. + using (var scope = factory.Services.CreateScope()) + { + var db = scope.ServiceProvider.GetRequiredService(); + var rows = await db.ViewerPresents + .Where(p => p.ViewerId == viewerId) + .ToListAsync(); + Assert.That(rows.Count, Is.EqualTo(5), + "RegisterAnonymousViewer must seed exactly the five TutorialPresents rows."); + Assert.That(rows.All(r => r.Status == PresentStatus.Unclaimed), Is.True); + Assert.That(rows.All(r => r.Source == "tutorial"), Is.True); + + var ids = rows.Select(r => r.PresentId).ToHashSet(); + Assert.That(ids, Is.EquivalentTo(new[] + { "71478626", "71478627", "71478628", "71478629", "71478630" })); + } + } }