feat: improve telegram session posts
Deploy Telegram Bot / build-and-push (push) Successful in 4m28s
Deploy Telegram Bot / deploy (push) Successful in 11s

This commit is contained in:
2026-05-04 09:52:07 +03:00
parent 25c22b2ff5
commit aefed5abd4
18 changed files with 271 additions and 74 deletions
@@ -1,4 +1,5 @@
using GmRelay.Bot.Features.Sessions.CreateSession;
using Telegram.Bot.Types;
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
@@ -33,6 +34,43 @@ public sealed class NewSessionCommandParserTests
Assert.Empty(result.InvalidTimeInputs);
}
[Fact]
public void Parse_ShouldExtractOptionalImageUrl()
{
var nowUtc = new DateTimeOffset(2026, 4, 23, 12, 0, 0, TimeSpan.Zero);
var text = """
/newsession
Название: Curse of Strahd
Время: 24.04.2026 19:30
Ссылка: https://example.test/room
Картинка: https://example.test/strahd.jpg
""";
var result = NewSessionCommandParser.Parse(text, nowUtc);
Assert.True(result.IsValid);
Assert.Equal("https://example.test/strahd.jpg", result.ImageUrl);
}
[Fact]
public void GetBatchImageReference_ShouldPreferAttachedPhotoOverParsedUrl()
{
var message = new Message
{
Photo =
[
new PhotoSize { FileId = "small-photo", Width = 320, Height = 180, FileSize = 10 },
new PhotoSize { FileId = "large-photo", Width = 1280, Height = 720, FileSize = 20 }
]
};
var imageReference = CreateSessionHandler.GetBatchImageReference(
message,
"https://example.test/cover.jpg");
Assert.Equal("large-photo", imageReference);
}
[Fact]
public void Parse_ShouldExpandRecurringSchedule_WhenRepeatCountAndIntervalProvided()
{
@@ -0,0 +1,58 @@
using GmRelay.Bot.Features.Sessions.ListSessions;
using GmRelay.Shared.Domain;
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)
};
var result = SessionListMessageRenderer.Render(sessions);
Assert.NotNull(result.Markup);
var buttons = result.Markup.InlineKeyboard.SelectMany(row => row).ToList();
Assert.Contains("Ravenloft", result.Text);
Assert.Collection(
buttons.Select(button => button.CallbackData),
callbackData => Assert.Equal($"cancel_session:{sessionId}", callbackData),
callbackData => Assert.Equal($"reschedule_session:{sessionId}", callbackData),
callbackData => Assert.Equal($"promote_waitlist:{sessionId}", callbackData),
callbackData => Assert.Equal($"delete_session:{sessionId}", callbackData));
}
[Fact]
public void Render_ShouldHideManagerActions_WhenUserCannotManage()
{
var sessions = new[]
{
new SessionListItemDto(
Guid.NewGuid(),
"Ravenloft",
new DateTime(2026, 5, 7, 16, 30, 0, DateTimeKind.Utc),
SessionStatus.Planned,
4,
3,
1,
false)
};
var result = SessionListMessageRenderer.Render(sessions);
Assert.Null(result.Markup);
}
}