{-# LANGUAGE OverloadedStrings #-} module SlashRedirect where import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.HUnit ((@?=), testCase) import Nero import Nero.Application (slashRedirect) app :: Request -> Maybe Response app request = request ^? _GET >>= slashRedirect (prefixed "/hello/" . suffixed "/") (\name -> ok $ "

Hello " <> name <> "

") tests :: TestTree tests = testGroup "SlashRedirect" [ testCase "withSlash" $ run "/hello/there/" @?= Just (ok "

Hello there

") , testCase "withoutSlash" $ run "/hello/there" @?= Just (movedPermanently $ dummyUrl & path .~ "/hello/there/") , testCase "NoMatch" $ run "/bye/there" @?= Nothing ] where run p = app $ dummyRequest & path .~ p main :: IO () main = defaultMain tests