graphql-engine/server/src-test/Hasura/GraphQL/Parser/MonadParseTest.hs
2022-06-28 10:08:09 +00:00

28 lines
874 B
Haskell

module Hasura.GraphQL.Parser.MonadParseTest (spec) where
import Data.Aeson.Internal
import Hasura.Base.Error
import Hasura.GraphQL.Parser.Class.Parse
import Hasura.GraphQL.Parser.Monad
import Hasura.Prelude
import Test.Hspec
runParse' :: Parse () -> Either QErr ()
runParse' = runParse @_ @()
errorStr :: Text
errorStr = "oh no"
spec :: Spec
spec = do
describe "withKey" $ do
it "Path is empty when no keys added" $ do
let parser = parseError errorStr
expected = (err400 ValidationFailed errorStr) {qePath = mempty}
runParse' parser `shouldBe` Left expected
it "Path has two items in the order they were added" $ do
let parser = withKey (Key "dog") (withKey (Key "log") (parseError errorStr))
expected = (err400 ValidationFailed errorStr) {qePath = [Key "dog", Key "log"]}
runParse' parser `shouldBe` Left expected