summaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/ErrorSpec.hs
blob: f64e70a38843f21246f98fa5864b4560c4ed4f31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{- This Source Code Form is subject to the terms of the Mozilla Public License,
   v. 2.0. If a copy of the MPL was not distributed with this file, You can
   obtain one at https://mozilla.org/MPL/2.0/. -}

{-# LANGUAGE OverloadedStrings #-}
module Language.GraphQL.ErrorSpec
    ( spec
    ) where

import qualified Data.Aeson as Aeson
import Data.List.NonEmpty (NonEmpty (..))
import Language.GraphQL.Error
import Test.Hspec
    ( Spec
    , describe
    , it
    , shouldBe
    )
import Text.Megaparsec (PosState(..))
import Text.Megaparsec.Error (ParseError(..), ParseErrorBundle(..))
import Text.Megaparsec.Pos (SourcePos(..), mkPos)

spec :: Spec
spec = describe "parseError" $
    it "generates response with a single error" $ do
        let parseErrors = TrivialError 0 Nothing mempty :| []
            posState = PosState
                { pstateInput = ""
                , pstateOffset = 0
                , pstateSourcePos = SourcePos "" (mkPos 1) (mkPos 1)
                , pstateTabWidth = mkPos 1
                , pstateLinePrefix = ""
                }
        Response Aeson.Null actual <-
            parseError (ParseErrorBundle parseErrors posState)
        length actual `shouldBe` 1