Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer committed Sep 13, 2024
1 parent f194dfc commit 5b15d20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/VahterBanBot.Tests/MLBanTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! msgBanned = fixture.MessageBanned spam.Message
Assert.False msgBanned
}

[<Fact>]
let ``Message with spam in photo caption also triggers auto-delete`` () = task {
// record a message, where 2 is in a training set as spam word
// but text is in a message.Caption
// ChatsToMonitor[0] doesn't have stopwords
let msgUpdate = Tg.quickMsg(chat = fixture.ChatsToMonitor[0], text = null, caption = "2")
let! _ = fixture.SendMessage msgUpdate

// assert that the message got auto banned
let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message
Assert.True msgBanned

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

View workflow job for this annotation

GitHub Actions / Test results

VahterBanBot.Tests.MLBanTests+MLBanTests ► Message with spam in photo caption also 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 [email protected]() in /home/runner/work/vahter-bot/vahter-bot/src/VahterBanBot.Tests/MLBanTests.fs:line 237
--- End of stack trace from previous location ---
}

interface IAssemblyFixture<VahterTestContainers>
interface IClassFixture<MlAwaitFixture>
3 changes: 2 additions & 1 deletion 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) =
static member quickMsg (?text: string, ?chat: Chat, ?from: User, ?date: DateTime, ?callback: CallbackQuery, ?caption: string) =
Update(
Id = next(),
Message =
Expand All @@ -42,6 +42,7 @@ type Tg() =
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
)
)
Expand Down

0 comments on commit 5b15d20

Please sign in to comment.