repo(viewer): add UDID lookup, anonymous register, Steam link helpers

Extracts the default-loadout body into a private BuildDefaultViewer
helper shared by the existing Steam-import path and a new
RegisterAnonymousViewer for /tool/signup. LinkSteamToViewer is the
seam SteamSessionAuthenticationHandler will call on first-Steam-touch
of a UDID-keyed viewer.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-27 14:01:02 -04:00
parent dffd7a9746
commit 30874c681f
3 changed files with 151 additions and 11 deletions

View File

@@ -71,4 +71,99 @@ public class ViewerRepositoryTests
Assert.That(viewer.LeaderSkins, Is.Not.Empty,
"Viewer should own at least one leader skin from class defaults.");
}
[Test]
public async Task RegisterAnonymousViewer_creates_viewer_with_udid_and_no_socials()
{
using var factory = new SVSimTestFactory();
var udid = Guid.NewGuid();
long viewerId;
using (var scope = factory.Services.CreateScope())
{
var repo = scope.ServiceProvider.GetRequiredService<IViewerRepository>();
var v = await repo.RegisterAnonymousViewer(udid);
viewerId = v.Id;
}
using var verifyScope = factory.Services.CreateScope();
var db = verifyScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
var loaded = await db.Viewers
.Include(v => v.Classes)
.Include(v => v.SocialAccountConnections)
.FirstAsync(v => v.Id == viewerId);
Assert.That(loaded.Udid, Is.EqualTo(udid));
Assert.That(loaded.SocialAccountConnections, Is.Empty);
Assert.That(loaded.Classes, Is.Not.Empty,
"Default-loadout body should populate Classes (smoke-test the shared BuildDefaultViewer helper).");
}
[Test]
public async Task RegisterAnonymousViewer_with_empty_udid_throws()
{
using var factory = new SVSimTestFactory();
using var scope = factory.Services.CreateScope();
var repo = scope.ServiceProvider.GetRequiredService<IViewerRepository>();
Assert.ThrowsAsync<InvalidOperationException>(async () =>
await repo.RegisterAnonymousViewer(Guid.Empty));
}
[Test]
public async Task GetViewerByUdid_returns_viewer_or_null()
{
using var factory = new SVSimTestFactory();
var udid = Guid.NewGuid();
long createdId;
using (var scope = factory.Services.CreateScope())
{
var repo = scope.ServiceProvider.GetRequiredService<IViewerRepository>();
createdId = (await repo.RegisterAnonymousViewer(udid)).Id;
}
using (var scope = factory.Services.CreateScope())
{
var repo = scope.ServiceProvider.GetRequiredService<IViewerRepository>();
var hit = await repo.GetViewerByUdid(udid);
var miss = await repo.GetViewerByUdid(Guid.NewGuid());
Assert.That(hit, Is.Not.Null);
Assert.That(hit!.Id, Is.EqualTo(createdId));
Assert.That(miss, Is.Null);
}
}
[Test]
public async Task LinkSteamToViewer_appends_steam_social_connection()
{
using var factory = new SVSimTestFactory();
var udid = Guid.NewGuid();
const ulong steamId = 76_561_198_900_000_001UL;
long viewerId;
using (var scope = factory.Services.CreateScope())
{
var repo = scope.ServiceProvider.GetRequiredService<IViewerRepository>();
viewerId = (await repo.RegisterAnonymousViewer(udid)).Id;
}
using (var scope = factory.Services.CreateScope())
{
var repo = scope.ServiceProvider.GetRequiredService<IViewerRepository>();
await repo.LinkSteamToViewer(viewerId, steamId);
}
using var verifyScope = factory.Services.CreateScope();
var db = verifyScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
var loaded = await db.Viewers
.Include(v => v.SocialAccountConnections)
.FirstAsync(v => v.Id == viewerId);
Assert.That(loaded.SocialAccountConnections, Has.Count.EqualTo(1));
Assert.That(loaded.SocialAccountConnections[0].AccountType,
Is.EqualTo(SocialAccountType.Steam));
Assert.That(loaded.SocialAccountConnections[0].AccountId, Is.EqualTo(steamId));
}
}