add explicit createCCNoteFolder for tests
This commit is contained in:
parent
185a8fdbd0
commit
5ba6b9554b
@ -26,7 +26,6 @@ import Simplex.Chat.Controller (ChatConfig (..), ChatController (..), ChatDataba
|
||||
import Simplex.Chat.Core
|
||||
import Simplex.Chat.Options
|
||||
import Simplex.Chat.Store
|
||||
import Simplex.Chat.Store.NoteFolders (createNoteFolder)
|
||||
import Simplex.Chat.Store.Profiles
|
||||
import Simplex.Chat.Terminal
|
||||
import Simplex.Chat.Terminal.Output (newChatTerminal)
|
||||
@ -192,10 +191,7 @@ groupLinkViaContactVRange = mkVersionRange 1 2
|
||||
createTestChat :: FilePath -> ChatConfig -> ChatOpts -> String -> Profile -> IO TestCC
|
||||
createTestChat tmp cfg opts@ChatOpts {coreOptions = CoreChatOpts {dbKey}} dbPrefix profile = do
|
||||
Right db@ChatDatabase {chatStore} <- createChatDatabase (tmp </> dbPrefix) dbKey False MCError
|
||||
Right user <- withTransaction chatStore $ \db' -> runExceptT $ do
|
||||
user <- createUserRecord db' (AgentUserId 1) profile True
|
||||
createNoteFolder db' user
|
||||
pure user
|
||||
Right user <- withTransaction chatStore $ \db' -> runExceptT $ createUserRecord db' (AgentUserId 1) profile True
|
||||
startTestChat_ db cfg opts user
|
||||
|
||||
startTestChat :: FilePath -> ChatConfig -> ChatOpts -> String -> IO TestCC
|
||||
|
@ -193,9 +193,9 @@ testPaginationAllChatTypes =
|
||||
|
||||
_ts6 <- iso8601Show <$> getCurrentTime
|
||||
|
||||
-- $notes
|
||||
alice `send` "/- psst"
|
||||
dropTime <$> getTermLine alice `shouldReturn` "- psst"
|
||||
-- -notes
|
||||
createCCNoteFolder alice
|
||||
alice /- "psst"
|
||||
|
||||
ts7 <- iso8601Show <$> getCurrentTime
|
||||
|
||||
|
@ -23,6 +23,8 @@ chatLocalTests = do
|
||||
|
||||
testNotes :: FilePath -> IO ()
|
||||
testNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
createCCNoteFolder alice
|
||||
|
||||
alice ##> "/contacts"
|
||||
-- not a contact
|
||||
|
||||
@ -50,6 +52,8 @@ testNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
|
||||
testUserNotes :: FilePath -> IO ()
|
||||
testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
createCCNoteFolder alice
|
||||
|
||||
alice /- "keep in mind"
|
||||
alice ##> "/tail"
|
||||
alice <# "- keep in mind"
|
||||
@ -66,6 +70,8 @@ testUserNotes tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
|
||||
testPreviewsPagination :: FilePath -> IO ()
|
||||
testPreviewsPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
createCCNoteFolder alice
|
||||
|
||||
tsS <- iso8601Show <$> getCurrentTime
|
||||
alice /- "first"
|
||||
tsM <- iso8601Show <$> getCurrentTime
|
||||
@ -82,6 +88,8 @@ testPreviewsPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -
|
||||
|
||||
testChatPagination :: FilePath -> IO ()
|
||||
testChatPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
createCCNoteFolder alice
|
||||
|
||||
alice /- "hello world"
|
||||
alice /- "memento mori"
|
||||
alice /- "knock-knock"
|
||||
@ -99,6 +107,7 @@ testChatPagination tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
testFiles :: FilePath -> IO ()
|
||||
testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
-- setup
|
||||
createCCNoteFolder alice
|
||||
let files = "./tests/tmp/app_files"
|
||||
alice ##> ("/_files_folder " <> files)
|
||||
alice <## "ok"
|
||||
@ -138,8 +147,3 @@ testFiles tmp = withNewTestChat tmp "alice" aliceProfile $ \alice -> do
|
||||
alice <## "chat db error: SEChatItemNotFoundByFileId {fileId = 1}"
|
||||
alice ##> "/tail"
|
||||
doesFileExist stored `shouldReturn` False
|
||||
|
||||
(/-) :: HasCallStack => TestCC -> String -> IO ()
|
||||
cc /- note = do
|
||||
cc `send` ("/- " <> note)
|
||||
(dropTime <$> getTermLine cc) `shouldReturn` ("- " <> note)
|
||||
|
@ -11,6 +11,7 @@ import Control.Concurrent (threadDelay)
|
||||
import Control.Concurrent.Async (concurrently_)
|
||||
import Control.Concurrent.STM
|
||||
import Control.Monad (unless, when)
|
||||
import Control.Monad.Except (runExceptT)
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Char (isDigit)
|
||||
import Data.List (isPrefixOf, isSuffixOf)
|
||||
@ -20,6 +21,7 @@ import qualified Data.Text as T
|
||||
import Database.SQLite.Simple (Only (..))
|
||||
import Simplex.Chat.Controller (ChatConfig (..), ChatController (..), InlineFilesConfig (..), defaultInlineFilesConfig)
|
||||
import Simplex.Chat.Protocol
|
||||
import Simplex.Chat.Store.NoteFolders (createNoteFolder)
|
||||
import Simplex.Chat.Store.Profiles (getUserContactProfiles)
|
||||
import Simplex.Chat.Types
|
||||
import Simplex.Chat.Types.Preferences
|
||||
@ -287,6 +289,11 @@ cc <##.. ls = do
|
||||
unless prefix $ print ("expected to start from one of: " <> show ls, ", got: " <> l)
|
||||
prefix `shouldBe` True
|
||||
|
||||
(/-) :: HasCallStack => TestCC -> String -> IO ()
|
||||
cc /- note = do
|
||||
cc `send` ("/- " <> note)
|
||||
(dropTime <$> getTermLine cc) `shouldReturn` ("- " <> note)
|
||||
|
||||
data ConsoleResponse
|
||||
= ConsoleString String
|
||||
| WithTime String
|
||||
@ -462,6 +469,12 @@ withCCTransaction :: TestCC -> (DB.Connection -> IO a) -> IO a
|
||||
withCCTransaction cc action =
|
||||
withTransaction (chatStore $ chatController cc) $ \db -> action db
|
||||
|
||||
createCCNoteFolder :: TestCC -> IO ()
|
||||
createCCNoteFolder cc =
|
||||
withCCTransaction cc $ \db ->
|
||||
withCCUser cc $ \user ->
|
||||
runExceptT (createNoteFolder db user) >>= either (fail . show) pure
|
||||
|
||||
getProfilePictureByName :: TestCC -> String -> IO (Maybe String)
|
||||
getProfilePictureByName cc displayName =
|
||||
withTransaction (chatStore $ chatController cc) $ \db ->
|
||||
|
Loading…
Reference in New Issue
Block a user