@@ -69,6 +69,28 @@ serversEqualSpec = describe "serversEqual" $ do
6969 show err `shouldContain` "Body: 2"
7070 show err `shouldContain` "Path: /failplz"
7171
72+ context "when JSON is equal but looks a bit different as a ByteString" $ do
73+
74+ it "considers equal JSON apis equal regardless of ordering or whitespace" $ do
75+ withServantServerAndContext jsonApi ctx jsonServer1 $ \burl1 ->
76+ withServantServerAndContext jsonApi ctx jsonServer2 $ \burl2 ->
77+ serversEqual jsonApi burl1 burl2 args jsonEquality
78+
79+ it "sees when JSON apis are not equal regardless of ordering or whitespace" $ do
80+ Right (Failure _ err) <- withServantServer jsonApi jsonServer2 $ \burl1 ->
81+ withServantServer jsonApi jsonServer3 $ \burl2 -> do
82+ safeEvalExample $ serversEqual jsonApi burl1 burl2 args jsonEquality
83+ show err `shouldContain` "Server equality failed"
84+ show err `shouldContain` "Path: /jsonComparison"
85+
86+ it "sees when JSON apis are not equal due to different keys but same values" $ do
87+ Right (Failure _ err) <- withServantServer jsonApi jsonServer2 $ \burl1 ->
88+ withServantServer jsonApi jsonServer4 $ \burl2 -> do
89+ safeEvalExample $ serversEqual jsonApi burl1 burl2 args jsonEquality
90+ show err `shouldContain` "Server equality failed"
91+ show err `shouldContain` "Path: /jsonComparison"
92+
93+
7294serverSatisfiesSpec :: Spec
7395serverSatisfiesSpec = describe "serverSatisfies" $ do
7496
@@ -262,6 +284,24 @@ octetAPI = Proxy
262284serverOctetAPI :: IO (Server OctetAPI)
263285serverOctetAPI = return $ return "blah"
264286
287+type JsonApi = "jsonComparison" :> Get '[OctetStream] BS.ByteString
288+
289+jsonApi :: Proxy JsonApi
290+jsonApi = Proxy
291+
292+jsonServer1 :: IO (Server JsonApi)
293+jsonServer1 = return $ return "{ \"b\": [\"b\"], \"a\": 1 }" -- whitespace, ordering different
294+
295+jsonServer2 :: IO (Server JsonApi)
296+jsonServer2 = return $ return "{\"a\": 1,\"b\":[\"b\"]}"
297+
298+jsonServer3 :: IO (Server JsonApi)
299+jsonServer3 = return $ return "{\"a\": 2, \"b\": [\"b\"]}"
300+
301+jsonServer4 :: IO (Server JsonApi)
302+jsonServer4 = return $ return "{\"c\": 1, \"d\": [\"b\"]}"
303+
304+
265305ctx :: Context '[BasicAuthCheck ()]
266306ctx = BasicAuthCheck (const . return $ NoSuchUser) :. EmptyContext
267307------------------------------------------------------------------------------