mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
df4ca23a39
## Description Hopefully this is relatively self-explanatory: this change splits the helper functions we've used to extend QuickCheck from the orphan instances and generators that we have defined for unit tests. These have now been placed in `Test.QuickCheck.Extended` and `Hasura.QuickCheck.Instances`, respectively. This change also adds some documentation to the functions defined in `Test.QuickCheck.Extended` in the spirit of similar functions defined by `Test.QuickCheck`, itself. ### Motivation We should adhere to the existing convention of constructing "extension modules" for common libraries separately from the code that takes advantage of these. Alone, this wouldn't be a reason to split up `Hasura.Generators`, but we should **also** follow a convention of defining **all** orphan instances in modules whose names clearly indicate that they exist solely for the purpose of exporting these orphan instances (e.g. `Hasura.QuickCheck.Instances`). PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3747 GitOrigin-RevId: fb856a790b4a39163f81481d4f900fafb1797ea6
22 lines
811 B
Haskell
22 lines
811 B
Haskell
module Hasura.GraphQL.NamespaceSpec (spec) where
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
|
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 = OMap.filter (namespacedField (const True) $ not . OMap.null) unflattened
|
|
in unflattenNamespaces (flattenNamespaces nonEmptyFields) `shouldBe` nonEmptyFields
|