2022-02-16 23:24:48 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2022-02-06 16:18:01 +00:00
|
|
|
|
|
|
|
module MobileTests where
|
|
|
|
|
|
|
|
import ChatClient
|
|
|
|
import ChatTests
|
|
|
|
import Control.Monad.Except
|
|
|
|
import Simplex.Chat.Mobile
|
|
|
|
import Simplex.Chat.Store
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
mobileTests :: Spec
|
|
|
|
mobileTests = do
|
|
|
|
describe "mobile API" $ do
|
|
|
|
it "start new chat without user" testChatApiNoUser
|
|
|
|
it "start new chat with existing user" testChatApi
|
|
|
|
|
|
|
|
noActiveUser :: String
|
2022-04-12 12:24:34 +01:00
|
|
|
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
2022-02-06 16:18:01 +00:00
|
|
|
noActiveUser = "{\"resp\":{\"chatCmdError\":{\"chatError\":{\"error\":{\"errorType\":{\"noActiveUser\":{}}}}}}}"
|
2022-02-16 23:24:48 +00:00
|
|
|
#else
|
|
|
|
noActiveUser = "{\"resp\":{\"type\":\"chatCmdError\",\"chatError\":{\"type\":\"error\",\"errorType\":{\"type\":\"noActiveUser\"}}}}"
|
|
|
|
#endif
|
2022-02-06 16:18:01 +00:00
|
|
|
|
|
|
|
activeUserExists :: String
|
2022-04-12 12:24:34 +01:00
|
|
|
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
2022-02-06 16:18:01 +00:00
|
|
|
activeUserExists = "{\"resp\":{\"chatCmdError\":{\"chatError\":{\"error\":{\"errorType\":{\"activeUserExists\":{}}}}}}}"
|
2022-02-16 23:24:48 +00:00
|
|
|
#else
|
|
|
|
activeUserExists = "{\"resp\":{\"type\":\"chatCmdError\",\"chatError\":{\"type\":\"error\",\"errorType\":{\"type\":\"activeUserExists\"}}}}"
|
|
|
|
#endif
|
2022-02-06 16:18:01 +00:00
|
|
|
|
|
|
|
activeUser :: String
|
2022-04-12 12:24:34 +01:00
|
|
|
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
2022-02-06 16:18:01 +00:00
|
|
|
activeUser = "{\"resp\":{\"activeUser\":{\"user\":{\"userId\":1,\"userContactId\":1,\"localDisplayName\":\"alice\",\"profile\":{\"displayName\":\"alice\",\"fullName\":\"Alice\"},\"activeUser\":true}}}}"
|
2022-02-16 23:24:48 +00:00
|
|
|
#else
|
|
|
|
activeUser = "{\"resp\":{\"type\":\"activeUser\",\"user\":{\"userId\":1,\"userContactId\":1,\"localDisplayName\":\"alice\",\"profile\":{\"displayName\":\"alice\",\"fullName\":\"Alice\"},\"activeUser\":true}}}"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
chatStarted :: String
|
2022-04-12 12:24:34 +01:00
|
|
|
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
2022-02-16 23:24:48 +00:00
|
|
|
chatStarted = "{\"resp\":{\"chatStarted\":{}}}"
|
|
|
|
#else
|
|
|
|
chatStarted = "{\"resp\":{\"type\":\"chatStarted\"}}"
|
|
|
|
#endif
|
2022-02-06 16:18:01 +00:00
|
|
|
|
|
|
|
testChatApiNoUser :: IO ()
|
|
|
|
testChatApiNoUser = withTmpFiles $ do
|
|
|
|
cc <- chatInit testDBPrefix
|
|
|
|
chatSendCmd cc "/u" `shouldReturn` noActiveUser
|
|
|
|
chatSendCmd cc "/_start" `shouldReturn` noActiveUser
|
|
|
|
chatSendCmd cc "/u alice Alice" `shouldReturn` activeUser
|
2022-02-16 23:24:48 +00:00
|
|
|
chatSendCmd cc "/_start" `shouldReturn` chatStarted
|
2022-02-06 16:18:01 +00:00
|
|
|
|
|
|
|
testChatApi :: IO ()
|
|
|
|
testChatApi = withTmpFiles $ do
|
2022-05-05 10:37:53 +01:00
|
|
|
let f = chatStoreFile $ testDBPrefix <> "1"
|
2022-02-07 15:19:34 +04:00
|
|
|
st <- createStore f 1 True
|
2022-02-06 16:18:01 +00:00
|
|
|
Right _ <- runExceptT $ createUser st aliceProfile True
|
2022-05-05 10:37:53 +01:00
|
|
|
cc <- chatInit $ testDBPrefix <> "1"
|
2022-02-06 16:18:01 +00:00
|
|
|
chatSendCmd cc "/u" `shouldReturn` activeUser
|
|
|
|
chatSendCmd cc "/u alice Alice" `shouldReturn` activeUserExists
|
2022-02-16 23:24:48 +00:00
|
|
|
chatSendCmd cc "/_start" `shouldReturn` chatStarted
|