-module(handler_search_tests). -include_lib("eunit/include/eunit.hrl"). handler_search_test_() -> case is_server_running() of true -> [ {"Search API requires authentication", fun test_search_requires_auth/0} ]; false -> io:format("Skipping handler tests: server not running~n"), [] end. is_server_running() -> case httpc:request(get, {"http://localhost:8080/health", []}, [], [{timeout, 1000}]) of {ok, {{_, 200, _}, _, _}} -> true; _ -> false end. test_search_requires_auth() -> {ok, {{_, 401, _}, _, Body}} = httpc:request(get, {"http://localhost:8080/v1/search?type=event", []}, [], []), ?assertMatch(#{<<"error">> := _}, jsx:decode(Body, [return_maps])).