1
Fork 0

Add instances for UTCTime

This commit is contained in:
Eugen Wissner 2023-06-26 16:50:14 +02:00
parent f90feb488d
commit 36f45861de
No known key found for this signature in database
GPG key ID: A27FDC1E8EE902C0
4 changed files with 71 additions and 0 deletions
tests/Language/GraphQL

View file

@ -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