mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
tests: Convert more Context -> Fixture in hspec tests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5384 GitOrigin-RevId: 582583b1722bb9942eda96c6b418eff8a69921d5
This commit is contained in:
parent
0460d7d6d1
commit
bcd7c01161
@ -4,12 +4,11 @@
|
||||
-- https://github.com/hasura/graphql-engine-mono/pull/4651
|
||||
module Test.ArrayParamPermissionSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..))
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -23,16 +22,12 @@ import Test.Hspec (SpecWith, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = postgresSetup,
|
||||
teardown = postgresTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
Fixture.run
|
||||
( [ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[postgresSetupTeardown testEnv]
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
@ -61,6 +56,12 @@ author =
|
||||
|
||||
-- ** Setup and teardown
|
||||
|
||||
postgresSetupTeardown :: TestEnvironment -> Fixture.SetupAction
|
||||
postgresSetupTeardown testEnv =
|
||||
Fixture.SetupAction
|
||||
(postgresSetup (testEnv, ()))
|
||||
(const $ postgresTeardown (testEnv, ()))
|
||||
|
||||
postgresSetup :: (TestEnvironment, ()) -> IO ()
|
||||
postgresSetup (testEnvironment, localTestEnvironment) = do
|
||||
Postgres.setup schema (testEnvironment, localTestEnvironment)
|
||||
@ -108,7 +109,7 @@ args:
|
||||
|
||||
-- * Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
it "non-matching X-Hasura-Allowed-Ids should return no data" $ \testEnvironment -> do
|
||||
let userHeaders = [("X-Hasura-Role", "user"), ("X-Hasura-Allowed-Ids", "{}")]
|
||||
|
@ -3,13 +3,12 @@
|
||||
-- | Test insert check permissions
|
||||
module Test.InsertCheckPermissionSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.Exceptions
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -23,17 +22,12 @@ import Test.Hspec (SpecWith, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = mssqlSetup,
|
||||
teardown = mssqlTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[mssqlSetupTeardown testEnv]
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -74,6 +68,12 @@ article =
|
||||
|
||||
-- ** Setup and teardown
|
||||
|
||||
mssqlSetupTeardown :: TestEnvironment -> Fixture.SetupAction
|
||||
mssqlSetupTeardown testEnv =
|
||||
Fixture.SetupAction
|
||||
(mssqlSetup (testEnv, ()))
|
||||
(const $ mssqlTeardown (testEnv, ()))
|
||||
|
||||
mssqlSetup :: (TestEnvironment, ()) -> IO ()
|
||||
mssqlSetup (testEnvironment, ()) = do
|
||||
Sqlserver.setup schema (testEnvironment, ())
|
||||
@ -170,7 +170,7 @@ args:
|
||||
|
||||
-- * Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let userHeaders = [("X-Hasura-Role", "user"), ("X-Hasura-User-Id", "2")]
|
||||
it "Insert article with mismatching author_id and X-Hasura-User-Id" $ \testEnvironment ->
|
||||
|
@ -5,12 +5,11 @@
|
||||
-- Test case for bug reported at https://github.com/hasura/graphql-engine/issues/7936
|
||||
module Test.ObjectRelationshipsLimitSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Postgres as Postgres
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql
|
||||
import Harness.Quoter.Yaml
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -24,17 +23,12 @@ import Test.Hspec
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = postgresSetup,
|
||||
teardown = postgresTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[postgresSetupTeardown testEnv]
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -77,6 +71,12 @@ article =
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
postgresSetupTeardown :: TestEnvironment -> Fixture.SetupAction
|
||||
postgresSetupTeardown testEnv =
|
||||
Fixture.SetupAction
|
||||
(postgresSetup (testEnv, ()))
|
||||
(const $ postgresTeardown (testEnv, ()))
|
||||
|
||||
-- ** Setup and teardown override
|
||||
|
||||
postgresSetup :: (TestEnvironment, ()) -> IO ()
|
||||
@ -127,7 +127,7 @@ args:
|
||||
--
|
||||
-- Because of that, we use 'shouldReturnOneOfYaml' and list all of the possible (valid)
|
||||
-- expected results.
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
it "Query by id" $ \testEnvironment ->
|
||||
shouldReturnOneOfYaml
|
||||
|
@ -3,7 +3,6 @@
|
||||
module Test.Schema.TableRelationships.ArrayRelationshipsSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Mysql qualified as Mysql
|
||||
@ -12,7 +11,7 @@ import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.Test.SchemaName
|
||||
@ -23,48 +22,33 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec = do
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.MySQL,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Mysql.setup schema,
|
||||
teardown = Mysql.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Citus,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Citus.setup schema,
|
||||
teardown = Citus.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Sqlserver.setup schema,
|
||||
teardown = Sqlserver.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = BigQuery.setup schema,
|
||||
teardown = BigQuery.teardown schema,
|
||||
customOptions =
|
||||
Just $
|
||||
Context.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
Fixture.run
|
||||
( [ (Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[Mysql.setupTablesAction schema testEnv]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[Postgres.setupTablesAction schema testEnv]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[Citus.setupTablesAction schema testEnv]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[Sqlserver.setupTablesAction schema testEnv]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[BigQuery.setupTablesAction schema testEnv],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
@ -114,7 +98,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
Loading…
Reference in New Issue
Block a user