Skip to content

Commit

Permalink
Tests: fix compilation after Funogram migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Oct 20, 2024
1 parent ae45c3c commit 3b1ad3b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 118 deletions.
33 changes: 17 additions & 16 deletions src/VahterBanBot.Tests/BanTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module VahterBanBot.Tests.BanTests
open System.Net
open VahterBanBot.Tests.ContainerTestBase
open VahterBanBot.Tests.TgMessageUtils
open VahterBanBot.Utils
open Xunit
open Xunit.Extensions.AssemblyFixture

Expand All @@ -16,12 +17,12 @@ type BanTests(fixture: VahterTestContainers) =

// send the ban message
let! banResp =
Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0])
Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

// assert that the message got banned
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.True msgBanned
}

Expand All @@ -33,12 +34,12 @@ type BanTests(fixture: VahterTestContainers) =

// send the ban message from a non-admin user
let! banResp =
Tg.replyMsg(msgUpdate.Message, "/ban", Tg.user())
Tg.replyMsg(msgUpdate.Message.Value, "/ban", Tg.user())
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

// assert that the message NOT banned
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgNotBanned
}

Expand All @@ -50,12 +51,12 @@ type BanTests(fixture: VahterTestContainers) =

// send the ban message
let! banResp =
Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0])
Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

// assert that the message NOT banned
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgNotBanned
}

Expand All @@ -67,12 +68,12 @@ type BanTests(fixture: VahterTestContainers) =

// send the ban message
let! banResp =
Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[1])
Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[1])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

// assert that the message NOT banned
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message
let! msgNotBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgNotBanned
}

Expand All @@ -84,22 +85,22 @@ type BanTests(fixture: VahterTestContainers) =

// send the ban message
let! banResp =
Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0])
Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

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

// send the unban message from another vahter
let! banResp =
Tg.quickMsg($"/unban {msgUpdate.Message.From.Id}", chat = fixture.ChatsToMonitor[0], from = fixture.Vahters[1])
Tg.quickMsg($"/unban {msgUpdate.Message.Value.FromId}", chat = fixture.ChatsToMonitor[0], from = fixture.Vahters[1])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

// assert that the message no longer banned
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgBanned
}

Expand All @@ -111,22 +112,22 @@ type BanTests(fixture: VahterTestContainers) =

// send the ban message
let! banResp =
Tg.replyMsg(msgUpdate.Message, "/ban", fixture.Vahters[0])
Tg.replyMsg(msgUpdate.Message.Value, "/ban", fixture.Vahters[0])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

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

// send the unban message from a random user
let! banResp =
Tg.quickMsg($"/unban {msgUpdate.Message.From.Id}", chat = fixture.ChatsToMonitor[0])
Tg.quickMsg($"/unban {msgUpdate.Message.Value.FromId}", chat = fixture.ChatsToMonitor[0])
|> fixture.SendMessage
Assert.Equal(HttpStatusCode.OK, banResp.StatusCode)

// assert that the message still banned
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.True msgBanned
}

Expand Down
4 changes: 2 additions & 2 deletions src/VahterBanBot.Tests/BaseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module BaseTests
open System
open System.Net.Http
open System.Text
open Telegram.Bot.Types
open Funogram.Telegram.Types
open VahterBanBot.Tests.ContainerTestBase
open Xunit
open Xunit.Extensions.AssemblyFixture
Expand All @@ -28,7 +28,7 @@ type BaseTests(fixture: VahterTestContainers) =

