sydtest-yesod-0.3.0.2: A yesod companion library for sydtest
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Syd.Yesod

Description

Testing a yesod site.

For a fully-worked example, see sydtest-yesod/blog-example.

Synopsis

Functions to run a test suite

Tests against a local instance of a site

yesodSpec :: YesodDispatch site => site -> YesodSpec site -> Spec Source #

Run a test suite using the given site.

If your site contains any resources that need to be set up, you probably want to be using one of the following functions instead.

Example usage with a minimal yesod App:

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE QuasiQuotes           #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE TypeFamilies          #-}

module Minimal where

import Yesod
import Test.Syd

data App = App -- | Empty App type

mkYesod "App" [parseRoutes|
    / HomeR GET
|]

instance Yesod App

getHomeR :: Handler Html
getHomeR = "Hello, world!"

main :: IO ()
main = Yesod.warp 3000 App

testMain :: IO ()
testMain = sydTest spec

spec :: Spec
spec = yesodSpec App $ do
  it "returns 200 on the homepage" $ do
    get HomeR
    statusIs 200

This function exists for backward compatibility with yesod-test.

yesodSpecWithSiteGenerator :: YesodDispatch site => IO site -> YesodSpec site -> Spec Source #

Run a test suite using the given site generator.

If your site contains any resources that you will want to have set up beforhand, you will probably want to use yesodSpecWithSiteGeneratorAndArgument or yesodSpecWithSiteSupplierWith instead.

Example usage with a yesod App that contains a secret key that is generated at startup but not used during tests:

data Key = Key -- The implementation of the actual key is omitted here for brevity.
genKey :: IO Key
genKey = pure Key

data App = App { appSecretKey :: Key }

genApp :: IO App
genApp = App <$> genKey

main :: IO ()
main = sydTest spec

spec :: Spec
spec = yesodSpecWithSiteGenerator genApp $ do
  it "returns 200 on the homepage" $ do
    get HomeR
    statusIs 200

This function exists for backward compatibility with yesod-test.

yesodSpecWithSiteGeneratorAndArgument :: YesodDispatch site => (a -> IO site) -> YesodSpec site -> SpecWith a Source #

Run a test suite using the given site generator which uses an inner resource.

If your site contains any resources that you need to set up using a withX function, you will want to use yesodSpecWithSiteSupplier instead.

This function exists for backward compatibility with yesod-test.

yesodSpecWithSiteSupplier :: YesodDispatch site => (forall r. (site -> IO r) -> IO r) -> YesodSpec site -> Spec Source #

Using a function that supplies a site, run a test suite.

Example usage with a yesod App that contains an sqlite database connection. See 'sydtest-persistent-sqlite'.

import Test.Syd.Persistent.Sqlite

data App = App { appConnectionPool :: ConnectionPool }

main :: IO ()
main = sydTest spec

appSupplier :: (App -> IO r) -> IO r
appSupplier func =
  withConnectionPool myMigration $ \pool ->
    func $ App { appConnectionPool = pool}

spec :: Spec
spec = yesodSpecWithSiteSupplier appSupplier $ do
  it "returns 200 on the homepage" $ do
    get HomeR
    statusIs 200

yesodSpecWithSiteSupplierWith :: YesodDispatch site => (forall r. (site -> IO r) -> inner -> IO r) -> YesodSpec site -> SpecWith inner Source #

Using a function that supplies a site, based on an inner resource, run a test suite.

yesodSpecWithSiteSetupFunc :: YesodDispatch site => (Manager -> SetupFunc site) -> TestDef (Manager ': outers) (YesodClient site) -> TestDef (Manager ': outers) () Source #

Using a function that supplies a site, using a SetupFunc

This function assumed that you've already set up the Manager beforehand using something like managerSpec.

