mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-21 14:31:55 +03:00
a1c5ac46f6
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6000 Co-authored-by: Daniel Chambers <1214352+daniel-chambers@users.noreply.github.com> GitOrigin-RevId: d8f3cd0194191ab4c51a5a7d350cb2c3a0a5a7f3
41 lines
1.8 KiB
Haskell
41 lines
1.8 KiB
Haskell
module Test.SchemaSpec (spec) where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Data.HashMap.Strict qualified as HashMap
|
|
import Data.List (sort, sortOn)
|
|
import Hasura.Backends.DataConnector.API qualified as API
|
|
import Servant.API (NamedRoutes)
|
|
import Servant.Client (Client, (//))
|
|
import Test.Data qualified as Data
|
|
import Test.Expectations (jsonShouldBe)
|
|
import Test.Hspec (Spec, describe, it)
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
removeDescriptionFromColumn :: API.ColumnInfo -> API.ColumnInfo
|
|
removeDescriptionFromColumn c = c {API._ciDescription = Nothing}
|
|
|
|
removeDescription :: API.TableInfo -> API.TableInfo
|
|
removeDescription t@API.TableInfo {API._tiColumns} = t {API._tiDescription = Nothing, API._tiColumns = newColumns}
|
|
where
|
|
newColumns = map removeDescriptionFromColumn _tiColumns
|
|
|
|
removeForeignKeys :: API.TableInfo -> API.TableInfo
|
|
removeForeignKeys t = t {API._tiForeignKeys = Nothing}
|
|
|
|
extractForeignKeys :: API.TableInfo -> [API.Constraint]
|
|
extractForeignKeys = foldMap (HashMap.elems . API.unConstraints) . API._tiForeignKeys
|
|
|
|
spec :: Client IO (NamedRoutes API.Routes) -> API.SourceName -> API.Config -> Spec
|
|
spec api sourceName config = describe "schema API" $ do
|
|
it "returns Chinook schema" $ do
|
|
tables <- (map removeDescription . sortOn API._tiName . API._srTables) <$> (api // API._schema) sourceName config
|
|
|
|
-- NOTE: Constraint names arent guaranteed to be the same across
|
|
-- Chinook backends so we compare Constraints without their names
|
|
-- independently from the rest of the schema.
|
|
(map removeForeignKeys tables) `jsonShouldBe` map (removeForeignKeys . removeDescription) Data.schemaTables
|
|
(map (sort . extractForeignKeys) tables) `jsonShouldBe` map (sort . extractForeignKeys) Data.schemaTables
|