graphql-engine/server/src-test/Hasura/GraphQL/NamespaceSpec.hs
Tom Harding b6799f0882 Import InsOrdHashMap, not OMap, OM, Map, HM, ...
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8946
GitOrigin-RevId: 434e7c335bc69119020dd35761c7d4539bc51ff8
2023-04-27 07:43:22 +00:00

22 lines
838 B
Haskell

module Hasura.GraphQL.NamespaceSpec (spec) where
import Data.HashMap.Strict.InsOrd qualified as InsOrdHashMap
import Hasura.GraphQL.Namespace
( NamespacedFieldMap,
flattenNamespaces,
namespacedField,
unflattenNamespaces,
)
import Hasura.Prelude
import Hasura.QuickCheck.Instances ()
import Test.Hspec (Spec, describe, shouldBe)
import Test.Hspec.QuickCheck (prop)
spec :: Spec
spec = do
describe "NamespacedField" $ do
prop "flatten/unflatten roundtrip" $ \(unflattened :: NamespacedFieldMap Int) ->
-- If all namespaced fields are non-empty then flattening then unflattening should be the identity
let nonEmptyFields = InsOrdHashMap.filter (namespacedField (const True) $ not . InsOrdHashMap.null) unflattened
in unflattenNamespaces (flattenNamespaces nonEmptyFields) `shouldBe` nonEmptyFields