test(gift): add SeedTutorialPresentsAsync helper

This commit is contained in:
gamer147
2026-06-08 20:37:26 -04:00
parent 2b35ae0890
commit fafd7ea183

View File

@@ -562,6 +562,36 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
await db.SaveChangesAsync();
}
/// <summary>
/// Seed the five tutorial ViewerPresent rows for a test viewer. RegisterViewer (admin/social
/// path) does NOT auto-seed; only the production /tool/signup -> RegisterAnonymousViewer flow
/// does. Tests opt in by calling this helper after SeedViewerAsync when they want a tutorial-
/// shaped inbox state.
/// </summary>
public async Task SeedTutorialPresentsAsync(long viewerId)
{
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
var createdAt = DateTime.UtcNow;
foreach (var spec in SVSim.Database.SeedData.TutorialPresents.All)
{
db.ViewerPresents.Add(new ViewerPresent
{
ViewerId = viewerId,
PresentId = spec.PresentId,
Status = PresentStatus.Unclaimed,
RewardType = spec.RewardType,
RewardDetailId = spec.RewardDetailId,
RewardCount = spec.RewardCount,
ItemType = spec.ItemType,
Message = spec.Message,
CreatedAt = createdAt,
Source = "tutorial",
});
}
await db.SaveChangesAsync();
}
/// <summary>
/// Reads the viewer's current owned count for <paramref name="itemId"/>. Returns 0 if no
/// row exists. Tests use this to assert ticket consumption after /tutorial/pack_open.