2022-03-31 07:45:03 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.API.V0.OrderBySpec (spec, genOrderBy, genOrderType) where
|
2022-03-31 07:45:03 +03:00
|
|
|
|
|
|
|
import Data.Aeson.QQ.Simple (aesonQQ)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.API
|
|
|
|
import Hasura.Backends.DataConnector.API.V0.ColumnSpec (genColumnName)
|
2022-03-31 07:45:03 +03:00
|
|
|
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
|