graphql-engine/server/src-test/Hasura/Backends/Postgres/Translate/DeleteSpec.hs
Evie Ciobanu 7e279b5c56 server/nada: use raw SQL literals to clarify tested queries
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5545
GitOrigin-RevId: 74344445aa33983b29e993e4b0cd8a335bce6b93
2022-08-18 11:32:03 +00:00

51 lines
1.4 KiB
Haskell

{-# LANGUAGE QuasiQuotes #-}
module Hasura.Backends.Postgres.Translate.DeleteSpec
( spec,
)
where
import Database.PG.Query.Pool qualified as QQ
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp (OpExpG (..))
import Hasura.RQL.IR.Returning (MutFldG (..), MutationOutputG (..))
import Test.Backend.Postgres.Delete qualified as Test
import Test.Backend.Postgres.Misc qualified as P
import Test.Hspec
import Test.Parser.Expectation as Expect
spec :: Spec
spec =
describe "Postgres.Translate.DeleteSpec" do
Test.runTest
Test.TestBuilder
{ name = "delete where id",
table = Expect.mkTable "test",
columns = [P.idColumn, P.nameColumn],
mutationOutput = MOutMultirowFields [("affected_rows", MCount)],
where_ = [(P.idColumn, [AEQ True P.integerOne])],
expectedSQL =
[QQ.sql|
DELETE FROM "public"."test"
WHERE
(("public"."test"."id") = (('1')::integer))
RETURNING *
|]
}
Test.runTest
Test.TestBuilder
{ name = "delete where column",
table = Expect.mkTable "test",
columns = [P.idColumn, P.nameColumn],
mutationOutput = MOutMultirowFields [("affected_rows", MCount)],
where_ = [(P.nameColumn, [AEQ True P.textOld])],
expectedSQL =
[QQ.sql|
DELETE FROM "public"."test"
WHERE
(("public"."test"."name") = (('old name')::text))
RETURNING *
|]
}