Add instances for UTCTime
This commit is contained in:
parent
f90feb488d
commit
36f45861de
4 changed files with 71 additions and 0 deletions
tests/Language/GraphQL
|
@ -8,6 +8,8 @@ module Language.GraphQL.ClassSpec
|
|||
) where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Data.Time (UTCTime(..))
|
||||
import Data.Time.Calendar.OrdinalDate (fromOrdinalDate)
|
||||
import qualified Language.GraphQL.Type as Type
|
||||
import Language.GraphQL.Class (FromGraphQL(..), ToGraphQL(..))
|
||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
||||
|
@ -30,6 +32,15 @@ spec = do
|
|||
it "converts singleton lists" $
|
||||
toGraphQL [True] `shouldBe` Type.List [Type.Boolean True]
|
||||
|
||||
it "converts UTCTime" $
|
||||
let given = UTCTime
|
||||
{ utctDay = fromOrdinalDate 2023 5
|
||||
, utctDayTime = 90
|
||||
}
|
||||
actual = toGraphQL given
|
||||
expected = Type.String "2023-01-05T00:01:30Z"
|
||||
in actual `shouldBe` expected
|
||||
|
||||
describe "FromGraphQL" $ do
|
||||
it "converts integers" $
|
||||
fromGraphQL (Type.Int 5) `shouldBe` Just (5 :: Int)
|
||||
|
@ -45,3 +56,12 @@ spec = do
|
|||
|
||||
it "converts singleton lists" $
|
||||
fromGraphQL (Type.List [Type.Boolean True]) `shouldBe` Just [True]
|
||||
|
||||
it "converts UTCTime" $
|
||||
let given = Type.String "2023-01-05T00:01:30Z"
|
||||
expected = Just $ UTCTime
|
||||
{ utctDay = fromOrdinalDate 2023 5
|
||||
, utctDayTime = 90
|
||||
}
|
||||
actual = fromGraphQL given
|
||||
in actual `shouldBe` expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue