Add factory reset admin endpoint and use it in smoke test

This commit is contained in:
2026-01-28 15:02:24 +01:00
parent 37c3eed552
commit 44514f8ecc
4 changed files with 32 additions and 3 deletions

View File

@@ -308,6 +308,26 @@ admin.MapPost("/reset", async (HttpContext ctx, AppDbContext db, IConfiguration
return Results.Ok(new { state.CurrentPhase, state.UpdatedAt });
});
admin.MapPost("/factory-reset", async (HttpContext ctx, AppDbContext db, IConfiguration config) =>
{
if (!IsAuthorized(ctx, config)) return Results.Unauthorized();
await using var tx = await db.Database.BeginTransactionAsync();
await db.Votes.ExecuteDeleteAsync();
await db.Suggestions.ExecuteDeleteAsync();
await db.Players.ExecuteDeleteAsync();
await db.AppState.ExecuteDeleteAsync();
var fresh = NewAppState();
db.AppState.Add(fresh);
await db.SaveChangesAsync();
await tx.CommitAsync();
return Results.Ok(new { fresh.CurrentPhase, fresh.UpdatedAt });
});
app.Run();
static async Task<Player> GetOrCreatePlayer(HttpContext ctx, AppDbContext db)
@@ -350,6 +370,13 @@ static bool IsAuthorized(HttpContext ctx, IConfiguration config)
return !string.IsNullOrWhiteSpace(expected) && provided == expected;
}
static AppState NewAppState() => new()
{
Id = 1,
CurrentPhase = Phase.Suggest,
UpdatedAt = DateTimeOffset.UnixEpoch
};
public record SetNameRequest(string Name);
public record SuggestionRequest(string Name, string? Genre, string? Description, string? ScreenshotUrl, string? YoutubeUrl);
public record SuggestionDto(int Id, string Name, string? Genre, string? Description, string? ScreenshotUrl, string? YoutubeUrl);