graphql-engine/server/src-test/Hasura/Backends/DataWrapper/API/V0/OrderBySpec.hs
David Overton 44577dab1b Add ToSchema instances to GDW API types
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4006
Co-authored-by: Daniel Chambers <1214352+daniel-chambers@users.noreply.github.com>
GitOrigin-RevId: 756ca0ed60865d0eb675562e8959f0d1839f9abe
2022-03-31 04:46:08 +00:00

41 lines
1.1 KiB
Haskell

{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.DataWrapper.API.V0.OrderBySpec (spec, genOrderBy, genOrderType) where
import Data.Aeson.QQ.Simple (aesonQQ)
import Hasura.Backends.DataWrapper.API.V0.API
import Hasura.Backends.DataWrapper.API.V0.ColumnSpec (genColumnName)
import Hasura.Prelude
import Hedgehog
import Hedgehog.Gen qualified as Gen
import Test.Aeson.Utils (jsonOpenApiProperties, testToFromJSONToSchema)
import Test.Hspec
spec :: Spec
spec = do
describe "OrderBy" $ do
testToFromJSONToSchema
(OrderBy (ColumnName "my_column_name") Ascending)
[aesonQQ|
{ "column": "my_column_name",
"ordering": "asc"
}
|]
jsonOpenApiProperties genOrderBy
describe "OrderType" $ do
describe "Ascending" $
testToFromJSONToSchema Ascending [aesonQQ|"asc"|]
describe "Descending" $
testToFromJSONToSchema Descending [aesonQQ|"desc"|]
jsonOpenApiProperties genOrderType
genOrderBy :: MonadGen m => m OrderBy
genOrderBy =
OrderBy
<$> genColumnName
<*> genOrderType
genOrderType :: MonadGen m => m OrderType
genOrderType = Gen.enumBounded