From c397aff607bed3682d0d1892fb19685c703cfc5c Mon Sep 17 00:00:00 2001 From: Ayrat Hudaygulov Date: Mon, 7 Oct 2024 18:05:24 +0100 Subject: [PATCH] added test --- src/VahterBanBot.Tests/MLBanTests.fs | 12 ++++++++++++ src/VahterBanBot.Tests/TgMessageUtils.fs | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/VahterBanBot.Tests/MLBanTests.fs b/src/VahterBanBot.Tests/MLBanTests.fs index 0ab5909..d380587 100644 --- a/src/VahterBanBot.Tests/MLBanTests.fs +++ b/src/VahterBanBot.Tests/MLBanTests.fs @@ -236,6 +236,18 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) = let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message Assert.True msgBanned } + + [] + let ``Message which were edited triggers auto-delete`` () = task { + // record a message, which originally was not a spam, + // but it was edited to be a spam + let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[0], text = "a", editedText = "2222222") + let! _ = fixture.SendMessage msgUpdate + + // assert that the message got auto banned + let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message + Assert.True msgBanned + } interface IAssemblyFixture interface IClassFixture diff --git a/src/VahterBanBot.Tests/TgMessageUtils.fs b/src/VahterBanBot.Tests/TgMessageUtils.fs index 6ab2921..97bf2d7 100644 --- a/src/VahterBanBot.Tests/TgMessageUtils.fs +++ b/src/VahterBanBot.Tests/TgMessageUtils.fs @@ -32,7 +32,7 @@ type Tg() = ) ) - static member quickMsg (?text: string, ?chat: Chat, ?from: User, ?date: DateTime, ?callback: CallbackQuery, ?caption: string) = + static member quickMsg (?text: string, ?chat: Chat, ?from: User, ?date: DateTime, ?callback: CallbackQuery, ?caption: string, ?editedText: string) = Update( Id = next(), Message = @@ -44,7 +44,19 @@ type Tg() = Date = (date |> Option.defaultValue DateTime.UtcNow), Caption = (caption |> Option.defaultValue null), ReplyToMessage = null - ) + ), + EditedMessage = + if editedText |> Option.isSome then + Message( + MessageId = next(), + Text = editedText.Value, + Chat = (chat |> Option.defaultValue (Tg.chat())), + From = (from |> Option.defaultValue (Tg.user())), + Date = (date |> Option.defaultValue DateTime.UtcNow), + Caption = (caption |> Option.defaultValue null), + ReplyToMessage = null + ) + else null ) static member replyMsg (msg: Message, ?text: string, ?from: User, ?date: DateTime) =