Files
EventHubBack/test/api/api_search_tests.erl

54 lines
2.1 KiB
Erlang
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-module(api_search_tests).
-export([test/0]).
-define(BASE_URL, api_test_runner:get_base_url()).
test() ->
io:format("Testing search API...~n"),
OwnerEmail = api_test_runner:unique_email(<<"search_owner">>),
OwnerToken = api_test_runner:register_and_login(OwnerEmail, <<"owner123">>),
CalId = api_test_runner:extract_json(
api_test_runner:http_post("/v1/calendars", #{title => <<"Search Cal">>}, OwnerToken), <<"id">>),
% Создаём события с тегами
api_test_runner:extract_json(
api_test_runner:http_post("/v1/calendars/" ++ binary_to_list(CalId) ++ "/events",
#{title => <<"Python Workshop">>, start_time => <<"2026-06-01T10:00:00Z">>, duration => 60,
tags => [<<"python">>, <<"workshop">>]}, OwnerToken), <<"id">>),
api_test_runner:extract_json(
api_test_runner:http_post("/v1/calendars/" ++ binary_to_list(CalId) ++ "/events",
#{title => <<"JavaScript">>, start_time => <<"2026-06-15T10:00:00Z">>, duration => 60,
tags => [<<"javascript">>]}, OwnerToken), <<"id">>),
timer:sleep(500),
% TEST 1: Text search
io:format(" TEST 1: Text search... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/search?type=event&q=Python", OwnerToken),
io:format("OK~n"),
% TEST 2: Tag search
io:format(" TEST 2: Tag search... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/search?type=event&tags=workshop", OwnerToken),
io:format("OK~n"),
% TEST 3: Combined search
io:format(" TEST 3: Combined search... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/search?type=event&q=Python&tags=workshop", OwnerToken),
io:format("OK~n"),
% TEST 4: Pagination
io:format(" TEST 4: Pagination... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/search?type=event&limit=2", OwnerToken),
io:format("OK~n"),
% TEST 5: Search calendars
io:format(" TEST 5: Search calendars... "),
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/search?type=calendar", OwnerToken),
io:format("OK~n"),
io:format("~n✅ Search API tests passed!~n"),
{?MODULE, ok}.