-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module PingTests | ||
|
||
open System.Net | ||
open VahterBanBot.Tests.ContainerTestBase | ||
open VahterBanBot.Tests.TgMessageUtils | ||
open Xunit | ||
open Xunit.Extensions.AssemblyFixture | ||
|
||
type PingTests(fixture: VahterTestContainers) = | ||
[<Fact>] | ||
let ``Message got recorded`` () = task { | ||
// chat from the allowed list | ||
let msg = Tg.quickMsg(chat = fixture.ChatsToMonitor[0]) | ||
|
||
// assert that the message is not in the db | ||
let! msgExist = fixture.MessageExist msg.Message | ||
Assert.False msgExist | ||
|
||
// send the message to the bot | ||
let! resp = fixture.SendMessage msg | ||
Assert.Equal(HttpStatusCode.OK, resp.StatusCode) | ||
|
||
// assert that the message is in the db | ||
let! msgExist = fixture.MessageExist msg.Message | ||
Assert.True msgExist | ||
} | ||
|
||
[<Fact>] | ||
let ``Message not recorded if chat is not on the list`` () = task { | ||
// some random chat | ||
let msg = Tg.quickMsg(chat = Tg.chat()) | ||
|
||
// assert that the message is not in the db | ||
let! msgExist = fixture.MessageExist msg.Message | ||
Assert.False msgExist | ||
|
||
// send the message to the bot | ||
let! resp = fixture.SendMessage msg | ||
Assert.Equal(HttpStatusCode.OK, resp.StatusCode) | ||
|
||
// assert that the message is still not in the db | ||
let! msgExist = fixture.MessageExist msg.Message | ||
Assert.False msgExist | ||
} | ||
|
||
interface IAssemblyFixture<VahterTestContainers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module VahterBanBot.Tests.TgMessageUtils | ||
|
||
open System | ||
open Telegram.Bot.Types | ||
|
||
type Tg() = | ||
static let rnd = Random.Shared | ||
static member user (?id: int64, ?username: string, ?firstName: string) = | ||
User( | ||
Id = (id |> Option.defaultValue (rnd.NextInt64())), | ||
Username = (username |> Option.defaultValue null), | ||
FirstName = (firstName |> Option.defaultWith (fun () -> Guid.NewGuid().ToString())) | ||
) | ||
static member chat (?id: int64, ?username: string) = | ||
Chat( | ||
Id = (id |> Option.defaultValue (rnd.NextInt64())), | ||
Username = (username |> Option.defaultValue null) | ||
) | ||
static member quickMsg (?text: string, ?chat: Chat, ?from: User, ?date: DateTime) = | ||
Update( | ||
Id = rnd.Next(), | ||
Message = | ||
Message( | ||
MessageId = rnd.Next(), | ||
Text = (text |> Option.defaultValue (Guid.NewGuid().ToString())), | ||
Chat = (chat |> Option.defaultValue (Tg.chat())), | ||
From = (from |> Option.defaultValue (Tg.user())), | ||
Date = (date |> Option.defaultValue DateTime.UtcNow) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters