This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
fradrive-old/test/Handler/ProfileSpec.hs
2018-11-01 17:44:12 +01:00

46 lines
1.3 KiB
Haskell

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Handler.ProfileSpec (spec) where
import TestImport
import qualified Data.CaseInsensitive as CI
import Yesod.Core.Handler (toTextUrl)
import Yesod.Core.Unsafe (fakeHandlerGetLogger)
spec :: Spec
spec = withApp $ do
describe "Profile page" $ do
it "asserts no access to my-account for anonymous users" $ do
get ProfileR
app <- getTestYesod
loginText <- fakeHandlerGetLogger appLogger app (toTextUrl $ AuthR LoginR)
assertHeader "Location" $ encodeUtf8 loginText
either (fail . unpack) (\_ -> return ()) =<< followRedirect
statusIs 200
it "asserts access to my-account for authenticated users" $ do
userEntity <- createUser "foo"
authenticateAs userEntity
get ProfileR
statusIs 200
it "displays basic user data" $ do
userEntity@(Entity _userId User{..}) <- createUser "foo"
authenticateAs userEntity
get ProfileDataR
statusIs 200
forM_ (words userDisplayName) $ \nameWord -> do
htmlAnyContain ".profile dd" $ unpack nameWord
htmlAnyContain ".profile dd" $ unpack userSurname
htmlAnyContain ".profile dd" . unpack $ CI.original userIdent
htmlAnyContain ".profile dd" . unpack $ CI.original userEmail