From 0fa3d1a90c023227e39550a43f93ae965bb78be4 Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Thu, 26 Oct 2017 17:19:30 -0400 Subject: [PATCH] Clean up tests and examples (#86) --- Makefile | 6 +- docs/Examples/AsyncResponse/Main.purs | 2 +- docs/Examples/Headers/Main.purs | 2 +- docs/Examples/HelloWorld/Main.purs | 2 +- docs/Examples/Middleware/Main.purs | 2 +- docs/Examples/MultiRoute/Main.purs | 2 +- docs/Examples/PathSegments/Main.purs | 2 +- docs/Examples/Post/Main.purs | 2 +- docs/Examples/QueryParameters/Main.purs | 2 +- docs/Examples/SSL/Main.purs | 2 +- test/HTTPure/HTTPureEffectsSpec.purs | 11 -- test/HTTPure/IntegrationSpec.purs | 113 ------------------ test/HTTPureSpec.purs | 37 ------ test/{ => Test}/HTTPure/BodySpec.purs | 18 +-- test/Test/HTTPure/HTTPureEffectsSpec.purs | 11 ++ test/{ => Test}/HTTPure/HeadersSpec.purs | 34 +++--- test/Test/HTTPure/IntegrationSpec.purs | 113 ++++++++++++++++++ test/{ => Test}/HTTPure/LookupSpec.purs | 16 +-- test/{ => Test}/HTTPure/MethodSpec.purs | 14 +-- test/{ => Test}/HTTPure/PathSpec.purs | 18 +-- test/{ => Test}/HTTPure/QuerySpec.purs | 24 ++-- test/{ => Test}/HTTPure/RequestSpec.purs | 16 +-- test/{ => Test}/HTTPure/ResponseSpec.purs | 30 ++--- test/{ => Test}/HTTPure/ServerSpec.purs | 16 +-- test/{ => Test}/HTTPure/StatusSpec.purs | 14 +-- .../HTTPure/TestHelpers.js} | 0 .../HTTPure/TestHelpers.purs} | 2 +- test/Test/Main.purs | 37 ++++++ 28 files changed, 272 insertions(+), 276 deletions(-) delete mode 100644 test/HTTPure/HTTPureEffectsSpec.purs delete mode 100644 test/HTTPure/IntegrationSpec.purs delete mode 100644 test/HTTPureSpec.purs rename test/{ => Test}/HTTPure/BodySpec.purs (57%) create mode 100644 test/Test/HTTPure/HTTPureEffectsSpec.purs rename test/{ => Test}/HTTPure/HeadersSpec.purs (85%) create mode 100644 test/Test/HTTPure/IntegrationSpec.purs rename test/{ => Test}/HTTPure/LookupSpec.purs (84%) rename test/{ => Test}/HTTPure/MethodSpec.purs (81%) rename test/{ => Test}/HTTPure/PathSpec.purs (60%) rename test/{ => Test}/HTTPure/QuerySpec.purs (69%) rename test/{ => Test}/HTTPure/RequestSpec.purs (85%) rename test/{ => Test}/HTTPure/ResponseSpec.purs (78%) rename test/{ => Test}/HTTPure/ServerSpec.purs (78%) rename test/{ => Test}/HTTPure/StatusSpec.purs (55%) rename test/{HTTPure/SpecHelpers.js => Test/HTTPure/TestHelpers.js} (100%) rename test/{HTTPure/SpecHelpers.purs => Test/HTTPure/TestHelpers.purs} (99%) create mode 100644 test/Test/Main.purs diff --git a/Makefile b/Makefile index 5e0bd5f..d23834e 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,6 @@ SOURCES := $(SRCPATH)/**/* TESTSOURCES := $(TESTPATH)/**/* EXAMPLESOURCES := $(EXAMPLESPATH)/**/* -# This is the module name for the entry point for the test suite -TESTMAIN := HTTPure.HTTPureSpec - # Install bower components $(COMPONENTS): $(BOWERJSON) $(BOWER) install @@ -65,7 +62,7 @@ $(EXAMPLE_INDEX): $(OUTPUT_EXAMPLE) $(BUILD) $(EXAMPLEPATH)/Main.purs --src-path $(EXAMPLEPATH) \ --include $(SRCPATH) \ --build-path $(BUILD) \ - --main $(EXAMPLE) \ + --main Examples.$(EXAMPLE).Main \ --to $(EXAMPLE_INDEX) # Run the example specified by the environment variable EXAMPLE @@ -91,7 +88,6 @@ test: $(BUILD) $(TESTSOURCES) $(EXAMPLESOURCES) --test-path $(TESTPATH) \ --include $(EXAMPLESPATH) \ --build-path $(BUILD) \ - --main $(TESTMAIN) \ $(BUILD_OPTIONS) # Launch a repl with all modules loaded diff --git a/docs/Examples/AsyncResponse/Main.purs b/docs/Examples/AsyncResponse/Main.purs index 2274b86..fa68427 100644 --- a/docs/Examples/AsyncResponse/Main.purs +++ b/docs/Examples/AsyncResponse/Main.purs @@ -1,4 +1,4 @@ -module AsyncResponse where +module Examples.AsyncResponse.Main where import Prelude diff --git a/docs/Examples/Headers/Main.purs b/docs/Examples/Headers/Main.purs index 0e3b469..c803a1c 100644 --- a/docs/Examples/Headers/Main.purs +++ b/docs/Examples/Headers/Main.purs @@ -1,4 +1,4 @@ -module Headers where +module Examples.Headers.Main where import Prelude diff --git a/docs/Examples/HelloWorld/Main.purs b/docs/Examples/HelloWorld/Main.purs index d7a44cc..c3b0734 100644 --- a/docs/Examples/HelloWorld/Main.purs +++ b/docs/Examples/HelloWorld/Main.purs @@ -1,4 +1,4 @@ -module HelloWorld where +module Examples.HelloWorld.Main where import Prelude diff --git a/docs/Examples/Middleware/Main.purs b/docs/Examples/Middleware/Main.purs index 0b0a635..ff6245c 100644 --- a/docs/Examples/Middleware/Main.purs +++ b/docs/Examples/Middleware/Main.purs @@ -1,4 +1,4 @@ -module Middleware where +module Examples.Middleware.Main where import Prelude diff --git a/docs/Examples/MultiRoute/Main.purs b/docs/Examples/MultiRoute/Main.purs index 12e5711..75d68f1 100644 --- a/docs/Examples/MultiRoute/Main.purs +++ b/docs/Examples/MultiRoute/Main.purs @@ -1,4 +1,4 @@ -module MultiRoute where +module Examples.MultiRoute.Main where import Prelude diff --git a/docs/Examples/PathSegments/Main.purs b/docs/Examples/PathSegments/Main.purs index a793b13..98b0fa2 100644 --- a/docs/Examples/PathSegments/Main.purs +++ b/docs/Examples/PathSegments/Main.purs @@ -1,4 +1,4 @@ -module PathSegments where +module Examples.PathSegments.Main where import Prelude diff --git a/docs/Examples/Post/Main.purs b/docs/Examples/Post/Main.purs index 629eef2..9d559bf 100644 --- a/docs/Examples/Post/Main.purs +++ b/docs/Examples/Post/Main.purs @@ -1,4 +1,4 @@ -module Post where +module Examples.Post.Main where import Prelude diff --git a/docs/Examples/QueryParameters/Main.purs b/docs/Examples/QueryParameters/Main.purs index a59e88b..887e77f 100644 --- a/docs/Examples/QueryParameters/Main.purs +++ b/docs/Examples/QueryParameters/Main.purs @@ -1,4 +1,4 @@ -module QueryParameters where +module Examples.QueryParameters.Main where import Prelude diff --git a/docs/Examples/SSL/Main.purs b/docs/Examples/SSL/Main.purs index 5718c1c..ca870ca 100644 --- a/docs/Examples/SSL/Main.purs +++ b/docs/Examples/SSL/Main.purs @@ -1,4 +1,4 @@ -module SSL where +module Examples.SSL.Main where import Prelude diff --git a/test/HTTPure/HTTPureEffectsSpec.purs b/test/HTTPure/HTTPureEffectsSpec.purs deleted file mode 100644 index 62cb2f4..0000000 --- a/test/HTTPure/HTTPureEffectsSpec.purs +++ /dev/null @@ -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 diff --git a/test/HTTPure/IntegrationSpec.purs b/test/HTTPure/IntegrationSpec.purs deleted file mode 100644 index 99299b5..0000000 --- a/test/HTTPure/IntegrationSpec.purs +++ /dev/null @@ -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 diff --git a/test/HTTPureSpec.purs b/test/HTTPureSpec.purs deleted file mode 100644 index d015f88..0000000 --- a/test/HTTPureSpec.purs +++ /dev/null @@ -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 diff --git a/test/HTTPure/BodySpec.purs b/test/Test/HTTPure/BodySpec.purs similarity index 57% rename from test/HTTPure/BodySpec.purs rename to test/Test/HTTPure/BodySpec.purs index cda6fa8..95c36e7 100644 --- a/test/HTTPure/BodySpec.purs +++ b/test/Test/HTTPure/BodySpec.purs @@ -1,4 +1,4 @@ -module HTTPure.BodySpec where +module Test.HTTPure.BodySpec where import Prelude @@ -7,26 +7,26 @@ import Test.Spec as Spec import HTTPure.Body as Body -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -readSpec :: SpecHelpers.Test +readSpec :: TestHelpers.Test readSpec = Spec.describe "read" 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 ?= "test" -writeSpec :: SpecHelpers.Test +writeSpec :: TestHelpers.Test writeSpec = Spec.describe "write" do Spec.it "writes the string to the Response body" do body <- EffClass.liftEff do - resp <- SpecHelpers.mockResponse + resp <- TestHelpers.mockResponse Body.write resp "test" - pure $ SpecHelpers.getResponseBody resp + pure $ TestHelpers.getResponseBody resp body ?= "test" -bodySpec :: SpecHelpers.Test +bodySpec :: TestHelpers.Test bodySpec = Spec.describe "Body" do readSpec writeSpec diff --git a/test/Test/HTTPure/HTTPureEffectsSpec.purs b/test/Test/HTTPure/HTTPureEffectsSpec.purs new file mode 100644 index 0000000..73f9acc --- /dev/null +++ b/test/Test/HTTPure/HTTPureEffectsSpec.purs @@ -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 diff --git a/test/HTTPure/HeadersSpec.purs b/test/Test/HTTPure/HeadersSpec.purs similarity index 85% rename from test/HTTPure/HeadersSpec.purs rename to test/Test/HTTPure/HeadersSpec.purs index e7854c5..8405620 100644 --- a/test/HTTPure/HeadersSpec.purs +++ b/test/Test/HTTPure/HeadersSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.HeadersSpec where +module Test.HTTPure.HeadersSpec where import Prelude @@ -10,10 +10,10 @@ import Test.Spec as Spec import HTTPure.Headers as Headers import HTTPure.Lookup ((!!)) -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -lookupSpec :: SpecHelpers.Test +lookupSpec :: TestHelpers.Test lookupSpec = Spec.describe "lookup" do Spec.describe "when the string is in the header set" do Spec.describe "when searching with lowercase" do @@ -26,13 +26,13 @@ lookupSpec = Spec.describe "lookup" do Spec.it "is Nothing" do ((Headers.empty !! "X-Test") :: Maybe.Maybe String) ?= Maybe.Nothing -showSpec :: SpecHelpers.Test +showSpec :: TestHelpers.Test showSpec = Spec.describe "show" do Spec.it "is a string representing the headers in HTTP format" do let mock = Headers.header "Test1" "1" <> Headers.header "Test2" "2" show mock ?= "Test1: 1\nTest2: 2\n\n" -eqSpec :: SpecHelpers.Test +eqSpec :: TestHelpers.Test eqSpec = Spec.describe "eq" do Spec.describe "when the two Headers contain the same keys and values" 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" Headers.header "Test1" "1" == mock ?= false -appendSpec :: SpecHelpers.Test +appendSpec :: TestHelpers.Test appendSpec = Spec.describe "append" do Spec.describe "when there are multiple keys" 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" mock ?= Headers.header "Test" "bar" -readSpec :: SpecHelpers.Test +readSpec :: TestHelpers.Test readSpec = Spec.describe "read" do Spec.describe "with no headers" do Spec.it "is an empty StrMap" do - request <- SpecHelpers.mockRequest "" "" "" [] + request <- TestHelpers.mockRequest "" "" "" [] Headers.read request ?= Headers.empty Spec.describe "with headers" do Spec.it "is an StrMap with the contents of the headers" do let testHeader = [Tuple.Tuple "X-Test" "test"] - request <- SpecHelpers.mockRequest "" "" "" testHeader + request <- TestHelpers.mockRequest "" "" "" testHeader Headers.read request ?= Headers.headers testHeader -writeSpec :: SpecHelpers.Test +writeSpec :: TestHelpers.Test writeSpec = Spec.describe "write" do Spec.it "writes the headers to the response" do header <- EffClass.liftEff do - mock <- SpecHelpers.mockResponse + mock <- TestHelpers.mockResponse Headers.write mock $ Headers.header "X-Test" "test" - pure $ SpecHelpers.getResponseHeader "X-Test" mock + pure $ TestHelpers.getResponseHeader "X-Test" mock header ?= "test" -emptySpec :: SpecHelpers.Test +emptySpec :: TestHelpers.Test emptySpec = Spec.describe "empty" do Spec.it "is a empty StrMap in an empty Headers" do show Headers.empty ?= "\n" -headerSpec :: SpecHelpers.Test +headerSpec :: TestHelpers.Test headerSpec = Spec.describe "header" do Spec.it "creates a singleton Headers" do show (Headers.header "X-Test" "test") ?= "X-Test: test\n\n" -headersFunctionSpec :: SpecHelpers.Test +headersFunctionSpec :: TestHelpers.Test headersFunctionSpec = Spec.describe "headers" do Spec.it "is equivalent to using Headers.header with <>" do test ?= expected @@ -109,7 +109,7 @@ headersFunctionSpec = Spec.describe "headers" do ] expected = Headers.header "X-Test-1" "1" <> Headers.header "X-Test-2" "2" -headersSpec :: SpecHelpers.Test +headersSpec :: TestHelpers.Test headersSpec = Spec.describe "Headers" do lookupSpec showSpec diff --git a/test/Test/HTTPure/IntegrationSpec.purs b/test/Test/HTTPure/IntegrationSpec.purs new file mode 100644 index 0000000..67604bb --- /dev/null +++ b/test/Test/HTTPure/IntegrationSpec.purs @@ -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 diff --git a/test/HTTPure/LookupSpec.purs b/test/Test/HTTPure/LookupSpec.purs similarity index 84% rename from test/HTTPure/LookupSpec.purs rename to test/Test/HTTPure/LookupSpec.purs index 7676dfe..8e70d22 100644 --- a/test/HTTPure/LookupSpec.purs +++ b/test/Test/HTTPure/LookupSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.LookupSpec where +module Test.HTTPure.LookupSpec where import Prelude @@ -9,10 +9,10 @@ import Test.Spec as Spec import HTTPure.Lookup ((!!), (!@), (!?)) -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -atSpec :: SpecHelpers.Test +atSpec :: TestHelpers.Test atSpec = Spec.describe "at" do Spec.describe "when the lookup returns a 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 [ "one", "two", "three" ] !@ 4 ?= "" -hasSpec :: SpecHelpers.Test +hasSpec :: TestHelpers.Test hasSpec = Spec.describe "has" do Spec.describe "when the lookup returns a Just" do Spec.it "is true" do @@ -30,7 +30,7 @@ hasSpec = Spec.describe "has" do Spec.it "is false" do [ "one", "two", "three" ] !? 4 ?= false -lookupArraySpec :: SpecHelpers.Test +lookupArraySpec :: TestHelpers.Test lookupArraySpec = Spec.describe "lookupArray" do Spec.describe "when the index is in bounds" 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 (([ "one", "two", "three" ] !! 4) :: Maybe.Maybe String) ?= Maybe.Nothing -lookupStrMapSpec :: SpecHelpers.Test +lookupStrMapSpec :: TestHelpers.Test lookupStrMapSpec = Spec.describe "lookupStrMap" do Spec.describe "when the key is in the StrMap" do Spec.it "is Just the value at the given key" do @@ -50,7 +50,7 @@ lookupStrMapSpec = Spec.describe "lookupStrMap" do where mockStrMap = StrMap.singleton "foo" "bar" -lookupSpec :: SpecHelpers.Test +lookupSpec :: TestHelpers.Test lookupSpec = Spec.describe "Lookup" do atSpec hasSpec diff --git a/test/HTTPure/MethodSpec.purs b/test/Test/HTTPure/MethodSpec.purs similarity index 81% rename from test/HTTPure/MethodSpec.purs rename to test/Test/HTTPure/MethodSpec.purs index b1e948e..599e6fc 100644 --- a/test/HTTPure/MethodSpec.purs +++ b/test/Test/HTTPure/MethodSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.MethodSpec where +module Test.HTTPure.MethodSpec where import Prelude @@ -6,10 +6,10 @@ import Test.Spec as Spec import HTTPure.Method as Method -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -showSpec :: SpecHelpers.Test +showSpec :: TestHelpers.Test showSpec = Spec.describe "show" do Spec.describe "with a Get" do Spec.it "is 'Get'" do @@ -39,14 +39,14 @@ showSpec = Spec.describe "show" do Spec.it "is 'Patch'" do show Method.Patch ?= "Patch" -readSpec :: SpecHelpers.Test +readSpec :: TestHelpers.Test readSpec = Spec.describe "read" do Spec.describe "with a 'GET' Request" do Spec.it "is Get" do - request <- SpecHelpers.mockRequest "GET" "" "" [] + request <- TestHelpers.mockRequest "GET" "" "" [] Method.read request ?= Method.Get -methodSpec :: SpecHelpers.Test +methodSpec :: TestHelpers.Test methodSpec = Spec.describe "Method" do showSpec readSpec diff --git a/test/HTTPure/PathSpec.purs b/test/Test/HTTPure/PathSpec.purs similarity index 60% rename from test/HTTPure/PathSpec.purs rename to test/Test/HTTPure/PathSpec.purs index 7689998..7e92931 100644 --- a/test/HTTPure/PathSpec.purs +++ b/test/Test/HTTPure/PathSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.PathSpec where +module Test.HTTPure.PathSpec where import Prelude @@ -6,28 +6,28 @@ import Test.Spec as Spec import HTTPure.Path as Path -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -readSpec :: SpecHelpers.Test +readSpec :: TestHelpers.Test readSpec = Spec.describe "read" do Spec.describe "with a query string" 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" ] Spec.describe "with no query string" do Spec.it "is the path" do - request <- SpecHelpers.mockRequest "GET" "test/path" "" [] + request <- TestHelpers.mockRequest "GET" "test/path" "" [] Path.read request ?= [ "test", "path" ] Spec.describe "with no segments" do Spec.it "is an empty array" do - request <- SpecHelpers.mockRequest "GET" "" "" [] + request <- TestHelpers.mockRequest "GET" "" "" [] Path.read request ?= [] Spec.describe "with 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" ] -pathSpec :: SpecHelpers.Test +pathSpec :: TestHelpers.Test pathSpec = Spec.describe "Path" do readSpec diff --git a/test/HTTPure/QuerySpec.purs b/test/Test/HTTPure/QuerySpec.purs similarity index 69% rename from test/HTTPure/QuerySpec.purs rename to test/Test/HTTPure/QuerySpec.purs index 27aa9ab..fc7a507 100644 --- a/test/HTTPure/QuerySpec.purs +++ b/test/Test/HTTPure/QuerySpec.purs @@ -1,4 +1,4 @@ -module HTTPure.QuerySpec where +module Test.HTTPure.QuerySpec where import Prelude @@ -8,38 +8,38 @@ import Test.Spec as Spec import HTTPure.Query as Query -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -readSpec :: SpecHelpers.Test +readSpec :: TestHelpers.Test readSpec = Spec.describe "read" do Spec.describe "with no query string" do Spec.it "is an empty StrMap" do - req <- SpecHelpers.mockRequest "" "/test" "" [] + req <- TestHelpers.mockRequest "" "/test" "" [] Query.read req ?= StrMap.empty Spec.describe "with an empty query string" do Spec.it "is an empty StrMap" do - req <- SpecHelpers.mockRequest "" "/test?" "" [] + req <- TestHelpers.mockRequest "" "/test?" "" [] Query.read req ?= StrMap.empty Spec.describe "with a query parameter in the query string" 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" Spec.describe "with empty fields in the query string" 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" Spec.describe "with duplicated params" 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" Spec.describe "with empty params" 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" Spec.describe "with complex params" 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 where expectedComplexResult = @@ -50,6 +50,6 @@ readSpec = Spec.describe "read" do , Tuple.Tuple "g" "true" ] -querySpec :: SpecHelpers.Test +querySpec :: TestHelpers.Test querySpec = Spec.describe "Query" do readSpec diff --git a/test/HTTPure/RequestSpec.purs b/test/Test/HTTPure/RequestSpec.purs similarity index 85% rename from test/HTTPure/RequestSpec.purs rename to test/Test/HTTPure/RequestSpec.purs index 0efb614..44e8fd8 100644 --- a/test/HTTPure/RequestSpec.purs +++ b/test/Test/HTTPure/RequestSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.RequestSpec where +module Test.HTTPure.RequestSpec where import Prelude @@ -10,10 +10,10 @@ import HTTPure.Headers as Headers import HTTPure.Method as Method import HTTPure.Request as Request -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -fromHTTPRequestSpec :: SpecHelpers.Test +fromHTTPRequestSpec :: TestHelpers.Test fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do Spec.it "contains the correct method" do mock <- mockRequest @@ -33,10 +33,10 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do where mockHeaders = [ Tuple.Tuple "Test" "test" ] mockHTTPRequest = - SpecHelpers.mockRequest "POST" "/test?a=b" "body" mockHeaders + TestHelpers.mockRequest "POST" "/test?a=b" "body" mockHeaders mockRequest = mockHTTPRequest >>= Request.fromHTTPRequest -fullPathSpec :: SpecHelpers.Test +fullPathSpec :: TestHelpers.Test fullPathSpec = Spec.describe "fullPath" do Spec.describe "without query parameters" do Spec.it "is correct" do @@ -63,10 +63,10 @@ fullPathSpec = Spec.describe "fullPath" do mock <- mockRequest "/foo///bar/?&a=b&&c" Request.fullPath mock ?= "/foo/bar?a=b&c=true" where - mockHTTPRequest path = SpecHelpers.mockRequest "POST" path "body" [] + mockHTTPRequest path = TestHelpers.mockRequest "POST" path "body" [] mockRequest path = mockHTTPRequest path >>= Request.fromHTTPRequest -requestSpec :: SpecHelpers.Test +requestSpec :: TestHelpers.Test requestSpec = Spec.describe "Request" do fromHTTPRequestSpec fullPathSpec diff --git a/test/HTTPure/ResponseSpec.purs b/test/Test/HTTPure/ResponseSpec.purs similarity index 78% rename from test/HTTPure/ResponseSpec.purs rename to test/Test/HTTPure/ResponseSpec.purs index f9705ec..e6ec551 100644 --- a/test/HTTPure/ResponseSpec.purs +++ b/test/Test/HTTPure/ResponseSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.ResponseSpec where +module Test.HTTPure.ResponseSpec where import Prelude @@ -8,34 +8,34 @@ import Test.Spec as Spec import HTTPure.Headers as Headers import HTTPure.Response as Response -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -sendSpec :: SpecHelpers.Test +sendSpec :: TestHelpers.Test sendSpec = Spec.describe "send" do Spec.it "writes the headers" do header <- EffClass.liftEff do - httpResponse <- SpecHelpers.mockResponse + httpResponse <- TestHelpers.mockResponse Response.send httpResponse mockResponse - pure $ SpecHelpers.getResponseHeader "Test" httpResponse + pure $ TestHelpers.getResponseHeader "Test" httpResponse header ?= "test" Spec.it "writes the status" do status <- EffClass.liftEff do - httpResponse <- SpecHelpers.mockResponse + httpResponse <- TestHelpers.mockResponse Response.send httpResponse mockResponse - pure $ SpecHelpers.getResponseStatus httpResponse + pure $ TestHelpers.getResponseStatus httpResponse status ?= 123 Spec.it "writes the body" do body <- EffClass.liftEff do - httpResponse <- SpecHelpers.mockResponse + httpResponse <- TestHelpers.mockResponse Response.send httpResponse mockResponse - pure $ SpecHelpers.getResponseBody httpResponse + pure $ TestHelpers.getResponseBody httpResponse body ?= "test" where mockHeaders = Headers.header "Test" "test" mockResponse = { status: 123, headers: mockHeaders, body: "test" } -responseFunctionSpec :: SpecHelpers.Test +responseFunctionSpec :: TestHelpers.Test responseFunctionSpec = Spec.describe "response" do Spec.it "has the right status" do resp <- Response.response 123 "test" @@ -47,7 +47,7 @@ responseFunctionSpec = Spec.describe "response" do resp <- Response.response 123 "test" resp.body ?= "test" -response'Spec :: SpecHelpers.Test +response'Spec :: TestHelpers.Test response'Spec = Spec.describe "response'" do Spec.it "has the right status" do resp <- mockResponse @@ -62,7 +62,7 @@ response'Spec = Spec.describe "response'" do mockHeaders = Headers.header "Test" "test" mockResponse = Response.response' 123 mockHeaders "test" -emptyResponseSpec :: SpecHelpers.Test +emptyResponseSpec :: TestHelpers.Test emptyResponseSpec = Spec.describe "emptyResponse" do Spec.it "has the right status" do resp <- Response.emptyResponse 123 @@ -74,7 +74,7 @@ emptyResponseSpec = Spec.describe "emptyResponse" do resp <- Response.emptyResponse 123 resp.body ?= "" -emptyResponse'Spec :: SpecHelpers.Test +emptyResponse'Spec :: TestHelpers.Test emptyResponse'Spec = Spec.describe "emptyResponse'" do Spec.it "has the right status" do resp <- mockResponse @@ -89,7 +89,7 @@ emptyResponse'Spec = Spec.describe "emptyResponse'" do mockHeaders = Headers.header "Test" "test" mockResponse = Response.emptyResponse' 123 mockHeaders -responseSpec :: SpecHelpers.Test +responseSpec :: TestHelpers.Test responseSpec = Spec.describe "Response" do sendSpec responseFunctionSpec diff --git a/test/HTTPure/ServerSpec.purs b/test/Test/HTTPure/ServerSpec.purs similarity index 78% rename from test/HTTPure/ServerSpec.purs rename to test/Test/HTTPure/ServerSpec.purs index e9c53ed..9c0e2df 100644 --- a/test/HTTPure/ServerSpec.purs +++ b/test/Test/HTTPure/ServerSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.ServerSpec where +module Test.HTTPure.ServerSpec where import Prelude @@ -12,25 +12,25 @@ import HTTPure.Request as Request import HTTPure.Response as Response import HTTPure.Server as Server -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) mockRouter :: forall e. Request.Request -> Response.ResponseM e mockRouter { path } = Response.ok $ "/" <> String.joinWith "/" path -serveSpec :: SpecHelpers.Test +serveSpec :: TestHelpers.Test serveSpec = Spec.describe "serve" do Spec.it "boots a server on the given port" do EffClass.liftEff $ Server.serve 7901 mockRouter $ pure unit - out <- SpecHelpers.get 7901 StrMap.empty "/test" + out <- TestHelpers.get 7901 StrMap.empty "/test" out ?= "/test" -serve'Spec :: SpecHelpers.Test +serve'Spec :: TestHelpers.Test 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 - out <- SpecHelpers.get' 7902 StrMap.empty "/test" + out <- TestHelpers.get' 7902 StrMap.empty "/test" out ?= "/test" Spec.describe "with invalid key and cert files" do Spec.it "throws" do @@ -40,7 +40,7 @@ serve'Spec = Spec.describe "serve" do cert = "./test/Mocks/Certificate.cer" key = "./test/Mocks/Key.key" -serverSpec :: SpecHelpers.Test +serverSpec :: TestHelpers.Test serverSpec = Spec.describe "Server" do serveSpec serve'Spec diff --git a/test/HTTPure/StatusSpec.purs b/test/Test/HTTPure/StatusSpec.purs similarity index 55% rename from test/HTTPure/StatusSpec.purs rename to test/Test/HTTPure/StatusSpec.purs index e60acf4..207aa9d 100644 --- a/test/HTTPure/StatusSpec.purs +++ b/test/Test/HTTPure/StatusSpec.purs @@ -1,4 +1,4 @@ -module HTTPure.StatusSpec where +module Test.HTTPure.StatusSpec where import Prelude @@ -7,18 +7,18 @@ import Test.Spec as Spec import HTTPure.Status as Status -import HTTPure.SpecHelpers as SpecHelpers -import HTTPure.SpecHelpers ((?=)) +import Test.HTTPure.TestHelpers as TestHelpers +import Test.HTTPure.TestHelpers ((?=)) -writeSpec :: SpecHelpers.Test +writeSpec :: TestHelpers.Test writeSpec = Spec.describe "write" do Spec.it "writes the given status code" do status <- EffClass.liftEff do - mock <- SpecHelpers.mockResponse + mock <- TestHelpers.mockResponse Status.write mock 123 - pure $ SpecHelpers.getResponseStatus mock + pure $ TestHelpers.getResponseStatus mock status ?= 123 -statusSpec :: SpecHelpers.Test +statusSpec :: TestHelpers.Test statusSpec = Spec.describe "Status" do writeSpec diff --git a/test/HTTPure/SpecHelpers.js b/test/Test/HTTPure/TestHelpers.js similarity index 100% rename from test/HTTPure/SpecHelpers.js rename to test/Test/HTTPure/TestHelpers.js diff --git a/test/HTTPure/SpecHelpers.purs b/test/Test/HTTPure/TestHelpers.purs similarity index 99% rename from test/HTTPure/SpecHelpers.purs rename to test/Test/HTTPure/TestHelpers.purs index 00c6c86..b6bf778 100644 --- a/test/HTTPure/SpecHelpers.purs +++ b/test/Test/HTTPure/TestHelpers.purs @@ -1,4 +1,4 @@ -module HTTPure.SpecHelpers where +module Test.HTTPure.TestHelpers where import Prelude diff --git a/test/Test/Main.purs b/test/Test/Main.purs new file mode 100644 index 0000000..205a606 --- /dev/null +++ b/test/Test/Main.purs @@ -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