2022-03-31 07:45:03 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.API.V0.TableSpec (spec, genTableName, genTableInfo) where
|
2022-03-31 07:45:03 +03:00
|
|
|
|
|
|
|
import Data.Aeson.QQ.Simple (aesonQQ)
|
2022-06-24 09:58:25 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0
|
2022-07-01 15:20:07 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.ColumnSpec (genColumnInfo, genColumnName)
|
2022-03-31 07:45:03 +03:00
|
|
|
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
|
2022-08-04 11:34:45 +03:00
|
|
|
testToFromJSONToSchema (TableName ["my_table_name"]) [aesonQQ|["my_table_name"]|]
|
2022-03-31 07:45:03 +03:00
|
|
|
jsonOpenApiProperties genTableName
|
|
|
|
describe "TableInfo" $ do
|
|
|
|
describe "minimal" $
|
|
|
|
testToFromJSONToSchema
|
2022-08-24 00:46:10 +03:00
|
|
|
(TableInfo (TableName ["my_table_name"]) [] Nothing Nothing Nothing)
|
2022-03-31 07:45:03 +03:00
|
|
|
[aesonQQ|
|
2022-08-04 11:34:45 +03:00
|
|
|
{ "name": ["my_table_name"],
|
2022-03-31 07:45:03 +03:00
|
|
|
"columns": []
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
describe "non-minimal" $
|
|
|
|
testToFromJSONToSchema
|
|
|
|
( TableInfo
|
2022-08-04 11:34:45 +03:00
|
|
|
(TableName ["my_table_name"])
|
2022-03-31 07:45:03 +03:00
|
|
|
[ColumnInfo (ColumnName "id") StringTy False Nothing]
|
2022-07-01 15:20:07 +03:00
|
|
|
(Just [ColumnName "id"])
|
2022-03-31 07:45:03 +03:00
|
|
|
(Just "my description")
|
2022-08-24 00:46:10 +03:00
|
|
|
Nothing
|
2022-03-31 07:45:03 +03:00
|
|
|
)
|
|
|
|
[aesonQQ|
|
2022-08-04 11:34:45 +03:00
|
|
|
{ "name": ["my_table_name"],
|
2022-03-31 07:45:03 +03:00
|
|
|
"columns": [{"name": "id", "type": "string", "nullable": false}],
|
2022-07-01 15:20:07 +03:00
|
|
|
"primary_key": ["id"],
|
2022-03-31 07:45:03 +03:00
|
|
|
"description": "my description"
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
jsonOpenApiProperties genTableInfo
|
|
|
|
|
|
|
|
genTableName :: MonadGen m => m TableName
|
2022-08-04 11:34:45 +03:00
|
|
|
genTableName = TableName <$> Gen.nonEmpty (linear 1 3) (text (linear 0 10) unicode)
|
2022-03-31 07:45:03 +03:00
|
|
|
|
|
|
|
genTableInfo :: MonadGen m => m TableInfo
|
|
|
|
genTableInfo =
|
|
|
|
TableInfo
|
|
|
|
<$> genTableName
|
|
|
|
<*> Gen.list (linear 0 5) genColumnInfo
|
2022-07-01 15:20:07 +03:00
|
|
|
<*> Gen.maybe (Gen.list (linear 0 5) genColumnName)
|
2022-03-31 07:45:03 +03:00
|
|
|
<*> Gen.maybe (text (linear 0 20) unicode)
|
2022-08-24 00:46:10 +03:00
|
|
|
<*> pure Nothing
|