From 3e7c130a0d672109795151f909ad5c843521e605 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Wed, 26 Oct 2022 19:38:13 +0200 Subject: [PATCH] test: Reorganize upsert tests matching contexts Signed-off-by: Wolfgang Walther --- test/spec/Feature/Query/UpsertSpec.hs | 73 ++++++++++++++------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/test/spec/Feature/Query/UpsertSpec.hs b/test/spec/Feature/Query/UpsertSpec.hs index db08aa89b..8f2f75d73 100644 --- a/test/spec/Feature/Query/UpsertSpec.hs +++ b/test/spec/Feature/Query/UpsertSpec.hs @@ -103,6 +103,24 @@ spec = , 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 it "INSERTs and ignores rows on pk conflict" $ request methodPost "/tiobe_pls" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")] @@ -174,44 +192,27 @@ spec = , matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation"] } - it "succeeds if the table has only PK cols and no other cols" $ do - request methodPost "/only_pk" [("Prefer", "return=representation"), ("Prefer", "resolution=ignore-duplicates")] - [json|[ { "id": 1 }, { "id": 2 }, { "id": 3} ]|] - `shouldRespondWith` - [json|[ { "id": 3} ]|] - { matchStatus = 201 , - matchHeaders = ["Preference-Applied" <:> "resolution=ignore-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=ignore-duplicates")] + [json|[ { "id": 1 }, { "id": 2 }, { "id": 3} ]|] + `shouldRespondWith` + [json|[ { "id": 3} ]|] + { matchStatus = 201 , + matchHeaders = ["Preference-Applied" <:> "resolution=ignore-duplicates, return=representation", + matchContentTypeJson] } - 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 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] } - 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"] } - - 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] } + 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 "Restrictions" $ do