test: upserts with case sensitive table and sequence name (#4131)

Closes #3712.
This commit is contained in:
Taimoor Zaeem
2025-06-07 12:39:50 -05:00
committed by GitHub
parent a9d4237bc2
commit 2eb9e4a8a4
5 changed files with 56 additions and 0 deletions
+28
View File
@@ -1,3 +1,6 @@
-- TODO: Separate this module into:
-- - Upsert/MergeDuplicates.hs and
-- - Upsert/IgnoreDuplicates.hs
module Feature.Query.UpsertSpec where
import Network.Wai (Application)
@@ -129,6 +132,19 @@ spec =
, matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, missing=default, return=representation", matchContentTypeJson]
}
it "INSERTs and UPDATEs rows with case sensitive table name with GENERATED BY DEFAULT surrogate primary keys using Prefer: missing=default" $
request methodPost "/Surr_Gen_Default_Upsert?columns=id,name&select=name,extra" [("Prefer", "return=representation"), ("Prefer", "resolution=merge-duplicates"), ("Prefer", "missing=default")]
[json| [
{ "id": 1, "name": "updated value" },
{ "name": "new value" }
]|] `shouldRespondWith` [json| [
{ "name": "updated value", "extra": "existing value cs" },
{ "name": "new value", "extra": null }
]|]
{ matchStatus = 201
, matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, missing=default, return=representation", matchContentTypeJson]
}
it "succeeds if the table has only PK cols and no other cols" $
request methodPost "/only_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=merge-duplicates")]
[json|[ { "id": 1 }, { "id": 2 }, { "id": 4} ]|]
@@ -242,6 +258,18 @@ spec =
, matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, missing=default, return=representation", matchContentTypeJson]
}
it "INSERTs and UPDATEs rows with case sensitive table name GENERATED BY DEFAULT surrogate primary keys using Prefer: missing=default" $
request methodPost "/Surr_Gen_Default_Upsert?columns=id,name&select=name,extra" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates"), ("Prefer", "missing=default")]
[json| [
{ "id": 1, "name": "updated value" },
{ "name": "new value" }
]|] `shouldRespondWith` [json| [
{ "name": "new value", "extra": null }
]|]
{ matchStatus = 201
, matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, missing=default, return=representation", matchContentTypeJson]
}
it "succeeds if the table has only PK cols and no other cols" $
request methodPost "/only_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
[json|[ { "id": 1 }, { "id": 2 }, { "id": 3} ]|]