Allow unlimited joker suggestions when granted repeatedly
This commit is contained in:
@@ -78,10 +78,9 @@ public static class SuggestEndpoints
|
|||||||
}
|
}
|
||||||
|
|
||||||
var existingCount = await db.Suggestions.CountAsync(s => s.PlayerId == player.Id);
|
var existingCount = await db.Suggestions.CountAsync(s => s.PlayerId == player.Id);
|
||||||
var maxSuggestions = usingJoker ? 6 : 5;
|
if (!usingJoker && existingCount >= 5)
|
||||||
if (existingCount >= maxSuggestions)
|
|
||||||
{
|
{
|
||||||
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
|
var suggestion = new Suggestion
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ public class SuggestionTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[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();
|
using var factory = new TestWebApplicationFactory();
|
||||||
var client = factory.CreateClientWithCookies();
|
var client = factory.CreateClientWithCookies();
|
||||||
@@ -286,6 +286,14 @@ public class SuggestionTests
|
|||||||
});
|
});
|
||||||
sixth.EnsureSuccessStatusCode();
|
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
|
var seventh = await client.PostAsJsonAsync("/api/suggestions", new
|
||||||
{
|
{
|
||||||
Name = "TooMany",
|
Name = "TooMany",
|
||||||
@@ -298,7 +306,22 @@ public class SuggestionTests
|
|||||||
MaxPlayers = (int?)null
|
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]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user