7cb5b03cc2
PR Checks / test-and-build (pull_request) Failing after 20m55s
Prevent offline sessions with empty join links from entering the 5-minute join-link notification flow, omit blank link lines from direct reminders, and add offline persistence/reminder regression coverage.
72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
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<NotSupportedException>(
|
|
() => 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<ArgumentException>(
|
|
() => 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<TelegramPlatformMessenger>.Instance);
|
|
|
|
private static string InvokeBuildDirectNotificationText(PlatformDirectSessionNotification notification)
|
|
{
|
|
var method = typeof(TelegramPlatformMessenger).GetMethod(
|
|
"BuildDirectNotificationText",
|
|
BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
Assert.NotNull(method);
|
|
return Assert.IsType<string>(method.Invoke(null, new object[] { notification }));
|
|
}
|
|
|
|
private static SessionBatchViewModel CreateView() =>
|
|
new("Test batch", []);
|
|
}
|