2022-03-16 03:39:21 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2021-11-19 18:13:33 +03:00
|
|
|
-- | Tests that `where' works.
|
2022-01-21 10:48:27 +03:00
|
|
|
module Test.WhereSpec (spec) where
|
2021-11-19 18:13:33 +03:00
|
|
|
|
2022-04-22 13:32:35 +03:00
|
|
|
import Harness.Backend.BigQuery qualified as Bigquery
|
|
|
|
import Harness.Backend.Citus qualified as Citus
|
2022-01-21 10:48:27 +03:00
|
|
|
import Harness.Backend.Mysql as Mysql
|
2022-04-22 13:32:35 +03:00
|
|
|
import Harness.Backend.Postgres qualified as Postgres
|
|
|
|
import Harness.Backend.Sqlserver qualified as Sqlserver
|
2021-11-19 18:13:33 +03:00
|
|
|
import Harness.GraphqlEngine qualified as GraphqlEngine
|
2022-01-21 10:48:27 +03:00
|
|
|
import Harness.Quoter.Graphql
|
|
|
|
import Harness.Quoter.Yaml
|
2022-02-21 20:05:09 +03:00
|
|
|
import Harness.Test.Context qualified as Context
|
2022-06-17 11:44:04 +03:00
|
|
|
import Harness.Test.Schema (Table (..), table)
|
2022-03-10 14:18:13 +03:00
|
|
|
import Harness.Test.Schema qualified as Schema
|
2022-04-20 20:15:42 +03:00
|
|
|
import Harness.TestEnvironment (TestEnvironment)
|
2021-11-19 18:13:33 +03:00
|
|
|
import Test.Hspec
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Preamble
|
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
spec :: SpecWith TestEnvironment
|
2021-11-19 18:13:33 +03:00
|
|
|
spec =
|
2022-02-21 20:05:09 +03:00
|
|
|
Context.run
|
|
|
|
[ Context.Context
|
2022-03-15 19:08:47 +03:00
|
|
|
{ name = Context.Backend Context.MySQL,
|
2022-04-20 20:15:42 +03:00
|
|
|
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
2022-03-10 14:18:13 +03:00
|
|
|
setup = Mysql.setup schema,
|
|
|
|
teardown = Mysql.teardown schema,
|
2022-02-18 16:35:32 +03:00
|
|
|
customOptions = Nothing
|
2022-04-22 13:32:35 +03:00
|
|
|
},
|
|
|
|
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
|
|
|
|
}
|
2022-02-14 20:24:24 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
tests
|
2021-11-19 18:13:33 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-03-10 14:18:13 +03:00
|
|
|
-- Schema
|
2021-11-19 18:13:33 +03:00
|
|
|
|
2022-03-10 14:18:13 +03:00
|
|
|
schema :: [Schema.Table]
|
|
|
|
schema = [author]
|
2021-11-19 18:13:33 +03:00
|
|
|
|
2022-03-10 14:18:13 +03:00
|
|
|
author :: Schema.Table
|
|
|
|
author =
|
2022-06-17 11:44:04 +03:00
|
|
|
(table "author")
|
|
|
|
{ tableColumns =
|
|
|
|
[ Schema.column "id" Schema.TInt,
|
|
|
|
Schema.column "name" Schema.TStr
|
|
|
|
],
|
|
|
|
tablePrimaryKey = ["id"],
|
|
|
|
tableData =
|
|
|
|
[ [Schema.VInt 1, Schema.VStr "Author 1"],
|
|
|
|
[Schema.VInt 2, Schema.VStr "Author 2"]
|
|
|
|
]
|
|
|
|
}
|
2021-11-19 18:13:33 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Tests
|
|
|
|
|
2022-04-20 20:15:42 +03:00
|
|
|
tests :: Context.Options -> SpecWith TestEnvironment
|
2022-02-09 18:26:14 +03:00
|
|
|
tests opts = do
|
2022-04-20 20:15:42 +03:00
|
|
|
it "Where id=1" \testEnvironment ->
|
2021-11-19 18:13:33 +03:00
|
|
|
shouldReturnYaml
|
2022-02-09 18:26:14 +03:00
|
|
|
opts
|
2021-11-19 18:13:33 +03:00
|
|
|
( GraphqlEngine.postGraphql
|
2022-04-20 20:15:42 +03:00
|
|
|
testEnvironment
|
2021-11-19 18:13:33 +03:00
|
|
|
[graphql|
|
|
|
|
query {
|
|
|
|
hasura_author(where: {id: {_eq: 1}}) {
|
|
|
|
name
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
)
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
hasura_author:
|
|
|
|
- name: Author 1
|
|
|
|
id: 1
|
2022-04-22 13:32:35 +03:00
|
|
|
|]
|
|
|
|
-- Equivalent python suite: test_select_query_where
|
|
|
|
-- https://github.com/hasura/graphql-engine/blob/369d1ab2f119634b0e27e9ed353fa3d08c22d3fb/server/tests-py/test_graphql_queries.py#L274
|
|
|
|
it "Where Name=Author2" \testEnvironment ->
|
|
|
|
shouldReturnYaml
|
|
|
|
opts
|
|
|
|
( GraphqlEngine.postGraphql
|
|
|
|
testEnvironment
|
|
|
|
[graphql|
|
|
|
|
query {
|
|
|
|
hasura_author(where: {name: {_eq: "Author 2"}}) {
|
|
|
|
name
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|]
|
|
|
|
)
|
|
|
|
[yaml|
|
|
|
|
data:
|
|
|
|
hasura_author:
|
|
|
|
- name: Author 2
|
|
|
|
id: 2
|
2021-11-19 18:13:33 +03:00
|
|
|
|]
|