Skip to content

Commit

Permalink
Added a callActionWithParams
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Oct 25, 2021
1 parent 502787a commit 8dc08cb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions IHP/Test/Mocking.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ setupWithContext action context = withContext action context >> pure context

-- | Runs a controller action in a mock environment
callAction :: forall application controller. (Controller controller, ContextParameters application, Typeable application, Typeable controller) => controller -> IO Response
callAction controller = do
callAction controller = callActionWithParams controller []

-- | Runs a controller action in a mock environment
callActionWithParams :: forall application controller. (Controller controller, ContextParameters application, Typeable application, Typeable controller) => controller -> [Param] -> IO Response
callActionWithParams controller params = do
responseRef <- newIORef Nothing
let customRespond response = do
writeIORef responseRef (Just response)
pure ResponseReceived
let requestContextWithOverridenRespond = ?context { respond = customRespond }
let requestContextWithOverridenRespond = ?context { respond = customRespond, requestBody = FormBody params [] }
let ?context = requestContextWithOverridenRespond
runActionWithNewContext controller
maybeResponse <- readIORef responseRef
Expand Down

0 comments on commit 8dc08cb

Please sign in to comment.