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
module Test.Regression.UsingTheSameFunctionForRootFieldAndComputedField8643Spec (spec) where
-- import Data.Aeson (Value (Null))
import Data.List.NonEmpty qualified as NE
import Data.Text qualified as T
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.Schema
import Harness.Test.Schema qualified as Schema
import Harness.TestEnvironment (TestEnvironment (..))
-- import Harness.Yaml (shouldReturnYaml)
import Hasura.Prelude
import Test.Hspec
@ -54,19 +52,24 @@ schema =
functionSetup :: TestEnvironment -> Fixture.SetupAction
functionSetup testEnvironment =
Fixture.SetupAction
let schemaName = T.unpack $ unSchemaName (getSchemaName testEnvironment)
in Fixture.SetupAction
{ setupAction =
Postgres.run_ testEnvironment $
"CREATE FUNCTION "
++ Constants.postgresDb
++ ".authors(author_row author) \
\RETURNS SETOF author AS $$ \
++ schemaName
++ ".authors(author_row "
++ schemaName
++ ".author) \
\RETURNS SETOF "
++ schemaName
++ ".author AS $$ \
\ SELECT * \
\ FROM "
++ Constants.postgresDb
++ schemaName
++ ".author \
\$$ LANGUAGE sql STABLE;",
teardownAction = \_ -> Postgres.run_ testEnvironment $ "DROP FUNCTION " ++ Constants.postgresDb ++ ".authors;"
teardownAction = \_ -> Postgres.run_ testEnvironment $ "DROP FUNCTION " ++ schemaName ++ ".authors;"
}
--------------------------------------------------------------------------------
@ -76,6 +79,7 @@ tests :: Fixture.Options -> SpecWith TestEnvironment
tests _opts = 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
let schemaName = T.unpack $ unSchemaName (getSchemaName testEnvironment)
-- The error message we're looking out for if this fails is:
--
-- {
@ -84,5 +88,5 @@ tests _opts = do
-- "path": "$"
-- }
Postgres.runSQL
("alter table \"" ++ Constants.postgresDb ++ "\".\"author\" add column \"iae\" integer\n null;")
("alter table \"" ++ schemaName ++ "\".\"author\" add column \"iae\" integer\n null;")
testEnvironment

View File

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