mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-20 22:11:45 +03:00
a9f77acb32
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
57 lines
1.8 KiB
Haskell
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
|