{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} module Main where import Polysemy import Polysemy.Final import Polysemy.WebServer import qualified Data.ByteString.Lazy as LBS import qualified Network.Wai as Wai import qualified Network.Wai.Handler.Warp as Warp import qualified Network.HTTP.Types.Status as HTTP import Network.HTTP.Simple import Polysemy.Async import Test.Hspec testServerApp :: WebServer `Member` r => Wai.Request -> PendingWebRequest -> Sem r Wai.ResponseReceived testServerApp _req pendingReq = respondWebRequest pendingReq ( Wai.responseLBS (HTTP.status200) [] "Success") main :: IO () main = runFinal . runWebServerFinal . asyncToIOFinal $ do -- With the WebServer effect, start a new server... async $ startWebServer 8123 testServerApp embedFinal . hspec $ do describe "Web Server" $ do it "should respond to requests" $ do -- Use a client library to test... req <- parseRequest "http://localhost:8123/" resp <- httpLBS req getResponseStatusCode resp `shouldBe` 200 getResponseBody resp `shouldBe` "Success"