Allow unlimited joker suggestions when granted repeatedly

This commit is contained in:
2026-02-05 19:38:56 +01:00
parent a2dd212377
commit 5b6fa7e407
2 changed files with 27 additions and 5 deletions

View File

@@ -78,10 +78,9 @@ public static class SuggestEndpoints
}
var existingCount = await db.Suggestions.CountAsync(s => s.PlayerId == player.Id);
var maxSuggestions = usingJoker ? 6 : 5;
if (existingCount >= maxSuggestions)
if (!usingJoker && existingCount >= 5)
{
return Results.BadRequest(new { error = "You have reached the suggestion limit." });
return Results.BadRequest(new { error = "You have reached the 5 suggestion limit." });
}
var suggestion = new Suggestion

View File

@@ -241,7 +241,7 @@ public class SuggestionTests
}
[Fact]
public async Task Joker_allows_sixth_suggestion_but_blocks_seventh()
public async Task Joker_allows_unlimited_extra_suggestions_when_granted_multiple_times()
{
using var factory = new TestWebApplicationFactory();
var client = factory.CreateClientWithCookies();
@@ -286,6 +286,14 @@ public class SuggestionTests
});
sixth.EnsureSuccessStatusCode();
// Grant another joker and add a seventh suggestion
await factory.WithDbContextAsync(async db =>
{
var p = await db.Players.FirstAsync();
p.HasJoker = true;
await db.SaveChangesAsync();
});
var seventh = await client.PostAsJsonAsync("/api/suggestions", new
{
Name = "TooMany",
@@ -298,7 +306,22 @@ public class SuggestionTests
MaxPlayers = (int?)null
});
Assert.Equal(HttpStatusCode.BadRequest, seventh.StatusCode);
seventh.EnsureSuccessStatusCode();
// No joker left; further suggestions should be blocked
var eighth = await client.PostAsJsonAsync("/api/suggestions", new
{
Name = "BlockedNow",
Genre = (string?)null,
Description = (string?)null,
ScreenshotUrl = (string?)null,
YoutubeUrl = (string?)null,
GameUrl = (string?)null,
MinPlayers = (int?)null,
MaxPlayers = (int?)null
});
Assert.Equal(HttpStatusCode.BadRequest, eighth.StatusCode);
}
[Fact]