Skip to content

Commit

Permalink
Add a test for JSON parsing (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR authored Feb 6, 2024
1 parent 6bdd05d commit 5919f2e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/Funogram.Tests/Deserializer.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module Funogram.Tests.Deserializer

open System.IO
open System.Text

open Xunit

open Funogram
open Funogram.Telegram.Types

[<Fact>]
let ``Deserializer should work``(): unit =
let brokenUpdate = """{
"ok": true,
"result": [
{
"update_id": 1,
"message": {
"message_id": 1,
"from": {
"id": 1,
"is_bot": false,
"first_name": "1",
"last_name": "1",
"username": "1"
},
"chat": {
"id": -1,
"title": "1",
"username": "1",
"type": "supergroup"
},
"date": 1707128434,
"message_thread_id": 1,
"reply_to_message": {
"message_id": 1,
"from": {
"id": 1,
"is_bot": false,
"first_name": "2",
"username": "2",
"is_premium": true
},
"chat": {
"id": -1,
"title": "1",
"username": "1",
"type": "supergroup"
},
"date": 1707117257,
"message_thread_id": 1,
"quote": {
"text": "Ins\\",
"position": 9,
"is_manual": true
}
}
}
}
]
}"""
let input = Encoding.UTF8.GetBytes brokenUpdate
use stream = new MemoryStream(input)
match Tools.parseJsonStreamApiResponse<Update[]> stream with
| Error e -> Assert.True(false, e.ToString())
| Ok result ->

let update = Assert.Single result
match update.Message with
| None -> Assert.True(false, "No message")
| Some message -> Assert.Equal(1L, message.MessageId)
1 change: 1 addition & 0 deletions src/Funogram.Tests/Funogram.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Compile Include="Extensions.fs" />
<Compile Include="Json.fs" />
<Compile Include="Core.fs" />
<Compile Include="Deserializer.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
Expand Down

0 comments on commit 5919f2e

Please sign in to comment.