54 lines
2.1 KiB
Erlang
54 lines
2.1 KiB
Erlang
-module(api_moderation_tests).
|
|
-export([test/0]).
|
|
|
|
-define(BASE_URL, "http://localhost:8080").
|
|
|
|
test() ->
|
|
io:format("Testing moderation API...~n"),
|
|
|
|
AdminToken = api_test_runner:get_admin_token(),
|
|
UserToken = api_test_runner:get_user_token(),
|
|
|
|
% Создаём календарь и событие
|
|
CalId = api_test_runner:extract_json(
|
|
api_test_runner:http_post("/v1/calendars", #{title => <<"Mod Cal">>}, UserToken), <<"id">>),
|
|
EventId = api_test_runner:extract_json(
|
|
api_test_runner:http_post("/v1/calendars/" ++ binary_to_list(CalId) ++ "/events",
|
|
#{title => <<"Mod Event">>, start_time => <<"2026-06-01T10:00:00Z">>, duration => 60}, UserToken), <<"id">>),
|
|
|
|
% TEST 1: Create report
|
|
io:format(" TEST 1: Create report... "),
|
|
ReportId = api_test_runner:extract_json(
|
|
api_test_runner:http_post("/v1/reports",
|
|
#{target_type => <<"event">>, target_id => EventId, reason => <<"Inappropriate">>}, UserToken), <<"id">>),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 2: Admin views reports
|
|
io:format(" TEST 2: Admin views reports... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/admin/reports", AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 3: Admin resolves report
|
|
io:format(" TEST 3: Admin resolves report... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_put("/v1/admin/reports/" ++ binary_to_list(ReportId),
|
|
#{action => <<"review">>}, AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 4: Add banned word
|
|
io:format(" TEST 4: Add banned word... "),
|
|
{ok, {{_, 201, _}, _, _}} = api_test_runner:http_post("/v1/admin/banned-words",
|
|
#{word => <<"badword">>}, AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 5: List banned words
|
|
io:format(" TEST 5: List banned words... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_get("/v1/admin/banned-words", AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
% TEST 6: Remove banned word
|
|
io:format(" TEST 6: Remove banned word... "),
|
|
{ok, {{_, 200, _}, _, _}} = api_test_runner:http_delete("/v1/admin/banned-words/badword", AdminToken),
|
|
io:format("OK~n"),
|
|
|
|
io:format("~n✅ Moderation API tests passed!~n"),
|
|
{?MODULE, ok}. |