tests: convert InsertDefaults Context test to Fixture

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5382
GitOrigin-RevId: 3964dda7307bde6e294be36791a76c8e459afa25
This commit is contained in:
Daniel Harvey 2022-08-10 17:15:29 +01:00 committed by hasura-bot
parent 712e3aeddd
commit 548edcc6e6

View File

@ -3,14 +3,13 @@
-- | Test insert with default values -- | Test insert with default values
module Test.InsertDefaultsSpec (spec) where module Test.InsertDefaultsSpec (spec) where
import Data.List.NonEmpty qualified as NE
import Harness.Backend.Citus qualified as Citus import Harness.Backend.Citus qualified as Citus
import Harness.Backend.Postgres qualified as Postgres import Harness.Backend.Postgres qualified as Postgres
import Harness.Backend.Sqlserver qualified as Sqlserver import Harness.Backend.Sqlserver qualified as Sqlserver
import Harness.GraphqlEngine qualified as GraphqlEngine import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Quoter.Graphql (graphql) import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml) 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 (Table (..), table)
import Harness.Test.Schema qualified as Schema import Harness.Test.Schema qualified as Schema
import Harness.TestEnvironment (TestEnvironment) import Harness.TestEnvironment (TestEnvironment)
@ -24,33 +23,24 @@ import Test.Hspec (SpecWith, it)
spec :: SpecWith TestEnvironment spec :: SpecWith TestEnvironment
spec = do spec = do
Context.run (NE.fromList [postgresContext, citusContext, mssqlContext]) commonTests Fixture.run ([postgresFixture, citusFixture, mssqlFixture]) commonTests
Context.run (NE.fromList [postgresContext, citusContext]) postgresTests Fixture.run ([postgresFixture, citusFixture]) postgresTests
Context.run (NE.fromList [mssqlContext]) mssqlTests Fixture.run ([mssqlFixture]) mssqlTests
where where
postgresContext = postgresFixture =
Context.Context (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
{ name = Context.Backend Context.Postgres, { Fixture.setupTeardown = \(testEnv, _) ->
mkLocalTestEnvironment = Context.noLocalTestEnvironment, [Postgres.setupTablesAction schema testEnv]
setup = Postgres.setup schema,
teardown = Postgres.teardown schema,
customOptions = Nothing
} }
citusContext = citusFixture =
Context.Context (Fixture.fixture $ Fixture.Backend Fixture.Citus)
{ name = Context.Backend Context.Citus, { Fixture.setupTeardown = \(testEnv, _) ->
mkLocalTestEnvironment = Context.noLocalTestEnvironment, [Citus.setupTablesAction schema testEnv]
setup = Citus.setup schema,
teardown = Citus.teardown schema,
customOptions = Nothing
} }
mssqlContext = mssqlFixture =
Context.Context (Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
{ name = Context.Backend Context.SQLServer, { Fixture.setupTeardown = \(testEnv, _) ->
mkLocalTestEnvironment = Context.noLocalTestEnvironment, [Sqlserver.setupTablesAction schema testEnv]
setup = Sqlserver.setup schema,
teardown = Sqlserver.teardown schema,
customOptions = Nothing
} }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -112,7 +102,7 @@ defaultDateTimeType =
-- * Tests -- * Tests
commonTests :: Context.Options -> SpecWith TestEnvironment commonTests :: Fixture.Options -> SpecWith TestEnvironment
commonTests opts = do commonTests opts = do
it "Insert empty object with default values" $ \testEnvironment -> it "Insert empty object with default values" $ \testEnvironment ->
shouldReturnYaml shouldReturnYaml
@ -184,7 +174,7 @@ data:
name: "a" name: "a"
|] |]
postgresTests :: Context.Options -> SpecWith TestEnvironment postgresTests :: Fixture.Options -> SpecWith TestEnvironment
postgresTests opts = do postgresTests opts = do
it "Upsert simple object with default values - check empty constraints" $ \testEnvironment -> it "Upsert simple object with default values - check empty constraints" $ \testEnvironment ->
shouldReturnYaml shouldReturnYaml
@ -282,7 +272,7 @@ data:
id: 1 id: 1
|] |]
mssqlTests :: Context.Options -> SpecWith TestEnvironment mssqlTests :: Fixture.Options -> SpecWith TestEnvironment
mssqlTests opts = do mssqlTests opts = do
it "Upsert simple object with default values - check empty if_matched" $ \testEnvironment -> it "Upsert simple object with default values - check empty if_matched" $ \testEnvironment ->
shouldReturnYaml shouldReturnYaml