mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-25 16:36:31 +03:00
6af3fa2d78
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6083 GitOrigin-RevId: 5a7ee37ed3a62224a062dbaac7d322dfd95b83c4
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 (TestData (..))
|
|
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 :: TestData -> Client IO (NamedRoutes API.Routes) -> API.SourceName -> API.Config -> Spec
|
|
spec TestData {..} 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) _tdSchemaTables
|
|
(map (sort . extractForeignKeys) tables) `jsonShouldBe` map (sort . extractForeignKeys) _tdSchemaTables
|