Files
GmRelayBot/tests/GmRelay.Bot.Tests/Infrastructure/Telegram/TelegramPlatformMessengerTests.cs
T
Toutsu 18e702cd04
PR Checks / test-and-build (pull_request) Successful in 13m7s
fix: validate platform schedule update target
2026-05-15 18:31:17 +03:00

45 lines
1.7 KiB
C#

using GmRelay.Bot.Infrastructure.Telegram;
using GmRelay.Shared.Platform;
using GmRelay.Shared.Rendering;
using Microsoft.Extensions.Logging.Abstractions;
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);
}
private static TelegramPlatformMessenger CreateMessenger() =>
new(null!, NullLogger<TelegramPlatformMessenger>.Instance);
private static SessionBatchViewModel CreateView() =>
new("Test batch", []);
}