test: Reorganize upsert tests matching contexts
Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
@@ -103,6 +103,24 @@ spec =
|
|||||||
, matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, return=representation", matchContentTypeJson]
|
, matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, 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} ]|]
|
||||||
|
`shouldRespondWith`
|
||||||
|
[json|[ { "id": 1 }, { "id": 2 }, { "id": 4} ]|]
|
||||||
|
{ matchStatus = 201 ,
|
||||||
|
matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, return=representation",
|
||||||
|
matchContentTypeJson] }
|
||||||
|
|
||||||
|
it "succeeds and ignores the Prefer: resolution header(no Preference-Applied present) if the table has no PK" $
|
||||||
|
request methodPost "/no_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=merge-duplicates")]
|
||||||
|
[json|[ { "a": "1", "b": "0" } ]|]
|
||||||
|
`shouldRespondWith`
|
||||||
|
[json|[ { "a": "1", "b": "0" } ]|]
|
||||||
|
{ matchStatus = 201
|
||||||
|
, matchHeaders = [matchContentTypeJson
|
||||||
|
, "Preference-Applied" <:> "return=representation"] }
|
||||||
|
|
||||||
context "when Prefer: resolution=ignore-duplicates is specified" $ do
|
context "when Prefer: resolution=ignore-duplicates is specified" $ do
|
||||||
it "INSERTs and ignores rows on pk conflict" $
|
it "INSERTs and ignores rows on pk conflict" $
|
||||||
request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
||||||
@@ -174,44 +192,27 @@ spec =
|
|||||||
, matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation"]
|
, matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation"]
|
||||||
}
|
}
|
||||||
|
|
||||||
it "succeeds if the table has only PK cols and no other cols" $ do
|
it "succeeds if the table has only PK cols and no other cols" $
|
||||||
request methodPost "/only_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
request methodPost "/only_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
||||||
[json|[ { "id": 1 }, { "id": 2 }, { "id": 3} ]|]
|
[json|[ { "id": 1 }, { "id": 2 }, { "id": 3} ]|]
|
||||||
`shouldRespondWith`
|
`shouldRespondWith`
|
||||||
[json|[ { "id": 3} ]|]
|
[json|[ { "id": 3} ]|]
|
||||||
{ matchStatus = 201 ,
|
{ matchStatus = 201 ,
|
||||||
matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation",
|
matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation",
|
||||||
matchContentTypeJson] }
|
matchContentTypeJson] }
|
||||||
|
|
||||||
request methodPost "/only_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=merge-duplicates")]
|
it "succeeds if not a single resource is created" $ do
|
||||||
[json|[ { "id": 1 }, { "id": 2 }, { "id": 4} ]|]
|
request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
||||||
`shouldRespondWith`
|
[json|[ { "name": "Java", "rank": 1 } ]|] `shouldRespondWith`
|
||||||
[json|[ { "id": 1 }, { "id": 2 }, { "id": 4} ]|]
|
[json|[]|]
|
||||||
{ matchStatus = 201 ,
|
{ matchStatus = 201
|
||||||
matchHeaders = ["Preference-Applied" <:> "resolution=merge-duplicates, return=representation",
|
, matchHeaders = [matchContentTypeJson] }
|
||||||
matchContentTypeJson] }
|
|
||||||
|
|
||||||
it "succeeds and ignores the Prefer: resolution header(no Preference-Applied present) if the table has no PK" $
|
request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
||||||
request methodPost "/no_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=merge-duplicates")]
|
[json|[ { "name": "Java", "rank": 1 }, { "name": "C", "rank": 2 } ]|] `shouldRespondWith`
|
||||||
[json|[ { "a": "1", "b": "0" } ]|]
|
[json|[]|]
|
||||||
`shouldRespondWith`
|
{ matchStatus = 201
|
||||||
[json|[ { "a": "1", "b": "0" } ]|]
|
, matchHeaders = [matchContentTypeJson] }
|
||||||
{ matchStatus = 201
|
|
||||||
, matchHeaders = [matchContentTypeJson
|
|
||||||
, "Preference-Applied" <:> "return=representation"] }
|
|
||||||
|
|
||||||
it "succeeds if not a single resource is created" $ do
|
|
||||||
request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
|
||||||
[json|[ { "name": "Java", "rank": 1 } ]|] `shouldRespondWith`
|
|
||||||
[json|[]|]
|
|
||||||
{ matchStatus = 201
|
|
||||||
, matchHeaders = [matchContentTypeJson] }
|
|
||||||
|
|
||||||
request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")]
|
|
||||||
[json|[ { "name": "Java", "rank": 1 }, { "name": "C", "rank": 2 } ]|] `shouldRespondWith`
|
|
||||||
[json|[]|]
|
|
||||||
{ matchStatus = 201
|
|
||||||
, matchHeaders = [matchContentTypeJson] }
|
|
||||||
|
|
||||||
context "with PUT" $ do
|
context "with PUT" $ do
|
||||||
context "Restrictions" $ do
|
context "Restrictions" $ do
|
||||||
|
|||||||
Reference in New Issue
Block a user