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.ColumnSpec (spec, genColumnName, genColumnInfo) 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-10-20 06:23:37 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.ScalarSpec (genScalarType)
|
2022-09-06 07:24:46 +03:00
|
|
|
import Hasura.Generator.Common (defaultRange, genArbitraryAlphaNumText)
|
2022-03-31 07:45:03 +03:00
|
|
|
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
|
2022-12-08 05:05:28 +03:00
|
|
|
describe "minimal" $
|
|
|
|
testFromJSON
|
|
|
|
(ColumnInfo (ColumnName "my_column_name") StringTy False Nothing False False)
|
2022-03-31 07:45:03 +03:00
|
|
|
[aesonQQ|
|
|
|
|
{ "name": "my_column_name",
|
|
|
|
"type": "string",
|
|
|
|
"nullable": false
|
|
|
|
}
|
|
|
|
|]
|
2022-12-08 05:05:28 +03:00
|
|
|
describe "non-minimal" $
|
2022-03-31 07:45:03 +03:00
|
|
|
testToFromJSONToSchema
|
2022-12-08 05:05:28 +03:00
|
|
|
(ColumnInfo (ColumnName "my_column_name") NumberTy True (Just "My column description") True True)
|
2022-03-31 07:45:03 +03:00
|
|
|
[aesonQQ|
|
|
|
|
{ "name": "my_column_name",
|
|
|
|
"type": "number",
|
|
|
|
"nullable": true,
|
2022-12-08 05:05:28 +03:00
|
|
|
"description": "My column description",
|
|
|
|
"insertable": true,
|
|
|
|
"updatable": true
|
2022-03-31 07:45:03 +03:00
|
|
|
}
|
|
|
|
|]
|
|
|
|
jsonOpenApiProperties genColumnInfo
|
|
|
|
|
|
|
|
genColumnName :: MonadGen m => m ColumnName
|
2022-09-06 07:24:46 +03:00
|
|
|
genColumnName = ColumnName <$> genArbitraryAlphaNumText defaultRange
|
2022-03-31 07:45:03 +03:00
|
|
|
|
2022-11-17 03:55:59 +03:00
|
|
|
genColumnInfo :: (MonadGen m, GenBase m ~ Identity) => m ColumnInfo
|
2022-03-31 07:45:03 +03:00
|
|
|
genColumnInfo =
|
|
|
|
ColumnInfo
|
|
|
|
<$> genColumnName
|
2022-10-20 06:23:37 +03:00
|
|
|
<*> genScalarType
|
2022-03-31 07:45:03 +03:00
|
|
|
<*> Gen.bool
|
2022-09-06 07:24:46 +03:00
|
|
|
<*> Gen.maybe (genArbitraryAlphaNumText defaultRange)
|
2022-12-08 05:05:28 +03:00
|
|
|
<*> Gen.bool
|
|
|
|
<*> Gen.bool
|