feat: add fulltext search with ?q= parameter
Filter posts by case-insensitive match in title and body. Extracted filter_by_lang and search_posts helpers to keep complexity in check.
This commit is contained in:
@@ -153,4 +153,29 @@ class ServerTest < Minitest::Test
|
||||
assert_includes data["items"].first["content_html"], "<strong>world</strong>"
|
||||
refute_includes data["items"].map { |i| i["title"] }, "Draft"
|
||||
end
|
||||
|
||||
def test_search_by_title
|
||||
get "/api/volumen/posts?q=Hello"
|
||||
data = JSON.parse(last_response.body)
|
||||
assert_equal 1, data["total"]
|
||||
assert_equal "hello", data["posts"].first["slug"]
|
||||
end
|
||||
|
||||
def test_search_by_body
|
||||
get "/api/volumen/posts?q=world"
|
||||
data = JSON.parse(last_response.body)
|
||||
assert_equal 1, data["total"]
|
||||
end
|
||||
|
||||
def test_search_no_match
|
||||
get "/api/volumen/posts?q=nonexistent"
|
||||
data = JSON.parse(last_response.body)
|
||||
assert_equal 0, data["total"]
|
||||
end
|
||||
|
||||
def test_search_is_case_insensitive
|
||||
get "/api/volumen/posts?q=HELLO"
|
||||
data = JSON.parse(last_response.body)
|
||||
assert_equal 1, data["total"]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user