Skip to content

Commit a0f974a

Browse files
committed
agent: tidy ConnectTarget tests
Three cosmetic cleanups flagged in code review: - Drop the vestigial () placeholder on decodesSuccessfully; use a prefix call instead of operator style. - Use Data.Either.isLeft instead of a local one-liner. - Add a symmetric CTLink JSON assertion to pin both branches of the wire shape, not just CTName.
1 parent d4757d3 commit a0f974a

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tests/CoreTests/ConnectTargetTests.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module CoreTests.ConnectTargetTests where
55

66
import AgentTests.ConnectionRequestTests (contactConnRequest, invConnRequest)
77
import qualified Data.Aeson as J
8+
import Data.Either (isLeft)
9+
import Data.Text.Encoding (decodeUtf8)
810
import Simplex.Messaging.Agent.Protocol (AConnectionLink (..), ConnectTarget (..), ConnectionLink (..), SConnectionMode (..))
911
import Simplex.Messaging.Encoding.String (strDecode, strEncode)
1012
import Test.Hspec hiding (fit, it)
@@ -29,11 +31,11 @@ connectTargetTests = describe "ConnectTarget" $ do
2931
describe "CTLink (connection link) round-trips" $ do
3032
it "parses simplex:/contact#… as CTLink and round-trips" $ do
3133
let s = strEncode (ACL SCMContact (CLFull contactConnRequest))
32-
s `decodesSuccessfully` ()
34+
decodesSuccessfully s
3335
s `encodesAs` s
3436
it "parses simplex:/invitation#… as CTLink" $ do
3537
let s = strEncode (ACL SCMInvitation (CLFull invConnRequest))
36-
s `decodesSuccessfully` ()
38+
decodesSuccessfully s
3739

3840
describe "rejects ambiguous bare input at this layer" $ do
3941
it "rejects bare 'alice' — no @, no #, no simplex:/name prefix" $
@@ -48,12 +50,16 @@ connectTargetTests = describe "ConnectTarget" $ do
4850
case strDecode @ConnectTarget "@alice.simplex" of
4951
Right ct -> J.toJSON ct `shouldBe` J.String "simplex:/name@alice.simplex"
5052
Left e -> expectationFailure $ "strDecode failed: " <> e
53+
it "encodes a CTLink as the canonical link JSON string" $ do
54+
let s = strEncode (ACL SCMContact (CLFull contactConnRequest))
55+
case strDecode @ConnectTarget s of
56+
Right ct -> J.toJSON ct `shouldBe` J.String (decodeUtf8 s)
57+
Left e -> expectationFailure $ "strDecode failed: " <> e
5158
it "parses JSON string back to ConnectTarget" $
5259
J.eitherDecode @ConnectTarget "\"@alice.simplex\""
5360
`shouldSatisfy` either (const False) (const True)
5461
where
5562
encodesAs input canonical =
5663
(strEncode <$> strDecode @ConnectTarget input) `shouldBe` Right canonical
57-
decodesSuccessfully s () =
64+
decodesSuccessfully s =
5865
strDecode @ConnectTarget s `shouldSatisfy` either (const False) (const True)
59-
isLeft = either (const True) (const False)

0 commit comments

Comments
 (0)