Clean up StarWars test queries
This commit is contained in:
parent
04d8d40b3a
commit
119f94b38e
@ -1,13 +1,14 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
module Test.StarWars.QueryTests where
|
module Test.StarWars.QueryTests (test) where
|
||||||
|
|
||||||
import Data.Aeson (object, (.=))
|
import Data.Aeson (object, (.=))
|
||||||
|
import qualified Data.Aeson as Aeson (Value)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Text.RawString.QQ (r)
|
import Text.RawString.QQ (r)
|
||||||
|
|
||||||
import Test.Tasty (TestTree, testGroup)
|
import Test.Tasty (TestTree, testGroup)
|
||||||
import Test.Tasty.HUnit (testCase, (@?=))
|
import Test.Tasty.HUnit (Assertion, testCase, (@?=))
|
||||||
|
|
||||||
import Data.GraphQL
|
import Data.GraphQL
|
||||||
|
|
||||||
@ -16,23 +17,22 @@ import Test.StarWars.Schema
|
|||||||
-- * Test
|
-- * Test
|
||||||
-- See https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsQueryTests.js
|
-- See https://github.com/graphql/graphql-js/blob/master/src/__tests__/starWarsQueryTests.js
|
||||||
|
|
||||||
|
testQuery :: Text -> Aeson.Value -> Assertion
|
||||||
|
testQuery q expected = graphql schema q @?= Just expected
|
||||||
|
|
||||||
test :: TestTree
|
test :: TestTree
|
||||||
test = testGroup "Star Wars Query Tests"
|
test = testGroup "Star Wars Query Tests"
|
||||||
[ testGroup "Basic Queries"
|
[ testGroup "Basic Queries"
|
||||||
[ testCase "R2-D2 hero" $ (@?=) (graphql schema [r|
|
[ testCase "R2-D2 hero" . testQuery
|
||||||
query HeroNameQuery {
|
[r| query HeroNameQuery {
|
||||||
hero {
|
hero {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}|]) . Just
|
}
|
||||||
$ object [
|
|]
|
||||||
"hero" .= object [
|
$ object ["hero" .= object ["id" .= ("2001" :: Text)]]
|
||||||
"id" .= ("2001" :: Text)
|
, testCase "R2-D2 ID and friends" . testQuery
|
||||||
]
|
[r| query HeroNameAndFriendsQuery {
|
||||||
]
|
|
||||||
|
|
||||||
, testCase "R2-D2 ID and friends" $ (@?=) (graphql schema [r|
|
|
||||||
query HeroNameAndFriendsQuery {
|
|
||||||
hero {
|
hero {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
@ -40,7 +40,8 @@ test = testGroup "Star Wars Query Tests"
|
|||||||
name
|
name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}|]) . Just
|
}
|
||||||
|
|]
|
||||||
$ object [
|
$ object [
|
||||||
"hero" .= object [
|
"hero" .= object [
|
||||||
"id" .= ("2001" :: Text)
|
"id" .= ("2001" :: Text)
|
||||||
@ -54,8 +55,8 @@ test = testGroup "Star Wars Query Tests"
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
, testGroup "Nested Queries"
|
, testGroup "Nested Queries"
|
||||||
[ testCase "R2-D2 friends" $ (@?=) (graphql schema [r|
|
[ testCase "R2-D2 friends" . testQuery
|
||||||
query NestedQuery {
|
[r| query NestedQuery {
|
||||||
hero {
|
hero {
|
||||||
name
|
name
|
||||||
friends {
|
friends {
|
||||||
@ -66,7 +67,8 @@ test = testGroup "Star Wars Query Tests"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}|]) . Just
|
}
|
||||||
|
|]
|
||||||
$ object [
|
$ object [
|
||||||
"hero" .= object [
|
"hero" .= object [
|
||||||
"name" .= ("R2-D2" :: Text)
|
"name" .= ("R2-D2" :: Text)
|
||||||
@ -103,12 +105,13 @@ test = testGroup "Star Wars Query Tests"
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
, testCase "Luke ID" $ (@?=) (graphql schema [r|
|
, testCase "Luke ID" . testQuery
|
||||||
query FetchLukeQuery {
|
[r| query FetchLukeQuery {
|
||||||
human(id: "1000") {
|
human(id: "1000") {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
}|]) . Just
|
}
|
||||||
|
|]
|
||||||
$ object [
|
$ object [
|
||||||
"human" .= object [
|
"human" .= object [
|
||||||
"name" .= ("Luke Skywalker" :: Text)
|
"name" .= ("Luke Skywalker" :: Text)
|
||||||
@ -116,4 +119,3 @@ query FetchLukeQuery {
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user