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 96699c5 commit b2549e3
Showing 1 changed file with 185 additions and 0 deletions.
185 changes: 185 additions & 0 deletions test/Test/TzBot/Slack/API/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Test.TzBot.Slack.API.Parser
( unit_Parse_message_channel_join_events
, unit_Parse_message_edited
, unit_Parse_message_with_broadcast
) where

import TzPrelude
Expand Down Expand Up @@ -58,6 +59,7 @@ unit_Parse_message_channel_join_events = do
}
)

-- | These events happen when a user sends a message to a channel and then edits it.
unit_Parse_message_edited :: Assertion
unit_Parse_message_edited =
parseEither @_ @MessageEvent parseJSON [aesonQQ|
Expand Down Expand Up @@ -212,3 +214,186 @@ unit_Parse_message_edited =
)
}
)

-- | These events happen when a user replies in a thread
-- and checks the "Also send to #channel" checkbox.
unit_Parse_message_with_broadcast :: Assertion
unit_Parse_message_with_broadcast =
parseEither @_ @MessageEvent parseJSON [aesonQQ|
{
"channel": "C02N85E82LV",
"channel_type": "channel",
"event_ts": "1694190804.002600",
"hidden": true,
"message": {
"blocks": [
{
"block_id": "kke",
"elements": [
{
"elements": [
{
"text": "This is a message with broadcast",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"client_msg_id": "203315b8-f848-475c-b0b5-da0db4acd993",
"root": {
"blocks": [
{
"block_id": "Sr5",
"elements": [
{
"elements": [
{
"text": "First message",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"client_msg_id": "2e3a25aa-4b9e-4c78-bef0-be3b8656a53d",
"is_locked": false,
"latest_reply": "1694190803.567119",
"reply_count": 1,
"reply_users": [
"U02N85E78QM"
],
"reply_users_count": 1,
"team": "T02NDBHSWSG",
"text": "First message",
"thread_ts": "1694190770.058699",
"ts": "1694190770.058699",
"type": "message",
"user": "U02N85E78QM"
},
"subtype": "thread_broadcast",
"text": "This is a message with broadcast",
"thread_ts": "1694190770.058699",
"ts": "1694190803.567119",
"type": "message",
"user": "U02N85E78QM"
},
"previous_message": {
"blocks": [
{
"block_id": "kke",
"elements": [
{
"elements": [
{
"text": "This is a message with broadcast",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"client_msg_id": "203315b8-f848-475c-b0b5-da0db4acd993",
"root": {
"blocks": [
{
"block_id": "Sr5",
"elements": [
{
"elements": [
{
"text": "First message",
"type": "text"
}
],
"type": "rich_text_section"
}
],
"type": "rich_text"
}
],
"client_msg_id": "2e3a25aa-4b9e-4c78-bef0-be3b8656a53d",
"is_locked": false,
"latest_reply": "1694190803.567119",
"reply_count": 1,
"reply_users": [
"U02N85E78QM"
],
"reply_users_count": 1,
"team": "T02NDBHSWSG",
"text": "First message",
"thread_ts": "1694190770.058699",
"ts": "1694190770.058699",
"type": "message",
"user": "U02N85E78QM"
},
"subtype": "thread_broadcast",
"text": "This is a message with broadcast",
"thread_ts": "1694190770.058699",
"ts": "1694190803.567119",
"type": "message",
"user": "U02N85E78QM"
},
"subtype": "message_changed",
"ts": "1694190804.002600",
"type": "message"
}
|] @?= Right
( MessageEvent
{ meChannel = ChannelId
{ unChannelId = "C02N85E82LV" }
, meChannelType = Just CTChannel
, meMessage = Message
{ mUser = UserId
{ unUserId = "U02N85E78QM" }
, mText = "This is a message with broadcast"
, mMessageId = MessageId
{ unMessageId = "1694190803.567119" }
, mTs = read "2023-09-08 16:33:23.567119 UTC"
, mThreadId = Just
( ThreadId
{ unThreadId = "1694190770.058699" }
)
, mEdited = False
, mSubType = Just "thread_broadcast"
, 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 message with broadcast"
, etStyle = Nothing
}
)
)
}
]
}
)
]
}
]
}
)
}
, meTs = read "2023-09-08 16:33:24.0026 UTC"
, meMessageDetails = MDMessageBroadcast
}
)

0 comments on commit b2549e3

Please sign in to comment.