test: Make PgSafeUpdateSpec parallel-ready
This commit is contained in:
@@ -10,7 +10,6 @@ import Test.Hspec.Wai
|
|||||||
import Test.Hspec.Wai.JSON
|
import Test.Hspec.Wai.JSON
|
||||||
|
|
||||||
import Protolude hiding (get, put)
|
import Protolude hiding (get, put)
|
||||||
import SpecHelper
|
|
||||||
|
|
||||||
tblDataBefore = [aesonQQ|[
|
tblDataBefore = [aesonQQ|[
|
||||||
{ "id": 1, "name": "item-1", "observation": null }
|
{ "id": 1, "name": "item-1", "observation": null }
|
||||||
@@ -36,15 +35,9 @@ spec =
|
|||||||
{ matchStatus = 400 }
|
{ matchStatus = 400 }
|
||||||
|
|
||||||
it "allows full table update if a filter is present" $
|
it "allows full table update if a filter is present" $
|
||||||
baseTable "safe_update_items" "id" tblDataBefore
|
request methodPatch "/safe_update_items?id=gt.0" mempty [json| {"name": "updated-item"} |]
|
||||||
`mutatesWith`
|
`shouldRespondWith`
|
||||||
requestMutation methodPatch "/safe_update_items?id=gt.0" mempty [json| {"name": "updated-item"} |]
|
204
|
||||||
`shouldMutateInto`
|
|
||||||
[json|[
|
|
||||||
{ "id": 1, "name": "updated-item", "observation": null }
|
|
||||||
, { "id": 2, "name": "updated-item", "observation": null }
|
|
||||||
, { "id": 3, "name": "updated-item", "observation": null }
|
|
||||||
]|]
|
|
||||||
|
|
||||||
context "Full table delete" $ do
|
context "Full table delete" $ do
|
||||||
it "does not delete and throws error if no condition is present" $
|
it "does not delete and throws error if no condition is present" $
|
||||||
@@ -59,31 +52,21 @@ spec =
|
|||||||
{ matchStatus = 400 }
|
{ matchStatus = 400 }
|
||||||
|
|
||||||
it "allows full table delete if a filter is present" $
|
it "allows full table delete if a filter is present" $
|
||||||
baseTable "safe_delete_items" "id" tblDataBefore
|
request methodDelete "/safe_delete_items?id=gt.0" mempty mempty
|
||||||
`mutatesWith`
|
`shouldRespondWith`
|
||||||
requestMutation methodDelete "/safe_delete_items?id=gt.0" mempty mempty
|
204
|
||||||
`shouldMutateInto`
|
|
||||||
[json|[]|]
|
|
||||||
|
|
||||||
disabledSpec :: SpecWith ((), Application)
|
disabledSpec :: SpecWith ((), Application)
|
||||||
disabledSpec =
|
disabledSpec =
|
||||||
describe "Disabling pg-safeupdate" $ do
|
describe "Disabling pg-safeupdate" $ do
|
||||||
context "Full table update" $ do
|
context "Full table update" $ do
|
||||||
it "works if no condition is present" $
|
it "works if no condition is present" $
|
||||||
baseTable "unsafe_update_items" "id" tblDataBefore
|
request methodPatch "/unsafe_update_items" mempty [json| {"name": "updated-item"} |]
|
||||||
`mutatesWith`
|
`shouldRespondWith`
|
||||||
requestMutation methodPatch "/unsafe_update_items" mempty [json| {"name": "updated-item"} |]
|
204
|
||||||
`shouldMutateInto`
|
|
||||||
[json|[
|
|
||||||
{ "id": 1, "name": "updated-item", "observation": null }
|
|
||||||
, { "id": 2, "name": "updated-item", "observation": null }
|
|
||||||
, { "id": 3, "name": "updated-item", "observation": null }
|
|
||||||
]|]
|
|
||||||
|
|
||||||
context "Full table delete" $ do
|
context "Full table delete" $ do
|
||||||
it "works if no condition is present" $
|
it "works if no condition is present" $
|
||||||
baseTable "unsafe_delete_items" "id" tblDataBefore
|
request methodDelete "/unsafe_delete_items" mempty mempty
|
||||||
`mutatesWith`
|
`shouldRespondWith`
|
||||||
requestMutation methodDelete "/unsafe_delete_items" mempty mempty
|
204
|
||||||
`shouldMutateInto`
|
|
||||||
[json|[]|]
|
|
||||||
|
|||||||
+5
-4
@@ -245,10 +245,6 @@ main = do
|
|||||||
parallel $ before planEnabledApp $
|
parallel $ before planEnabledApp $
|
||||||
describe "Feature.Query.PlanSpec.spec" $ Feature.Query.PlanSpec.spec actualPgVersion
|
describe "Feature.Query.PlanSpec.spec" $ Feature.Query.PlanSpec.spec actualPgVersion
|
||||||
|
|
||||||
-- this test runs with a pre request to enable the pg-safeupdate library per-session
|
|
||||||
parallel $ before pgSafeUpdateApp $
|
|
||||||
describe "Feature.Query.PgSafeUpdateSpec.spec" Feature.Query.PgSafeUpdateSpec.spec
|
|
||||||
|
|
||||||
-- this test runs with server-trace-header set
|
-- this test runs with server-trace-header set
|
||||||
parallel $ before obsApp $
|
parallel $ before obsApp $
|
||||||
describe "Feature.ObservabilitySpec.spec" Feature.ObservabilitySpec.spec
|
describe "Feature.ObservabilitySpec.spec" Feature.ObservabilitySpec.spec
|
||||||
@@ -277,6 +273,11 @@ main = do
|
|||||||
before forceRollbackApp $
|
before forceRollbackApp $
|
||||||
describe "Feature.RollbackForcedSpec" Feature.RollbackSpec.forced
|
describe "Feature.RollbackForcedSpec" Feature.RollbackSpec.forced
|
||||||
|
|
||||||
|
-- This test runs with a pre request to enable the pg-safeupdate library per-session.
|
||||||
|
-- This needs to run last, because once pg safe update is loaded, it can't be unloaded again.
|
||||||
|
before pgSafeUpdateApp $
|
||||||
|
describe "Feature.Query.PgSafeUpdateSpec.spec" Feature.Query.PgSafeUpdateSpec.spec
|
||||||
|
|
||||||
where
|
where
|
||||||
loadSCache pool conf =
|
loadSCache pool conf =
|
||||||
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ querySchemaCache conf)
|
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ querySchemaCache conf)
|
||||||
|
|||||||
Reference in New Issue
Block a user