Clean up tests and examples (#86)
This commit is contained in:
parent
f28a9bfed7
commit
0fa3d1a90c
6
Makefile
6
Makefile
@ -38,9 +38,6 @@ SOURCES := $(SRCPATH)/**/*
|
|||||||
TESTSOURCES := $(TESTPATH)/**/*
|
TESTSOURCES := $(TESTPATH)/**/*
|
||||||
EXAMPLESOURCES := $(EXAMPLESPATH)/**/*
|
EXAMPLESOURCES := $(EXAMPLESPATH)/**/*
|
||||||
|
|
||||||
# This is the module name for the entry point for the test suite
|
|
||||||
TESTMAIN := HTTPure.HTTPureSpec
|
|
||||||
|
|
||||||
# Install bower components
|
# Install bower components
|
||||||
$(COMPONENTS): $(BOWERJSON)
|
$(COMPONENTS): $(BOWERJSON)
|
||||||
$(BOWER) install
|
$(BOWER) install
|
||||||
@ -65,7 +62,7 @@ $(EXAMPLE_INDEX): $(OUTPUT_EXAMPLE) $(BUILD) $(EXAMPLEPATH)/Main.purs
|
|||||||
--src-path $(EXAMPLEPATH) \
|
--src-path $(EXAMPLEPATH) \
|
||||||
--include $(SRCPATH) \
|
--include $(SRCPATH) \
|
||||||
--build-path $(BUILD) \
|
--build-path $(BUILD) \
|
||||||
--main $(EXAMPLE) \
|
--main Examples.$(EXAMPLE).Main \
|
||||||
--to $(EXAMPLE_INDEX)
|
--to $(EXAMPLE_INDEX)
|
||||||
|
|
||||||
# Run the example specified by the environment variable EXAMPLE
|
# Run the example specified by the environment variable EXAMPLE
|
||||||
@ -91,7 +88,6 @@ test: $(BUILD) $(TESTSOURCES) $(EXAMPLESOURCES)
|
|||||||
--test-path $(TESTPATH) \
|
--test-path $(TESTPATH) \
|
||||||
--include $(EXAMPLESPATH) \
|
--include $(EXAMPLESPATH) \
|
||||||
--build-path $(BUILD) \
|
--build-path $(BUILD) \
|
||||||
--main $(TESTMAIN) \
|
|
||||||
$(BUILD_OPTIONS)
|
$(BUILD_OPTIONS)
|
||||||
|
|
||||||
# Launch a repl with all modules loaded
|
# Launch a repl with all modules loaded
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module AsyncResponse where
|
module Examples.AsyncResponse.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Headers where
|
module Examples.Headers.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module HelloWorld where
|
module Examples.HelloWorld.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Middleware where
|
module Examples.Middleware.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module MultiRoute where
|
module Examples.MultiRoute.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module PathSegments where
|
module Examples.PathSegments.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Post where
|
module Examples.Post.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module QueryParameters where
|
module Examples.QueryParameters.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module SSL where
|
module Examples.SSL.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
module HTTPure.HTTPureEffectsSpec where
|
|
||||||
|
|
||||||
import Prelude
|
|
||||||
|
|
||||||
import Test.Spec as Spec
|
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
|
||||||
|
|
||||||
httpureEffectsSpec :: SpecHelpers.Test
|
|
||||||
httpureEffectsSpec = Spec.describe "HTTPureEffects" do
|
|
||||||
pure unit
|
|
@ -1,113 +0,0 @@
|
|||||||
module HTTPure.IntegrationSpec where
|
|
||||||
|
|
||||||
import Prelude
|
|
||||||
|
|
||||||
import Control.Monad.Eff.Class as EffClass
|
|
||||||
import Data.StrMap as StrMap
|
|
||||||
import Test.Spec as Spec
|
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
|
||||||
import HTTPure.SpecHelpers ((?=))
|
|
||||||
|
|
||||||
import AsyncResponse as AsyncResponse
|
|
||||||
import Headers as Headers
|
|
||||||
import HelloWorld as HelloWorld
|
|
||||||
import Middleware as Middleware
|
|
||||||
import MultiRoute as MultiRoute
|
|
||||||
import PathSegments as PathSegments
|
|
||||||
import QueryParameters as QueryParameters
|
|
||||||
import Post as Post
|
|
||||||
import SSL as SSL
|
|
||||||
|
|
||||||
asyncResponseSpec :: SpecHelpers.Test
|
|
||||||
asyncResponseSpec = Spec.it "runs the async response example" do
|
|
||||||
EffClass.liftEff AsyncResponse.main
|
|
||||||
response <- SpecHelpers.get port StrMap.empty "/"
|
|
||||||
response ?= "hello world!"
|
|
||||||
where port = AsyncResponse.port
|
|
||||||
|
|
||||||
headersSpec :: SpecHelpers.Test
|
|
||||||
headersSpec = Spec.it "runs the headers example" do
|
|
||||||
EffClass.liftEff Headers.main
|
|
||||||
header <- SpecHelpers.getHeader port StrMap.empty "/" "X-Example"
|
|
||||||
header ?= "hello world!"
|
|
||||||
response <- SpecHelpers.get port (StrMap.singleton "X-Input" "test") "/"
|
|
||||||
response ?= "test"
|
|
||||||
where port = Headers.port
|
|
||||||
|
|
||||||
helloWorldSpec :: SpecHelpers.Test
|
|
||||||
helloWorldSpec = Spec.it "runs the hello world example" do
|
|
||||||
EffClass.liftEff HelloWorld.main
|
|
||||||
response <- SpecHelpers.get port StrMap.empty "/"
|
|
||||||
response ?= "hello world!"
|
|
||||||
where port = HelloWorld.port
|
|
||||||
|
|
||||||
middlewareSpec :: SpecHelpers.Test
|
|
||||||
middlewareSpec = Spec.it "runs the middleware example" do
|
|
||||||
EffClass.liftEff Middleware.main
|
|
||||||
header <- SpecHelpers.getHeader port StrMap.empty "/" "X-Middleware"
|
|
||||||
header ?= "router"
|
|
||||||
body <- SpecHelpers.get port StrMap.empty "/"
|
|
||||||
body ?= "hello"
|
|
||||||
header' <- SpecHelpers.getHeader port StrMap.empty "/middleware" "X-Middleware"
|
|
||||||
header' ?= "middleware"
|
|
||||||
body' <- SpecHelpers.get port StrMap.empty "/middleware"
|
|
||||||
body' ?= "Middleware!"
|
|
||||||
where port = Middleware.port
|
|
||||||
|
|
||||||
multiRouteSpec :: SpecHelpers.Test
|
|
||||||
multiRouteSpec = Spec.it "runs the multi route example" do
|
|
||||||
EffClass.liftEff MultiRoute.main
|
|
||||||
hello <- SpecHelpers.get port StrMap.empty "/hello"
|
|
||||||
hello ?= "hello"
|
|
||||||
goodbye <- SpecHelpers.get port StrMap.empty "/goodbye"
|
|
||||||
goodbye ?= "goodbye"
|
|
||||||
where port = MultiRoute.port
|
|
||||||
|
|
||||||
pathSegmentsSpec :: SpecHelpers.Test
|
|
||||||
pathSegmentsSpec = Spec.it "runs the path segments example" do
|
|
||||||
EffClass.liftEff PathSegments.main
|
|
||||||
foo <- SpecHelpers.get port StrMap.empty "/segment/foo"
|
|
||||||
foo ?= "foo"
|
|
||||||
somebars <- SpecHelpers.get port StrMap.empty "/some/bars"
|
|
||||||
somebars ?= "[\"some\",\"bars\"]"
|
|
||||||
where port = PathSegments.port
|
|
||||||
|
|
||||||
queryParametersSpec :: SpecHelpers.Test
|
|
||||||
queryParametersSpec = Spec.it "runs the query parameters example" do
|
|
||||||
EffClass.liftEff QueryParameters.main
|
|
||||||
foo <- SpecHelpers.get port StrMap.empty "/?foo"
|
|
||||||
foo ?= "foo"
|
|
||||||
bar <- SpecHelpers.get port StrMap.empty "/?bar=test"
|
|
||||||
bar ?= "bar"
|
|
||||||
notbar <- SpecHelpers.get port StrMap.empty "/?bar=nottest"
|
|
||||||
notbar ?= ""
|
|
||||||
baz <- SpecHelpers.get port StrMap.empty "/?baz=test"
|
|
||||||
baz ?= "test"
|
|
||||||
where port = QueryParameters.port
|
|
||||||
|
|
||||||
postSpec :: SpecHelpers.Test
|
|
||||||
postSpec = Spec.it "runs the post example" do
|
|
||||||
EffClass.liftEff Post.main
|
|
||||||
response <- SpecHelpers.post port StrMap.empty "/" "test"
|
|
||||||
response ?= "test"
|
|
||||||
where port = Post.port
|
|
||||||
|
|
||||||
sslSpec :: SpecHelpers.Test
|
|
||||||
sslSpec = Spec.it "runs the ssl example" do
|
|
||||||
EffClass.liftEff SSL.main
|
|
||||||
response <- SpecHelpers.get' port StrMap.empty "/"
|
|
||||||
response ?= "hello world!"
|
|
||||||
where port = SSL.port
|
|
||||||
|
|
||||||
integrationSpec :: SpecHelpers.Test
|
|
||||||
integrationSpec = Spec.describe "Integration" do
|
|
||||||
asyncResponseSpec
|
|
||||||
headersSpec
|
|
||||||
helloWorldSpec
|
|
||||||
middlewareSpec
|
|
||||||
multiRouteSpec
|
|
||||||
pathSegmentsSpec
|
|
||||||
queryParametersSpec
|
|
||||||
postSpec
|
|
||||||
sslSpec
|
|
@ -1,37 +0,0 @@
|
|||||||
module HTTPure.HTTPureSpec where
|
|
||||||
|
|
||||||
import Prelude
|
|
||||||
|
|
||||||
import Test.Spec as Spec
|
|
||||||
import Test.Spec.Reporter as Reporter
|
|
||||||
import Test.Spec.Runner as Runner
|
|
||||||
|
|
||||||
import HTTPure.BodySpec as BodySpec
|
|
||||||
import HTTPure.HeadersSpec as HeadersSpec
|
|
||||||
import HTTPure.HTTPureEffectsSpec as HTTPureEffectsSpec
|
|
||||||
import HTTPure.LookupSpec as LookupSpec
|
|
||||||
import HTTPure.MethodSpec as MethodSpec
|
|
||||||
import HTTPure.PathSpec as PathSpec
|
|
||||||
import HTTPure.QuerySpec as QuerySpec
|
|
||||||
import HTTPure.RequestSpec as RequestSpec
|
|
||||||
import HTTPure.ResponseSpec as ResponseSpec
|
|
||||||
import HTTPure.ServerSpec as ServerSpec
|
|
||||||
import HTTPure.StatusSpec as StatusSpec
|
|
||||||
import HTTPure.IntegrationSpec as IntegrationSpec
|
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
|
||||||
|
|
||||||
main :: SpecHelpers.TestSuite
|
|
||||||
main = Runner.run [ Reporter.specReporter ] $ Spec.describe "HTTPure" do
|
|
||||||
BodySpec.bodySpec
|
|
||||||
HeadersSpec.headersSpec
|
|
||||||
HTTPureEffectsSpec.httpureEffectsSpec
|
|
||||||
LookupSpec.lookupSpec
|
|
||||||
MethodSpec.methodSpec
|
|
||||||
PathSpec.pathSpec
|
|
||||||
QuerySpec.querySpec
|
|
||||||
RequestSpec.requestSpec
|
|
||||||
ResponseSpec.responseSpec
|
|
||||||
ServerSpec.serverSpec
|
|
||||||
StatusSpec.statusSpec
|
|
||||||
IntegrationSpec.integrationSpec
|
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.BodySpec where
|
module Test.HTTPure.BodySpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -7,26 +7,26 @@ import Test.Spec as Spec
|
|||||||
|
|
||||||
import HTTPure.Body as Body
|
import HTTPure.Body as Body
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
readSpec :: SpecHelpers.Test
|
readSpec :: TestHelpers.Test
|
||||||
readSpec = Spec.describe "read" do
|
readSpec = Spec.describe "read" do
|
||||||
Spec.it "is the body of the Request" do
|
Spec.it "is the body of the Request" do
|
||||||
request <- SpecHelpers.mockRequest "GET" "" "test" []
|
request <- TestHelpers.mockRequest "GET" "" "test" []
|
||||||
body <- Body.read request
|
body <- Body.read request
|
||||||
body ?= "test"
|
body ?= "test"
|
||||||
|
|
||||||
writeSpec :: SpecHelpers.Test
|
writeSpec :: TestHelpers.Test
|
||||||
writeSpec = Spec.describe "write" do
|
writeSpec = Spec.describe "write" do
|
||||||
Spec.it "writes the string to the Response body" do
|
Spec.it "writes the string to the Response body" do
|
||||||
body <- EffClass.liftEff do
|
body <- EffClass.liftEff do
|
||||||
resp <- SpecHelpers.mockResponse
|
resp <- TestHelpers.mockResponse
|
||||||
Body.write resp "test"
|
Body.write resp "test"
|
||||||
pure $ SpecHelpers.getResponseBody resp
|
pure $ TestHelpers.getResponseBody resp
|
||||||
body ?= "test"
|
body ?= "test"
|
||||||
|
|
||||||
bodySpec :: SpecHelpers.Test
|
bodySpec :: TestHelpers.Test
|
||||||
bodySpec = Spec.describe "Body" do
|
bodySpec = Spec.describe "Body" do
|
||||||
readSpec
|
readSpec
|
||||||
writeSpec
|
writeSpec
|
11
test/Test/HTTPure/HTTPureEffectsSpec.purs
Normal file
11
test/Test/HTTPure/HTTPureEffectsSpec.purs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module Test.HTTPure.HTTPureEffectsSpec where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Test.Spec as Spec
|
||||||
|
|
||||||
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
|
|
||||||
|
httpureEffectsSpec :: TestHelpers.Test
|
||||||
|
httpureEffectsSpec = Spec.describe "HTTPureEffects" do
|
||||||
|
pure unit
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.HeadersSpec where
|
module Test.HTTPure.HeadersSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -10,10 +10,10 @@ import Test.Spec as Spec
|
|||||||
import HTTPure.Headers as Headers
|
import HTTPure.Headers as Headers
|
||||||
import HTTPure.Lookup ((!!))
|
import HTTPure.Lookup ((!!))
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
lookupSpec :: SpecHelpers.Test
|
lookupSpec :: TestHelpers.Test
|
||||||
lookupSpec = Spec.describe "lookup" do
|
lookupSpec = Spec.describe "lookup" do
|
||||||
Spec.describe "when the string is in the header set" do
|
Spec.describe "when the string is in the header set" do
|
||||||
Spec.describe "when searching with lowercase" do
|
Spec.describe "when searching with lowercase" do
|
||||||
@ -26,13 +26,13 @@ lookupSpec = Spec.describe "lookup" do
|
|||||||
Spec.it "is Nothing" do
|
Spec.it "is Nothing" do
|
||||||
((Headers.empty !! "X-Test") :: Maybe.Maybe String) ?= Maybe.Nothing
|
((Headers.empty !! "X-Test") :: Maybe.Maybe String) ?= Maybe.Nothing
|
||||||
|
|
||||||
showSpec :: SpecHelpers.Test
|
showSpec :: TestHelpers.Test
|
||||||
showSpec = Spec.describe "show" do
|
showSpec = Spec.describe "show" do
|
||||||
Spec.it "is a string representing the headers in HTTP format" do
|
Spec.it "is a string representing the headers in HTTP format" do
|
||||||
let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
||||||
show mock ?= "Test1: 1\nTest2: 2\n\n"
|
show mock ?= "Test1: 1\nTest2: 2\n\n"
|
||||||
|
|
||||||
eqSpec :: SpecHelpers.Test
|
eqSpec :: TestHelpers.Test
|
||||||
eqSpec = Spec.describe "eq" do
|
eqSpec = Spec.describe "eq" do
|
||||||
Spec.describe "when the two Headers contain the same keys and values" do
|
Spec.describe "when the two Headers contain the same keys and values" do
|
||||||
Spec.it "is true" do
|
Spec.it "is true" do
|
||||||
@ -48,7 +48,7 @@ eqSpec = Spec.describe "eq" do
|
|||||||
let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2"
|
||||||
Headers.header "Test1" "1" == mock ?= false
|
Headers.header "Test1" "1" == mock ?= false
|
||||||
|
|
||||||
appendSpec :: SpecHelpers.Test
|
appendSpec :: TestHelpers.Test
|
||||||
appendSpec = Spec.describe "append" do
|
appendSpec = Spec.describe "append" do
|
||||||
Spec.describe "when there are multiple keys" do
|
Spec.describe "when there are multiple keys" do
|
||||||
Spec.it "appends the headers correctly" do
|
Spec.it "appends the headers correctly" do
|
||||||
@ -66,38 +66,38 @@ appendSpec = Spec.describe "append" do
|
|||||||
let mock = Headers.header "Test" "foo" <> Headers.header "Test" "bar"
|
let mock = Headers.header "Test" "foo" <> Headers.header "Test" "bar"
|
||||||
mock ?= Headers.header "Test" "bar"
|
mock ?= Headers.header "Test" "bar"
|
||||||
|
|
||||||
readSpec :: SpecHelpers.Test
|
readSpec :: TestHelpers.Test
|
||||||
readSpec = Spec.describe "read" do
|
readSpec = Spec.describe "read" do
|
||||||
Spec.describe "with no headers" do
|
Spec.describe "with no headers" do
|
||||||
Spec.it "is an empty StrMap" do
|
Spec.it "is an empty StrMap" do
|
||||||
request <- SpecHelpers.mockRequest "" "" "" []
|
request <- TestHelpers.mockRequest "" "" "" []
|
||||||
Headers.read request ?= Headers.empty
|
Headers.read request ?= Headers.empty
|
||||||
Spec.describe "with headers" do
|
Spec.describe "with headers" do
|
||||||
Spec.it "is an StrMap with the contents of the headers" do
|
Spec.it "is an StrMap with the contents of the headers" do
|
||||||
let testHeader = [Tuple.Tuple "X-Test" "test"]
|
let testHeader = [Tuple.Tuple "X-Test" "test"]
|
||||||
request <- SpecHelpers.mockRequest "" "" "" testHeader
|
request <- TestHelpers.mockRequest "" "" "" testHeader
|
||||||
Headers.read request ?= Headers.headers testHeader
|
Headers.read request ?= Headers.headers testHeader
|
||||||
|
|
||||||
writeSpec :: SpecHelpers.Test
|
writeSpec :: TestHelpers.Test
|
||||||
writeSpec = Spec.describe "write" do
|
writeSpec = Spec.describe "write" do
|
||||||
Spec.it "writes the headers to the response" do
|
Spec.it "writes the headers to the response" do
|
||||||
header <- EffClass.liftEff do
|
header <- EffClass.liftEff do
|
||||||
mock <- SpecHelpers.mockResponse
|
mock <- TestHelpers.mockResponse
|
||||||
Headers.write mock $ Headers.header "X-Test" "test"
|
Headers.write mock $ Headers.header "X-Test" "test"
|
||||||
pure $ SpecHelpers.getResponseHeader "X-Test" mock
|
pure $ TestHelpers.getResponseHeader "X-Test" mock
|
||||||
header ?= "test"
|
header ?= "test"
|
||||||
|
|
||||||
emptySpec :: SpecHelpers.Test
|
emptySpec :: TestHelpers.Test
|
||||||
emptySpec = Spec.describe "empty" do
|
emptySpec = Spec.describe "empty" do
|
||||||
Spec.it "is a empty StrMap in an empty Headers" do
|
Spec.it "is a empty StrMap in an empty Headers" do
|
||||||
show Headers.empty ?= "\n"
|
show Headers.empty ?= "\n"
|
||||||
|
|
||||||
headerSpec :: SpecHelpers.Test
|
headerSpec :: TestHelpers.Test
|
||||||
headerSpec = Spec.describe "header" do
|
headerSpec = Spec.describe "header" do
|
||||||
Spec.it "creates a singleton Headers" do
|
Spec.it "creates a singleton Headers" do
|
||||||
show (Headers.header "X-Test" "test") ?= "X-Test: test\n\n"
|
show (Headers.header "X-Test" "test") ?= "X-Test: test\n\n"
|
||||||
|
|
||||||
headersFunctionSpec :: SpecHelpers.Test
|
headersFunctionSpec :: TestHelpers.Test
|
||||||
headersFunctionSpec = Spec.describe "headers" do
|
headersFunctionSpec = Spec.describe "headers" do
|
||||||
Spec.it "is equivalent to using Headers.header with <>" do
|
Spec.it "is equivalent to using Headers.header with <>" do
|
||||||
test ?= expected
|
test ?= expected
|
||||||
@ -109,7 +109,7 @@ headersFunctionSpec = Spec.describe "headers" do
|
|||||||
]
|
]
|
||||||
expected = Headers.header "X-Test-1" "1" <> Headers.header "X-Test-2" "2"
|
expected = Headers.header "X-Test-1" "1" <> Headers.header "X-Test-2" "2"
|
||||||
|
|
||||||
headersSpec :: SpecHelpers.Test
|
headersSpec :: TestHelpers.Test
|
||||||
headersSpec = Spec.describe "Headers" do
|
headersSpec = Spec.describe "Headers" do
|
||||||
lookupSpec
|
lookupSpec
|
||||||
showSpec
|
showSpec
|
113
test/Test/HTTPure/IntegrationSpec.purs
Normal file
113
test/Test/HTTPure/IntegrationSpec.purs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
module Test.HTTPure.IntegrationSpec where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Control.Monad.Eff.Class as EffClass
|
||||||
|
import Data.StrMap as StrMap
|
||||||
|
import Test.Spec as Spec
|
||||||
|
|
||||||
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
|
import Examples.AsyncResponse.Main as AsyncResponse
|
||||||
|
import Examples.Headers.Main as Headers
|
||||||
|
import Examples.HelloWorld.Main as HelloWorld
|
||||||
|
import Examples.Middleware.Main as Middleware
|
||||||
|
import Examples.MultiRoute.Main as MultiRoute
|
||||||
|
import Examples.PathSegments.Main as PathSegments
|
||||||
|
import Examples.QueryParameters.Main as QueryParameters
|
||||||
|
import Examples.Post.Main as Post
|
||||||
|
import Examples.SSL.Main as SSL
|
||||||
|
|
||||||
|
asyncResponseSpec :: TestHelpers.Test
|
||||||
|
asyncResponseSpec = Spec.it "runs the async response example" do
|
||||||
|
EffClass.liftEff AsyncResponse.main
|
||||||
|
response <- TestHelpers.get port StrMap.empty "/"
|
||||||
|
response ?= "hello world!"
|
||||||
|
where port = AsyncResponse.port
|
||||||
|
|
||||||
|
headersSpec :: TestHelpers.Test
|
||||||
|
headersSpec = Spec.it "runs the headers example" do
|
||||||
|
EffClass.liftEff Headers.main
|
||||||
|
header <- TestHelpers.getHeader port StrMap.empty "/" "X-Example"
|
||||||
|
header ?= "hello world!"
|
||||||
|
response <- TestHelpers.get port (StrMap.singleton "X-Input" "test") "/"
|
||||||
|
response ?= "test"
|
||||||
|
where port = Headers.port
|
||||||
|
|
||||||
|
helloWorldSpec :: TestHelpers.Test
|
||||||
|
helloWorldSpec = Spec.it "runs the hello world example" do
|
||||||
|
EffClass.liftEff HelloWorld.main
|
||||||
|
response <- TestHelpers.get port StrMap.empty "/"
|
||||||
|
response ?= "hello world!"
|
||||||
|
where port = HelloWorld.port
|
||||||
|
|
||||||
|
middlewareSpec :: TestHelpers.Test
|
||||||
|
middlewareSpec = Spec.it "runs the middleware example" do
|
||||||
|
EffClass.liftEff Middleware.main
|
||||||
|
header <- TestHelpers.getHeader port StrMap.empty "/" "X-Middleware"
|
||||||
|
header ?= "router"
|
||||||
|
body <- TestHelpers.get port StrMap.empty "/"
|
||||||
|
body ?= "hello"
|
||||||
|
header <- TestHelpers.getHeader port StrMap.empty "/middleware" "X-Middleware"
|
||||||
|
header ?= "middleware"
|
||||||
|
body' <- TestHelpers.get port StrMap.empty "/middleware"
|
||||||
|
body' ?= "Middleware!"
|
||||||
|
where port = Middleware.port
|
||||||
|
|
||||||
|
multiRouteSpec :: TestHelpers.Test
|
||||||
|
multiRouteSpec = Spec.it "runs the multi route example" do
|
||||||
|
EffClass.liftEff MultiRoute.main
|
||||||
|
hello <- TestHelpers.get port StrMap.empty "/hello"
|
||||||
|
hello ?= "hello"
|
||||||
|
goodbye <- TestHelpers.get port StrMap.empty "/goodbye"
|
||||||
|
goodbye ?= "goodbye"
|
||||||
|
where port = MultiRoute.port
|
||||||
|
|
||||||
|
pathSegmentsSpec :: TestHelpers.Test
|
||||||
|
pathSegmentsSpec = Spec.it "runs the path segments example" do
|
||||||
|
EffClass.liftEff PathSegments.main
|
||||||
|
foo <- TestHelpers.get port StrMap.empty "/segment/foo"
|
||||||
|
foo ?= "foo"
|
||||||
|
somebars <- TestHelpers.get port StrMap.empty "/some/bars"
|
||||||
|
somebars ?= "[\"some\",\"bars\"]"
|
||||||
|
where port = PathSegments.port
|
||||||
|
|
||||||
|
queryParametersSpec :: TestHelpers.Test
|
||||||
|
queryParametersSpec = Spec.it "runs the query parameters example" do
|
||||||
|
EffClass.liftEff QueryParameters.main
|
||||||
|
foo <- TestHelpers.get port StrMap.empty "/?foo"
|
||||||
|
foo ?= "foo"
|
||||||
|
bar <- TestHelpers.get port StrMap.empty "/?bar=test"
|
||||||
|
bar ?= "bar"
|
||||||
|
notbar <- TestHelpers.get port StrMap.empty "/?bar=nottest"
|
||||||
|
notbar ?= ""
|
||||||
|
baz <- TestHelpers.get port StrMap.empty "/?baz=test"
|
||||||
|
baz ?= "test"
|
||||||
|
where port = QueryParameters.port
|
||||||
|
|
||||||
|
postSpec :: TestHelpers.Test
|
||||||
|
postSpec = Spec.it "runs the post example" do
|
||||||
|
EffClass.liftEff Post.main
|
||||||
|
response <- TestHelpers.post port StrMap.empty "/" "test"
|
||||||
|
response ?= "test"
|
||||||
|
where port = Post.port
|
||||||
|
|
||||||
|
sslSpec :: TestHelpers.Test
|
||||||
|
sslSpec = Spec.it "runs the ssl example" do
|
||||||
|
EffClass.liftEff SSL.main
|
||||||
|
response <- TestHelpers.get' port StrMap.empty "/"
|
||||||
|
response ?= "hello world!"
|
||||||
|
where port = SSL.port
|
||||||
|
|
||||||
|
integrationSpec :: TestHelpers.Test
|
||||||
|
integrationSpec = Spec.describe "Integration" do
|
||||||
|
asyncResponseSpec
|
||||||
|
headersSpec
|
||||||
|
helloWorldSpec
|
||||||
|
middlewareSpec
|
||||||
|
multiRouteSpec
|
||||||
|
pathSegmentsSpec
|
||||||
|
queryParametersSpec
|
||||||
|
postSpec
|
||||||
|
sslSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.LookupSpec where
|
module Test.HTTPure.LookupSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -9,10 +9,10 @@ import Test.Spec as Spec
|
|||||||
|
|
||||||
import HTTPure.Lookup ((!!), (!@), (!?))
|
import HTTPure.Lookup ((!!), (!@), (!?))
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
atSpec :: SpecHelpers.Test
|
atSpec :: TestHelpers.Test
|
||||||
atSpec = Spec.describe "at" do
|
atSpec = Spec.describe "at" do
|
||||||
Spec.describe "when the lookup returns a Just" do
|
Spec.describe "when the lookup returns a Just" do
|
||||||
Spec.it "is the value inside the Just" do
|
Spec.it "is the value inside the Just" do
|
||||||
@ -21,7 +21,7 @@ atSpec = Spec.describe "at" do
|
|||||||
Spec.it "is mempty" do
|
Spec.it "is mempty" do
|
||||||
[ "one", "two", "three" ] !@ 4 ?= ""
|
[ "one", "two", "three" ] !@ 4 ?= ""
|
||||||
|
|
||||||
hasSpec :: SpecHelpers.Test
|
hasSpec :: TestHelpers.Test
|
||||||
hasSpec = Spec.describe "has" do
|
hasSpec = Spec.describe "has" do
|
||||||
Spec.describe "when the lookup returns a Just" do
|
Spec.describe "when the lookup returns a Just" do
|
||||||
Spec.it "is true" do
|
Spec.it "is true" do
|
||||||
@ -30,7 +30,7 @@ hasSpec = Spec.describe "has" do
|
|||||||
Spec.it "is false" do
|
Spec.it "is false" do
|
||||||
[ "one", "two", "three" ] !? 4 ?= false
|
[ "one", "two", "three" ] !? 4 ?= false
|
||||||
|
|
||||||
lookupArraySpec :: SpecHelpers.Test
|
lookupArraySpec :: TestHelpers.Test
|
||||||
lookupArraySpec = Spec.describe "lookupArray" do
|
lookupArraySpec = Spec.describe "lookupArray" do
|
||||||
Spec.describe "when the index is in bounds" do
|
Spec.describe "when the index is in bounds" do
|
||||||
Spec.it "is Just the value at the index" do
|
Spec.it "is Just the value at the index" do
|
||||||
@ -39,7 +39,7 @@ lookupArraySpec = Spec.describe "lookupArray" do
|
|||||||
Spec.it "is Nothing" do
|
Spec.it "is Nothing" do
|
||||||
(([ "one", "two", "three" ] !! 4) :: Maybe.Maybe String) ?= Maybe.Nothing
|
(([ "one", "two", "three" ] !! 4) :: Maybe.Maybe String) ?= Maybe.Nothing
|
||||||
|
|
||||||
lookupStrMapSpec :: SpecHelpers.Test
|
lookupStrMapSpec :: TestHelpers.Test
|
||||||
lookupStrMapSpec = Spec.describe "lookupStrMap" do
|
lookupStrMapSpec = Spec.describe "lookupStrMap" do
|
||||||
Spec.describe "when the key is in the StrMap" do
|
Spec.describe "when the key is in the StrMap" do
|
||||||
Spec.it "is Just the value at the given key" do
|
Spec.it "is Just the value at the given key" do
|
||||||
@ -50,7 +50,7 @@ lookupStrMapSpec = Spec.describe "lookupStrMap" do
|
|||||||
where
|
where
|
||||||
mockStrMap = StrMap.singleton "foo" "bar"
|
mockStrMap = StrMap.singleton "foo" "bar"
|
||||||
|
|
||||||
lookupSpec :: SpecHelpers.Test
|
lookupSpec :: TestHelpers.Test
|
||||||
lookupSpec = Spec.describe "Lookup" do
|
lookupSpec = Spec.describe "Lookup" do
|
||||||
atSpec
|
atSpec
|
||||||
hasSpec
|
hasSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.MethodSpec where
|
module Test.HTTPure.MethodSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -6,10 +6,10 @@ import Test.Spec as Spec
|
|||||||
|
|
||||||
import HTTPure.Method as Method
|
import HTTPure.Method as Method
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
showSpec :: SpecHelpers.Test
|
showSpec :: TestHelpers.Test
|
||||||
showSpec = Spec.describe "show" do
|
showSpec = Spec.describe "show" do
|
||||||
Spec.describe "with a Get" do
|
Spec.describe "with a Get" do
|
||||||
Spec.it "is 'Get'" do
|
Spec.it "is 'Get'" do
|
||||||
@ -39,14 +39,14 @@ showSpec = Spec.describe "show" do
|
|||||||
Spec.it "is 'Patch'" do
|
Spec.it "is 'Patch'" do
|
||||||
show Method.Patch ?= "Patch"
|
show Method.Patch ?= "Patch"
|
||||||
|
|
||||||
readSpec :: SpecHelpers.Test
|
readSpec :: TestHelpers.Test
|
||||||
readSpec = Spec.describe "read" do
|
readSpec = Spec.describe "read" do
|
||||||
Spec.describe "with a 'GET' Request" do
|
Spec.describe "with a 'GET' Request" do
|
||||||
Spec.it "is Get" do
|
Spec.it "is Get" do
|
||||||
request <- SpecHelpers.mockRequest "GET" "" "" []
|
request <- TestHelpers.mockRequest "GET" "" "" []
|
||||||
Method.read request ?= Method.Get
|
Method.read request ?= Method.Get
|
||||||
|
|
||||||
methodSpec :: SpecHelpers.Test
|
methodSpec :: TestHelpers.Test
|
||||||
methodSpec = Spec.describe "Method" do
|
methodSpec = Spec.describe "Method" do
|
||||||
showSpec
|
showSpec
|
||||||
readSpec
|
readSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.PathSpec where
|
module Test.HTTPure.PathSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -6,28 +6,28 @@ import Test.Spec as Spec
|
|||||||
|
|
||||||
import HTTPure.Path as Path
|
import HTTPure.Path as Path
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
readSpec :: SpecHelpers.Test
|
readSpec :: TestHelpers.Test
|
||||||
readSpec = Spec.describe "read" do
|
readSpec = Spec.describe "read" do
|
||||||
Spec.describe "with a query string" do
|
Spec.describe "with a query string" do
|
||||||
Spec.it "is just the path" do
|
Spec.it "is just the path" do
|
||||||
request <- SpecHelpers.mockRequest "GET" "test/path?blabla" "" []
|
request <- TestHelpers.mockRequest "GET" "test/path?blabla" "" []
|
||||||
Path.read request ?= [ "test", "path" ]
|
Path.read request ?= [ "test", "path" ]
|
||||||
Spec.describe "with no query string" do
|
Spec.describe "with no query string" do
|
||||||
Spec.it "is the path" do
|
Spec.it "is the path" do
|
||||||
request <- SpecHelpers.mockRequest "GET" "test/path" "" []
|
request <- TestHelpers.mockRequest "GET" "test/path" "" []
|
||||||
Path.read request ?= [ "test", "path" ]
|
Path.read request ?= [ "test", "path" ]
|
||||||
Spec.describe "with no segments" do
|
Spec.describe "with no segments" do
|
||||||
Spec.it "is an empty array" do
|
Spec.it "is an empty array" do
|
||||||
request <- SpecHelpers.mockRequest "GET" "" "" []
|
request <- TestHelpers.mockRequest "GET" "" "" []
|
||||||
Path.read request ?= []
|
Path.read request ?= []
|
||||||
Spec.describe "with empty segments" do
|
Spec.describe "with empty segments" do
|
||||||
Spec.it "strips the empty segments" do
|
Spec.it "strips the empty segments" do
|
||||||
request <- SpecHelpers.mockRequest "GET" "//test//path///?query" "" []
|
request <- TestHelpers.mockRequest "GET" "//test//path///?query" "" []
|
||||||
Path.read request ?= [ "test", "path" ]
|
Path.read request ?= [ "test", "path" ]
|
||||||
|
|
||||||
pathSpec :: SpecHelpers.Test
|
pathSpec :: TestHelpers.Test
|
||||||
pathSpec = Spec.describe "Path" do
|
pathSpec = Spec.describe "Path" do
|
||||||
readSpec
|
readSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.QuerySpec where
|
module Test.HTTPure.QuerySpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -8,38 +8,38 @@ import Test.Spec as Spec
|
|||||||
|
|
||||||
import HTTPure.Query as Query
|
import HTTPure.Query as Query
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
readSpec :: SpecHelpers.Test
|
readSpec :: TestHelpers.Test
|
||||||
readSpec = Spec.describe "read" do
|
readSpec = Spec.describe "read" do
|
||||||
Spec.describe "with no query string" do
|
Spec.describe "with no query string" do
|
||||||
Spec.it "is an empty StrMap" do
|
Spec.it "is an empty StrMap" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test" "" []
|
req <- TestHelpers.mockRequest "" "/test" "" []
|
||||||
Query.read req ?= StrMap.empty
|
Query.read req ?= StrMap.empty
|
||||||
Spec.describe "with an empty query string" do
|
Spec.describe "with an empty query string" do
|
||||||
Spec.it "is an empty StrMap" do
|
Spec.it "is an empty StrMap" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test?" "" []
|
req <- TestHelpers.mockRequest "" "/test?" "" []
|
||||||
Query.read req ?= StrMap.empty
|
Query.read req ?= StrMap.empty
|
||||||
Spec.describe "with a query parameter in the query string" do
|
Spec.describe "with a query parameter in the query string" do
|
||||||
Spec.it "is a correct StrMap" do
|
Spec.it "is a correct StrMap" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test?a=b" "" []
|
req <- TestHelpers.mockRequest "" "/test?a=b" "" []
|
||||||
Query.read req ?= StrMap.singleton "a" "b"
|
Query.read req ?= StrMap.singleton "a" "b"
|
||||||
Spec.describe "with empty fields in the query string" do
|
Spec.describe "with empty fields in the query string" do
|
||||||
Spec.it "ignores the empty fields" do
|
Spec.it "ignores the empty fields" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test?&&a=b&&" "" []
|
req <- TestHelpers.mockRequest "" "/test?&&a=b&&" "" []
|
||||||
Query.read req ?= StrMap.singleton "a" "b"
|
Query.read req ?= StrMap.singleton "a" "b"
|
||||||
Spec.describe "with duplicated params" do
|
Spec.describe "with duplicated params" do
|
||||||
Spec.it "takes the last param value" do
|
Spec.it "takes the last param value" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test?a=b&a=c" "" []
|
req <- TestHelpers.mockRequest "" "/test?a=b&a=c" "" []
|
||||||
Query.read req ?= StrMap.singleton "a" "c"
|
Query.read req ?= StrMap.singleton "a" "c"
|
||||||
Spec.describe "with empty params" do
|
Spec.describe "with empty params" do
|
||||||
Spec.it "uses 'true' as the value" do
|
Spec.it "uses 'true' as the value" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test?a" "" []
|
req <- TestHelpers.mockRequest "" "/test?a" "" []
|
||||||
Query.read req ?= StrMap.singleton "a" "true"
|
Query.read req ?= StrMap.singleton "a" "true"
|
||||||
Spec.describe "with complex params" do
|
Spec.describe "with complex params" do
|
||||||
Spec.it "is the correct StrMap" do
|
Spec.it "is the correct StrMap" do
|
||||||
req <- SpecHelpers.mockRequest "" "/test?&&a&b=c&b=d&&&e=f&g=&" "" []
|
req <- TestHelpers.mockRequest "" "/test?&&a&b=c&b=d&&&e=f&g=&" "" []
|
||||||
Query.read req ?= expectedComplexResult
|
Query.read req ?= expectedComplexResult
|
||||||
where
|
where
|
||||||
expectedComplexResult =
|
expectedComplexResult =
|
||||||
@ -50,6 +50,6 @@ readSpec = Spec.describe "read" do
|
|||||||
, Tuple.Tuple "g" "true"
|
, Tuple.Tuple "g" "true"
|
||||||
]
|
]
|
||||||
|
|
||||||
querySpec :: SpecHelpers.Test
|
querySpec :: TestHelpers.Test
|
||||||
querySpec = Spec.describe "Query" do
|
querySpec = Spec.describe "Query" do
|
||||||
readSpec
|
readSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.RequestSpec where
|
module Test.HTTPure.RequestSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -10,10 +10,10 @@ import HTTPure.Headers as Headers
|
|||||||
import HTTPure.Method as Method
|
import HTTPure.Method as Method
|
||||||
import HTTPure.Request as Request
|
import HTTPure.Request as Request
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
fromHTTPRequestSpec :: SpecHelpers.Test
|
fromHTTPRequestSpec :: TestHelpers.Test
|
||||||
fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
||||||
Spec.it "contains the correct method" do
|
Spec.it "contains the correct method" do
|
||||||
mock <- mockRequest
|
mock <- mockRequest
|
||||||
@ -33,10 +33,10 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
|||||||
where
|
where
|
||||||
mockHeaders = [ Tuple.Tuple "Test" "test" ]
|
mockHeaders = [ Tuple.Tuple "Test" "test" ]
|
||||||
mockHTTPRequest =
|
mockHTTPRequest =
|
||||||
SpecHelpers.mockRequest "POST" "/test?a=b" "body" mockHeaders
|
TestHelpers.mockRequest "POST" "/test?a=b" "body" mockHeaders
|
||||||
mockRequest = mockHTTPRequest >>= Request.fromHTTPRequest
|
mockRequest = mockHTTPRequest >>= Request.fromHTTPRequest
|
||||||
|
|
||||||
fullPathSpec :: SpecHelpers.Test
|
fullPathSpec :: TestHelpers.Test
|
||||||
fullPathSpec = Spec.describe "fullPath" do
|
fullPathSpec = Spec.describe "fullPath" do
|
||||||
Spec.describe "without query parameters" do
|
Spec.describe "without query parameters" do
|
||||||
Spec.it "is correct" do
|
Spec.it "is correct" do
|
||||||
@ -63,10 +63,10 @@ fullPathSpec = Spec.describe "fullPath" do
|
|||||||
mock <- mockRequest "/foo///bar/?&a=b&&c"
|
mock <- mockRequest "/foo///bar/?&a=b&&c"
|
||||||
Request.fullPath mock ?= "/foo/bar?a=b&c=true"
|
Request.fullPath mock ?= "/foo/bar?a=b&c=true"
|
||||||
where
|
where
|
||||||
mockHTTPRequest path = SpecHelpers.mockRequest "POST" path "body" []
|
mockHTTPRequest path = TestHelpers.mockRequest "POST" path "body" []
|
||||||
mockRequest path = mockHTTPRequest path >>= Request.fromHTTPRequest
|
mockRequest path = mockHTTPRequest path >>= Request.fromHTTPRequest
|
||||||
|
|
||||||
requestSpec :: SpecHelpers.Test
|
requestSpec :: TestHelpers.Test
|
||||||
requestSpec = Spec.describe "Request" do
|
requestSpec = Spec.describe "Request" do
|
||||||
fromHTTPRequestSpec
|
fromHTTPRequestSpec
|
||||||
fullPathSpec
|
fullPathSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.ResponseSpec where
|
module Test.HTTPure.ResponseSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -8,34 +8,34 @@ import Test.Spec as Spec
|
|||||||
import HTTPure.Headers as Headers
|
import HTTPure.Headers as Headers
|
||||||
import HTTPure.Response as Response
|
import HTTPure.Response as Response
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
sendSpec :: SpecHelpers.Test
|
sendSpec :: TestHelpers.Test
|
||||||
sendSpec = Spec.describe "send" do
|
sendSpec = Spec.describe "send" do
|
||||||
Spec.it "writes the headers" do
|
Spec.it "writes the headers" do
|
||||||
header <- EffClass.liftEff do
|
header <- EffClass.liftEff do
|
||||||
httpResponse <- SpecHelpers.mockResponse
|
httpResponse <- TestHelpers.mockResponse
|
||||||
Response.send httpResponse mockResponse
|
Response.send httpResponse mockResponse
|
||||||
pure $ SpecHelpers.getResponseHeader "Test" httpResponse
|
pure $ TestHelpers.getResponseHeader "Test" httpResponse
|
||||||
header ?= "test"
|
header ?= "test"
|
||||||
Spec.it "writes the status" do
|
Spec.it "writes the status" do
|
||||||
status <- EffClass.liftEff do
|
status <- EffClass.liftEff do
|
||||||
httpResponse <- SpecHelpers.mockResponse
|
httpResponse <- TestHelpers.mockResponse
|
||||||
Response.send httpResponse mockResponse
|
Response.send httpResponse mockResponse
|
||||||
pure $ SpecHelpers.getResponseStatus httpResponse
|
pure $ TestHelpers.getResponseStatus httpResponse
|
||||||
status ?= 123
|
status ?= 123
|
||||||
Spec.it "writes the body" do
|
Spec.it "writes the body" do
|
||||||
body <- EffClass.liftEff do
|
body <- EffClass.liftEff do
|
||||||
httpResponse <- SpecHelpers.mockResponse
|
httpResponse <- TestHelpers.mockResponse
|
||||||
Response.send httpResponse mockResponse
|
Response.send httpResponse mockResponse
|
||||||
pure $ SpecHelpers.getResponseBody httpResponse
|
pure $ TestHelpers.getResponseBody httpResponse
|
||||||
body ?= "test"
|
body ?= "test"
|
||||||
where
|
where
|
||||||
mockHeaders = Headers.header "Test" "test"
|
mockHeaders = Headers.header "Test" "test"
|
||||||
mockResponse = { status: 123, headers: mockHeaders, body: "test" }
|
mockResponse = { status: 123, headers: mockHeaders, body: "test" }
|
||||||
|
|
||||||
responseFunctionSpec :: SpecHelpers.Test
|
responseFunctionSpec :: TestHelpers.Test
|
||||||
responseFunctionSpec = Spec.describe "response" do
|
responseFunctionSpec = Spec.describe "response" do
|
||||||
Spec.it "has the right status" do
|
Spec.it "has the right status" do
|
||||||
resp <- Response.response 123 "test"
|
resp <- Response.response 123 "test"
|
||||||
@ -47,7 +47,7 @@ responseFunctionSpec = Spec.describe "response" do
|
|||||||
resp <- Response.response 123 "test"
|
resp <- Response.response 123 "test"
|
||||||
resp.body ?= "test"
|
resp.body ?= "test"
|
||||||
|
|
||||||
response'Spec :: SpecHelpers.Test
|
response'Spec :: TestHelpers.Test
|
||||||
response'Spec = Spec.describe "response'" do
|
response'Spec = Spec.describe "response'" do
|
||||||
Spec.it "has the right status" do
|
Spec.it "has the right status" do
|
||||||
resp <- mockResponse
|
resp <- mockResponse
|
||||||
@ -62,7 +62,7 @@ response'Spec = Spec.describe "response'" do
|
|||||||
mockHeaders = Headers.header "Test" "test"
|
mockHeaders = Headers.header "Test" "test"
|
||||||
mockResponse = Response.response' 123 mockHeaders "test"
|
mockResponse = Response.response' 123 mockHeaders "test"
|
||||||
|
|
||||||
emptyResponseSpec :: SpecHelpers.Test
|
emptyResponseSpec :: TestHelpers.Test
|
||||||
emptyResponseSpec = Spec.describe "emptyResponse" do
|
emptyResponseSpec = Spec.describe "emptyResponse" do
|
||||||
Spec.it "has the right status" do
|
Spec.it "has the right status" do
|
||||||
resp <- Response.emptyResponse 123
|
resp <- Response.emptyResponse 123
|
||||||
@ -74,7 +74,7 @@ emptyResponseSpec = Spec.describe "emptyResponse" do
|
|||||||
resp <- Response.emptyResponse 123
|
resp <- Response.emptyResponse 123
|
||||||
resp.body ?= ""
|
resp.body ?= ""
|
||||||
|
|
||||||
emptyResponse'Spec :: SpecHelpers.Test
|
emptyResponse'Spec :: TestHelpers.Test
|
||||||
emptyResponse'Spec = Spec.describe "emptyResponse'" do
|
emptyResponse'Spec = Spec.describe "emptyResponse'" do
|
||||||
Spec.it "has the right status" do
|
Spec.it "has the right status" do
|
||||||
resp <- mockResponse
|
resp <- mockResponse
|
||||||
@ -89,7 +89,7 @@ emptyResponse'Spec = Spec.describe "emptyResponse'" do
|
|||||||
mockHeaders = Headers.header "Test" "test"
|
mockHeaders = Headers.header "Test" "test"
|
||||||
mockResponse = Response.emptyResponse' 123 mockHeaders
|
mockResponse = Response.emptyResponse' 123 mockHeaders
|
||||||
|
|
||||||
responseSpec :: SpecHelpers.Test
|
responseSpec :: TestHelpers.Test
|
||||||
responseSpec = Spec.describe "Response" do
|
responseSpec = Spec.describe "Response" do
|
||||||
sendSpec
|
sendSpec
|
||||||
responseFunctionSpec
|
responseFunctionSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.ServerSpec where
|
module Test.HTTPure.ServerSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -12,25 +12,25 @@ import HTTPure.Request as Request
|
|||||||
import HTTPure.Response as Response
|
import HTTPure.Response as Response
|
||||||
import HTTPure.Server as Server
|
import HTTPure.Server as Server
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
mockRouter :: forall e. Request.Request -> Response.ResponseM e
|
mockRouter :: forall e. Request.Request -> Response.ResponseM e
|
||||||
mockRouter { path } = Response.ok $ "/" <> String.joinWith "/" path
|
mockRouter { path } = Response.ok $ "/" <> String.joinWith "/" path
|
||||||
|
|
||||||
serveSpec :: SpecHelpers.Test
|
serveSpec :: TestHelpers.Test
|
||||||
serveSpec = Spec.describe "serve" do
|
serveSpec = Spec.describe "serve" do
|
||||||
Spec.it "boots a server on the given port" do
|
Spec.it "boots a server on the given port" do
|
||||||
EffClass.liftEff $ Server.serve 7901 mockRouter $ pure unit
|
EffClass.liftEff $ Server.serve 7901 mockRouter $ pure unit
|
||||||
out <- SpecHelpers.get 7901 StrMap.empty "/test"
|
out <- TestHelpers.get 7901 StrMap.empty "/test"
|
||||||
out ?= "/test"
|
out ?= "/test"
|
||||||
|
|
||||||
serve'Spec :: SpecHelpers.Test
|
serve'Spec :: TestHelpers.Test
|
||||||
serve'Spec = Spec.describe "serve" do
|
serve'Spec = Spec.describe "serve" do
|
||||||
Spec.describe "with valid key and cert files" do
|
Spec.describe "with valid key and cert files" do
|
||||||
Spec.it "boots a server on the given port" do
|
Spec.it "boots a server on the given port" do
|
||||||
EffClass.liftEff $ Server.serve' 7902 cert key mockRouter $ pure unit
|
EffClass.liftEff $ Server.serve' 7902 cert key mockRouter $ pure unit
|
||||||
out <- SpecHelpers.get' 7902 StrMap.empty "/test"
|
out <- TestHelpers.get' 7902 StrMap.empty "/test"
|
||||||
out ?= "/test"
|
out ?= "/test"
|
||||||
Spec.describe "with invalid key and cert files" do
|
Spec.describe "with invalid key and cert files" do
|
||||||
Spec.it "throws" do
|
Spec.it "throws" do
|
||||||
@ -40,7 +40,7 @@ serve'Spec = Spec.describe "serve" do
|
|||||||
cert = "./test/Mocks/Certificate.cer"
|
cert = "./test/Mocks/Certificate.cer"
|
||||||
key = "./test/Mocks/Key.key"
|
key = "./test/Mocks/Key.key"
|
||||||
|
|
||||||
serverSpec :: SpecHelpers.Test
|
serverSpec :: TestHelpers.Test
|
||||||
serverSpec = Spec.describe "Server" do
|
serverSpec = Spec.describe "Server" do
|
||||||
serveSpec
|
serveSpec
|
||||||
serve'Spec
|
serve'Spec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.StatusSpec where
|
module Test.HTTPure.StatusSpec where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
@ -7,18 +7,18 @@ import Test.Spec as Spec
|
|||||||
|
|
||||||
import HTTPure.Status as Status
|
import HTTPure.Status as Status
|
||||||
|
|
||||||
import HTTPure.SpecHelpers as SpecHelpers
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
import HTTPure.SpecHelpers ((?=))
|
import Test.HTTPure.TestHelpers ((?=))
|
||||||
|
|
||||||
writeSpec :: SpecHelpers.Test
|
writeSpec :: TestHelpers.Test
|
||||||
writeSpec = Spec.describe "write" do
|
writeSpec = Spec.describe "write" do
|
||||||
Spec.it "writes the given status code" do
|
Spec.it "writes the given status code" do
|
||||||
status <- EffClass.liftEff do
|
status <- EffClass.liftEff do
|
||||||
mock <- SpecHelpers.mockResponse
|
mock <- TestHelpers.mockResponse
|
||||||
Status.write mock 123
|
Status.write mock 123
|
||||||
pure $ SpecHelpers.getResponseStatus mock
|
pure $ TestHelpers.getResponseStatus mock
|
||||||
status ?= 123
|
status ?= 123
|
||||||
|
|
||||||
statusSpec :: SpecHelpers.Test
|
statusSpec :: TestHelpers.Test
|
||||||
statusSpec = Spec.describe "Status" do
|
statusSpec = Spec.describe "Status" do
|
||||||
writeSpec
|
writeSpec
|
@ -1,4 +1,4 @@
|
|||||||
module HTTPure.SpecHelpers where
|
module Test.HTTPure.TestHelpers where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
37
test/Test/Main.purs
Normal file
37
test/Test/Main.purs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
module Test.Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Test.Spec as Spec
|
||||||
|
import Test.Spec.Reporter as Reporter
|
||||||
|
import Test.Spec.Runner as Runner
|
||||||
|
|
||||||
|
import Test.HTTPure.BodySpec as BodySpec
|
||||||
|
import Test.HTTPure.HeadersSpec as HeadersSpec
|
||||||
|
import Test.HTTPure.HTTPureEffectsSpec as HTTPureEffectsSpec
|
||||||
|
import Test.HTTPure.LookupSpec as LookupSpec
|
||||||
|
import Test.HTTPure.MethodSpec as MethodSpec
|
||||||
|
import Test.HTTPure.PathSpec as PathSpec
|
||||||
|
import Test.HTTPure.QuerySpec as QuerySpec
|
||||||
|
import Test.HTTPure.RequestSpec as RequestSpec
|
||||||
|
import Test.HTTPure.ResponseSpec as ResponseSpec
|
||||||
|
import Test.HTTPure.ServerSpec as ServerSpec
|
||||||
|
import Test.HTTPure.StatusSpec as StatusSpec
|
||||||
|
import Test.HTTPure.IntegrationSpec as IntegrationSpec
|
||||||
|
|
||||||
|
import Test.HTTPure.TestHelpers as TestHelpers
|
||||||
|
|
||||||
|
main :: TestHelpers.TestSuite
|
||||||
|
main = Runner.run [ Reporter.specReporter ] $ Spec.describe "HTTPure" do
|
||||||
|
BodySpec.bodySpec
|
||||||
|
HeadersSpec.headersSpec
|
||||||
|
HTTPureEffectsSpec.httpureEffectsSpec
|
||||||
|
LookupSpec.lookupSpec
|
||||||
|
MethodSpec.methodSpec
|
||||||
|
PathSpec.pathSpec
|
||||||
|
QuerySpec.querySpec
|
||||||
|
RequestSpec.requestSpec
|
||||||
|
ResponseSpec.responseSpec
|
||||||
|
ServerSpec.serverSpec
|
||||||
|
StatusSpec.statusSpec
|
||||||
|
IntegrationSpec.integrationSpec
|
Loading…
Reference in New Issue
Block a user