2022-04-10 07:47:15 +03:00
|
|
|
module Test.SchemaSpec (spec) where
|
|
|
|
|
|
|
|
import Data.List (sortOn)
|
2022-06-03 11:06:31 +03:00
|
|
|
import Hasura.Backends.DataConnector.API (Config, Routes (..), SchemaResponse (..), SourceName, TableInfo (..))
|
2022-07-19 03:37:04 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Column (ColumnInfo (..))
|
2022-04-10 07:47:15 +03:00
|
|
|
import Servant.API (NamedRoutes)
|
|
|
|
import Servant.Client (Client, (//))
|
|
|
|
import Test.Data qualified as Data
|
2022-08-04 04:00:48 +03:00
|
|
|
import Test.Expectations (jsonShouldBe)
|
2022-04-10 07:47:15 +03:00
|
|
|
import Test.Hspec (Spec, describe, it)
|
|
|
|
import Prelude
|
|
|
|
|
2022-07-19 03:37:04 +03:00
|
|
|
removeDescriptionFromColumn :: ColumnInfo -> ColumnInfo
|
|
|
|
removeDescriptionFromColumn c = c {dciDescription = Nothing}
|
|
|
|
|
|
|
|
removeDescription :: TableInfo -> TableInfo
|
|
|
|
removeDescription t@TableInfo {dtiColumns} = t {dtiDescription = Nothing, dtiColumns = newColumns}
|
|
|
|
where
|
|
|
|
newColumns = map removeDescriptionFromColumn dtiColumns
|
|
|
|
|
2022-06-03 11:06:31 +03:00
|
|
|
spec :: Client IO (NamedRoutes Routes) -> SourceName -> Config -> Spec
|
|
|
|
spec api sourceName config = describe "schema API" $ do
|
2022-04-10 07:47:15 +03:00
|
|
|
it "returns Chinook schema" $ do
|
2022-07-19 03:37:04 +03:00
|
|
|
tables <- (map removeDescription . sortOn dtiName . srTables) <$> (api // _schema) sourceName config
|
2022-08-04 04:00:48 +03:00
|
|
|
tables `jsonShouldBe` map removeDescription Data.schemaTables
|