yesodSpecWithSiteSetupFunc' :: YesodDispatch site => (Manager -> inner -> SetupFunc site) -> TestDef (Manager ': outers) (YesodClient site) -> TestDef (Manager ': outers) inner Source #

Using a function that supplies a site, using a SetupFunc.

This function assumed that you've already set up the Manager beforehand using something like managerSpec.

Setup functions

Tests against a remote instance of a site

yesodE2ESpec :: URI -> YesodSpec (E2E site) -> Spec Source #

Run an end-to-end yesod test suite against a remote server at the given URI.

If you would like to write tests that can be run against both a local and a remote instance of your site, you can use the following type:

mySpec :: (Yesod site, RedirectUrl site (Route App)) => YesodSpec site
mySpec = do
  it "responds 200 OK to GET HomeR" $ do
    get HomeR
    statusIs 200

yesodE2ESpec' :: URI -> YesodSpec (E2E site) -> TestDef '[Manager] () Source #

Like yesodE2ESpec, but doesn't set up the Manager for you.

If you are running the end-to-end test against a server that uses https://, make sure to use a TLS-enabled Manager.

You can do this using beforeAll newTlsManager.

data E2E site Source #

A dummy type that is an instance of Yesod, with as a phantom type, the app that it represents.

That is to say, E2E site is an instance of Yesod that pretends to be a site. You can treat it as a site in end-to-end tests, except that you cannot use the site value because there is none in there.

Constructors

E2E 

Instances

Instances details
Generic (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Associated Types

type Rep (E2E site) :: Type -> Type #

Methods

from :: E2E site -> Rep (E2E site) x #

to :: Rep (E2E site) x -> E2E site #

Generic (Route (E2E site)) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Associated Types

type Rep (Route (E2E site)) :: Type -> Type #

Methods

from :: Route (E2E site) -> Rep (Route (E2E site)) x #

to :: Rep (Route (E2E site)) x -> Route (E2E site) #

Show (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

showsPrec :: Int -> E2E site -> ShowS #

show :: E2E site -> String #

showList :: [E2E site] -> ShowS #

Show (Route site) => Show (Route (E2E site)) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

showsPrec :: Int -> Route (E2E site) -> ShowS #

show :: Route (E2E site) -> String #

showList :: [Route (E2E site)] -> ShowS #

Eq (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

(==) :: E2E site -> E2E site -> Bool #

(/=) :: E2E site -> E2E site -> Bool #

Eq (Route site) => Eq (Route (E2E site)) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

(==) :: Route (E2E site) -> Route (E2E site) -> Bool #

(/=) :: Route (E2E site) -> Route (E2E site) -> Bool #

Yesod site => Yesod (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

approot :: Approot (E2E site) #

catchHandlerExceptions :: MonadUnliftIO m => E2E site -> m a -> (SomeException -> m a) -> m a #

errorHandler :: ErrorResponse -> HandlerFor (E2E site) TypedContent #

defaultLayout :: WidgetFor (E2E site) () -> HandlerFor (E2E site) Html #

urlParamRenderOverride :: E2E site -> Route (E2E site) -> [(Text, Text)] -> Maybe Builder #

isAuthorized :: Route (E2E site) -> Bool -> HandlerFor (E2E site) AuthResult #

isWriteRequest :: Route (E2E site) -> HandlerFor (E2E site) Bool #

authRoute :: E2E site -> Maybe (Route (E2E site)) #

cleanPath :: E2E site -> [Text] -> Either [Text] [Text] #

joinPath :: E2E site -> Text -> [Text] -> [(Text, Text)] -> Builder #

addStaticContent :: Text -> Text -> ByteString -> HandlerFor (E2E site) (Maybe (Either Text (Route (E2E site), [(Text, Text)]))) #

maximumContentLength :: E2E site -> Maybe (Route (E2E site)) -> Maybe Word64 #

maximumContentLengthIO :: E2E site -> Maybe (Route (E2E site)) -> IO (Maybe Word64) #

makeLogger :: E2E site -> IO Logger #

messageLoggerSource :: E2E site -> Logger -> Loc -> LogSource -> LogLevel -> LogStr -> IO () #

jsLoader :: E2E site -> ScriptLoadPosition (E2E site) #

jsAttributes :: E2E site -> [(Text, Text)] #

jsAttributesHandler :: HandlerFor (E2E site) [(Text, Text)] #

makeSessionBackend :: E2E site -> IO (Maybe SessionBackend) #

fileUpload :: E2E site -> RequestBodyLength -> FileUpload #

shouldLogIO :: E2E site -> LogSource -> LogLevel -> IO Bool #

yesodMiddleware :: ToTypedContent res => HandlerFor (E2E site) res -> HandlerFor (E2E site) res #

yesodWithInternalState :: E2E site -> Maybe (Route (E2E site)) -> (InternalState -> IO a) -> IO a #

defaultMessageWidget :: Html -> HtmlUrl (Route (E2E site)) -> WidgetFor (E2E site) () #

ParseRoute site => ParseRoute (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

parseRoute :: ([Text], [(Text, Text)]) -> Maybe (Route (E2E site)) #

(Eq (Route site), RenderRoute site) => RenderRoute (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Associated Types

data Route (E2E site) #

Methods

renderRoute :: Route (E2E site) -> ([Text], [(Text, Text)]) #

RenderRoute site => RedirectUrl (E2E site) (Route site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

Methods

toTextUrl :: (MonadHandler m, HandlerSite m ~ E2E site) => Route site -> m Text #

type Rep (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

type Rep (E2E site) = D1 ('MetaData "E2E" "Test.Syd.Yesod.E2E" "sydtest-yesod-0.3.0.2-KtanN3rUmDp9Q8nAuuA5iX" 'False) (C1 ('MetaCons "E2E" 'PrefixI 'False) (U1 :: Type -> Type))
type Rep (Route (E2E site)) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

type Rep (Route (E2E site)) = D1 ('MetaData "Route" "Test.Syd.Yesod.E2E" "sydtest-yesod-0.3.0.2-KtanN3rUmDp9Q8nAuuA5iX" 'False) (C1 ('MetaCons "E2ERoute" 'PrefixI 'True) (S1 ('MetaSel ('Just "unE2ERoute") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Route site))))
data Route (E2E site) Source # 
Instance details

Defined in Test.Syd.Yesod.E2E

data Route (E2E site) = E2ERoute {}

localToE2ESpec :: YesodSpec (E2E site) -> YesodSpec site Source #

See localToE2EClient

Turn an end-to-end yesod test suite into a local yesod test suite by treating a local instance as remote.

localToE2EClient :: YesodClient site -> YesodClient (E2E site) Source #

Turn a local 'YesodClient site' into a remote 'YesodClient (E2E site)'.

Core

type YesodSpec site = TestDef '[Manager] (YesodClient site) Source #

For backward compatibility with yesod-test

data YesodClient site Source #

A client environment to call a Yesod app.

Constructors

YesodClient 

Fields

Instances

Instances details
Generic (YesodClient site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Associated Types

type Rep (YesodClient site) :: Type -> Type #

Methods

from :: YesodClient site -> Rep (YesodClient site) x #

to :: Rep (YesodClient site) x -> YesodClient site #

MonadReader (YesodClient site) (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

ask :: YesodClientM site (YesodClient site) #

local :: (YesodClient site -> YesodClient site) -> YesodClientM site a -> YesodClientM site a #

reader :: (YesodClient site -> a) -> YesodClientM site a #

MonadReader (YesodClient site) (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

ask :: RequestBuilder site (YesodClient site) #

local :: (YesodClient site -> YesodClient site) -> RequestBuilder site a -> RequestBuilder site a #

reader :: (YesodClient site -> a) -> RequestBuilder site a #

type Rep (YesodClient site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Rep (YesodClient site) = D1 ('MetaData "YesodClient" "Test.Syd.Yesod.Client" "sydtest-yesod-0.3.0.2-KtanN3rUmDp9Q8nAuuA5iX" 'False) (C1 ('MetaCons "YesodClient" 'PrefixI 'True) (S1 ('MetaSel ('Just "yesodClientSite") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 site) :*: (S1 ('MetaSel ('Just "yesodClientManager") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Manager) :*: S1 ('MetaSel ('Just "yesodClientSiteURI") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 URI))))

data YesodClientState Source #

The state that is maintained throughout a YesodClientM

Constructors

YesodClientState 

Fields

Instances

Instances details
Generic YesodClientState Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Associated Types

type Rep YesodClientState :: Type -> Type #

MonadState YesodClientState (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Rep YesodClientState Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Rep YesodClientState = D1 ('MetaData "YesodClientState" "Test.Syd.Yesod.Client" "sydtest-yesod-0.3.0.2-KtanN3rUmDp9Q8nAuuA5iX" 'False) (C1 ('MetaCons "YesodClientState" 'PrefixI 'True) (S1 ('MetaSel ('Just "yesodClientStateLast") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe (Request, Response ByteString))) :*: S1 ('MetaSel ('Just "yesodClientStateCookies") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CookieJar)))

newtype YesodClientM site a Source #

A monad to call a Yesod app.

This has access to a 'YesodClient site'.

Instances

Instances details
MonadState YesodClientState (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

MonadFail (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

fail :: String -> YesodClientM site a #

MonadIO (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

liftIO :: IO a -> YesodClientM site a #

Applicative (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

pure :: a -> YesodClientM site a #

(<*>) :: YesodClientM site (a -> b) -> YesodClientM site a -> YesodClientM site b #

liftA2 :: (a -> b -> c) -> YesodClientM site a -> YesodClientM site b -> YesodClientM site c #

(*>) :: YesodClientM site a -> YesodClientM site b -> YesodClientM site b #

(<*) :: YesodClientM site a -> YesodClientM site b -> YesodClientM site a #

Functor (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

fmap :: (a -> b) -> YesodClientM site a -> YesodClientM site b #

(<$) :: a -> YesodClientM site b -> YesodClientM site a #

Monad (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

(>>=) :: YesodClientM site a -> (a -> YesodClientM site b) -> YesodClientM site b #

(>>) :: YesodClientM site a -> YesodClientM site b -> YesodClientM site b #

return :: a -> YesodClientM site a #

MonadThrow (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

throwM :: Exception e => e -> YesodClientM site a #

MonadReader (YesodClient site) (YesodClientM site) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Methods

ask :: YesodClientM site (YesodClient site) #

local :: (YesodClient site -> YesodClient site) -> YesodClientM site a -> YesodClientM site a #

reader :: (YesodClient site -> a) -> YesodClientM site a #

IsTest (YesodClientM site ()) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Associated Types

type Arg1 (YesodClientM site ()) #

type Arg2 (YesodClientM site ()) #

Methods

runTest :: YesodClientM site () -> TestRunSettings -> ProgressReporter -> ((Arg1 (YesodClientM site ()) -> Arg2 (YesodClientM site ()) -> IO ()) -> IO ()) -> IO TestRunResult #

IsTest (outerArgs -> YesodClientM site ()) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

Associated Types

type Arg1 (outerArgs -> YesodClientM site ()) #

type Arg2 (outerArgs -> YesodClientM site ()) #

Methods

runTest :: (outerArgs -> YesodClientM site ()) -> TestRunSettings -> ProgressReporter -> ((Arg1 (outerArgs -> YesodClientM site ()) -> Arg2 (outerArgs -> YesodClientM site ()) -> IO ()) -> IO ()) -> IO TestRunResult #

type Arg1 (YesodClientM site ()) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Arg1 (YesodClientM site ()) = ()
type Arg1 (outerArgs -> YesodClientM site ()) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Arg1 (outerArgs -> YesodClientM site ()) = outerArgs
type Arg2 (YesodClientM site ()) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Arg2 (YesodClientM site ()) = YesodClient site
type Arg2 (outerArgs -> YesodClientM site ()) Source # 
Instance details

Defined in Test.Syd.Yesod.Client

type Arg2 (outerArgs -> YesodClientM site ()) = YesodClient site

runYesodClientM :: YesodClient site -> YesodClientM site a -> IO a Source #

Run a YesodClientM site using a YesodClient site

type YesodExample site a = YesodClientM site a Source #

For backward compatibility

Helper functions to define tests

yit :: forall site. HasCallStack => String -> YesodClientM site () -> YesodSpec site Source #

Define a test in the YesodClientM site monad instead of IO.

The YesodClientM site () type is a member of IsTest, so yit is defined as it. This function is only here for backward compatibility.

yit = it

ydescribe :: String -> YesodSpec site -> YesodSpec site Source #

For compatibility with yesod-test

ydescribe = describe

Making requests

get :: (Yesod site, RedirectUrl site url) => url -> YesodClientM site () Source #

Make a GET request for the given route

it "returns 200 on the home route" $ do
  get HomeR
  statusIs 200

post :: (Yesod site, RedirectUrl site url) => url -> YesodClientM site () Source #

Make a POST request for the given route

it "returns 200 on the start processing route" $ do
  post StartProcessingR
  statusIs 200

followRedirect Source #

Arguments

:: Yesod site 
=> YesodExample site (Either Text Text)

Left with an error message if not a redirect, Right with the redirected URL if it was

Follow a redirect, if the last response was a redirect.

(We consider a request a redirect if the status is 301, 302, 303, 307 or 308, and the Location header is set.)

 it "redirects home" $ do
   get RedirectHomeR
   statusIs 303
   locationShouldBe HomeR
   _ <- followRedirect
   statusIs 200

Using the request builder

request :: RequestBuilder site a -> YesodClientM site () Source #

Perform the request that is built by the given RequestBuilder.

it "returns 200 on this post request" $ do
  request $ do
    setUrl StartProcessingR
    setMethod "POST"
    addPostParam "key" "value"
  statusIs 200

setUrl :: (Yesod site, RedirectUrl site url) => url -> RequestBuilder site () Source #

Set the url of the RequestBuilder to the given route.

setMethod :: Method -> RequestBuilder site () Source #

Set the method of the RequestBuilder.

addRequestHeader :: Header -> RequestBuilder site () Source #

Add the given request header to the RequestBuilder.

addGetParam :: Text -> Text -> RequestBuilder site () Source #

Add the given GET parameter to the RequestBuilder.

addPostParam :: Text -> Text -> RequestBuilder site () Source #

Add the given POST parameter to the RequestBuilder.

addFile Source #

Arguments

:: Text

The parameter name for the file.

-> FilePath

The path to the file.

-> Text

The MIME type of the file, e.g. "image/png".

-> RequestBuilder site () 

addFileWith Source #

Arguments

:: Text

The parameter name for the file.

-> FilePath

The path to the file.

-> ByteString

The contents of the file.

-> Maybe Text

The MIME type of the file, e.g. "image/png".

-> RequestBuilder site () 

setRequestBody :: ByteString -> RequestBuilder site () Source #

Set the request body of the RequestBuilder.

Note that this invalidates any of the other post parameters that may have been set.

Helpers

performMethod :: (Yesod site, RedirectUrl site url) => Method -> url -> YesodClientM site () Source #

Perform a request using an arbitrary method for the given route.

performRequest :: Request -> YesodClientM site () Source #

Perform the given request as-is.

Note that this function does not check whether you are making a request to the site under test. You could make a request to https://example.com if you wanted.

Types

newtype RequestBuilder site a Source #

A request builder monad that allows you to monadically build a request using runRequestBuilder.

This request builder has access to the entire YesodClientM underneath. This includes the Site under test, as well as cookies etc.

See YesodClientM for more details.

Constructors

RequestBuilder 

Instances

Instances details
MonadFail (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

fail :: String -> RequestBuilder site a #

MonadIO (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

liftIO :: IO a -> RequestBuilder site a #

Applicative (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

pure :: a -> RequestBuilder site a #

(<*>) :: RequestBuilder site (a -> b) -> RequestBuilder site a -> RequestBuilder site b #

liftA2 :: (a -> b -> c) -> RequestBuilder site a -> RequestBuilder site b -> RequestBuilder site c #

(*>) :: RequestBuilder site a -> RequestBuilder site b -> RequestBuilder site b #

(<*) :: RequestBuilder site a -> RequestBuilder site b -> RequestBuilder site a #

Functor (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

fmap :: (a -> b) -> RequestBuilder site a -> RequestBuilder site b #

(<$) :: a -> RequestBuilder site b -> RequestBuilder site a #

Monad (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

(>>=) :: RequestBuilder site a -> (a -> RequestBuilder site b) -> RequestBuilder site b #

(>>) :: RequestBuilder site a -> RequestBuilder site b -> RequestBuilder site b #

return :: a -> RequestBuilder site a #

MonadThrow (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

throwM :: Exception e => e -> RequestBuilder site a #

MonadReader (YesodClient site) (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

Methods

ask :: RequestBuilder site (YesodClient site) #

local :: (YesodClient site -> YesodClient site) -> RequestBuilder site a -> RequestBuilder site a #

reader :: (YesodClient site -> a) -> RequestBuilder site a #

MonadState (RequestBuilderData site) (RequestBuilder site) Source # 
Instance details

Defined in Test.Syd.Yesod.Request

runRequestBuilder :: RequestBuilder site a -> YesodClientM site Request Source #

Run a RequestBuilder to make the Request that it defines.

Token

addToken :: HasCallStack => RequestBuilder site () Source #

Look up the CSRF token from the only form data and add it to the request header

addToken_ :: HasCallStack => Text -> RequestBuilder site () Source #

Look up the CSRF token from the given form data and add it to the request header

addTokenFromCookie :: HasCallStack => RequestBuilder site () Source #

Look up the CSRF token from the cookie with name defaultCsrfCookieName and add it to the request header with name defaultCsrfHeaderName.

addTokenFromCookieNamedToHeaderNamed Source #

Arguments

:: HasCallStack 
=> ByteString

The name of the cookie

-> CI ByteString

The name of the header

-> RequestBuilder site () 

Looks up the CSRF token stored in the cookie with the given name and adds it to the given request header.

Queries

getStatus :: YesodClientM site (Maybe Int) Source #

Get the status of the most recently received response.

requireStatus :: YesodClientM site Int Source #

Get the status of the most recently received response, and assert that it already exists.

getRequest :: YesodClientM site (Maybe Request) Source #

Get the most recently sent request.

requireRequest :: YesodClientM site Request Source #

Get the most recently sent request.

getResponse :: YesodClientM site (Maybe (Response ByteString)) Source #

Get the most recently received response.

requireResponse :: YesodClientM site (Response ByteString) Source #

Get the most recently received response, and assert that it already exists.

getLocation :: ParseRoute site => YesodClientM localSite (Either Text (Route site)) Source #

Get the Location header of most recently received response.

requireLocation :: ParseRoute site => YesodClientM localSite (Route site) Source #

Get the Location header of most recently received response, and assert that it is a valid Route.

getLast :: YesodClientM site (Maybe (Request, Response ByteString)) Source #

Get the most recently sent request and the response to it.

requireLast :: YesodClientM site (Request, Response ByteString) Source #

Get the most recently sent request and the response to it, and assert that they already exist.

Declaring assertions

statusShouldBe :: HasCallStack => Int -> YesodClientM site () Source #

Assert the status of the most recently received response.

it "returns 200 on the home route" $ do
  get HomeR
  statusShouldBe 200

locationShouldBe :: (ParseRoute site, Show (Route site)) => Route site -> YesodClientM localSite () Source #

Assert the redirect location of the most recently received response.

it "redirects to the overview on the home route" $ do
  get HomeR
  statusIs 301
  locationShouldBe OverviewR

bodyContains :: HasCallStack => String -> YesodExample site () Source #

Assert the last response has the given text.

The check is performed using the response body in full text form without any html parsing.

statusIs :: HasCallStack => Int -> YesodClientM site () Source #

Synonym of statusShouldBe for compatibility with yesod-test

Just to be sure we didn't forget any exports

Reexports