mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-04 04:46:04 +00:00
79 lines
2.6 KiB
Haskell
79 lines
2.6 KiB
Haskell
{-# LANGUAGE BlockArguments #-}
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module AgentTests.SQLite where
|
|
|
|
import qualified Database.SQLite.Simple as DB
|
|
import Simplex.Messaging.Agent.Store
|
|
import Simplex.Messaging.Agent.Store.SQLite
|
|
import Simplex.Messaging.Agent.Transmission
|
|
import Test.Hspec
|
|
import UnliftIO.Directory
|
|
|
|
testDB :: String
|
|
testDB = "smp-agent.test.db"
|
|
|
|
withStore :: SpecWith SQLiteStore -> Spec
|
|
withStore =
|
|
beforeAll (newSQLiteStore testDB)
|
|
. afterAll (\store -> DB.close (conn store) >> removeFile testDB)
|
|
|
|
storeTests :: Spec
|
|
storeTests = withStore do
|
|
describe "store methods" do
|
|
describe "createRcvConn" testCreateRcvConn
|
|
describe "createSndConn" testCreateSndConn
|
|
|
|
testCreateRcvConn :: SpecWith SQLiteStore
|
|
testCreateRcvConn = do
|
|
it "should create receive connection and add send queue" $ \store -> do
|
|
let rcvQueue =
|
|
ReceiveQueue
|
|
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
|
rcvId = "1234",
|
|
rcvPrivateKey = "abcd",
|
|
sndId = Just "5678",
|
|
sndKey = Nothing,
|
|
decryptKey = "dcba",
|
|
verifyKey = Nothing,
|
|
status = New,
|
|
ackMode = AckMode On
|
|
}
|
|
createRcvConn store "1" rcvQueue
|
|
`shouldReturn` Right (ReceiveConnection "1" rcvQueue)
|
|
getConn store "1"
|
|
`shouldReturn` Right (SomeConn SCReceive $ ReceiveConnection "1" rcvQueue)
|
|
let sndQueue =
|
|
SendQueue
|
|
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
|
sndId = "1234",
|
|
sndPrivateKey = "abcd",
|
|
encryptKey = "dcba",
|
|
signKey = "edcb",
|
|
status = New,
|
|
ackMode = AckMode On
|
|
}
|
|
addSndQueue store "1" sndQueue
|
|
`shouldReturn` Right (DuplexConnection "1" rcvQueue sndQueue)
|
|
getConn store "1"
|
|
`shouldReturn` Right (SomeConn SCDuplex $ DuplexConnection "1" rcvQueue sndQueue)
|
|
|
|
testCreateSndConn :: SpecWith SQLiteStore
|
|
testCreateSndConn = do
|
|
it "should create and get send connection" $ \store -> do
|
|
let sndQueue =
|
|
SendQueue
|
|
{ server = SMPServer "smp.simplex.im" (Just "5223") (Just "1234"),
|
|
sndId = "5678",
|
|
sndPrivateKey = "abcd",
|
|
encryptKey = "dcba",
|
|
signKey = "edcb",
|
|
status = New,
|
|
ackMode = AckMode On
|
|
}
|
|
createSndConn store "2" sndQueue
|
|
`shouldReturn` Right (SendConnection "2" sndQueue)
|
|
getConn store "2"
|
|
`shouldReturn` Right (SomeConn SCSend $ SendConnection "2" sndQueue)
|