test: add GameSystem fuzzy matching and showcase query tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 16:33:29 +03:00
parent 76c6818952
commit b496a401fc
3 changed files with 126 additions and 0 deletions
@@ -0,0 +1,61 @@
using GmRelay.Shared.Domain;
namespace GmRelay.Bot.Tests.Domain;
public sealed class GameSystemTests
{
[Theory]
[InlineData("Dnd5e", GameSystem.Dnd5e)]
[InlineData("D&D", GameSystem.Dnd5e)]
[InlineData("dnd5e", GameSystem.Dnd5e)]
[InlineData("pathfinder", GameSystem.Pathfinder2e)]
[InlineData("call of cthulhu", GameSystem.CallOfCthulhu7e)]
[InlineData("shadow", GameSystem.Shadowdark)]
[InlineData("unknown xyz", GameSystem.Other)]
public void TryParseFuzzy_ShouldMapInputToExpectedSystem(string input, GameSystem expected)
{
var result = GameSystemExtensions.TryParseFuzzy(input);
Assert.Equal(expected, result);
}
[Theory]
[InlineData("днд")]
[InlineData("колова")]
public void TryParseFuzzy_ShouldReturnOtherForUnmatchedCyrillicInput(string input)
{
var result = GameSystemExtensions.TryParseFuzzy(input);
Assert.Equal(GameSystem.Other, result);
}
[Fact]
public void TryParseFuzzy_ShouldReturnNullForNullInput()
{
var result = GameSystemExtensions.TryParseFuzzy(null!);
Assert.Null(result);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
public void TryParseFuzzy_ShouldReturnNullForEmptyOrWhitespaceInput(string input)
{
var result = GameSystemExtensions.TryParseFuzzy(input);
Assert.Null(result);
}
[Theory]
[InlineData(GameSystem.Dnd5e, "D&D 5e")]
[InlineData(GameSystem.Other, "Другое")]
[InlineData(GameSystem.Pathfinder2e, "Pathfinder 2e")]
[InlineData(GameSystem.Shadowdark, "Shadowdark")]
public void ToDisplayName_ShouldReturnExpectedName(GameSystem system, string expected)
{
var result = system.ToDisplayName();
Assert.Equal(expected, result);
}
}
@@ -2,6 +2,7 @@ using GmRelay.Web.Services;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using GmRelay.Shared.Domain; using GmRelay.Shared.Domain;
using GmRelay.Shared.Features.Showcase;
namespace GmRelay.Bot.Tests.Web; namespace GmRelay.Bot.Tests.Web;
@@ -1209,6 +1210,15 @@ public sealed class AuthorizedSessionServiceTests
public Task UpsertPlayerAsync(string platform, string externalUserId, string displayName, string? avatarUrl) => public Task UpsertPlayerAsync(string platform, string externalUserId, string displayName, string? avatarUrl) =>
Task.CompletedTask; Task.CompletedTask;
public Task<IReadOnlyList<ShowcaseSessionDto>> GetShowcaseSessionsAsync(ShowcaseFilter filter, int page, int pageSize) =>
Task.FromResult<IReadOnlyList<ShowcaseSessionDto>>([]);
public Task<ShowcaseSessionDto?> GetShowcaseSessionAsync(Guid sessionId) =>
Task.FromResult<ShowcaseSessionDto?>(null);
public Task<bool> RegisterFromShowcaseAsync(Guid sessionId, string platform, string externalUserId, string displayName) =>
Task.FromResult(false);
private bool IsManager(Guid groupId, long telegramId) => private bool IsManager(Guid groupId, long telegramId) =>
IsOwner(groupId, telegramId) || IsOwner(groupId, telegramId) ||
managers.Any(manager => manager.GroupId == groupId && manager.TelegramId == telegramId); managers.Any(manager => manager.GroupId == groupId && manager.TelegramId == telegramId);
@@ -0,0 +1,55 @@
using GmRelay.Bot.Features.Sessions.CreateSession;
using GmRelay.Shared.Domain;
namespace GmRelay.Bot.Tests.Web;
public sealed class ShowcaseQueryTests
{
[Fact]
public void RegisterFromShowcase_WhenUnlimitedSeats_ShouldReturnActive()
{
var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: null, activeParticipants: 5);
Assert.Equal(ParticipantRegistrationStatus.Active, status);
}
[Fact]
public void RegisterFromShowcase_WhenOneFreeSeat_ShouldReturnActive()
{
var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 4, activeParticipants: 3);
Assert.Equal(ParticipantRegistrationStatus.Active, status);
}
[Fact]
public void RegisterFromShowcase_WhenExactlyAtCapacity_ShouldReturnWaitlisted()
{
var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 4, activeParticipants: 4);
Assert.Equal(ParticipantRegistrationStatus.Waitlisted, status);
}
[Fact]
public void RegisterFromShowcase_WhenOverCapacity_ShouldReturnWaitlisted()
{
var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 3, activeParticipants: 5);
Assert.Equal(ParticipantRegistrationStatus.Waitlisted, status);
}
[Fact]
public void RegisterFromShowcase_WhenZeroActiveAndZeroMax_ShouldReturnWaitlisted()
{
var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 0, activeParticipants: 0);
Assert.Equal(ParticipantRegistrationStatus.Waitlisted, status);
}
[Fact]
public void RegisterFromShowcase_WhenZeroActiveAndPositiveMax_ShouldReturnActive()
{
var status = SessionCapacityRules.DecideJoinStatus(maxPlayers: 1, activeParticipants: 0);
Assert.Equal(ParticipantRegistrationStatus.Active, status);
}
}