2017-08-15 09:42:24 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Control.Monad (join)
|
|
|
|
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.Wai
|
|
|
|
|
|
|
|
import qualified System.Exit as Exit
|
|
|
|
|
|
|
|
import qualified FirstApp.Conf as Conf
|
|
|
|
import qualified FirstApp.DB as DB
|
|
|
|
import qualified FirstApp.Main as Main
|
|
|
|
import qualified FirstApp.Types as Types
|
2017-08-17 01:54:02 +03:00
|
|
|
import qualified FirstApp.AppM as AppM
|
2017-08-15 09:42:24 +03:00
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
let dieWith m = print m >> Exit.exitFailure
|
|
|
|
|
2017-08-17 04:31:46 +03:00
|
|
|
-- Keeping everything in sync with out larger application changes.
|
2017-08-15 09:42:24 +03:00
|
|
|
reqsE <- Main.prepareAppReqs
|
|
|
|
case reqsE of
|
|
|
|
|
|
|
|
Left err -> dieWith err
|
|
|
|
|
2017-08-17 01:54:02 +03:00
|
|
|
Right env -> do
|
|
|
|
let app' = pure ( Main.app env )
|
2017-08-15 09:42:24 +03:00
|
|
|
|
2017-08-24 07:53:08 +03:00
|
|
|
-- Write a function to clear the comments for a specific topic.
|
|
|
|
-- This will be run before each test is run.
|
2017-08-15 09:42:24 +03:00
|
|
|
flushTopic =
|
2017-08-23 10:14:29 +03:00
|
|
|
error "Flush topic not implemented"
|
2017-08-15 09:42:24 +03:00
|
|
|
|
|
|
|
-- Run the tests with a DB topic flush between each spec
|
|
|
|
hspec . with ( flushTopic >> app' ) $ do
|
|
|
|
|
|
|
|
-- AddRq Spec
|
|
|
|
describe "POST /topic/add" $ do
|
|
|
|
|
|
|
|
it "Should return 200 with well formed request" $ do
|
|
|
|
post "/fudge/add" "Fred" `shouldRespondWith` "Success"
|
|
|
|
|
|
|
|
it "Should 400 on empty input" $
|
|
|
|
post "/fudge/add" "" `shouldRespondWith` 400
|
|
|
|
|
|
|
|
-- ViewRq Spec
|
|
|
|
describe "GET /topic/view" $ do
|
|
|
|
it "Should return 200 with content" $ do
|
|
|
|
post "/fudge/add" "Fred"
|
|
|
|
get "/fudge/view" `shouldRespondWith` 200
|
|
|
|
|
|
|
|
-- ListRq Spec
|
|
|
|
describe "GET /list" $ do
|
|
|
|
it "Should return 200 with content" $ do
|
|
|
|
post "/fudge/add" "Fred"
|
|
|
|
get "/list" `shouldRespondWith` "[\"fudge\"]"
|