fix: validate platform schedule update target
PR Checks / test-and-build (pull_request) Successful in 13m7s
PR Checks / test-and-build (pull_request) Successful in 13m7s
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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", []);
|
||||
}
|
||||
Reference in New Issue
Block a user