diff --git a/test/Test/TzBot/Slack/API/Parser.hs b/test/Test/TzBot/Slack/API/Parser.hs index 77f895b..31e138d 100644 --- a/test/Test/TzBot/Slack/API/Parser.hs +++ b/test/Test/TzBot/Slack/API/Parser.hs @@ -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 @@ -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|