No count by default (#700)

* WIP: disable counting total table size by default

* Remove commented tests since PUT is no longer supported

* Fix tests for invalid range which require count

* Do not report count in PATCH response if not asked

* Return count of deleted items only if asked

* Return count for bulk insert when requested

* Changelog entry
This commit is contained in:
Joe Nelson
2016-09-04 10:31:24 -07:00
committed by GitHub
parent 7278507c42
commit af75988dd4
9 changed files with 100 additions and 150 deletions
+30 -31
View File
@@ -28,8 +28,7 @@ spec = do
context "when I don't want the count" $ do
it "returns range Content-Range with */* for empty range" $
request methodPost "/rpc/getitemrange"
[("Prefer", "count=none")] emptyRange
request methodPost "/rpc/getitemrange" [] emptyRange
`shouldRespondWith` ResponseMatcher {
matchBody = Just [json| [] |]
, matchStatus = 200
@@ -37,8 +36,7 @@ spec = do
}
it "returns range Content-Range with range/*" $
request methodPost "/rpc/getitemrange"
[("Prefer", "count=none")] defaultRange
request methodPost "/rpc/getitemrange" [] defaultRange
`shouldRespondWith` ResponseMatcher {
matchBody = Just [json| [{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15}] |]
, matchStatus = 200
@@ -53,8 +51,8 @@ spec = do
(rangeHdrs $ ByteRangeFromTo 0 1) defaultRange
liftIO $ do
simpleHeaders r `shouldSatisfy`
matchHeader "Content-Range" "0-1/15"
simpleStatus r `shouldBe` partialContent206
matchHeader "Content-Range" "0-1/*"
simpleStatus r `shouldBe` ok200
it "understands open-ended ranges" $
request methodPost "/rpc/getitemrange"
@@ -67,7 +65,7 @@ spec = do
`shouldRespondWith` ResponseMatcher {
matchBody = Just "[]"
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "*/0"]
, matchHeaders = ["Content-Range" <:> "*/*"]
}
it "allows one-item requests" $ do
@@ -75,16 +73,16 @@ spec = do
(rangeHdrs $ ByteRangeFromTo 0 0) defaultRange
liftIO $ do
simpleHeaders r `shouldSatisfy`
matchHeader "Content-Range" "0-0/15"
simpleStatus r `shouldBe` partialContent206
matchHeader "Content-Range" "0-0/*"
simpleStatus r `shouldBe` ok200
it "handles ranges beyond collection length via truncation" $ do
r <- request methodPost "/rpc/getitemrange"
(rangeHdrs $ ByteRangeFromTo 10 100) defaultRange
liftIO $ do
simpleHeaders r `shouldSatisfy`
matchHeader "Content-Range" "10-14/15"
simpleStatus r `shouldBe` partialContent206
matchHeader "Content-Range" "10-14/*"
simpleStatus r `shouldBe` ok200
context "of invalid range" $ do
it "fails with 416 for offside range" $
@@ -94,7 +92,7 @@ spec = do
it "refuses a range with nonzero start when there are no items" $
request methodPost "/rpc/getitemrange"
(rangeHdrs $ ByteRangeFromTo 1 2) emptyRange
(rangeHdrsWithCount $ ByteRangeFromTo 1 2) emptyRange
`shouldRespondWith` ResponseMatcher {
matchBody = Nothing
, matchStatus = 416
@@ -103,12 +101,13 @@ spec = do
it "refuses a range requesting start past last item" $
request methodPost "/rpc/getitemrange"
(rangeHdrs $ ByteRangeFromTo 100 199) defaultRange
(rangeHdrsWithCount $ ByteRangeFromTo 100 199) defaultRange
`shouldRespondWith` ResponseMatcher {
matchBody = Nothing
, matchStatus = 416
, matchHeaders = ["Content-Range" <:> "*/15"]
}
describe "GET /items" $ do
context "without range headers" $ do
context "with response under server size limit" $
@@ -149,30 +148,30 @@ spec = do
`shouldRespondWith` ResponseMatcher {
matchBody = Just [str|[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15}]|]
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "0-14/15"]
, matchHeaders = ["Content-Range" <:> "0-14/*"]
}
it "top level limit with parameter" $
get "/items?select=id&order=id.asc&limit=3"
`shouldRespondWith` ResponseMatcher {
matchBody = Just [str|[{"id":1},{"id":2},{"id":3}]|]
, matchStatus = 206
, matchHeaders = ["Content-Range" <:> "0-2/15"]
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "0-2/*"]
}
it "headers override get parameters" $
request methodGet "/items?select=id&order=id.asc&limit=3"
(rangeHdrs $ ByteRangeFromTo 0 1) ""
`shouldRespondWith` ResponseMatcher {
matchBody = Just [str|[{"id":1},{"id":2}]|]
, matchStatus = 206
, matchHeaders = ["Content-Range" <:> "0-1/15"]
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "0-1/*"]
}
it "limit works on all levels" $
get "/clients?select=id,projects{id,tasks{id}}&order=id.asc&limit=1&projects.order=id.asc&projects.limit=1&projects.tasks.order=id.asc&projects.tasks.limit=2"
`shouldRespondWith` ResponseMatcher {
matchBody = Just [str|[{"id":1,"projects":[{"id":1,"tasks":[{"id":1},{"id":2}]}]}]|]
, matchStatus = 206
, matchHeaders = ["Content-Range" <:> "0-0/2"]
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "0-0/*"]
}
it "fails on offset specified below level 1" $
@@ -183,8 +182,8 @@ spec = do
get "/items?select=id&order=id.asc&limit=3&offset=2"
`shouldRespondWith` ResponseMatcher {
matchBody = Just [str|[{"id":3},{"id":4},{"id":5}]|]
, matchStatus = 206
, matchHeaders = ["Content-Range" <:> "2-4/15"]
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "2-4/*"]
}
context "with range headers" $ do
@@ -195,8 +194,8 @@ spec = do
(rangeHdrs $ ByteRangeFromTo 0 1) ""
liftIO $ do
simpleHeaders r `shouldSatisfy`
matchHeader "Content-Range" "0-1/15"
simpleStatus r `shouldBe` partialContent206
matchHeader "Content-Range" "0-1/*"
simpleStatus r `shouldBe` ok200
it "understands open-ended ranges" $
request methodGet "/items"
@@ -209,7 +208,7 @@ spec = do
`shouldRespondWith` ResponseMatcher {
matchBody = Just "[]"
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "*/0"]
, matchHeaders = ["Content-Range" <:> "*/*"]
}
it "allows one-item requests" $ do
@@ -217,16 +216,16 @@ spec = do
(rangeHdrs $ ByteRangeFromTo 0 0) ""
liftIO $ do
simpleHeaders r `shouldSatisfy`
matchHeader "Content-Range" "0-0/15"
simpleStatus r `shouldBe` partialContent206
matchHeader "Content-Range" "0-0/*"
simpleStatus r `shouldBe` ok200
it "handles ranges beyond collection length via truncation" $ do
r <- request methodGet "/items"
(rangeHdrs $ ByteRangeFromTo 10 100) ""
liftIO $ do
simpleHeaders r `shouldSatisfy`
matchHeader "Content-Range" "10-14/15"
simpleStatus r `shouldBe` partialContent206
matchHeader "Content-Range" "10-14/*"
simpleStatus r `shouldBe` ok200
context "of invalid range" $ do
it "fails with 416 for offside range" $
@@ -236,7 +235,7 @@ spec = do
it "refuses a range with nonzero start when there are no items" $
request methodGet "/menagerie"
(rangeHdrs $ ByteRangeFromTo 1 2) ""
(rangeHdrsWithCount $ ByteRangeFromTo 1 2) ""
`shouldRespondWith` ResponseMatcher {
matchBody = Nothing
, matchStatus = 416
@@ -245,7 +244,7 @@ spec = do
it "refuses a range requesting start past last item" $
request methodGet "/items"
(rangeHdrs $ ByteRangeFromTo 100 199) ""
(rangeHdrsWithCount $ ByteRangeFromTo 100 199) ""
`shouldRespondWith` ResponseMatcher {
matchBody = Nothing
, matchStatus = 416