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