From b2549e3c1c41975dc6c0c63c4ab8df9a3b6c574b Mon Sep 17 00:00:00 2001 From: Diogo Castro Date: Fri, 8 Sep 2023 17:38:48 +0100 Subject: [PATCH] fixup! [Chore] Add parser tests --- test/Test/TzBot/Slack/API/Parser.hs | 185 ++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) diff --git a/test/Test/TzBot/Slack/API/Parser.hs b/test/Test/TzBot/Slack/API/Parser.hs index 2e07b93..77f895b 100644 --- a/test/Test/TzBot/Slack/API/Parser.hs +++ b/test/Test/TzBot/Slack/API/Parser.hs @@ -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 @@ -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| @@ -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 + } + )