graphql-engine/server/src-test/Hasura/Backends/DataWrapper/API/V0/TableSpec.hs
David Overton 44577dab1b Add ToSchema instances to GDW API types
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4006
Co-authored-by: Daniel Chambers <1214352+daniel-chambers@users.noreply.github.com>
GitOrigin-RevId: 756ca0ed60865d0eb675562e8959f0d1839f9abe
2022-03-31 04:46:08 +00:00

58 lines
1.7 KiB
Haskell

{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.DataWrapper.API.V0.TableSpec (spec, genTableName, genTableInfo) where
import Data.Aeson.QQ.Simple (aesonQQ)
import Hasura.Backends.DataWrapper.API.V0.API
import Hasura.Backends.DataWrapper.API.V0.ColumnSpec (genColumnInfo)
import Hasura.Prelude
import Hedgehog
import Hedgehog.Gen
import Hedgehog.Gen qualified as Gen
import Hedgehog.Range
import Test.Aeson.Utils
import Test.Hspec
spec :: Spec
spec = do
describe "TableName" $ do
testToFromJSONToSchema (TableName "my_table_name") [aesonQQ|"my_table_name"|]
jsonOpenApiProperties genTableName
describe "TableInfo" $ do
describe "minimal" $
testToFromJSONToSchema
(TableInfo (TableName "my_table_name") [] Nothing Nothing)
[aesonQQ|
{ "table_name": "my_table_name",
"columns": []
}
|]
describe "non-minimal" $
testToFromJSONToSchema
( TableInfo
(TableName "my_table_name")
[ColumnInfo (ColumnName "id") StringTy False Nothing]
(Just "id")
(Just "my description")
)
[aesonQQ|
{ "table_name": "my_table_name",
"columns": [{"name": "id", "type": "string", "nullable": false}],
"primary_key": "id",
"description": "my description"
}
|]
jsonOpenApiProperties genTableInfo
genTableName :: MonadGen m => m TableName
genTableName = TableName <$> text (linear 0 10) unicode
genTableInfo :: MonadGen m => m TableInfo
genTableInfo =
TableInfo
<$> genTableName
<*> Gen.list (linear 0 5) genColumnInfo
<*> Gen.maybe (text (linear 0 10) unicode)
<*> Gen.maybe (text (linear 0 20) unicode)