test: add tests for bulk upserts with surrogate keys
This commit is contained in:
@@ -103,6 +103,32 @@ spec =
|
||||
, matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, return=representation", matchContentTypeJson]
|
||||
}
|
||||
|
||||
it "INSERTs and UPDATEs rows with SERIAL surrogate primary keys using Prefer: missing=default" $
|
||||
request methodPost "/surr_serial_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" },
|
||||
{ "name": "new value", "extra": null }
|
||||
]|]
|
||||
{ matchStatus = 201
|
||||
, matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, missing=default, return=representation", matchContentTypeJson]
|
||||
}
|
||||
|
||||
it "INSERTs and UPDATEs rows 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" },
|
||||
{ "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} ]|]
|
||||
@@ -192,6 +218,30 @@ spec =
|
||||
, matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation"]
|
||||
}
|
||||
|
||||
it "INSERTs and UPDATEs rows with SERIAL surrogate primary keys using Prefer: missing=default" $
|
||||
request methodPost "/surr_serial_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 "INSERTs and UPDATEs rows 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=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} ]|]
|
||||
|
||||
Reference in New Issue
Block a user