@@ -145,6 +145,14 @@ spec = do
145145 it " returns whole range with status 200" $
146146 get " /items" `shouldRespondWith` 200
147147
148+ context " count with an empty body" $ do
149+ it " returns empty body with Content-Range */0" $
150+ request methodGet " /items?id=eq.0"
151+ [(" Prefer" , " count=exact" )] " "
152+ `shouldRespondWith`
153+ [json |[]|]
154+ { matchHeaders = [" Content-Range" <:> " */0" ] }
155+
148156 context " when I don't want the count" $ do
149157 it " returns range Content-Range with /*" $
150158 request methodGet " /menagerie"
@@ -211,11 +219,24 @@ spec = do
211219 , " Content-Range" <:> " 2-4/*" ]
212220 }
213221
214- it " succeeds if offset equals 0 as a no-op" $
215- get " /items?select=id&offset=0&order=id"
216- `shouldRespondWith`
217- [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}]|]
218- { matchHeaders = [" Content-Range" <:> " 0-14/*" ] }
222+ context " succeeds if offset equals 0 as a no-op" $ do
223+ it " no items" $ do
224+ get " /items?offset=0&id=eq.0"
225+ `shouldRespondWith`
226+ [json |[]|]
227+ { matchHeaders = [" Content-Range" <:> " */*" ] }
228+
229+ request methodGet " /items?offset=0&id=eq.0"
230+ [(" Prefer" , " count=exact" )] " "
231+ `shouldRespondWith`
232+ [json |[]|]
233+ { matchHeaders = [" Content-Range" <:> " */0" ] }
234+
235+ it " one or more items" $
236+ get " /items?select=id&offset=0&order=id"
237+ `shouldRespondWith`
238+ [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}]|]
239+ { matchHeaders = [" Content-Range" <:> " 0-14/*" ] }
219240
220241 it " succeeds if offset is negative as a no-op" $
221242 get " /items?select=id&offset=-4&order=id"
@@ -413,15 +434,6 @@ spec = do
413434 matchHeader " Content-Range" " 10-14/*"
414435 simpleStatus r `shouldBe` ok200
415436
416- it " does not throw error when offset is 0 and and total is 0" $
417- request methodGet " /rpc/getitemrange?min=0&max=0"
418- (rangeHdrsWithCount $ ByteRangeFromTo 0 1 ) mempty
419- `shouldRespondWith`
420- [json |[]|]
421- { matchStatus = 200
422- , matchHeaders = [" Content-Range" <:> " */0" ]
423- }
424-
425437 context " of invalid range" $ do
426438 it " fails with 416 for offside range" $
427439 request methodGet " /items"
@@ -462,17 +474,3 @@ spec = do
462474 { matchStatus = 416
463475 , matchHeaders = [" Content-Range" <:> " */15" ]
464476 }
465-
466- it " refuses a range with first position the same as number of items" $
467- request methodGet " /rpc/getitemrange?min=1&max=2"
468- (rangeHdrsWithCount $ ByteRangeFromTo 1 2 ) mempty
469- `shouldRespondWith`
470- [json | {
471- "message":"Requested range not satisfiable",
472- "code":"PGRST103",
473- "details":"An offset of 1 was requested, but there are only 1 rows.",
474- "hint":null
475- }|]
476- { matchStatus = 416
477- , matchHeaders = [" Content-Range" <:> " */1" ]
478- }
0 commit comments