1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# OPTIONS_GHC -Wno-missing-signatures #-}
4 module Hspec.Client.Raw where
6 import Data.Either (Either(..))
7 import Data.Function (($))
11 import Test.Tasty.Hspec
12 import Test.Tasty.HUnit (assertFailure)
13 import Text.Show (Show(..))
14 import qualified Network.HTTP.Client as Client
15 import qualified Network.HTTP.Types as HTTP
16 import qualified Network.Wai as Wai
19 import Symantic.HTTP.Client
20 import Symantic.HTTP.Server
22 import Hspec.Utils.Server
24 api = "success" </> raw
31 route_success _req res = res $ Wai.responseLBS HTTP.ok200 [] "rawSuccess"
32 route_failure _req res = res $ Wai.responseLBS HTTP.badRequest400 [] "rawFailure"
38 hspec :: IO [TestTree]
39 hspec = testSpecs $ describe "raw" $
40 beforeAll (runTestServer srv) $
41 afterAll killTestServer $ do
42 it "raw on success" $ \TestServer{..} -> do
43 res <- runClient env (cli_success HTTP.methodGet)
45 Left e -> assertFailure $ show e
47 Client.responseStatus r `shouldBe` HTTP.status200
48 Client.responseBody r `shouldBe` "rawSuccess"
49 it "raw should return a Left in case of failure" $ \TestServer{..} -> do
50 res <- runClient env (cli_failure HTTP.methodGet)
52 Right (_a::ClientResponse) -> do
53 assertFailure "expected Left, but got Right"
54 Left (ClientError_FailureResponse r) -> do
55 Client.responseStatus r `shouldBe` HTTP.status400
56 Client.responseBody r `shouldBe` "rawFailure"
57 Left e -> assertFailure $ "expected FailureResponse, but got " <> show e