-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
777ee7e
commit 706b14d
Showing
5 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-} | ||
|
||
module OperatorTests (operatorTests) where | ||
|
||
import qualified Data.List.NonEmpty as L | ||
import Simplex.Chat | ||
import Simplex.Chat.Operators | ||
import Simplex.Chat.Types | ||
import Simplex.FileTransfer.Client.Presets (defaultXFTPServers) | ||
import Simplex.Messaging.Agent.Env.SQLite (ServerRoles (..), allRoles) | ||
import Simplex.Messaging.Protocol | ||
import Test.Hspec | ||
|
||
operatorTests :: Spec | ||
operatorTests = describe "managing server operators" $ do | ||
validateServers | ||
|
||
validateServers :: Spec | ||
validateServers = describe "validate user servers" $ do | ||
it "should pass valid user servers" $ validateUserServers [valid] [] `shouldBe` [] | ||
it "should fail without servers" $ do | ||
validateUserServers [invalidNoServers] [] `shouldBe` [USENoServers aSMP Nothing] | ||
validateUserServers [invalidDisabled] [] `shouldBe` [USENoServers aSMP Nothing] | ||
validateUserServers [invalidDisabledOp] [] `shouldBe` [USENoServers aSMP Nothing, USENoServers aXFTP Nothing] | ||
it "should fail without servers with storage role" $ do | ||
validateUserServers [invalidNoStorage] [] `shouldBe` [USEStorageMissing aSMP Nothing, USEStorageMissing aXFTP Nothing] | ||
it "should fail with duplicate host" $ do | ||
validateUserServers [invalidDuplicate] [] `shouldBe` | ||
[ USEDuplicateServer aSMP "smp://[email protected],beccx4yfxxbvyhqypaavemqurytl6hozr47wfc7uuecacjqdvwpw2xid.onion" "smp8.simplex.im", | ||
USEDuplicateServer aSMP "smp://[email protected]" "smp8.simplex.im" | ||
] | ||
it "should fail with invalid host" $ do | ||
validateUserServers [invalidHost] [] `shouldBe` [USENoServers aXFTP Nothing, USEInvalidServer aSMP "smp:[email protected]"] | ||
where | ||
aSMP = AProtocolType SPSMP | ||
aXFTP = AProtocolType SPXFTP | ||
|
||
deriving instance Eq User | ||
|
||
deriving instance Eq UserServersError | ||
|
||
valid :: UpdatedUserOperatorServers | ||
valid = | ||
UpdatedUserOperatorServers | ||
{ operator = Just operatorSimpleXChat {operatorId = DBEntityId 1}, | ||
smpServers = map (AUS SDBNew) simplexChatSMPServers, | ||
xftpServers = map (AUS SDBNew . presetServer True) $ L.toList defaultXFTPServers | ||
} | ||
|
||
invalidNoServers :: UpdatedUserOperatorServers | ||
invalidNoServers = (valid :: UpdatedUserOperatorServers) {smpServers = []} | ||
|
||
invalidDisabled :: UpdatedUserOperatorServers | ||
invalidDisabled = | ||
(valid :: UpdatedUserOperatorServers) | ||
{ smpServers = map (AUS SDBNew . (\srv -> (srv :: NewUserServer 'PSMP) {enabled = False})) simplexChatSMPServers | ||
} | ||
|
||
invalidDisabledOp :: UpdatedUserOperatorServers | ||
invalidDisabledOp = | ||
(valid :: UpdatedUserOperatorServers) | ||
{ operator = Just operatorSimpleXChat {operatorId = DBEntityId 1, enabled = False} | ||
} | ||
|
||
invalidNoStorage :: UpdatedUserOperatorServers | ||
invalidNoStorage = | ||
(valid :: UpdatedUserOperatorServers) | ||
{ operator = Just operatorSimpleXChat {operatorId = DBEntityId 1, roles = allRoles {storage = False}} | ||
} | ||
|
||
invalidDuplicate :: UpdatedUserOperatorServers | ||
invalidDuplicate = | ||
(valid :: UpdatedUserOperatorServers) | ||
{ smpServers = map (AUS SDBNew) $ simplexChatSMPServers <> [presetServer True "smp://[email protected]"] | ||
} | ||
|
||
invalidHost :: ValidatedUserOperatorServers | ||
invalidHost = | ||
ValidatedUserOperatorServers | ||
{ operator = Just operatorSimpleXChat {operatorId = DBEntityId 1}, | ||
smpServers = [validatedServer (Left "smp:[email protected]"), validatedServer (Right "smp://[email protected]")], | ||
xftpServers = [] | ||
} | ||
where | ||
validatedServer srv = | ||
AVS SDBNew (presetServer @'PSMP True "smp://[email protected]") {server = ValidatedProtoServer srv} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters