Stage 10 final
This commit is contained in:
54
test/api/api_search_tests.erl
Normal file
54
test/api/api_search_tests.erl
Normal file
@@ -0,0 +1,54 @@
|
||||
-module(api_search_tests).
|
||||
-export([test/0]).
|
||||
|
||||
-define(BASE_URL, "http://localhost:8080").
|
||||
|
||||
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}.
|
||||
Reference in New Issue
Block a user