[<Fact>]
let ``Should be possible to interact with the bot`` () = task {
let! resp = Update(Id = 123) |> fixture.SendMessage
let! resp = Update.Create(updateId = 123) |> fixture.SendMessage
let! body = resp.Content.ReadAsStringAsync()
Assert.Equal(System.Net.HttpStatusCode.OK, resp.StatusCode)
Assert.Equal("null", body)
Expand Down
2 changes: 1 addition & 1 deletion src/VahterBanBot.Tests/ContainerTestBase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ open System.Threading.Tasks
open DotNet.Testcontainers.Builders
open DotNet.Testcontainers.Configurations
open DotNet.Testcontainers.Containers
open Funogram.Telegram.Types
open Npgsql
open Telegram.Bot.Types
open Testcontainers.PostgreSql
open VahterBanBot.Tests.TgMessageUtils
open VahterBanBot.Types
Expand Down
62 changes: 31 additions & 31 deletions src/VahterBanBot.Tests/MLBanTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -29,7 +29,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -42,7 +42,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -54,7 +54,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -65,7 +65,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -76,7 +76,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -88,19 +88,19 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

// assert that the message got auto banned
let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message
let! msgBanned = fixture.MessageIsAutoDeleted msgUpdate.Message.Value
Assert.True msgBanned
// assert it is not false-positive
let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message
let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message.Value
Assert.False isFalsePositive

// send a callback to mark it as false-positive
let! callbackId = fixture.GetCallbackId msgUpdate.Message "NotASpam"
let! callbackId = fixture.GetCallbackId msgUpdate.Message.Value "NotASpam"
let msgCallback = Tg.callback(string callbackId, from = fixture.Vahters[0])
let! _ = fixture.SendMessage msgCallback

// assert it is false-positive
let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message
let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message.Value
Assert.True isFalsePositive
}

Expand All @@ -112,17 +112,17 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

// send a callback to mark it as false-positive
// we are sending this as a usual user
let! callbackId = fixture.GetCallbackId msgUpdate.Message (nameof CallbackMessage.NotASpam)
let msgCallback = Tg.callback(string callbackId, from = msgUpdate.Message.From)
let! callbackId = fixture.GetCallbackId msgUpdate.Message.Value (nameof CallbackMessage.NotASpam)
let msgCallback = Tg.callback(string callbackId, from = msgUpdate.Message.Value.From.Value)
let! _ = fixture.SendMessage msgCallback

// assert it is still NOT a false-positive
let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message
let! isFalsePositive = fixture.IsMessageFalsePositive msgUpdate.Message.Value
Assert.False isFalsePositive
}

Expand All @@ -135,22 +135,22 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =

// 1 - no ban
let! _ = fixture.SendMessage msgUpdate
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgBanned

// 2 - no ban
let! _ = fixture.SendMessage msgUpdate
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgBanned

// 3 - no ban
let! _ = fixture.SendMessage msgUpdate
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.False msgBanned

// 4 - ban (depends on the ML_SPAM_AUTOBAN_SCORE_THRESHOLD)
let! _ = fixture.SendMessage msgUpdate
let! msgBanned = fixture.MessageBanned msgUpdate.Message
let! msgBanned = fixture.MessageBanned msgUpdate.Message.Value
Assert.True msgBanned
}

Expand All @@ -164,27 +164,27 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =

// 1 - no ban
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned

// 1.5 - no ban
let! _ = fixture.SendMessage notSpam
let! msgBanned = fixture.MessageBanned notSpam.Message
let! msgBanned = fixture.MessageBanned notSpam.Message.Value
Assert.False msgBanned

// 2 - no ban
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned

// 3 - no ban
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned

// 4 - no ban (as user posted 1 good message in beetween)
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned
}

Expand All @@ -197,30 +197,30 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =

// 1 - no ban
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgDeleted = fixture.MessageIsAutoDeleted spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
let! msgDeleted = fixture.MessageIsAutoDeleted spam.Message.Value
Assert.True msgDeleted
Assert.False msgBanned

// 1.5 - vahter marked as false-positive via button
// send a callback to mark it as false-positive
let! callbackId = fixture.GetCallbackId spam.Message "NotASpam"
let! callbackId = fixture.GetCallbackId spam.Message.Value "NotASpam"
let msgCallback = Tg.callback(string callbackId, from = fixture.Vahters[0])
let! _ = fixture.SendMessage msgCallback

// 2 - no ban
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned

// 3 - no ban
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned

// 4 - no ban (as vahter marked this as false positive)
let! _ = fixture.SendMessage spam
let! msgBanned = fixture.MessageBanned spam.Message
let! msgBanned = fixture.MessageBanned spam.Message.Value
Assert.False msgBanned
}

Expand All @@ -233,7 +233,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand All @@ -245,7 +245,7 @@ type MLBanTests(fixture: VahterTestContainers, _unused: MlAwaitFixture) =
let! _ = fixture.SendMessage msgUpdate

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

Expand Down
Loading

0 comments on commit 3b1ad3b

Please sign in to comment.