graphql-engine/server/tests-hspec/Test/OrderingSpec.hs
jkachmar 647231b685 Yeet some default-extensions
Manually enables:
* EmptyCase
* ExistentialQuantification
* QuantifiedConstraints
* QuasiQuotes
* TemplateHaskell
* TypeFamilyDependencies

...in the following components:
* 'graphql-engine' library
* 'graphql-engine' 'src-test'
* 'graphql-engine' 'tests/integration'
* 'graphql-engine' tests-hspec'

Additionally, performs some light refactoring and documentation.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3991
GitOrigin-RevId: 514477d3466b01f60eca8935d0fef60dd0756838
2022-03-16 00:40:17 +00:00

151 lines
2.8 KiB
Haskell

{-# LANGUAGE QuasiQuotes #-}
-- | Test ordering by fields.
module Test.OrderingSpec (spec) where
import Harness.Backend.Mysql as Mysql
import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Quoter.Graphql
import Harness.Quoter.Yaml
import Harness.State (State)
import Harness.Test.Context qualified as Context
import Harness.Test.Schema qualified as Schema
import Test.Hspec
import Prelude
--------------------------------------------------------------------------------
-- Preamble
spec :: SpecWith State
spec =
Context.run
[ Context.Context
{ name = Context.Backend Context.MySQL,
mkLocalState = Context.noLocalState,
setup = Mysql.setup schema,
teardown = Mysql.teardown schema,
customOptions = Nothing
}
]
tests
--------------------------------------------------------------------------------
-- Schema
schema :: [Schema.Table]
schema = [author]
author :: Schema.Table
author =
Schema.Table
"author"
[ Schema.column "id" Schema.TInt,
Schema.column "name" Schema.TStr
]
["id"]
[]
[ [Schema.VInt 1, Schema.VStr "Author 1"],
[Schema.VInt 2, Schema.VStr "Author 2"]
]
--------------------------------------------------------------------------------
-- Tests
-- Added equivalents from <https://github.com/hasura/graphql-engine-mono/blob/ee524e94caf6405ce0ae39edfe161dadd223d60f/server/tests-py/queries/graphql_query/mysql/select_query_author_order_by.yaml#L1>
-- That includes order by {text,id} {desc,asc}
--
tests :: Context.Options -> SpecWith State
tests opts = do
it "Order by id ascending" $ \state ->
shouldReturnYaml
opts
( GraphqlEngine.postGraphql
state
[graphql|
query {
hasura_author (order_by: {id: asc}) {
name
id
}
}
|]
)
[yaml|
data:
hasura_author:
- name: Author 1
id: 1
- name: Author 2
id: 2
|]
it "Order by id descending" $ \state ->
shouldReturnYaml
opts
( GraphqlEngine.postGraphql
state
[graphql|
query {
hasura_author (order_by: {id: desc}) {
name
id
}
}
|]
)
[yaml|
data:
hasura_author:
- name: Author 2
id: 2
- name: Author 1
id: 1
|]
it "Order by name ascending" $ \state ->
shouldReturnYaml
opts
( GraphqlEngine.postGraphql
state
[graphql|
query {
hasura_author (order_by: {name: asc}) {
name
id
}
}
|]
)
[yaml|
data:
hasura_author:
- name: Author 1
id: 1
- name: Author 2
id: 2
|]
it "Order by name descending" $ \state ->
shouldReturnYaml
opts
( GraphqlEngine.postGraphql
state
[graphql|
query {
hasura_author (order_by: {name: desc}) {
name
id
}
}
|]
)
[yaml|
data:
hasura_author:
- name: Author 2
id: 2
- name: Author 1
id: 1
|]