version 1 done
This commit is contained in:
commit
59e14ce390
47 changed files with 9188 additions and 0 deletions
47
test/Handler/CommentSpec.hs
Normal file
47
test/Handler/CommentSpec.hs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Handler.CommentSpec (spec) where
|
||||
|
||||
import TestImport
|
||||
import Data.Aeson
|
||||
|
||||
spec :: Spec
|
||||
spec = withApp $ do
|
||||
describe "valid request" $ do
|
||||
it "gives a 200" $ do
|
||||
get HomeR
|
||||
statusIs 200
|
||||
|
||||
let message = "My message" :: Text
|
||||
body = object [ "message" .= message ]
|
||||
encoded = encode body
|
||||
|
||||
request $ do
|
||||
setMethod "POST"
|
||||
setUrl CommentR
|
||||
setRequestBody encoded
|
||||
addRequestHeader ("Content-Type", "application/json")
|
||||
|
||||
statusIs 200
|
||||
|
||||
comments <- runDB $ selectList [CommentMessage ==. message] []
|
||||
Entity _id comment <-
|
||||
case comments of
|
||||
[ent] -> pure ent
|
||||
_ -> error "needed 1 entity"
|
||||
assertEq "Should have " comment (Comment message Nothing)
|
||||
|
||||
describe "invalid requests" $ do
|
||||
it "400s when the JSON body is invalid" $ do
|
||||
get HomeR
|
||||
|
||||
let body = object [ "foo" .= ("My message" :: Value) ]
|
||||
|
||||
request $ do
|
||||
setMethod "POST"
|
||||
setUrl CommentR
|
||||
setRequestBody $ encode body
|
||||
addRequestHeader ("Content-Type", "application/json")
|
||||
|
||||
statusIs 400
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue