2022-06-03 11:06:31 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
|
|
|
module Hasura.Backends.DataConnector.API.V0.CapabilitiesSpec (spec) where
|
|
|
|
|
|
|
|
import Data.Aeson.QQ.Simple (aesonQQ)
|
2022-10-27 03:42:49 +03:00
|
|
|
import Data.HashMap.Strict qualified as HashMap
|
2022-06-03 11:06:31 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Capabilities
|
|
|
|
import Hasura.Backends.DataConnector.API.V0.ConfigSchema
|
2022-10-27 03:42:49 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Scalar (ScalarType (..))
|
|
|
|
import Hasura.Backends.DataConnector.API.V0.ScalarSpec (genScalarType)
|
2022-09-06 07:24:46 +03:00
|
|
|
import Hasura.Generator.Common
|
2022-06-03 11:06:31 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hedgehog
|
|
|
|
import Hedgehog.Gen qualified as Gen
|
2022-09-06 07:24:46 +03:00
|
|
|
import Language.GraphQL.Draft.Syntax.QQ qualified as G
|
2022-06-03 11:06:31 +03:00
|
|
|
import Test.Aeson.Utils
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
|
|
|
describe "Capabilities" $ do
|
2022-10-10 09:58:12 +03:00
|
|
|
testToFromJSONToSchema defaultCapabilities [aesonQQ|{}|]
|
2022-06-03 11:06:31 +03:00
|
|
|
jsonOpenApiProperties genCapabilities
|
|
|
|
describe "CapabilitiesResponse" $ do
|
|
|
|
testToFromJSON
|
2022-10-10 09:58:12 +03:00
|
|
|
(CapabilitiesResponse (defaultCapabilities {_cRelationships = Just RelationshipCapabilities {}}) emptyConfigSchemaResponse)
|
2022-09-21 08:11:53 +03:00
|
|
|
[aesonQQ|{"capabilities": {"relationships": {}}, "config_schemas": {"config_schema": {}, "other_schemas": {}}}|]
|
2022-10-27 03:42:49 +03:00
|
|
|
describe "ScalarTypesCapabilities" $ do
|
2022-10-28 04:12:54 +03:00
|
|
|
testToFromJSONToSchema (ScalarTypesCapabilities (HashMap.singleton StringTy (ScalarTypeCapabilities mempty mempty))) [aesonQQ|{"string": {}}|]
|
2022-10-27 03:42:49 +03:00
|
|
|
jsonOpenApiProperties genScalarTypesCapabilities
|
2022-09-06 07:24:46 +03:00
|
|
|
describe "ScalarTypeCapabilities" $ do
|
2022-10-28 04:12:54 +03:00
|
|
|
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
|
2022-06-16 11:30:01 +03:00
|
|
|
|
2022-10-10 09:58:12 +03:00
|
|
|
genDataSchemaCapabilities :: MonadGen m => m DataSchemaCapabilities
|
|
|
|
genDataSchemaCapabilities =
|
|
|
|
DataSchemaCapabilities
|
|
|
|
<$> Gen.bool
|
|
|
|
<*> Gen.bool
|
|
|
|
<*> genColumnNullability
|
|
|
|
|
|
|
|
genColumnNullability :: MonadGen m => m ColumnNullability
|
|
|
|
genColumnNullability =
|
|
|
|
Gen.element [NullableAndNonNullableColumns, OnlyNullableColumns]
|
|
|
|
|
2022-06-16 11:30:01 +03:00
|
|
|
genQueryCapabilities :: MonadGen m => m QueryCapabilities
|
2022-10-10 09:58:12 +03:00
|
|
|
genQueryCapabilities = pure QueryCapabilities
|
2022-06-16 11:30:01 +03:00
|
|
|
|
|
|
|
genMutationCapabilities :: MonadGen m => m MutationCapabilities
|
|
|
|
genMutationCapabilities = pure MutationCapabilities {}
|
|
|
|
|
|
|
|
genSubscriptionCapabilities :: MonadGen m => m SubscriptionCapabilities
|
|
|
|
genSubscriptionCapabilities = pure SubscriptionCapabilities {}
|
|
|
|
|
2022-10-28 04:12:54 +03:00
|
|
|
genComparisonOperators :: MonadGen m => m ComparisonOperators
|
|
|
|
genComparisonOperators =
|
|
|
|
ComparisonOperators <$> genHashMap (genGName defaultRange) genScalarType defaultRange
|
|
|
|
|
2022-10-27 03:42:49 +03:00
|
|
|
genAggregateFunctions :: MonadGen m => m AggregateFunctions
|
|
|
|
genAggregateFunctions =
|
|
|
|
AggregateFunctions <$> genHashMap (genGName defaultRange) genScalarType defaultRange
|
|
|
|
|
2022-09-06 07:24:46 +03:00
|
|
|
genScalarTypeCapabilities :: MonadGen m => m ScalarTypeCapabilities
|
2022-10-27 03:42:49 +03:00
|
|
|
genScalarTypeCapabilities =
|
|
|
|
ScalarTypeCapabilities
|
2022-10-28 04:12:54 +03:00
|
|
|
<$> genComparisonOperators
|
|
|
|
<*> genAggregateFunctions
|
2022-09-06 07:24:46 +03:00
|
|
|
|
|
|
|
genScalarTypesCapabilities :: MonadGen m => m ScalarTypesCapabilities
|
|
|
|
genScalarTypesCapabilities =
|
2022-10-27 03:42:49 +03:00
|
|
|
ScalarTypesCapabilities <$> genHashMap genScalarType genScalarTypeCapabilities defaultRange
|
2022-06-16 11:30:01 +03:00
|
|
|
|
|
|
|
genRelationshipCapabilities :: MonadGen m => m RelationshipCapabilities
|
|
|
|
genRelationshipCapabilities = pure RelationshipCapabilities {}
|
2022-06-03 11:06:31 +03:00
|
|
|
|
2022-09-20 06:59:47 +03:00
|
|
|
genComparisonCapabilities :: MonadGen m => m ComparisonCapabilities
|
|
|
|
genComparisonCapabilities =
|
|
|
|
ComparisonCapabilities
|
2022-09-21 13:46:46 +03:00
|
|
|
<$> Gen.maybe genSubqueryComparisonCapabilities
|
2022-09-20 06:59:47 +03:00
|
|
|
|
2022-09-21 13:46:46 +03:00
|
|
|
genSubqueryComparisonCapabilities :: MonadGen m => m SubqueryComparisonCapabilities
|
|
|
|
genSubqueryComparisonCapabilities =
|
|
|
|
SubqueryComparisonCapabilities
|
2022-09-20 06:59:47 +03:00
|
|
|
<$> Gen.bool
|
|
|
|
|
2022-08-17 04:46:18 +03:00
|
|
|
genMetricsCapabilities :: MonadGen m => m MetricsCapabilities
|
|
|
|
genMetricsCapabilities = pure MetricsCapabilities {}
|
|
|
|
|
2022-08-29 06:38:24 +03:00
|
|
|
genExplainCapabilities :: MonadGen m => m ExplainCapabilities
|
|
|
|
genExplainCapabilities = pure ExplainCapabilities {}
|
|
|
|
|
2022-09-23 00:07:54 +03:00
|
|
|
genRawCapabilities :: MonadGen m => m RawCapabilities
|
|
|
|
genRawCapabilities = pure RawCapabilities {}
|
|
|
|
|
2022-09-06 07:24:46 +03:00
|
|
|
genCapabilities :: Gen Capabilities
|
2022-06-16 11:30:01 +03:00
|
|
|
genCapabilities =
|
|
|
|
Capabilities
|
2022-10-10 09:58:12 +03:00
|
|
|
<$> genDataSchemaCapabilities
|
|
|
|
<*> Gen.maybe genQueryCapabilities
|
2022-06-16 11:30:01 +03:00
|
|
|
<*> Gen.maybe genMutationCapabilities
|
|
|
|
<*> Gen.maybe genSubscriptionCapabilities
|
2022-10-28 04:12:54 +03:00
|
|
|
<*> genScalarTypesCapabilities
|
2022-06-16 11:30:01 +03:00
|
|
|
<*> Gen.maybe genRelationshipCapabilities
|
2022-09-20 06:59:47 +03:00
|
|
|
<*> Gen.maybe genComparisonCapabilities
|
2022-08-17 04:46:18 +03:00
|
|
|
<*> Gen.maybe genMetricsCapabilities
|
2022-08-29 06:38:24 +03:00
|
|
|
<*> Gen.maybe genExplainCapabilities
|
2022-09-23 00:07:54 +03:00
|
|
|
<*> Gen.maybe genRawCapabilities
|
2022-06-03 11:06:31 +03:00
|
|
|
|
|
|
|
emptyConfigSchemaResponse :: ConfigSchemaResponse
|
|
|
|
emptyConfigSchemaResponse = ConfigSchemaResponse mempty mempty
|