1
0
mirror of https://github.com/hasura/graphql-engine.git synced 2024-12-22 06:51:32 +03:00
graphql-engine/server/src-test/Hasura/Backends/MySQL/DataLoader/ExecuteTests.hs
Evie Ciobanu 0a4194a1bc server: throw broken invariant on data loader error
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3010
GitOrigin-RevId: 3b09a7d61343d406d1ecc5d6aaab866564c9dff8
2021-12-01 12:50:38 +00:00

80 lines
2.1 KiB
Haskell

module Hasura.Backends.MySQL.DataLoader.ExecuteTests
( spec,
)
where
import Data.HashMap.Strict.InsOrd qualified as HMS
import Data.Vector qualified as V
import Hasura.Backends.MySQL.DataLoader.Execute
import Hasura.Prelude
import Hedgehog
import Hedgehog.Gen
import Hedgehog.Range
import Test.Hspec
import Test.Hspec.Hedgehog
spec :: Spec
spec = do
describe "joinObjectRows" $ do
joinObjectRowsThrowsIfRightRowsIsEmpty
joinObjectRowsThrowsIfRightRowsIsLargerThanOne
describe "leftObjectJoin" $ do
leftObjectJoinThrowsIfRightRowsIsEmpty
leftObjectJoinThrowsIfRightRowsIsLargerThanOne
joinObjectRowsThrowsIfRightRowsIsEmpty :: Spec
joinObjectRowsThrowsIfRightRowsIsEmpty =
it "throws if rightRows is empty" $
joinObjectRows
Nothing
""
HMS.empty
empty
`shouldSatisfy` invariant
joinObjectRowsThrowsIfRightRowsIsLargerThanOne :: Spec
joinObjectRowsThrowsIfRightRowsIsLargerThanOne = do
it "throws if rightRows is two or more"
. hedgehog
$ do
size <- forAll $ integral (linear 2 100)
let result =
joinObjectRows
Nothing
""
HMS.empty
(V.replicate size HMS.empty)
assert $ invariant result
leftObjectJoinThrowsIfRightRowsIsEmpty :: Spec
leftObjectJoinThrowsIfRightRowsIsEmpty =
it "throws if rightRows is empty" $
leftObjectJoin
Nothing
""
[]
(RecordSet Nothing (V.singleton HMS.empty) Nothing)
(RecordSet Nothing mempty Nothing)
`shouldSatisfy` invariant
leftObjectJoinThrowsIfRightRowsIsLargerThanOne :: Spec
leftObjectJoinThrowsIfRightRowsIsLargerThanOne =
it "throws if rightRows is two or more"
. hedgehog
$ do
size <- forAll $ integral (linear 2 100)
let result =
leftObjectJoin
Nothing
""
[]
(RecordSet Nothing (V.singleton HMS.empty) Nothing)
(RecordSet Nothing (V.replicate size HMS.empty) Nothing)
assert $ invariant result
invariant :: Either ExecuteProblem a -> Bool
invariant =
\case
Left (BrokenJoinInvariant _) -> True
_ -> False