graphql-engine/server/src-test/Hasura/Backends/DataConnector/API/V0/ColumnSpec.hs
David Overton a9f77acb32 Remove builtin scalar types from Data Connector backend
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7167
Co-authored-by: Daniel Chambers <1214352+daniel-chambers@users.noreply.github.com>
GitOrigin-RevId: 926e7282b908e3a9669ac39d625aa54971e11c37
2023-01-11 02:37:26 +00:00

57 lines
1.8 KiB
Haskell

{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.DataConnector.API.V0.ColumnSpec (spec, genColumnName, genColumnInfo) where
import Data.Aeson.QQ.Simple (aesonQQ)
import Hasura.Backends.DataConnector.API.V0
import Hasura.Backends.DataConnector.API.V0.ScalarSpec (genScalarType)
import Hasura.Generator.Common (defaultRange, genArbitraryAlphaNumText)
import Hasura.Prelude
import Hedgehog
import Hedgehog.Gen qualified as Gen
import Test.Aeson.Utils
import Test.Hspec
spec :: Spec
spec = do
describe "ColumnName" $ do
testToFromJSONToSchema (ColumnName "my_column_name") [aesonQQ|"my_column_name"|]
jsonOpenApiProperties genColumnName
describe "ColumnInfo" $ do
describe "minimal" $
testFromJSON
(ColumnInfo (ColumnName "my_column_name") (ScalarType "string") False Nothing False False)
[aesonQQ|
{ "name": "my_column_name",
"type": "string",
"nullable": false
}
|]
describe "non-minimal" $
testToFromJSONToSchema
(ColumnInfo (ColumnName "my_column_name") (ScalarType "number") True (Just "My column description") True True)
[aesonQQ|
{ "name": "my_column_name",
"type": "number",
"nullable": true,
"description": "My column description",
"insertable": true,
"updatable": true
}
|]
jsonOpenApiProperties genColumnInfo
genColumnName :: MonadGen m => m ColumnName
genColumnName = ColumnName <$> genArbitraryAlphaNumText defaultRange
genColumnInfo :: (MonadGen m, GenBase m ~ Identity) => m ColumnInfo
genColumnInfo =
ColumnInfo
<$> genColumnName
<*> genScalarType
<*> Gen.bool
<*> Gen.maybe (genArbitraryAlphaNumText defaultRange)
<*> Gen.bool
<*> Gen.bool