mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
ef0ca7dea2
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5478 GitOrigin-RevId: 269d33d48f7d41efc7ab4ac6efd9442c6741d08c
91 lines
2.8 KiB
Haskell
91 lines
2.8 KiB
Haskell
{-# LANGUAGE OverloadedLists #-}
|
|
{-# LANGUAGE QuasiQuotes #-}
|
|
|
|
module Hasura.Backends.DataConnector.API.V0.AggregateSpec
|
|
( spec,
|
|
genAggregate,
|
|
genSingleColumnAggregate,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson.QQ.Simple (aesonQQ)
|
|
import Hasura.Backends.DataConnector.API.V0
|
|
import Hasura.Backends.DataConnector.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 "Aggregate" $ do
|
|
describe "SingleColumn" $ do
|
|
testToFromJSONToSchema
|
|
(SingleColumn $ SingleColumnAggregate Average (ColumnName "my_column_name"))
|
|
[aesonQQ|
|
|
{ "type": "single_column",
|
|
"function": "avg",
|
|
"column": "my_column_name"
|
|
}
|
|
|]
|
|
describe "ColumnCount" $ do
|
|
testToFromJSONToSchema
|
|
(ColumnCount $ ColumnCountAggregate (ColumnName "my_column_name") True)
|
|
[aesonQQ|
|
|
{ "type": "column_count",
|
|
"column": "my_column_name",
|
|
"distinct": true
|
|
}
|
|
|]
|
|
describe "StarCount" $ do
|
|
testToFromJSONToSchema
|
|
(StarCount)
|
|
[aesonQQ|
|
|
{ "type": "star_count"
|
|
}
|
|
|]
|
|
jsonOpenApiProperties genAggregate
|
|
|
|
describe "SingleColumnAggregateFunction" $ do
|
|
describe "Average" $
|
|
testToFromJSONToSchema Average [aesonQQ|"avg"|]
|
|
describe "Max" $
|
|
testToFromJSONToSchema Max [aesonQQ|"max"|]
|
|
describe "Min" $
|
|
testToFromJSONToSchema Min [aesonQQ|"min"|]
|
|
describe "StandardDeviationPopulation" $
|
|
testToFromJSONToSchema StandardDeviationPopulation [aesonQQ|"stddev_pop"|]
|
|
describe "StandardDeviationSample" $
|
|
testToFromJSONToSchema StandardDeviationSample [aesonQQ|"stddev_samp"|]
|
|
describe "Sum" $
|
|
testToFromJSONToSchema Sum [aesonQQ|"sum"|]
|
|
describe "VariancePopulation" $
|
|
testToFromJSONToSchema VariancePopulation [aesonQQ|"var_pop"|]
|
|
describe "VarianceSample" $
|
|
testToFromJSONToSchema VarianceSample [aesonQQ|"var_samp"|]
|
|
jsonOpenApiProperties genSingleColumnAggregateFunction
|
|
|
|
genAggregate :: MonadGen m => m Aggregate
|
|
genAggregate =
|
|
Gen.choice
|
|
[ SingleColumn <$> genSingleColumnAggregate,
|
|
ColumnCount <$> genColumnCountAggregate,
|
|
pure StarCount
|
|
]
|
|
|
|
genSingleColumnAggregate :: MonadGen m => m SingleColumnAggregate
|
|
genSingleColumnAggregate =
|
|
SingleColumnAggregate
|
|
<$> genSingleColumnAggregateFunction
|
|
<*> genColumnName
|
|
|
|
genColumnCountAggregate :: MonadGen m => m ColumnCountAggregate
|
|
genColumnCountAggregate =
|
|
ColumnCountAggregate
|
|
<$> genColumnName
|
|
<*> Gen.bool
|
|
|
|
genSingleColumnAggregateFunction :: MonadGen m => m SingleColumnAggregateFunction
|
|
genSingleColumnAggregateFunction = Gen.enumBounded
|