Stage 10 final
This commit is contained in:
23
test/unit/handler_search_tests.erl
Normal file
23
test/unit/handler_search_tests.erl
Normal file
@@ -0,0 +1,23 @@
|
||||
-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])).
|
||||
Reference in New Issue
Block a user