Refactor TelegramBotService to streamline message sending process
Updated the TelegramBotService to replace the SendMessageAsync method with a new NoticeAsync method, improving clarity and functionality. Adjusted related tests to ensure proper handling of message IDs and maintain consistency in message management. This change enhances the overall user experience by simplifying the message notification process.
This commit is contained in:
@@ -212,13 +212,14 @@ public class TelegramBotTests
|
||||
|
||||
var api = Substitute.For<ITelegramApi>();
|
||||
string? sent = null;
|
||||
await api.SendMessageAsync(
|
||||
Arg.Any<TelegramSettings>(),
|
||||
Arg.Any<long>(),
|
||||
Arg.Do<string>(text => sent = text),
|
||||
Arg.Any<IReadOnlyList<IReadOnlyList<TelegramButton>>?>(),
|
||||
Arg.Any<CancellationToken>()
|
||||
);
|
||||
api.SendMessageAsync(
|
||||
Arg.Any<TelegramSettings>(),
|
||||
Arg.Any<long>(),
|
||||
Arg.Do<string>(text => sent = text),
|
||||
Arg.Any<IReadOnlyList<IReadOnlyList<TelegramButton>>?>(),
|
||||
Arg.Any<CancellationToken>()
|
||||
)
|
||||
.Returns(4242L);
|
||||
|
||||
await using var db = fixture.New();
|
||||
await new TelegramBotService(db, api).HandleAsync(
|
||||
@@ -230,6 +231,12 @@ public class TelegramBotTests
|
||||
|
||||
Assert.NotNull(sent);
|
||||
Assert.Contains("Симпсоны", sent, StringComparison.Ordinal);
|
||||
// Программа — одноразовое сообщение: её идентификатор запомнен, чтобы снять при следующем
|
||||
// показе. Без этого чат копит одинаковые программы на разное время.
|
||||
await using (var check = fixture.New())
|
||||
{
|
||||
Assert.Equal(4242L, check.TelegramSubscribers.Single().NoticeMessageId);
|
||||
}
|
||||
Assert.Contains("Футурама", sent, StringComparison.Ordinal);
|
||||
// Две подряд идущие серии Симпсонов дают одну строку, а не две.
|
||||
Assert.Equal(1, sent!.Split("Симпсоны").Length - 1);
|
||||
|
||||
Reference in New Issue
Block a user