purescript-postgres/test/Spec.Data.Postgres.Query.Builder.purs

33 lines
1.0 KiB
Haskell
Raw Normal View History

2023-12-18 00:38:30 +00:00
module Spec.Data.Postgres.Query.Builder where
import Prelude
import Control.Monad.Trans.Class (lift)
import Data.Postgres.Query.Builder (param, runBuilder)
import Data.Tuple.Nested ((/\))
import Foreign (unsafeFromForeign)
import Foreign.Internal.Stringify (unsafeStringify)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
spec :: Spec Unit
spec =
describe "Data.Postgres.Query.Builder" do
describe "runBuilder" do
it "empty" do
_ /\ ps <- runBuilder (pure unit)
map unsafeStringify ps `shouldEqual` []
describe "param" do
it "single" do
p /\ ps <- runBuilder $ param 123
p `shouldEqual` "$1"
map unsafeFromForeign ps `shouldEqual` [ 123 ]
it "many" do
_ /\ ps <- runBuilder do
a <- param 123
b <- param "abc"
c <- param [ 123 ]
d <- param true
lift $ [ a, b, c, d ] `shouldEqual` [ "$1", "$2", "$3", "$4" ]
map unsafeStringify ps `shouldEqual` [ "123", "\"abc\"", "[123]", "true" ]