2017-05-25 19:12:29 +00:00
|
|
|
module HTTPure.IntegrationSpec where
|
|
|
|
|
2017-07-18 05:31:46 +00:00
|
|
|
import Prelude
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import Control.Monad.Eff.Class as EffClass
|
2017-07-18 17:09:03 +00:00
|
|
|
import Data.StrMap as StrMap
|
2017-07-10 10:17:13 +00:00
|
|
|
import Test.Spec as Spec
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import HTTPure.SpecHelpers as SpecHelpers
|
2017-07-19 05:36:56 +00:00
|
|
|
import HTTPure.SpecHelpers ((?=))
|
2017-07-10 10:17:13 +00:00
|
|
|
|
2017-09-27 13:55:36 +00:00
|
|
|
import AsyncResponse as AsyncResponse
|
2017-07-18 17:09:03 +00:00
|
|
|
import Headers as Headers
|
2017-07-10 10:17:13 +00:00
|
|
|
import HelloWorld as HelloWorld
|
2017-09-27 19:34:00 +00:00
|
|
|
import Middleware as Middleware
|
2017-07-10 10:17:13 +00:00
|
|
|
import MultiRoute as MultiRoute
|
2017-09-26 06:08:07 +00:00
|
|
|
import PathSegments as PathSegments
|
2017-09-26 07:14:06 +00:00
|
|
|
import QueryParameters as QueryParameters
|
2017-07-18 17:09:03 +00:00
|
|
|
import Post as Post
|
2017-07-23 19:17:02 +00:00
|
|
|
import SSL as SSL
|
2017-07-18 17:09:03 +00:00
|
|
|
|
2017-09-27 13:55:36 +00:00
|
|
|
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
|
|
|
|
|
2017-07-18 17:09:03 +00:00
|
|
|
headersSpec :: SpecHelpers.Test
|
|
|
|
headersSpec = Spec.it "runs the headers example" do
|
|
|
|
EffClass.liftEff Headers.main
|
2017-07-19 05:44:38 +00:00
|
|
|
header <- SpecHelpers.getHeader port StrMap.empty "/" "X-Example"
|
2017-07-19 05:36:56 +00:00
|
|
|
header ?= "hello world!"
|
2017-07-19 05:44:38 +00:00
|
|
|
response <- SpecHelpers.get port (StrMap.singleton "X-Input" "test") "/"
|
2017-07-19 05:36:56 +00:00
|
|
|
response ?= "test"
|
2017-07-19 05:44:38 +00:00
|
|
|
where port = Headers.port
|
2017-07-10 10:17:13 +00:00
|
|
|
|
|
|
|
helloWorldSpec :: SpecHelpers.Test
|
|
|
|
helloWorldSpec = Spec.it "runs the hello world example" do
|
|
|
|
EffClass.liftEff HelloWorld.main
|
2017-07-19 05:44:38 +00:00
|
|
|
response <- SpecHelpers.get port StrMap.empty "/"
|
2017-07-19 05:36:56 +00:00
|
|
|
response ?= "hello world!"
|
2017-07-19 05:44:38 +00:00
|
|
|
where port = HelloWorld.port
|
2017-07-10 10:17:13 +00:00
|
|
|
|
2017-09-27 19:34:00 +00:00
|
|
|
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
|
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
multiRouteSpec :: SpecHelpers.Test
|
|
|
|
multiRouteSpec = Spec.it "runs the multi route example" do
|
|
|
|
EffClass.liftEff MultiRoute.main
|
2017-07-19 05:44:38 +00:00
|
|
|
hello <- SpecHelpers.get port StrMap.empty "/hello"
|
2017-07-19 05:36:56 +00:00
|
|
|
hello ?= "hello"
|
2017-07-19 05:44:38 +00:00
|
|
|
goodbye <- SpecHelpers.get port StrMap.empty "/goodbye"
|
2017-07-19 05:36:56 +00:00
|
|
|
goodbye ?= "goodbye"
|
2017-07-19 05:44:38 +00:00
|
|
|
where port = MultiRoute.port
|
2017-07-10 10:17:13 +00:00
|
|
|
|
2017-09-26 06:08:07 +00:00
|
|
|
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"
|
2017-09-26 07:14:06 +00:00
|
|
|
somebars ?= "[\"some\",\"bars\"]"
|
2017-09-26 06:08:07 +00:00
|
|
|
where port = PathSegments.port
|
|
|
|
|
2017-09-26 07:14:06 +00:00
|
|
|
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
|
|
|
|
|
2017-07-18 17:09:03 +00:00
|
|
|
postSpec :: SpecHelpers.Test
|
|
|
|
postSpec = Spec.it "runs the post example" do
|
|
|
|
EffClass.liftEff Post.main
|
2017-07-19 05:44:38 +00:00
|
|
|
response <- SpecHelpers.post port StrMap.empty "/" "test"
|
2017-07-19 05:36:56 +00:00
|
|
|
response ?= "test"
|
2017-07-19 05:44:38 +00:00
|
|
|
where port = Post.port
|
2017-07-17 23:42:13 +00:00
|
|
|
|
2017-07-23 19:17:02 +00:00
|
|
|
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
|
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
integrationSpec :: SpecHelpers.Test
|
|
|
|
integrationSpec = Spec.describe "Integration" do
|
2017-09-27 13:55:36 +00:00
|
|
|
asyncResponseSpec
|
2017-07-18 17:09:03 +00:00
|
|
|
headersSpec
|
2017-07-10 10:17:13 +00:00
|
|
|
helloWorldSpec
|
2017-09-27 19:34:00 +00:00
|
|
|
middlewareSpec
|
2017-07-10 10:17:13 +00:00
|
|
|
multiRouteSpec
|
2017-09-26 06:08:07 +00:00
|
|
|
pathSegmentsSpec
|
2017-09-26 07:14:06 +00:00
|
|
|
queryParametersSpec
|
2017-07-18 17:09:03 +00:00
|
|
|
postSpec
|
2017-07-23 19:17:02 +00:00
|
|
|
sslSpec
|