-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDriveSpec.purs
More file actions
55 lines (48 loc) · 2.37 KB
/
DriveSpec.purs
File metadata and controls
55 lines (48 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module Hyper.DriveSpec where
import Prelude
import Data.Maybe (Maybe(..))
import Data.Monoid (mempty)
import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..))
import Foreign.Object as Object
import Hyper.Drive (Response(..), hyperdrive)
import Hyper.Middleware (evalMiddleware)
import Hyper.Status (statusNotFound, statusOK)
import Hyper.Test.TestServer (TestRequest(..), TestResponse(..), defaultRequest, testHeaders, testServer, testStatus, testStringBody)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldContain, shouldEqual)
spec :: Spec Unit
spec = do
let runHyperdrive app =
{ request: TestRequest $ defaultRequest { body = "Bonjour" }
, response: TestResponse Nothing [] []
, components: {}
}
# evalMiddleware (hyperdrive app)
# testServer
describe "Hyper.Drive" do
describe "hyperdrive" do
it "responds with the supplied status" do
conn <- runHyperdrive (const $ pure $ Response { status: statusNotFound
, headers: mempty
, body: mempty
})
testStatus conn `shouldEqual` Just statusNotFound
it "responds with the supplied headers" do
conn <- runHyperdrive (const $ pure $ Response { status: statusOK
, headers: Object.singleton "foo" "bar"
, body: mempty
})
testHeaders conn `shouldContain` Tuple "foo" "bar"
it "responds with the supplied body" do
conn <- runHyperdrive (const $ pure $ Response { status: statusOK
, headers: mempty
, body: "Hello"
})
testStringBody conn `shouldEqual` "Hello"
it "knows the request body" do
conn <- runHyperdrive (\req -> pure $ Response { status: statusOK
, headers: mempty
, body: (unwrap req).body
})
testStringBody conn `shouldEqual` "Bonjour"