fix(tests): SeedViewerAsync tutorialState param is no longer sentinel-overloaded

The previous `if (tutorialState != 0)` block silently dropped overrides for state 0,
so `SeedViewerAsync(tutorialState: 0)` returned whatever BuildDefaultViewer set
(state 1), not state 0. Tests that wanted a fresh-signup viewer were getting one
by accident, and the stale comment claimed the default was 0. Always override.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@
This commit is contained in:
gamer147
2026-05-28 19:56:06 -04:00
parent ad5c9e91ae
commit c2c6a95170

View File

@@ -174,13 +174,14 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
await db.SaveChangesAsync(); await db.SaveChangesAsync();
} }
// Third scope: override TutorialState to the requested value when non-zero. // Third scope: write the requested TutorialState. The parameter defaults to 100 —
// BuildDefaultViewer now starts viewers at 0 (PRE_TUTORIAL_STEP). Tests that want // the post-tutorial baseline that ~30 existing tests rely on — so callers that don't
// a pre-completed-tutorial viewer (the common case for existing tests) pass the // care about the tutorial step keep working unchanged. Pass tutorialState: 1 to seed
// default tutorialState=100 here. // a fresh-signup viewer, or any other value to land mid-tutorial. RegisterViewer's
if (tutorialState != 0) // own default (set in BuildDefaultViewer) is irrelevant here because this override
// always runs.
using (var scope = Services.CreateScope())
{ {
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>(); var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
var viewer = await db.Viewers.Include(v => v.MissionData).FirstAsync(v => v.Id == viewerId); var viewer = await db.Viewers.Include(v => v.MissionData).FirstAsync(v => v.Id == viewerId);
viewer.MissionData.TutorialState = tutorialState; viewer.MissionData.TutorialState = tutorialState;