{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PostfixOperators #-} module ChatTests.Feed where import ChatClient import ChatTests.DBUtils import ChatTests.Utils import qualified Data.ByteString.Char8 as B import Simplex.Chat.Controller (ChatConfig (..)) import Test.Hspec hiding (it) chatFeedTests :: SpecWith TestParams chatFeedTests = do describe "feed" $ do it "broadcast to contacts and customer groups in several buckets" testFeedBuckets it "edit and delete the broadcast in every chat" testFeedEditDelete it "recipient with dropped feed receives nothing" testFeedDropped it "dropped feed keeps applying edits to earlier items" testFeedDroppedAfterReceiving it "instance edited in its chat is detached from the feed" testFeedDetached it "broadcast a file to all contacts" testFeedFile it "incognito contact is excluded from the broadcast" testFeedSkipsIncognito feedTestCfg :: ChatConfig feedTestCfg = testCfg {feedBucketSize = 1} testFeedBuckets :: HasCallStack => TestParams -> IO () testFeedBuckets = testChatCfg5 feedTestCfg businessProfile aliceProfile bobProfile cathProfile danProfile $ \biz alice bob cath dan -> do createCCFeed biz connectUsers biz alice connectUsers biz bob cLink <- businessAddress biz connectToBusiness biz cath cLink "cath" "Catherine" connectToBusiness biz dan cLink "dan" "Daniel" biz `send` "/feed hello everyone" biz <# "% hello everyone" alice <# "biz> hello everyone" bob <# "biz> hello everyone" cath <# "#biz biz_1> hello everyone" dan <# "#biz biz_1> hello everyone" chatItems biz "%1" 10 `shouldReturn` [(1, "hello everyone")] chatItems biz "@2" 1 `shouldReturn` [(1, "hello everyone")] chatItems biz "@3" 1 `shouldReturn` [(1, "hello everyone")] chatItems biz "#1" 1 `shouldReturn` [(1, "hello everyone")] chatItems biz "#2" 1 `shouldReturn` [(1, "hello everyone")] biz @@@ [("%", "hello everyone"), ("@alice", "hello everyone"), ("@bob", "hello everyone"), ("#cath", "hello everyone"), ("#dan", "hello everyone")] testFeedEditDelete :: HasCallStack => TestParams -> IO () testFeedEditDelete = testChatCfg4 feedTestCfg businessProfile aliceProfile bobProfile cathProfile $ \biz alice bob cath -> do createCCFeed biz connectUsers biz alice connectUsers biz bob cLink <- businessAddress biz connectToBusiness biz cath cLink "cath" "Catherine" biz `send` "/feed hello everyone" biz <# "% hello everyone" alice <# "biz> hello everyone" bob <# "biz> hello everyone" cath <# "#biz biz_1> hello everyone" biz ##> "! % (hello everyone) hello again" biz <# "% [edited] hello again" alice <# "biz> [edited] hello again" bob <# "biz> [edited] hello again" cath <# "#biz biz_1> [edited] hello again" chatItems biz "%1" 10 `shouldReturn` [(1, "hello again")] chatItems biz "@2" 1 `shouldReturn` [(1, "hello again")] chatItems biz "@3" 1 `shouldReturn` [(1, "hello again")] chatItems biz "#1" 1 `shouldReturn` [(1, "hello again")] biz ##> "\\ % hello again" biz <### [ConsoleString "message being deleted", ConsoleString "message deleted"] alice <# "biz> [marked deleted] hello again" bob <# "biz> [marked deleted] hello again" cath <# "#biz biz_1> [marked deleted] hello again" chatItems biz "%1" 10 `shouldReturn` [] chatItems biz "@2" 1 `shouldReturn` [(1, "hello again [marked deleted]")] chatItems biz "#1" 1 `shouldReturn` [(1, "hello again [marked deleted]")] testFeedDropped :: HasCallStack => TestParams -> IO () testFeedDropped = testChatCfg3 feedTestCfg businessProfile aliceProfile bobProfile $ \biz alice bob -> do createCCFeed biz connectUsers biz alice connectUsers biz bob bob ##> "/feed drop @biz on" bob <## "ok" biz `send` "/feed hello everyone" biz <# "% hello everyone" alice <# "biz> hello everyone" (bob ) chatItems bob "@2" 1 `shouldReturn` [(0, "Audio/video calls: enabled")] biz ##> "! % (hello everyone) hello again" biz <# "% [edited] hello again" alice <# "biz> [edited] hello again" (bob ) biz ##> "\\ % hello again" biz <### [ConsoleString "message being deleted", ConsoleString "message deleted"] alice <# "biz> [marked deleted] hello again" (bob ) chatItems bob "@2" 1 `shouldReturn` [(0, "Audio/video calls: enabled")] testFeedDroppedAfterReceiving :: HasCallStack => TestParams -> IO () testFeedDroppedAfterReceiving = testChatCfg3 feedTestCfg businessProfile aliceProfile cathProfile $ \biz alice cath -> do createCCFeed biz connectUsers biz alice cLink <- businessAddress biz connectToBusiness biz cath cLink "cath" "Catherine" biz `send` "/feed hello everyone" biz <# "% hello everyone" alice <# "biz> hello everyone" cath <# "#biz biz_1> hello everyone" alice ##> "/feed drop @biz on" alice <## "ok" cath ##> "/feed drop #biz on" cath <## "ok" biz `send` "/feed second" biz <# "% second" (alice ) (cath ) biz ##> "! % (hello everyone) hello again" biz <# "% [edited] hello again" alice <# "biz> [edited] hello again" cath <# "#biz biz_1> [edited] hello again" chatItems alice "@2" 100 >>= (`shouldContain` [(0, "hello again")]) chatItems cath "#1" 100 >>= (`shouldContain` [(0, "hello again")]) testFeedDetached :: HasCallStack => TestParams -> IO () testFeedDetached = testChatCfg3 feedTestCfg businessProfile aliceProfile bobProfile $ \biz alice bob -> do createCCFeed biz connectUsers biz alice connectUsers biz bob biz `send` "/feed hello everyone" biz <# "% hello everyone" alice <# "biz> hello everyone" bob <# "biz> hello everyone" biz ##> "! @alice (hello everyone) hello alice" biz <# "@alice [edited] hello alice" alice <# "biz> [edited] hello alice" biz ##> "! % (hello everyone) hello again" biz <# "% [edited] hello again" bob <# "biz> [edited] hello again" (alice ) chatItems biz "%1" 10 `shouldReturn` [(1, "hello again")] chatItems biz "@2" 1 `shouldReturn` [(1, "hello alice")] chatItems biz "@3" 1 `shouldReturn` [(1, "hello again")] testFeedFile :: HasCallStack => TestParams -> IO () testFeedFile = testChatCfg3 feedTestCfg businessProfile aliceProfile bobProfile $ \biz alice bob -> withXFTPServer $ do createCCFeed biz connectUsers biz alice connectUsers biz bob biz #> "/f % ./tests/fixtures/test.pdf" biz <## "use /fc 1 to cancel sending" alice <# "biz> sends file test.pdf (266.0 KiB / 272376 bytes)" alice <## "use /fr 1 [