a391c51761
For non-managers /listsessions now shows player-friendly actions: - ✅ Записаться <date> when not registered - ✖️ Выйти <date> when already active - ✖️ Выйти из ожидания <date> when waitlisted Extend SessionListItemDto and the shared SQL query with IsUserActive and IsUserWaitlisted flags so the renderer can choose the right button. Update tests to cover all three player states.
126 lines
4.4 KiB
C#
126 lines
4.4 KiB
C#
using GmRelay.Bot.Features.Sessions.ListSessions;
|
||
using GmRelay.Shared.Domain;
|
||
using GmRelay.Shared.Features.Sessions.ListSessions;
|
||
|
||
namespace GmRelay.Bot.Tests.Features.Sessions.ListSessions;
|
||
|
||
public sealed class SessionListMessageRendererTests
|
||
{
|
||
[Fact]
|
||
public void Render_ShouldIncludeManagerActions_WhenUserCanManage()
|
||
{
|
||
var sessionId = Guid.NewGuid();
|
||
var sessions = new[]
|
||
{
|
||
new SessionListItemDto(
|
||
sessionId,
|
||
"Ravenloft",
|
||
new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
|
||
SessionStatus.Planned,
|
||
4,
|
||
3,
|
||
1,
|
||
true,
|
||
false,
|
||
false)
|
||
};
|
||
|
||
var text = SessionListMessageRenderer.RenderText(sessions);
|
||
var actions = SessionListMessageRenderer.RenderActions(sessions);
|
||
|
||
Assert.Contains("Ravenloft", text);
|
||
Assert.Equal(4, actions.Count);
|
||
Assert.Contains(actions, a => a.Payload == $"cancel_session:{sessionId}");
|
||
Assert.Contains(actions, a => a.Payload == $"reschedule_session:{sessionId}");
|
||
Assert.Contains(actions, a => a.Payload == $"promote_waitlist:{sessionId}");
|
||
Assert.Contains(actions, a => a.Payload == $"delete_session:{sessionId}");
|
||
|
||
var shortDate = new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc).FormatMoscowShort();
|
||
Assert.Contains(actions, a => a.Label == $"❌ Отменить {shortDate}");
|
||
Assert.Contains(actions, a => a.Label == $"⏰ Перенести {shortDate}");
|
||
Assert.Contains(actions, a => a.Label == $"⬆️ С ожидания {shortDate}");
|
||
Assert.Contains(actions, a => a.Label == $"🗑 Удалить {shortDate}");
|
||
}
|
||
|
||
[Fact]
|
||
public void Render_ShouldIncludeJoinAction_WhenPlayerIsNotRegistered()
|
||
{
|
||
var sessionId = Guid.NewGuid();
|
||
var sessions = new[]
|
||
{
|
||
new SessionListItemDto(
|
||
sessionId,
|
||
"Ravenloft",
|
||
new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
|
||
SessionStatus.Planned,
|
||
4,
|
||
3,
|
||
0,
|
||
false,
|
||
false,
|
||
false)
|
||
};
|
||
|
||
var actions = SessionListMessageRenderer.RenderActions(sessions);
|
||
var shortDate = new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc).FormatMoscowShort();
|
||
|
||
Assert.Single(actions);
|
||
Assert.Contains(actions, a => a.Payload == $"join_session:{sessionId}");
|
||
Assert.Contains(actions, a => a.Label == $"✅ Записаться {shortDate}");
|
||
}
|
||
|
||
[Fact]
|
||
public void Render_ShouldIncludeLeaveAction_WhenPlayerIsActive()
|
||
{
|
||
var sessionId = Guid.NewGuid();
|
||
var sessions = new[]
|
||
{
|
||
new SessionListItemDto(
|
||
sessionId,
|
||
"Ravenloft",
|
||
new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
|
||
SessionStatus.Planned,
|
||
4,
|
||
3,
|
||
0,
|
||
false,
|
||
true,
|
||
false)
|
||
};
|
||
|
||
var actions = SessionListMessageRenderer.RenderActions(sessions);
|
||
var shortDate = new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc).FormatMoscowShort();
|
||
|
||
Assert.Single(actions);
|
||
Assert.Contains(actions, a => a.Payload == $"leave_session:{sessionId}");
|
||
Assert.Contains(actions, a => a.Label == $"✖️ Выйти {shortDate}");
|
||
}
|
||
|
||
[Fact]
|
||
public void Render_ShouldIncludeLeaveWaitlistAction_WhenPlayerIsWaitlisted()
|
||
{
|
||
var sessionId = Guid.NewGuid();
|
||
var sessions = new[]
|
||
{
|
||
new SessionListItemDto(
|
||
sessionId,
|
||
"Ravenloft",
|
||
new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
|
||
SessionStatus.Planned,
|
||
4,
|
||
3,
|
||
1,
|
||
false,
|
||
false,
|
||
true)
|
||
};
|
||
|
||
var actions = SessionListMessageRenderer.RenderActions(sessions);
|
||
var shortDate = new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc).FormatMoscowShort();
|
||
|
||
Assert.Single(actions);
|
||
Assert.Contains(actions, a => a.Payload == $"leave_session:{sessionId}");
|
||
Assert.Contains(actions, a => a.Label == $"✖️ Выйти из ожидания {shortDate}");
|
||
}
|
||
}
|