Skip to content

Commit

Permalink
make tests independent of JSON fields order (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Jan 17, 2022
1 parent fca063e commit aef697e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/ProtocolTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module ProtocolTests where

import qualified Data.Aeson as J
import Data.ByteString.Char8 (ByteString)
import Simplex.Chat.Protocol
import Simplex.Chat.Types
Expand Down Expand Up @@ -59,7 +60,9 @@ s ==# msg = do
parseAll strP s `shouldBe` Right (ChatMessage msg)

(#==) :: ByteString -> ChatMsgEvent -> Expectation
s #== msg = strEncode (ChatMessage msg) `shouldBe` s
s #== msg =
J.eitherDecodeStrict' (strEncode $ ChatMessage msg)
`shouldBe` (J.eitherDecodeStrict' s :: Either String J.Value)

(#==#) :: ByteString -> ChatMsgEvent -> Expectation
s #==# msg = do
Expand Down Expand Up @@ -109,7 +112,7 @@ decodeChatMessageTest = describe "Chat message encoding/decoding" $ do
#==# XGrpMemFwd MemberInfo {memberId = MemberId "\1\2\3\4", memberRole = GRAdmin, profile = testProfile} IntroInvitation {groupConnReq = testConnReq, directConnReq = testConnReq}
it "x.grp.mem.info" $
"{\"event\":\"x.grp.mem.info\",\"params\":{\"memberId\":\"AQIDBA==\",\"profile\":{\"fullName\":\"Alice\",\"displayName\":\"alice\"}}}"
#== XGrpMemInfo (MemberId "\1\2\3\4") testProfile
#==# XGrpMemInfo (MemberId "\1\2\3\4") testProfile
it "x.grp.mem.con" $ "{\"event\":\"x.grp.mem.con\",\"params\":{\"memberId\":\"AQIDBA==\"}}" #==# XGrpMemCon (MemberId "\1\2\3\4")
it "x.grp.mem.con.all" $ "{\"event\":\"x.grp.mem.con.all\",\"params\":{\"memberId\":\"AQIDBA==\"}}" #==# XGrpMemConAll (MemberId "\1\2\3\4")
it "x.grp.mem.del" $ "{\"event\":\"x.grp.mem.del\",\"params\":{\"memberId\":\"AQIDBA==\"}}" #==# XGrpMemDel (MemberId "\1\2\3\4")
Expand Down

0 comments on commit aef697e

Please sign in to comment.