feat: add has_next and has_prev to paginated posts response

Clients no longer need to compute page boundaries themselves; the API
now returns boolean flags indicating whether more pages exist in each
direction. Includes tests for first, middle, and last page.
This commit is contained in:
2026-06-26 20:36:16 +02:00
parent e11c7d24a4
commit bc2e056b68
2 changed files with 31 additions and 1 deletions
+27
View File
@@ -274,4 +274,31 @@ class ServerTest < Minitest::Test
data = JSON.parse(last_response.body)
assert_equal 1, data["total"]
end
def test_pagination_has_next_and_prev
# Create enough posts to paginate
5.times do |i|
File.write(File.join(@dir, "post-#{i}.md"), <<~POST)
+++
title = "Post #{i}"
+++
Body #{i}.
POST
end
get "/api/volumen/posts?page=1&limit=2"
data = JSON.parse(last_response.body)
assert_equal true, data["has_next"]
assert_equal false, data["has_prev"]
get "/api/volumen/posts?page=2&limit=2"
data = JSON.parse(last_response.body)
assert_equal true, data["has_next"]
assert_equal true, data["has_prev"]
get "/api/volumen/posts?page=3&limit=2"
data = JSON.parse(last_response.body)
assert_equal false, data["has_next"]
assert_equal true, data["has_prev"]
end
end