mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
1e48af2d03
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5543 GitOrigin-RevId: 55646f653926559f1847aa692d3522627a463d25
60 lines
1.9 KiB
Haskell
60 lines
1.9 KiB
Haskell
-- | Test Backend Postgres Insert
|
|
--
|
|
-- Helpers to build 'Hasura.RQL.IR.Insert.InsertQueryP1' and test the results
|
|
-- of running 'Hasura.Backends.Postgres.Translate.Insert.mkInsertCTE' as raw
|
|
-- SQL.
|
|
--
|
|
-- See 'Hasura.Backends.Postgres.Translate.InserSpec.spec' for usage examples.
|
|
module Test.Backend.Postgres.Insert
|
|
( TestBuilder (..),
|
|
runTest,
|
|
)
|
|
where
|
|
|
|
import Hasura.Backends.Postgres.SQL.Types (QualifiedTable)
|
|
import Hasura.Backends.Postgres.Translate.Insert qualified as Insert
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.IR.Returning (MutationOutputG (..))
|
|
import Hasura.RQL.IR.Value (UnpreparedValue (..))
|
|
import Hasura.RQL.Types.Column (ColumnInfo)
|
|
import Hasura.SQL.Backend (PostgresKind (Vanilla))
|
|
import Hasura.SQL.Types (toSQLTxt)
|
|
import Test.Backend.Postgres.Misc (PG)
|
|
import Test.Hspec
|
|
import Test.Parser.Insert qualified as Expect
|
|
import Test.SIString qualified as SI
|
|
|
|
-- | Describes a /mkInsertCTE/ test.
|
|
data TestBuilder = TestBuilder
|
|
{ -- | test name
|
|
name :: String,
|
|
-- | table details
|
|
table :: QualifiedTable,
|
|
-- | columns used in the insert statement
|
|
insertColumns :: [ColumnInfo PG],
|
|
-- | rows of values to be inserted
|
|
values :: [[UnpreparedValue PG]],
|
|
-- | table columns
|
|
columns :: [ColumnInfo PG],
|
|
-- | expected output fields
|
|
mutationOutput :: MutationOutputG PG Void (UnpreparedValue PG),
|
|
-- | expected SQL
|
|
expectedSQL :: Text
|
|
}
|
|
|
|
-- | Runs a test for insert queries.
|
|
runTest :: TestBuilder -> Spec
|
|
runTest TestBuilder {..} =
|
|
it name do
|
|
let ins =
|
|
Expect.mkInsertQuery
|
|
Expect.InsertQueryBuilder
|
|
{ iqbTable = table,
|
|
iqbInsertColumns = insertColumns,
|
|
iqbValues = values,
|
|
iqbOutput = mutationOutput,
|
|
iqbAllColumns = columns
|
|
}
|
|
(SI.fromText . toSQLTxt . Insert.mkInsertCTE @'Vanilla $ ins)
|
|
`shouldBe` SI.fromText expectedSQL
|