在我的 yesod 测试中,我希望能够在测试中间修改数据库中的记录。
这是我想出的代码
yit "post is created by authorized user" $ do
request $ do
addPostParam "ident" "dummy"
setMethod "POST"
setUrl ("http://localhost:3000/auth/page/dummy" :: Text)
update 0 [UserAuthorized =. True]
postBody PostR (encode $ object [
"body" .= ("test post" :: Text),
"title" .= ("test post" :: Text),
"coverImage" .= ("test post" :: Text),
"author" .= (0 :: Int)
])
statusIs 200
这失败并出现错误
• Couldn't match expected type ‘IO a0’
with actual type ‘ReaderT backend0 m0 ()’
• In the second argument of ‘($)’, namely
‘update 0 [UserAuthorized =. True]’
In a stmt of a 'do' block:
runIO $ update 0 [UserAuthorized =. True]
In the expression:
do { settings <- runIO
$ loadYamlSettings
["config/test-settings.yml", "config/settings.yml"] [] useEnv;
foundation <- runIO $ makeFoundation settings;
yesodSpec foundation $ do { ydescribe "Auth" $ do { ... } };
runIO $ update 0 [UserAuthorized =. True];
.... }
我可以说这是因为update
返回m ()
而不是YesodExample site ()
喜欢request
,postBody
并且statusIs
做。
我怎样才能在这个测试中进行数据库更新?