purescript-httpurple/test/Test/HTTPure/ServerSpec.purs

47 lines
1.5 KiB
Haskell
Raw Normal View History

2017-10-26 21:19:30 +00:00
module Test.HTTPure.ServerSpec where
import Prelude
2017-07-10 10:17:13 +00:00
import Control.Monad.Eff.Class as EffClass
2017-09-26 06:08:07 +00:00
import Data.String as String
import Data.StrMap as StrMap
2017-07-10 10:17:13 +00:00
import Test.Spec as Spec
2017-07-23 19:17:02 +00:00
import Test.Spec.Assertions.Aff as AffAssertions
import HTTPure.Request as Request
import HTTPure.Response as Response
import HTTPure.Server as Server
2017-10-26 21:19:30 +00:00
import Test.HTTPure.TestHelpers as TestHelpers
import Test.HTTPure.TestHelpers ((?=))
mockRouter :: forall e. Request.Request -> Response.ResponseM e
2017-09-26 06:08:07 +00:00
mockRouter { path } = Response.ok $ "/" <> String.joinWith "/" path
2017-07-10 10:17:13 +00:00
2017-10-26 21:19:30 +00:00
serveSpec :: TestHelpers.Test
serveSpec = Spec.describe "serve" do
2017-07-10 10:17:13 +00:00
Spec.it "boots a server on the given port" do
EffClass.liftEff $ Server.serve 7901 mockRouter $ pure unit
2017-10-26 21:19:30 +00:00
out <- TestHelpers.get 7901 StrMap.empty "/test"
out ?= "/test"
2017-07-10 10:17:13 +00:00
2017-10-26 21:19:30 +00:00
serve'Spec :: TestHelpers.Test
2017-07-23 19:17:02 +00:00
serve'Spec = Spec.describe "serve" do
Spec.describe "with valid key and cert files" do
Spec.it "boots a server on the given port" do
EffClass.liftEff $ Server.serve' 7902 cert key mockRouter $ pure unit
2017-10-26 21:19:30 +00:00
out <- TestHelpers.get' 7902 StrMap.empty "/test"
2017-07-23 19:17:02 +00:00
out ?= "/test"
Spec.describe "with invalid key and cert files" do
Spec.it "throws" do
AffAssertions.expectError do
EffClass.liftEff $ Server.serve' 7903 "" "" mockRouter $ pure unit
where
cert = "./test/Mocks/Certificate.cer"
key = "./test/Mocks/Key.key"
2017-10-26 21:19:30 +00:00
serverSpec :: TestHelpers.Test
2017-07-10 10:17:13 +00:00
serverSpec = Spec.describe "Server" do
serveSpec
2017-07-23 19:17:02 +00:00
serve'Spec