using GmRelay.Bot.Infrastructure.Telegram; using GmRelay.Shared.Platform; using GmRelay.Shared.Rendering; using Microsoft.Extensions.Logging.Abstractions; using System.Reflection; namespace GmRelay.Bot.Tests.Infrastructure.Telegram; public sealed class TelegramPlatformMessengerTests { [Fact] public async Task UpdateScheduleAsync_ShouldRejectNonTelegramExistingMessageReference() { var messenger = CreateMessenger(); var message = new PlatformScheduleMessage( new PlatformGroup(PlatformKind.Telegram, "100", "Telegram group"), CreateView(), new PlatformMessageRef(PlatformKind.Discord, "100", null, "200")); await Assert.ThrowsAsync( () => messenger.UpdateScheduleAsync(message, CancellationToken.None)); } [Fact] public async Task UpdateScheduleAsync_ShouldRejectMismatchedGroupAndExistingMessageReference() { var messenger = CreateMessenger(); var message = new PlatformScheduleMessage( new PlatformGroup(PlatformKind.Telegram, "100", "Telegram group", ExternalThreadId: "7"), CreateView(), new PlatformMessageRef(PlatformKind.Telegram, "101", "7", "200")); var exception = await Assert.ThrowsAsync( () => messenger.UpdateScheduleAsync(message, CancellationToken.None)); Assert.Equal("message", exception.ParamName); Assert.Contains("Existing schedule message reference must match the schedule group.", exception.Message); } [Fact] public void BuildDirectNotificationText_OneHourReminderWithoutJoinLink_ShouldNotRenderBlankLinkLine() { var notification = new PlatformDirectSessionNotification( PlatformDirectSessionNotificationKind.OneHourReminder, new PlatformUser(PlatformKind.Telegram, "123", "Player", "player"), Guid.NewGuid(), "Offline Game", DateTime.UtcNow, JoinLink: string.Empty); var text = InvokeBuildDirectNotificationText(notification); Assert.DoesNotContain("🔗", text); } private static TelegramPlatformMessenger CreateMessenger() => new(null!, NullLogger.Instance); private static string InvokeBuildDirectNotificationText(PlatformDirectSessionNotification notification) { var method = typeof(TelegramPlatformMessenger).GetMethod( "BuildDirectNotificationText", BindingFlags.NonPublic | BindingFlags.Static); Assert.NotNull(method); return Assert.IsType(method.Invoke(null, new object[] { notification })); } private static SessionBatchViewModel CreateView() => new("Test batch", []); }