server/tests: Avoid schema aliasing

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6942
GitOrigin-RevId: d439290ae60f8f4be616c9217d03137cace675a6
This commit is contained in:
Philip Lykke Carlsen 2022-11-18 16:55:58 +01:00 committed by hasura-bot
parent 4683d4786d
commit cdb62ff277
2 changed files with 26 additions and 22 deletions

View File

@ -1,15 +1,13 @@
-- | Testing regression reported at https://github.com/hasura/graphql-engine/issues/8643 -- | Testing regression reported at https://github.com/hasura/graphql-engine/issues/8643
module Test.Regression.UsingTheSameFunctionForRootFieldAndComputedField8643Spec (spec) where module Test.Regression.UsingTheSameFunctionForRootFieldAndComputedField8643Spec (spec) where
-- import Data.Aeson (Value (Null))
import Data.List.NonEmpty qualified as NE import Data.List.NonEmpty qualified as NE
import Data.Text qualified as T
import Harness.Backend.Postgres qualified as Postgres import Harness.Backend.Postgres qualified as Postgres
import Harness.Constants qualified as Constants
-- import Harness.Quoter.Yaml (yaml)
import Harness.Test.Fixture qualified as Fixture import Harness.Test.Fixture qualified as Fixture
import Harness.Test.Schema
import Harness.Test.Schema qualified as Schema import Harness.Test.Schema qualified as Schema
import Harness.TestEnvironment (TestEnvironment (..)) import Harness.TestEnvironment (TestEnvironment (..))
-- import Harness.Yaml (shouldReturnYaml)
import Hasura.Prelude import Hasura.Prelude
import Test.Hspec import Test.Hspec
@ -54,20 +52,25 @@ schema =
functionSetup :: TestEnvironment -> Fixture.SetupAction functionSetup :: TestEnvironment -> Fixture.SetupAction
functionSetup testEnvironment = functionSetup testEnvironment =
Fixture.SetupAction let schemaName = T.unpack $ unSchemaName (getSchemaName testEnvironment)
{ setupAction = in Fixture.SetupAction
Postgres.run_ testEnvironment $ { setupAction =
"CREATE FUNCTION " Postgres.run_ testEnvironment $
++ Constants.postgresDb "CREATE FUNCTION "
++ ".authors(author_row author) \ ++ schemaName
\RETURNS SETOF author AS $$ \ ++ ".authors(author_row "
\ SELECT * \ ++ schemaName
\ FROM " ++ ".author) \
++ Constants.postgresDb \RETURNS SETOF "
++ ".author \ ++ schemaName
\$$ LANGUAGE sql STABLE;", ++ ".author AS $$ \
teardownAction = \_ -> Postgres.run_ testEnvironment $ "DROP FUNCTION " ++ Constants.postgresDb ++ ".authors;" \ SELECT * \
} \ FROM "
++ schemaName
++ ".author \
\$$ LANGUAGE sql STABLE;",
teardownAction = \_ -> Postgres.run_ testEnvironment $ "DROP FUNCTION " ++ schemaName ++ ".authors;"
}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Tests -- Tests
@ -76,6 +79,7 @@ tests :: Fixture.Options -> SpecWith TestEnvironment
tests _opts = do tests _opts = do
describe "Tracking the same function as a root field and as a computed field" do describe "Tracking the same function as a root field and as a computed field" do
it "Does not give rise to metadata inconsistencies" \testEnvironment -> do it "Does not give rise to metadata inconsistencies" \testEnvironment -> do
let schemaName = T.unpack $ unSchemaName (getSchemaName testEnvironment)
-- The error message we're looking out for if this fails is: -- The error message we're looking out for if this fails is:
-- --
-- { -- {
@ -84,5 +88,5 @@ tests _opts = do
-- "path": "$" -- "path": "$"
-- } -- }
Postgres.runSQL Postgres.runSQL
("alter table \"" ++ Constants.postgresDb ++ "\".\"author\" add column \"iae\" integer\n null;") ("alter table \"" ++ schemaName ++ "\".\"author\" add column \"iae\" integer\n null;")
testEnvironment testEnvironment

View File

@ -102,14 +102,14 @@ setupPostgres testEnvironment =
Postgres.run_ Postgres.run_
testEnvironment testEnvironment
[sql| [sql|
CREATE OR REPLACE VIEW author_view CREATE OR REPLACE VIEW hasura.author_view
AS SELECT * FROM author AS SELECT * FROM hasura.author
|], |],
Fixture.teardownAction = \_ -> Fixture.teardownAction = \_ ->
Postgres.run_ Postgres.run_
testEnvironment testEnvironment
[sql| [sql|
DROP VIEW IF EXISTS author_view DROP VIEW IF EXISTS hasura.author_view
|] |]
} }