add test cases for singular minimal

This commit is contained in:
Wolfgang Walther
2020-07-03 13:54:39 -05:00
committed by Steve Chavez
parent 43d71e95ac
commit a5bc293372
2 changed files with 20 additions and 5 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ spec = describe "When raw-media-types config variable is missing or left empty"
{ matchHeaders= ["Content-Type" <:> "application/json; charset=utf-8"] } { matchHeaders= ["Content-Type" <:> "application/json; charset=utf-8"] }
it "responds json to a GET request to RPC with Firefox Accept headers" $ it "responds json to a GET request to RPC with Firefox Accept headers" $
request methodGet "/rpc/get_projects_below?id=3" chromeAcceptHdrs "" request methodGet "/rpc/get_projects_below?id=3" firefoxAcceptHdrs ""
`shouldRespondWith` [json|[{"id":1,"name":"Windows 7","client_id":1}, {"id":2,"name":"Windows 10","client_id":1}]|] `shouldRespondWith` [json|[{"id":1,"name":"Windows 7","client_id":1}, {"id":2,"name":"Windows 10","client_id":1}]|]
{ matchHeaders= ["Content-Type" <:> "application/json; charset=utf-8"] } { matchHeaders= ["Content-Type" <:> "application/json; charset=utf-8"] }
it "responds json to a GET request to RPC with Chrome Accept headers" $ it "responds json to a GET request to RPC with Chrome Accept headers" $
+19 -4
View File
@@ -43,7 +43,7 @@ spec =
{ matchHeaders = ["Content-Type" <:> "application/vnd.pgrst.object+json; charset=utf-8"] } { matchHeaders = ["Content-Type" <:> "application/vnd.pgrst.object+json; charset=utf-8"] }
context "when updating rows" $ do context "when updating rows" $ do
it "works for one row" $ do it "works for one row with return=rep" $ do
_ <- post "/addresses" [json| { id: 97, address: "A Street" } |] _ <- post "/addresses" [json| { id: 97, address: "A Street" } |]
request methodPatch request methodPatch
"/addresses?id=eq.97" "/addresses?id=eq.97"
@@ -52,6 +52,15 @@ spec =
`shouldRespondWith` `shouldRespondWith`
[str|{"id":97,"address":"B Street"}|] [str|{"id":97,"address":"B Street"}|]
it "works for one row with return=minimal" $
request methodPatch
"/addresses?id=eq.97"
[("Prefer", "return=minimal"), singular]
[json| { address: "C Street" } |]
`shouldRespondWith`
""
{ matchStatus = 204 }
it "raises an error for multiple rows" $ do it "raises an error for multiple rows" $ do
_ <- post "/addresses" [json| { id: 98, address: "xxx" } |] _ <- post "/addresses" [json| { id: 98, address: "xxx" } |]
_ <- post "/addresses" [json| { id: 99, address: "yyy" } |] _ <- post "/addresses" [json| { id: 99, address: "yyy" } |]
@@ -97,14 +106,14 @@ spec =
} }
context "when creating rows" $ do context "when creating rows" $ do
it "works for one row" $ do it "works for one row with return=rep" $ do
p <- request methodPost p <- request methodPost
"/addresses" "/addresses"
[("Prefer", "return=representation"), singular] [("Prefer", "return=representation"), singular]
[json| [ { id: 102, address: "xxx" } ] |] [json| [ { id: 102, address: "xxx" } ] |]
liftIO $ simpleBody p `shouldBe` [str|{"id":102,"address":"xxx"}|] liftIO $ simpleBody p `shouldBe` [str|{"id":102,"address":"xxx"}|]
it "works for one row even with return=minimal" $ do it "works for one row with return=minimal" $ do
request methodPost "/addresses" request methodPost "/addresses"
[("Prefer", "return=minimal"), singular] [("Prefer", "return=minimal"), singular]
[json| [ { id: 103, address: "xxx" } ] |] [json| [ { id: 103, address: "xxx" } ] |]
@@ -173,12 +182,18 @@ spec =
} }
context "when deleting rows" $ do context "when deleting rows" $ do
it "works for one row" $ do it "works for one row with return=rep" $ do
p <- request methodDelete p <- request methodDelete
"/items?id=eq.11" "/items?id=eq.11"
[("Prefer", "return=representation"), singular] "" [("Prefer", "return=representation"), singular] ""
liftIO $ simpleBody p `shouldBe` [str|{"id":11}|] liftIO $ simpleBody p `shouldBe` [str|{"id":11}|]
it "works for one row with return=minimal" $ do
p <- request methodDelete
"/items?id=eq.12"
[("Prefer", "return=minimal"), singular] ""
liftIO $ simpleBody p `shouldBe` ""
it "raises an error when attempting to delete multiple entities" $ do it "raises an error when attempting to delete multiple entities" $ do
let firstItems = "/items?id=gt.0&id=lt.6" let firstItems = "/items?id=gt.0&id=lt.6"
request methodDelete firstItems request methodDelete firstItems