{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PostfixOperators #-} module ChatTests.Files where import ChatClient import ChatTests.Utils import Control.Concurrent (threadDelay) import Control.Concurrent.Async (concurrently_) import qualified Data.ByteString.Char8 as B import Simplex.Chat.Controller (ChatConfig (..), InlineFilesConfig (..), XFTPFileConfig (..), defaultInlineFilesConfig) import Simplex.Chat.Options (ChatOpts (..)) import Simplex.FileTransfer.Client.Main (xftpClientCLI) import Simplex.Messaging.Util (unlessM) import System.Directory (copyFile, doesFileExist) import System.Environment (withArgs) import System.IO.Silently (capture_) import Test.Hspec chatFileTests :: SpecWith FilePath chatFileTests = do describe "sending and receiving files" $ do describe "send and receive file" $ fileTestMatrix2 runTestFileTransfer it "send and receive file inline (without accepting)" testInlineFileTransfer it "accept inline file transfer, sender cancels during transfer" testAcceptInlineFileSndCancelDuringTransfer it "send and receive small file inline (default config)" testSmallInlineFileTransfer it "small file sent without acceptance is ignored in terminal by default" testSmallInlineFileIgnored it "receive file inline with inline=on option" testReceiveInline describe "send and receive a small file" $ fileTestMatrix2 runTestSmallFileTransfer describe "sender cancelled file transfer before transfer" $ fileTestMatrix2 runTestFileSndCancelBeforeTransfer it "sender cancelled file transfer during transfer" testFileSndCancelDuringTransfer it "recipient cancelled file transfer" testFileRcvCancel describe "send and receive file to group" $ fileTestMatrix3 runTestGroupFileTransfer it "send and receive file inline to group (without accepting)" testInlineGroupFileTransfer it "send and receive small file inline to group (default config)" testSmallInlineGroupFileTransfer it "small file sent without acceptance is ignored in terminal by default" testSmallInlineGroupFileIgnored describe "sender cancelled group file transfer before transfer" $ fileTestMatrix3 runTestGroupFileSndCancelBeforeTransfer describe "messages with files" $ do describe "send and receive message with file" $ fileTestMatrix2 runTestMessageWithFile it "send and receive image" testSendImage it "files folder: send and receive image" testFilesFoldersSendImage it "files folder: sender deleted file during transfer" testFilesFoldersImageSndDelete it "files folder: recipient deleted file during transfer" testFilesFoldersImageRcvDelete it "send and receive image with text and quote" testSendImageWithTextAndQuote describe "send and receive image to group" testGroupSendImage it "send and receive image with text and quote to group" testGroupSendImageWithTextAndQuote describe "async sending and receiving files" $ do it "send and receive file, sender restarts" testAsyncFileTransferSenderRestarts it "send and receive file, receiver restarts" testAsyncFileTransferReceiverRestarts xdescribe "send and receive file, fully asynchronous" $ do it "v2" testAsyncFileTransfer it "v1" testAsyncFileTransferV1 xit "send and receive file to group, fully asynchronous" testAsyncGroupFileTransfer describe "file transfer over XFTP" $ do it "send and receive file" testXFTPFileTransfer it "send and receive file in group" testXFTPGroupFileTransfer it "with changed XFTP config: send and receive file" testXFTPWithChangedConfig it "with relative paths: send and receive file" testXFTPWithRelativePaths it "continue receiving file after restart" testXFTPContinueRcv it "cancel receiving file, repeat receive" testXFTPCancelRcvRepeat runTestFileTransfer :: HasCallStack => TestCC -> TestCC -> IO () runTestFileTransfer alice bob = do connectUsers alice bob startFileTransfer' alice bob "test.pdf" "266.0 KiB / 272376 bytes" concurrentlyN_ [ do bob #> "@alice receiving here..." bob <## "completed receiving file 1 (test.pdf) from alice", alice <### [ WithTime "bob> receiving here...", "completed sending file 1 (test.pdf) to bob" ] ] src <- B.readFile "./tests/fixtures/test.pdf" dest <- B.readFile "./tests/tmp/test.pdf" dest `shouldBe` src testInlineFileTransfer :: HasCallStack => FilePath -> IO () testInlineFileTransfer = testChatCfg2 cfg aliceProfile bobProfile $ \alice bob -> do connectUsers alice bob bob ##> "/_files_folder ./tests/tmp/" bob <## "ok" alice ##> "/_send @2 json {\"msgContent\":{\"type\":\"voice\", \"duration\":10, \"text\":\"\"}, \"filePath\":\"./tests/fixtures/test.jpg\"}" alice <# "@bob voice message (00:10)" alice <# "/f @bob ./tests/fixtures/test.jpg" -- below is not shown in "sent" mode -- alice <## "use /fc 1 to cancel sending" bob <# "alice> voice message (00:10)" bob <# "alice> sends file test.jpg (136.5 KiB / 139737 bytes)" -- below is not shown in "sent" mode -- bob <## "use /fr 1 [