graphql-engine/server/tests-hspec/Harness/Test/Hspec/Extended.hs
Philip Lykke Carlsen b658df1c43 Spike attempt at adding logging to the hspec test-suite
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4772
Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
GitOrigin-RevId: 5c6c9056952574462d5b309774331a909a7eac6d
2022-08-03 14:19:53 +00:00

27 lines
918 B
Haskell

-- | This module contains auxiliary extentions to hspec
module Harness.Test.Hspec.Extended
( mapItemAction,
)
where
import Hasura.Prelude
import Test.Hspec
import Test.Hspec.Core.Spec
-- | Modify an 'Item'@ a@ by way of mapping its 'ActionWith'@ a@ function to
-- some 'ActionWith'@ b@, producing an 'Item'@ b@.
--
-- This can be useful when one wants to modify the testEnvironment parameter in a
-- 'SpecWith' test tree, without having to resolve the type mismatch using some
-- combination of type families and helper type classes.
--
-- NOTE: This should go in some sort of @Test.Hspec.Core.Spec.Extended@ module.
mapItemAction :: (ActionWith a -> ActionWith b) -> Item a -> Item b
mapItemAction mapActionWith item@Item {itemExample} =
let mappedExample params next callback =
itemExample
params
(next . mapActionWith)
callback
in item {itemExample = mappedExample}