mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-15 02:21:08 +00:00
core: don't show no connections diff on event (fix tests) (#6403)
* different approach * fix tests
This commit is contained in:
@@ -76,8 +76,8 @@ toDBOpts ChatDbOpts {dbFilePrefix, dbKey, trackQueries, vacuumOnMigration} dbSuf
|
||||
{ dbFilePath = dbFilePrefix <> dbSuffix,
|
||||
dbKey,
|
||||
keepKey,
|
||||
track = trackQueries,
|
||||
vacuum = vacuumOnMigration
|
||||
vacuum = vacuumOnMigration,
|
||||
track = trackQueries
|
||||
}
|
||||
|
||||
chatSuffix :: String
|
||||
|
||||
@@ -1422,21 +1422,30 @@ viewUserPrivacy User {userId} User {userId = userId', localDisplayName = n', sho
|
||||
]
|
||||
|
||||
viewConnDiffSync :: DatabaseDiff AgentUserId -> DatabaseDiff AgentConnId -> [StyledString]
|
||||
viewConnDiffSync userDiff connDiff =
|
||||
viewConnDiffSummary userDiff connDiff
|
||||
<> ["removed extra users in agent" | not (null $ extraIds userDiff)]
|
||||
<> ["removed extra connections in agent" | not (null $ extraIds connDiff)]
|
||||
viewConnDiffSync userDiff connDiff
|
||||
| noDiff userDiff && noDiff connDiff = []
|
||||
| otherwise =
|
||||
viewConnDiffSummary' userDiff connDiff
|
||||
<> ["removed extra users in agent" | not (null $ extraIds userDiff)]
|
||||
<> ["removed extra connections in agent" | not (null $ extraIds connDiff)]
|
||||
where
|
||||
noDiff DatabaseDiff {missingIds, extraIds} = null missingIds && null extraIds
|
||||
|
||||
viewConnDiffSummary :: DatabaseDiff AgentUserId -> DatabaseDiff AgentConnId -> [StyledString]
|
||||
viewConnDiffSummary userDiff connDiff
|
||||
| noDiff userDiff && noDiff connDiff =
|
||||
["no difference between agent and chat connections"]
|
||||
| otherwise =
|
||||
["connections difference summary:"]
|
||||
<> showDatabaseDiff "users" userDiff
|
||||
<> showDatabaseDiff "connections" connDiff
|
||||
viewConnDiffSummary' userDiff connDiff
|
||||
where
|
||||
noDiff DatabaseDiff {missingIds, extraIds} = null missingIds && null extraIds
|
||||
|
||||
viewConnDiffSummary' :: DatabaseDiff AgentUserId -> DatabaseDiff AgentConnId -> [StyledString]
|
||||
viewConnDiffSummary' userDiff connDiff =
|
||||
["connections difference summary:"]
|
||||
<> showDatabaseDiff "users" userDiff
|
||||
<> showDatabaseDiff "connections" connDiff
|
||||
where
|
||||
showDatabaseDiff name DatabaseDiff {missingIds, extraIds} =
|
||||
["number of missing " <> name <> " in agent: " <> sShow (length missingIds) | not (null missingIds)]
|
||||
<> ["number of extra " <> name <> " in agent: " <> sShow (length extraIds) | not (null extraIds)]
|
||||
|
||||
@@ -28,6 +28,12 @@ chatStartedSwift = "{\"result\":{\"_owsf\":true,\"chatStarted\":{}}}"
|
||||
chatStartedTagged :: LB.ByteString
|
||||
chatStartedTagged = "{\"result\":{\"type\":\"chatStarted\"}}"
|
||||
|
||||
connectionsDiffSwift :: LB.ByteString
|
||||
connectionsDiffSwift = "{\"result\":{\"_owsf\":true,\"connectionsDiff\":{\"userIds\":{\"missingIds\":[],\"extraIds\":[]},\"connIds\":{\"missingIds\":[],\"extraIds\":[]}}}}"
|
||||
|
||||
connectionsDiffTagged :: LB.ByteString
|
||||
connectionsDiffTagged = "{\"result\":{\"type\":\"connectionsDiff\",\"userIds\":{\"missingIds\":[],\"extraIds\":[]},\"connIds\":{\"missingIds\":[],\"extraIds\":[]}}}"
|
||||
|
||||
userJSON :: LB.ByteString
|
||||
userJSON = "{\"userId\":1,\"agentUserId\":\"1\",\"userContactId\":1,\"localDisplayName\":\"alice\",\"profile\":{\"profileId\":1,\"displayName\":\"alice\",\"fullName\":\"\",\"shortDescr\":\"Alice\",\"localAlias\":\"\"},\"fullPreferences\":{\"timedMessages\":{\"allow\":\"yes\"},\"fullDelete\":{\"allow\":\"no\"},\"reactions\":{\"allow\":\"yes\"},\"voice\":{\"allow\":\"yes\"},\"files\":{\"allow\":\"always\"},\"calls\":{\"allow\":\"yes\"},\"sessions\":{\"allow\":\"no\"},\"commands\":[]},\"activeUser\":true,\"activeOrder\":1,\"showNtfs\":true,\"sendRcptsContacts\":true,\"sendRcptsSmallGroups\":true,\"autoAcceptMemberContacts\":false}"
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ owsf2TaggedJSONTest = do
|
||||
activeUserExistsSwift `to` activeUserExistsTagged
|
||||
activeUserSwift `to` activeUserTagged
|
||||
chatStartedSwift `to` chatStartedTagged
|
||||
connectionsDiffSwift `to` connectionsDiffTagged
|
||||
parsedMarkdownSwift `to` parsedMarkdownTagged
|
||||
where
|
||||
to :: LB.ByteString -> LB.ByteString -> IO ()
|
||||
|
||||
+17
-5
@@ -1,4 +1,6 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
@@ -7,6 +9,7 @@
|
||||
|
||||
module MobileTests (mobileTests) where
|
||||
|
||||
import ChatClient
|
||||
import ChatTests.DBUtils
|
||||
import ChatTests.Utils
|
||||
import Control.Concurrent.STM
|
||||
@@ -28,7 +31,8 @@ import Foreign.StablePtr
|
||||
import Foreign.Storable (peek)
|
||||
import GHC.IO.Encoding (setLocaleEncoding, setFileSystemEncoding, setForeignEncoding)
|
||||
import JSONFixtures
|
||||
import Simplex.Chat.Controller (ChatController (..))
|
||||
import Simplex.Chat
|
||||
import Simplex.Chat.Controller (ChatController (..), ChatDatabase (..))
|
||||
import Simplex.Chat.Mobile hiding (error)
|
||||
import Simplex.Chat.Mobile.File
|
||||
import Simplex.Chat.Mobile.Shared
|
||||
@@ -37,7 +41,6 @@ import Simplex.Chat.Options.DB
|
||||
import Simplex.Chat.Store
|
||||
import Simplex.Chat.Store.Profiles
|
||||
import Simplex.Chat.Types (AgentUserId (..), Profile (..))
|
||||
import Simplex.Messaging.Agent.Store.Interface
|
||||
import Simplex.Messaging.Agent.Store.Shared (MigrationConfig (..), MigrationConfirmation (..))
|
||||
import qualified Simplex.Messaging.Agent.Store.SQLite.DB as DB
|
||||
import qualified Simplex.Messaging.Crypto as C
|
||||
@@ -111,6 +114,14 @@ chatStarted =
|
||||
chatStartedTagged
|
||||
#endif
|
||||
|
||||
connectionsDiff :: LB.ByteString
|
||||
connectionsDiff =
|
||||
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
||||
connectionsDiffSwift
|
||||
#else
|
||||
connectionsDiffTagged
|
||||
#endif
|
||||
|
||||
parsedMarkdown :: LB.ByteString
|
||||
parsedMarkdown =
|
||||
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
||||
@@ -134,15 +145,16 @@ testChatApi :: TestParams -> IO ()
|
||||
testChatApi ps = do
|
||||
let tmp = tmpPath ps
|
||||
dbPrefix = tmp </> "1"
|
||||
f = dbPrefix <> chatSuffix
|
||||
Right st <- createChatStore (DBOpts f "myKey" False True DB.TQOff) (MigrationConfig MCYesUp Nothing)
|
||||
Right _ <- withTransaction st $ \db -> runExceptT $ createUserRecord db (AgentUserId 1) aliceProfile {preferences = Nothing} True
|
||||
Right ChatDatabase {chatStore, agentStore} <- createChatDatabase (ChatDbOpts dbPrefix "myKey" DB.TQOff True) (MigrationConfig MCYesUp Nothing)
|
||||
insertUser agentStore
|
||||
Right _ <- withTransaction chatStore $ \db -> runExceptT $ createUserRecord db (AgentUserId 1) aliceProfile {preferences = Nothing} True
|
||||
Right cc <- chatMigrateInit dbPrefix "myKey" "yesUp"
|
||||
Left (DBMErrorNotADatabase _) <- chatMigrateInit dbPrefix "" "yesUp"
|
||||
Left (DBMErrorNotADatabase _) <- chatMigrateInit dbPrefix "anotherKey" "yesUp"
|
||||
chatSendCmd cc "/u" `shouldReturn` activeUser
|
||||
chatSendCmd cc "/create user alice Alice" `shouldReturn` activeUserExists
|
||||
chatSendCmd cc "/_start" `shouldReturn` chatStarted
|
||||
chatRecvMsg cc `shouldReturn` connectionsDiff
|
||||
chatRecvMsgWait cc 10000 `shouldReturn` ""
|
||||
chatParseMarkdown "hello" `shouldBe` "{}"
|
||||
chatParseMarkdown "*hello*" `shouldBe` parsedMarkdown
|
||||
|
||||
Reference in New Issue
Block a user