Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer committed Oct 7, 2024
1 parent 92f1666 commit c397aff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/VahterBanBot.Tests/MLBanTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message
Assert.True msgBanned
}

[<Fact>]
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

Check failure on line 249 in src/VahterBanBot.Tests/MLBanTests.fs

View workflow job for this annotation

GitHub Actions / Test results

VahterBanBot.Tests.MLBanTests+MLBanTests ► Message which were edited triggers auto-delete

Failed test found in: src/VahterBanBot.Tests/TestResults/test-results.trx Error: Assert.True() Failure Expected: True Actual: False
Raw output
Assert.True() Failure
Expected: True
Actual:   False
   at VahterBanBot.Tests.MLBanTests.clo@241-16.MoveNext() in /home/runner/work/vahter-bot/vahter-bot/src/VahterBanBot.Tests/MLBanTests.fs:line 249
--- End of stack trace from previous location ---
}

interface IAssemblyFixture<VahterTestContainers>
interface IClassFixture<MlAwaitFixture>
16 changes: 14 additions & 2 deletions src/VahterBanBot.Tests/TgMessageUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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) =
Expand Down

0 comments on commit c397aff

Please sign in to comment.