diff options
| author | Eugen Wissner <belka@caraus.de> | 2022-03-23 21:58:12 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2022-03-23 22:07:20 +0100 |
| commit | c93c64a7f4828a202770b1cfadc79f28aba1da99 (patch) | |
| tree | 6dcd83f518c486f8db3be716e2dd49de9e9098cd /tests/Language/GraphQL/FragmentSpec.hs | |
| parent | 0cf459b8eb9e4847f9b199566d130e816760a0d3 (diff) | |
| download | graphql-spice-c93c64a7f4828a202770b1cfadc79f28aba1da99.tar.gz | |
Put test helpers into Test.Hspec.GraphQL
Diffstat (limited to 'tests/Language/GraphQL/FragmentSpec.hs')
| -rw-r--r-- | tests/Language/GraphQL/FragmentSpec.hs | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/tests/Language/GraphQL/FragmentSpec.hs b/tests/Language/GraphQL/FragmentSpec.hs index dd13bea..a003f4c 100644 --- a/tests/Language/GraphQL/FragmentSpec.hs +++ b/tests/Language/GraphQL/FragmentSpec.hs @@ -4,20 +4,23 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE PackageImports #-} + module Language.GraphQL.FragmentSpec ( spec ) where -import Data.Aeson ((.=)) -import qualified Data.Aeson as Aeson import qualified Data.HashMap.Strict as HashMap import Data.Text (Text) -import Language.GraphQL.Foundation +import Language.GraphQL.AST (Name) +import Data.HashMap.Strict (HashMap) import Language.GraphQL.Type +import Language.GraphQL.Error import qualified Language.GraphQL.Type.Out as Out import Language.GraphQL.TH +import qualified Language.GraphQL as GraphQL import Test.Hspec (Spec, describe, it) -import Test.Hspec.GraphQL +import "graphql-spice" Test.Hspec.GraphQL size :: (Text, Value) size = ("size", String "L") @@ -88,23 +91,23 @@ spec :: Spec spec = do describe "Inline fragment executor" $ do it "chooses the first selection if the type matches" $ do - actual <- graphql (toSchema "Hat" $ garment "Hat") inlineQuery - let expected = HashMap.singleton "data" - $ Aeson.object - [ "garment" .= Aeson.object - [ "circumference" .= (60 :: Int) - ] - ] + let localSchema = toSchema "Hat" $ garment "Hat" + actual <- GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) inlineQuery + let expected = Object + $ HashMap.singleton "garment" + $ Object + $ HashMap.singleton "circumference" + $ Int 60 in actual `shouldResolveTo` expected it "chooses the last selection if the type matches" $ do - actual <- graphql (toSchema "Shirt" $ garment "Shirt") inlineQuery - let expected = HashMap.singleton "data" - $ Aeson.object - [ "garment" .= Aeson.object - [ "size" .= ("L" :: Text) - ] - ] + let localSchema = toSchema "Shirt" $ garment "Shirt" + actual <- GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) inlineQuery + let expected = Object + $ HashMap.singleton "garment" + $ Object + $ HashMap.singleton "size" + $ String "L" in actual `shouldResolveTo` expected it "embeds inline fragments without type" $ do @@ -116,12 +119,12 @@ spec = do } } |] - actual <- graphql (toSchema "circumference" circumference) sourceQuery - let expected = HashMap.singleton "data" - $ Aeson.object - [ "circumference" .= (60 :: Int) - , "size" .= ("L" :: Text) - ] + let localSchema = toSchema "circumference" circumference + actual <- GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) sourceQuery + let expected = Object $ HashMap.fromList + [ ("circumference", Int 60) + , ("size", String "L") + ] in actual `shouldResolveTo` expected it "evaluates fragments on Query" $ do @@ -132,7 +135,10 @@ spec = do } } |] - in graphql (toSchema "size" size) `shouldResolve` sourceQuery + localSchema = toSchema "size" size + actual :: Text -> IO (Either (ResponseEventStream IO Value) (Response Value)) + actual = GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) + in actual `shouldResolve` sourceQuery describe "Fragment spread executor" $ do it "evaluates fragment spreads" $ do @@ -145,12 +151,11 @@ spec = do circumference } |] - - actual <- graphql (toSchema "circumference" circumference) sourceQuery - let expected = HashMap.singleton "data" - $ Aeson.object - [ "circumference" .= (60 :: Int) - ] + let localSchema = toSchema "circumference" circumference + actual <- GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) sourceQuery + let expected = Object + $ HashMap.singleton "circumference" + $ Int 60 in actual `shouldResolveTo` expected it "evaluates nested fragments" $ do @@ -169,14 +174,13 @@ spec = do circumference } |] - - actual <- graphql (toSchema "Hat" $ garment "Hat") sourceQuery - let expected = HashMap.singleton "data" - $ Aeson.object - [ "garment" .= Aeson.object - [ "circumference" .= (60 :: Int) - ] - ] + let localSchema = toSchema "Hat" $ garment "Hat" + actual <- GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) sourceQuery + let expected = Object + $ HashMap.singleton "garment" + $ Object + $ HashMap.singleton "circumference" + $ Int 60 in actual `shouldResolveTo` expected it "considers type condition" $ do @@ -194,11 +198,11 @@ spec = do size } |] - expected = HashMap.singleton "data" - $ Aeson.object - [ "garment" .= Aeson.object - [ "circumference" .= (60 :: Int) - ] - ] - actual <- graphql (toSchema "Hat" $ garment "Hat") sourceQuery + expected = Object + $ HashMap.singleton "garment" + $ Object + $ HashMap.singleton "circumference" + $ Int 60 + let localSchema = toSchema "Hat" $ garment "Hat" + actual <- GraphQL.graphql localSchema Nothing (mempty :: HashMap Name Value) sourceQuery actual `shouldResolveTo` expected |
