2021-10-29 17:42:07 +03:00
|
|
|
module Hasura.GraphQL.NamespaceSpec (spec) where
|
|
|
|
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
|
|
|
import Hasura.GraphQL.Namespace
|
2022-02-22 18:32:36 +03:00
|
|
|
( NamespacedFieldMap,
|
|
|
|
flattenNamespaces,
|
|
|
|
namespacedField,
|
|
|
|
unflattenNamespaces,
|
|
|
|
)
|
2021-10-29 17:42:07 +03:00
|
|
|
import Hasura.Prelude
|
2022-02-22 18:32:36 +03:00
|
|
|
import Hasura.QuickCheck.Instances ()
|
|
|
|
import Test.Hspec (Spec, describe, shouldBe)
|
|
|
|
import Test.Hspec.QuickCheck (prop)
|
2021-10-29 17:42:07 +03:00
|
|
|
|
|
|
|
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 = OMap.filter (namespacedField (const True) $ not . OMap.null) unflattened
|
|
|
|
in unflattenNamespaces (flattenNamespaces nonEmptyFields) `shouldBe` nonEmptyFields
|