graphql-engine/server/src-test/Hasura/Backends/DataConnector/API/V0/CapabilitiesSpec.hs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

143 lines
5.5 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.DataConnector.API.V0.CapabilitiesSpec (spec) where
import Data.Aeson.QQ.Simple (aesonQQ)
import Data.HashMap.Strict qualified as HashMap
import Hasura.Backends.DataConnector.API.V0.Capabilities
import Hasura.Backends.DataConnector.API.V0.ConfigSchema
import Hasura.Backends.DataConnector.API.V0.Scalar (ScalarType (..))
import Hasura.Backends.DataConnector.API.V0.ScalarSpec (genScalarType)
import Hasura.Generator.Common
import Hasura.Prelude
import Hedgehog
import Hedgehog.Gen qualified as Gen
import Language.GraphQL.Draft.Syntax.QQ qualified as G
import Test.Aeson.Utils
import Test.Hspec
spec :: Spec
spec = do
describe "Capabilities" $ do
testToFromJSONToSchema defaultCapabilities [aesonQQ|{}|]
jsonOpenApiProperties genCapabilities
describe "CapabilitiesResponse" $ do
testToFromJSON
(CapabilitiesResponse (defaultCapabilities {_cRelationships = Just RelationshipCapabilities {}}) emptyConfigSchemaResponse Nothing Nothing)
[aesonQQ|{"capabilities": {"relationships": {}}, "config_schemas": {"config_schema": {}, "other_schemas": {}}}|]
describe "ScalarTypesCapabilities" $ do
testToFromJSONToSchema (ScalarTypesCapabilities (HashMap.singleton StringTy (ScalarTypeCapabilities mempty mempty))) [aesonQQ|{"string": {}}|]
jsonOpenApiProperties genScalarTypesCapabilities
describe "ScalarTypeCapabilities" $ do
let comparisonOperators = ComparisonOperators $ HashMap.fromList [([G.name|same_day_as|], CustomTy "DateTime")]
let aggregateFunctions = AggregateFunctions $ HashMap.fromList [([G.name|max|], CustomTy "DateTime")]
let json =
[aesonQQ|{
"comparison_operators": {
"same_day_as": "DateTime"
},
"aggregate_functions": {
"max": "DateTime"
}
}|]
testToFromJSONToSchema (ScalarTypeCapabilities comparisonOperators aggregateFunctions) json
genDataSchemaCapabilities :: MonadGen m => m DataSchemaCapabilities
genDataSchemaCapabilities =
DataSchemaCapabilities
<$> Gen.bool
<*> Gen.bool
<*> genColumnNullability
genColumnNullability :: MonadGen m => m ColumnNullability
genColumnNullability =
Gen.element [NullableAndNonNullableColumns, OnlyNullableColumns]
genQueryCapabilities :: MonadGen m => m QueryCapabilities
genQueryCapabilities = pure QueryCapabilities
genMutationCapabilities :: MonadGen m => m MutationCapabilities
genMutationCapabilities =
MutationCapabilities
<$> Gen.maybe genInsertCapabilities
<*> Gen.maybe genUpdateCapabilities
<*> Gen.maybe genDeleteCapabilities
<*> Gen.maybe genAtomicitySupportLevel
<*> Gen.maybe genReturningCapabilities
genInsertCapabilities :: MonadGen m => m InsertCapabilities
genInsertCapabilities = InsertCapabilities <$> Gen.bool
genUpdateCapabilities :: MonadGen m => m UpdateCapabilities
genUpdateCapabilities = pure UpdateCapabilities
genDeleteCapabilities :: MonadGen m => m DeleteCapabilities
genDeleteCapabilities = pure DeleteCapabilities
genAtomicitySupportLevel :: MonadGen m => m AtomicitySupportLevel
genAtomicitySupportLevel = Gen.enumBounded
genReturningCapabilities :: MonadGen m => m ReturningCapabilities
genReturningCapabilities = pure ReturningCapabilities
genSubscriptionCapabilities :: MonadGen m => m SubscriptionCapabilities
genSubscriptionCapabilities = pure SubscriptionCapabilities {}
genComparisonOperators :: (MonadGen m, GenBase m ~ Identity) => m ComparisonOperators
genComparisonOperators =
ComparisonOperators <$> genHashMap (genGName defaultRange) genScalarType defaultRange
genAggregateFunctions :: (MonadGen m, GenBase m ~ Identity) => m AggregateFunctions
genAggregateFunctions =
AggregateFunctions <$> genHashMap (genGName defaultRange) genScalarType defaultRange
genScalarTypeCapabilities :: (MonadGen m, GenBase m ~ Identity) => m ScalarTypeCapabilities
genScalarTypeCapabilities =
ScalarTypeCapabilities
<$> genComparisonOperators
<*> genAggregateFunctions
genScalarTypesCapabilities :: (MonadGen m, GenBase m ~ Identity) => m ScalarTypesCapabilities
genScalarTypesCapabilities =
ScalarTypesCapabilities <$> genHashMap genScalarType genScalarTypeCapabilities defaultRange
genRelationshipCapabilities :: MonadGen m => m RelationshipCapabilities
genRelationshipCapabilities = pure RelationshipCapabilities {}
genComparisonCapabilities :: MonadGen m => m ComparisonCapabilities
genComparisonCapabilities =
ComparisonCapabilities
<$> Gen.maybe genSubqueryComparisonCapabilities
genSubqueryComparisonCapabilities :: MonadGen m => m SubqueryComparisonCapabilities
genSubqueryComparisonCapabilities =
SubqueryComparisonCapabilities
<$> Gen.bool
genMetricsCapabilities :: MonadGen m => m MetricsCapabilities
genMetricsCapabilities = pure MetricsCapabilities {}
genExplainCapabilities :: MonadGen m => m ExplainCapabilities
genExplainCapabilities = pure ExplainCapabilities {}
genRawCapabilities :: MonadGen m => m RawCapabilities
genRawCapabilities = pure RawCapabilities {}
genCapabilities :: Gen Capabilities
genCapabilities =
Capabilities
<$> genDataSchemaCapabilities
<*> Gen.maybe genQueryCapabilities
<*> Gen.maybe genMutationCapabilities
<*> Gen.maybe genSubscriptionCapabilities
<*> genScalarTypesCapabilities
<*> Gen.maybe genRelationshipCapabilities
<*> Gen.maybe genComparisonCapabilities
<*> Gen.maybe genMetricsCapabilities
<*> Gen.maybe genExplainCapabilities
<*> Gen.maybe genRawCapabilities
emptyConfigSchemaResponse :: ConfigSchemaResponse
emptyConfigSchemaResponse = ConfigSchemaResponse mempty mempty