add upsert postgres test
This commit is contained in:
parent
3ebb31af58
commit
ba650748f0
@ -11,7 +11,6 @@
|
|||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import Control.Arrow ((&&&))
|
import Control.Arrow ((&&&))
|
||||||
import Control.Exception (evaluate)
|
|
||||||
import Control.Monad (void, when)
|
import Control.Monad (void, when)
|
||||||
import Control.Monad.Catch (MonadCatch, catch)
|
import Control.Monad.Catch (MonadCatch, catch)
|
||||||
import Control.Monad.IO.Class (MonadIO(liftIO))
|
import Control.Monad.IO.Class (MonadIO(liftIO))
|
||||||
@ -954,8 +953,8 @@ testInsertUniqueViolation :: Spec
|
|||||||
testInsertUniqueViolation =
|
testInsertUniqueViolation =
|
||||||
describe "Unique Violation on Insert" $
|
describe "Unique Violation on Insert" $
|
||||||
it "Unique throws exception" $ run (do
|
it "Unique throws exception" $ run (do
|
||||||
u1k <- insert u1
|
_ <- insert u1
|
||||||
u2k <- insert u2
|
_ <- insert u2
|
||||||
insert u3) `shouldThrow` (==) exception
|
insert u3) `shouldThrow` (==) exception
|
||||||
where
|
where
|
||||||
exception = SqlError {
|
exception = SqlError {
|
||||||
@ -965,6 +964,20 @@ testInsertUniqueViolation =
|
|||||||
sqlErrorDetail = "Key (value)=(0) already exists.",
|
sqlErrorDetail = "Key (value)=(0) already exists.",
|
||||||
sqlErrorHint = ""}
|
sqlErrorHint = ""}
|
||||||
|
|
||||||
|
testUpsert :: Spec
|
||||||
|
testUpsert =
|
||||||
|
describe "Upsert test" $ do
|
||||||
|
it "Upsert can insert like normal" $ run $ do
|
||||||
|
u1e <- EP.upsert u1 [OneUniqueName =. val "fifth"]
|
||||||
|
liftIO $ entityVal u1e `shouldBe` u1
|
||||||
|
it "Upsert performs update on collision" $ run $ do
|
||||||
|
u1e <- EP.upsert u1 [OneUniqueName =. val "fifth"]
|
||||||
|
liftIO $ entityVal u1e `shouldBe` u1
|
||||||
|
u2e <- EP.upsert u2 [OneUniqueName =. val "fifth"]
|
||||||
|
liftIO $ entityVal u2e `shouldBe` u2
|
||||||
|
u3e <- EP.upsert u3 [OneUniqueName =. val "fifth"]
|
||||||
|
liftIO $ entityVal u3e `shouldBe` u1{oneUniqueName="fifth"}
|
||||||
|
|
||||||
type JSONValue = Maybe (JSONB A.Value)
|
type JSONValue = Maybe (JSONB A.Value)
|
||||||
|
|
||||||
createSaneSQL :: (PersistField a) => SqlExpr (Value a) -> T.Text -> [PersistValue] -> IO ()
|
createSaneSQL :: (PersistField a) => SqlExpr (Value a) -> T.Text -> [PersistValue] -> IO ()
|
||||||
@ -1037,6 +1050,7 @@ main = do
|
|||||||
testPostgresqlCoalesce
|
testPostgresqlCoalesce
|
||||||
testPostgresqlTextFunctions
|
testPostgresqlTextFunctions
|
||||||
testInsertUniqueViolation
|
testInsertUniqueViolation
|
||||||
|
testUpsert
|
||||||
describe "PostgreSQL JSON tests" $ do
|
describe "PostgreSQL JSON tests" $ do
|
||||||
-- NOTE: We only clean the table once, so we
|
-- NOTE: We only clean the table once, so we
|
||||||
-- can use its contents across all JSON tests
|
-- can use its contents across all JSON tests
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user