test(signup): assert tutorial presents seeded by RegisterAnonymousViewer
This commit is contained in:
@@ -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<IViewerRepository>();
|
||||
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<SVSimDbContext>();
|
||||
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" }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user