Skip to content

Commit

Permalink
fixup! [Chore] Add parser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastro committed Sep 8, 2023
1 parent b2549e3 commit 6652432
Showing 1 changed file with 87 additions and 2 deletions.
89 changes: 87 additions & 2 deletions test/Test/TzBot/Slack/API/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
-- SPDX-License-Identifier: MPL-2.0

module Test.TzBot.Slack.API.Parser
( unit_Parse_message_channel_join_events
( unit_Parse_normal_message
, unit_Parse_message_channel_join_events
, unit_Parse_message_edited
, unit_Parse_message_with_broadcast
) where
Expand All @@ -21,7 +22,91 @@ import TzBot.Slack.API.MessageBlock
import TzBot.Slack.Events
import TzBot.Util

-- | https://github.com/serokell/tzbot/issues/107
-- | These events happen when a user sends a message to a channel
unit_Parse_normal_message :: Assertion
unit_Parse_normal_message = do
parseEither @_ @MessageEvent parseJSON [aesonQQ|
{
"blocks": [
{
"block_id": "gcG",
"elements": [
{
"elements": [
{
"text": "This is a normal message",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"channel": "C02N85E82LV",
"channel_type": "channel",
"client_msg_id": "9f4b9529-f19f-4587-9b12-a412fe36d070",
"event_ts": "1694191319.871489",
"team": "T02NDBHSWSG",
"text": "This is a normal message",
"ts": "1694191319.871489",
"type": "message",
"user": "U02N85E78QM"
}
|] @?=
Right
( MessageEvent
{ meChannel = ChannelId
{ unChannelId = "C02N85E82LV" }
, meChannelType = Just CTChannel
, meMessage = Message
{ mUser = UserId
{ unUserId = "U02N85E78QM" }
, mText = "This is a normal message"
, mMessageId = MessageId
{ unMessageId = "1694191319.871489" }
, mTs = read "2023-09-08 16:41:59.871489 UTC"
, mThreadId = Nothing
, mEdited = False
, mSubType = Nothing
, msgBlocks = Just
( WithUnknown
{ unUnknown = Right
[ MessageBlock
{ mbElements =
[ BEL1Plain
( PlainBlockElementLevel1
{ beType = WithUnknown { unUnknown = Right BETRichTextSection }
, beElements = Just
[ WithUnknown
{ unUnknown = Right
( BEL2ElementText
( ElementText
{ etText = "This is a normal message"
, etStyle = Nothing
}
)
)
}
]
}
)
]
}
]
}
)
}
, meTs = read "2023-09-08 16:41:59.871489 UTC"
, meMessageDetails = MDMessage
}
)

-- | These events happen when a user joins a channel
-- and Slack displays a grey message like "John joined the channel".
--
-- https://github.com/serokell/tzbot/issues/107
unit_Parse_message_channel_join_events :: Assertion
unit_Parse_message_channel_join_events = do
parseEither @_ @MessageEvent parseJSON [aesonQQ|
Expand Down

0 comments on commit 6652432

Please sign in to comment.