This commit is contained in:
2026-04-21 11:54:13 +03:00
parent ee8928fa5f
commit fc6ef8de7e
12 changed files with 1469 additions and 1 deletions

View File

@@ -0,0 +1,80 @@
-module(core_banned_word_tests).
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
setup() ->
mnesia:start(),
mnesia:create_table(banned_word, [
{attributes, record_info(fields, banned_word)},
{ram_copies, [node()]}
]),
ok.
cleanup(_) ->
mnesia:delete_table(banned_word),
mnesia:stop(),
ok.
core_banned_word_test_() ->
{foreach,
fun setup/0,
fun cleanup/1,
[
{"Add banned word test", fun test_add_word/0},
{"Add duplicate word test", fun test_add_duplicate/0},
{"Remove banned word test", fun test_remove_word/0},
{"List banned words test", fun test_list_words/0},
{"Is banned test", fun test_is_banned/0},
{"Check text test", fun test_check_text/0},
{"Filter text test", fun test_filter_text/0}
]}.
test_add_word() ->
Word = <<"badword">>,
{ok, BannedWord} = core_banned_word:add(Word),
?assertEqual(Word, BannedWord#banned_word.word),
?assert(is_binary(BannedWord#banned_word.id)).
test_add_duplicate() ->
Word = <<"badword">>,
{ok, _} = core_banned_word:add(Word),
{error, already_exists} = core_banned_word:add(Word),
{error, already_exists} = core_banned_word:add(<<"BADWORD">>). % case insensitive
test_remove_word() ->
Word = <<"badword">>,
{ok, _} = core_banned_word:add(Word),
{ok, removed} = core_banned_word:remove(Word),
{error, not_found} = core_banned_word:remove(<<"nonexistent">>).
test_list_words() ->
{ok, _} = core_banned_word:add(<<"word1">>),
{ok, _} = core_banned_word:add(<<"word2">>),
{ok, _} = core_banned_word:add(<<"word3">>),
{ok, Words} = core_banned_word:list_all(),
?assertEqual(3, length(Words)),
?assert(lists:member(<<"word1">>, Words)).
test_is_banned() ->
Word = <<"badword">>,
?assertNot(core_banned_word:is_banned(Word)),
{ok, _} = core_banned_word:add(Word),
?assert(core_banned_word:is_banned(Word)),
?assert(core_banned_word:is_banned(<<"BADWORD">>)). % case insensitive
test_check_text() ->
{ok, _} = core_banned_word:add(<<"bad">>),
{ok, _} = core_banned_word:add(<<"spam">>),
?assertNot(core_banned_word:check_text(<<"Hello world">>)),
?assert(core_banned_word:check_text(<<"This is bad">>)),
?assert(core_banned_word:check_text(<<"This is SPAM">>)).
test_filter_text() ->
{ok, _} = core_banned_word:add(<<"bad">>),
{ok, _} = core_banned_word:add(<<"spam">>),
?assertEqual(<<"Hello world">>, core_banned_word:filter_text(<<"Hello world">>)),
?assertEqual(<<"This is ***">>, core_banned_word:filter_text(<<"This is bad">>)),
?assertEqual(<<"*** and ***">>, core_banned_word:filter_text(<<"bad and spam">>)).

101
test/core_report_tests.erl Normal file
View File

@@ -0,0 +1,101 @@
-module(core_report_tests).
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
setup() ->
mnesia:start(),
mnesia:create_table(report, [
{attributes, record_info(fields, report)},
{ram_copies, [node()]}
]),
ok.
cleanup(_) ->
mnesia:delete_table(report),
mnesia:stop(),
ok.
core_report_test_() ->
{foreach,
fun setup/0,
fun cleanup/1,
[
{"Create report test", fun test_create_report/0},
{"Get report by id test", fun test_get_by_id/0},
{"List reports by target test", fun test_list_by_target/0},
{"List reports by reporter test", fun test_list_by_reporter/0},
{"Update report status test", fun test_update_status/0},
{"Get count by target test", fun test_get_count_by_target/0}
]}.
test_create_report() ->
ReporterId = <<"user123">>,
TargetType = event,
TargetId = <<"event123">>,
Reason = <<"Inappropriate content">>,
{ok, Report} = core_report:create(ReporterId, TargetType, TargetId, Reason),
?assertEqual(ReporterId, Report#report.reporter_id),
?assertEqual(TargetType, Report#report.target_type),
?assertEqual(TargetId, Report#report.target_id),
?assertEqual(Reason, Report#report.reason),
?assertEqual(pending, Report#report.status),
?assertEqual(undefined, Report#report.resolved_at),
?assertEqual(undefined, Report#report.resolved_by),
?assert(is_binary(Report#report.id)).
test_get_by_id() ->
ReporterId = <<"user123">>,
{ok, Report} = core_report:create(ReporterId, event, <<"ev1">>, <<"Bad">>),
{ok, Found} = core_report:get_by_id(Report#report.id),
?assertEqual(Report#report.id, Found#report.id),
{error, not_found} = core_report:get_by_id(<<"nonexistent">>).
test_list_by_target() ->
User1 = <<"user1">>,
User2 = <<"user2">>,
EventId = <<"event123">>,
{ok, _} = core_report:create(User1, event, EventId, <<"Reason 1">>),
{ok, _} = core_report:create(User2, event, EventId, <<"Reason 2">>),
{ok, _} = core_report:create(User1, calendar, <<"cal1">>, <<"Reason 3">>),
{ok, Reports} = core_report:list_by_target(event, EventId),
?assertEqual(2, length(Reports)).
test_list_by_reporter() ->
User1 = <<"user1">>,
User2 = <<"user2">>,
{ok, _} = core_report:create(User1, event, <<"ev1">>, <<"">>),
{ok, _} = core_report:create(User1, event, <<"ev2">>, <<"">>),
{ok, _} = core_report:create(User2, event, <<"ev3">>, <<"">>),
{ok, Reports} = core_report:list_by_reporter(User1),
?assertEqual(2, length(Reports)).
test_update_status() ->
ReporterId = <<"user123">>,
AdminId = <<"admin123">>,
{ok, Report} = core_report:create(ReporterId, event, <<"ev1">>, <<"">>),
{ok, Updated} = core_report:update_status(Report#report.id, reviewed, AdminId),
?assertEqual(reviewed, Updated#report.status),
?assertEqual(AdminId, Updated#report.resolved_by),
?assert(Updated#report.resolved_at =/= undefined).
test_get_count_by_target() ->
User1 = <<"user1">>,
User2 = <<"user2">>,
EventId = <<"event123">>,
?assertEqual(0, core_report:get_count_by_target(event, EventId)),
{ok, _} = core_report:create(User1, event, EventId, <<"">>),
?assertEqual(1, core_report:get_count_by_target(event, EventId)),
{ok, _} = core_report:create(User2, event, EventId, <<"">>),
?assertEqual(2, core_report:get_count_by_target(event, EventId)).

View File

@@ -0,0 +1,146 @@
-module(logic_moderation_tests).
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
setup() ->
mnesia:start(),
mnesia:create_table(user, [{attributes, record_info(fields, user)}, {ram_copies, [node()]}]),
mnesia:create_table(calendar, [{attributes, record_info(fields, calendar)}, {ram_copies, [node()]}]),
mnesia:create_table(event, [{attributes, record_info(fields, event)}, {ram_copies, [node()]}]),
mnesia:create_table(report, [{attributes, record_info(fields, report)}, {ram_copies, [node()]}]),
mnesia:create_table(banned_word, [{attributes, record_info(fields, banned_word)}, {ram_copies, [node()]}]),
ok.
cleanup(_) ->
mnesia:delete_table(banned_word),
mnesia:delete_table(report),
mnesia:delete_table(event),
mnesia:delete_table(calendar),
mnesia:delete_table(user),
mnesia:stop(),
ok.
logic_moderation_test_() ->
{foreach,
fun setup/0,
fun cleanup/1,
[
{"Create report test", fun test_create_report/0},
{"Get reports test", fun test_get_reports/0},
{"Resolve report test", fun test_resolve_report/0},
{"Add banned word test", fun test_add_banned_word/0},
{"Remove banned word test", fun test_remove_banned_word/0},
{"Auto freeze by reports test", fun test_auto_freeze/0},
{"Freeze/unfreeze calendar test", fun test_freeze_calendar/0},
{"Freeze/unfreeze event test", fun test_freeze_event/0},
{"Check content test", fun test_check_content/0}
]}.
create_test_user(Role) ->
UserId = base64:encode(crypto:strong_rand_bytes(16), #{mode => urlsafe, padding => false}),
User = #user{id = UserId, email = <<UserId/binary, "@test.com">>, password_hash = <<"hash">>,
role = Role, status = active, created_at = calendar:universal_time(), updated_at = calendar:universal_time()},
mnesia:dirty_write(User),
UserId.
create_test_calendar(OwnerId) ->
{ok, Calendar} = core_calendar:create(OwnerId, <<"Test">>, <<"">>, manual),
Calendar#calendar.id.
create_test_event(CalendarId) ->
{ok, Event} = core_event:create(CalendarId, <<"Event">>, {{2026, 6, 1}, {10, 0, 0}}, 60),
Event#event.id.
test_create_report() ->
ReporterId = create_test_user(user),
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId),
EventId = create_test_event(CalendarId),
{ok, Report} = logic_moderation:create_report(ReporterId, event, EventId, <<"Bad content">>),
?assertEqual(ReporterId, Report#report.reporter_id),
?assertEqual(pending, Report#report.status).
test_get_reports() ->
AdminId = create_test_user(admin),
ReporterId = create_test_user(user),
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId),
EventId = create_test_event(CalendarId),
{ok, _} = logic_moderation:create_report(ReporterId, event, EventId, <<"">>),
{ok, Reports} = logic_moderation:get_reports(AdminId),
?assertEqual(1, length(Reports)).
test_resolve_report() ->
AdminId = create_test_user(admin),
ReporterId = create_test_user(user),
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId),
EventId = create_test_event(CalendarId),
{ok, Report} = logic_moderation:create_report(ReporterId, event, EventId, <<"">>),
{ok, Resolved} = logic_moderation:resolve_report(AdminId, Report#report.id, reviewed),
?assertEqual(reviewed, Resolved#report.status),
?assertEqual(AdminId, Resolved#report.resolved_by).
test_add_banned_word() ->
AdminId = create_test_user(admin),
{ok, _} = logic_moderation:add_banned_word(AdminId, <<"badword">>),
?assert(core_banned_word:is_banned(<<"badword">>)).
test_remove_banned_word() ->
AdminId = create_test_user(admin),
{ok, _} = logic_moderation:add_banned_word(AdminId, <<"badword">>),
{ok, removed} = logic_moderation:remove_banned_word(AdminId, <<"badword">>),
?assertNot(core_banned_word:is_banned(<<"badword">>)).
test_auto_freeze() ->
Reporter1 = create_test_user(user),
Reporter2 = create_test_user(user),
Reporter3 = create_test_user(user),
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId),
EventId = create_test_event(CalendarId),
% 3 жалобы должны заморозить событие
{ok, _} = logic_moderation:create_report(Reporter1, event, EventId, <<"">>),
{ok, _} = logic_moderation:create_report(Reporter2, event, EventId, <<"">>),
{ok, _} = logic_moderation:create_report(Reporter3, event, EventId, <<"">>),
{ok, Event} = core_event:get_by_id(EventId),
?assertEqual(frozen, Event#event.status).
test_freeze_calendar() ->
AdminId = create_test_user(admin),
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId),
{ok, Frozen} = logic_moderation:freeze_calendar(AdminId, CalendarId),
?assertEqual(frozen, Frozen#calendar.status),
{ok, Unfrozen} = logic_moderation:unfreeze_calendar(AdminId, CalendarId),
?assertEqual(active, Unfrozen#calendar.status).
test_freeze_event() ->
AdminId = create_test_user(admin),
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId),
EventId = create_test_event(CalendarId),
{ok, Frozen} = logic_moderation:freeze_event(AdminId, EventId),
?assertEqual(frozen, Frozen#event.status),
{ok, Unfrozen} = logic_moderation:unfreeze_event(AdminId, EventId),
?assertEqual(active, Unfrozen#event.status).
test_check_content() ->
AdminId = create_test_user(admin),
{ok, _} = logic_moderation:add_banned_word(AdminId, <<"bad">>),
?assertNot(logic_moderation:check_content(<<"Hello">>)),
?assert(logic_moderation:check_content(<<"This is bad">>)),
?assertEqual(<<"Hello">>, logic_moderation:auto_moderate(<<"Hello">>)),
?assertEqual(<<"This is ***">>, logic_moderation:auto_moderate(<<"This is bad">>)).

View File

@@ -0,0 +1,370 @@
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
BASE_URL="http://localhost:8080"
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
extract_json() {
echo "$1" | grep -o "\"$2\":\"[^\"]*\"" | head -1 | sed "s/\"$2\":\"//;s/\"$//"
}
http_post() {
local url=$1; local data=$2; local token=$3
if [ -n "$token" ]; then
curl -s -X POST "$url" -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d "$data"
else
curl -s -X POST "$url" -H "Content-Type: application/json" -d "$data"
fi
}
http_get() {
local url=$1; local token=$2
if [ -n "$token" ]; then
curl -s -X GET "$url" -H "Authorization: Bearer $token"
else
curl -s -X GET "$url"
fi
}
http_put() {
local url=$1; local data=$2; local token=$3
curl -s -X PUT "$url" -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d "$data"
}
http_delete() {
local url=$1; local token=$2
curl -s -X DELETE "$url" -H "Authorization: Bearer $token"
}
echo "============================================================"
echo " EVENTHUB MODERATION API TEST SCRIPT"
echo "============================================================"
echo ""
log_info "Checking if server is running..."
if ! curl -s "$BASE_URL/health" | grep -q "ok"; then
log_error "Server is not running"
exit 1
fi
log_success "Server is running"
echo ""
log_info "============================================================"
log_info "STEP 1: Create test users"
log_info "============================================================"
# Админ (первый пользователь)
ADMIN_EMAIL="mod_admin_$(date +%s)@example.com"
ADMIN_PASSWORD="admin123"
log_info "Creating admin user..."
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\"}" "")
ADMIN_TOKEN=$(extract_json "$response" "token")
ADMIN_ID=$(extract_json "$response" "id")
log_success "Admin created"
# Владелец календаря
OWNER_EMAIL="mod_owner_$(date +%s)@example.com"
OWNER_PASSWORD="owner123"
log_info "Creating calendar owner..."
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$OWNER_EMAIL\",\"password\":\"$OWNER_PASSWORD\"}" "")
OWNER_TOKEN=$(extract_json "$response" "token")
OWNER_ID=$(extract_json "$response" "id")
log_success "Owner created"
# Пользователь 1 (репортер)
USER1_EMAIL="mod_user1_$(date +%s)@example.com"
USER1_PASSWORD="user1_123"
log_info "Creating user 1..."
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$USER1_EMAIL\",\"password\":\"$USER1_PASSWORD\"}" "")
USER1_TOKEN=$(extract_json "$response" "token")
log_success "User 1 created"
# Пользователь 2 (репортер)
USER2_EMAIL="mod_user2_$(date +%s)@example.com"
USER2_PASSWORD="user2_123"
log_info "Creating user 2..."
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$USER2_EMAIL\",\"password\":\"$USER2_PASSWORD\"}" "")
USER2_TOKEN=$(extract_json "$response" "token")
log_success "User 2 created"
# Пользователь 3 (для третьего репорта)
USER3_EMAIL="mod_user3_$(date +%s)@example.com"
USER3_PASSWORD="user3_123"
log_info "Creating user 3..."
response=$(http_post "$BASE_URL/v1/register" "{\"email\":\"$USER3_EMAIL\",\"password\":\"$USER3_PASSWORD\"}" "")
USER3_TOKEN=$(extract_json "$response" "token")
log_success "User 3 created"
echo ""
log_info "============================================================"
log_info "STEP 2: Create calendar and event"
log_info "============================================================"
log_info "Creating calendar..."
response=$(http_post "$BASE_URL/v1/calendars" \
"{\"title\":\"Moderation Test Calendar\"}" "$OWNER_TOKEN")
CALENDAR_ID=$(extract_json "$response" "id")
log_success "Calendar created: $CALENDAR_ID"
log_info "Creating event..."
EVENT_START="2026-06-01T10:00:00Z"
response=$(http_post "$BASE_URL/v1/calendars/$CALENDAR_ID/events" \
"{\"title\":\"Test Event\",\"start_time\":\"$EVENT_START\",\"duration\":60}" "$OWNER_TOKEN")
EVENT_ID=$(extract_json "$response" "id")
log_success "Event created: $EVENT_ID"
echo ""
log_info "============================================================"
log_info "TEST 1: Create report for event"
log_info "============================================================"
log_info "User 1 reporting event..."
response=$(http_post "$BASE_URL/v1/reports" \
"{\"target_type\":\"event\",\"target_id\":\"$EVENT_ID\",\"reason\":\"Inappropriate content\"}" "$USER1_TOKEN")
REPORT1_ID=$(extract_json "$response" "id")
if [ -n "$REPORT1_ID" ]; then
log_success "Report created: $REPORT1_ID"
else
log_error "Failed to create report: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 2: Create second report"
log_info "============================================================"
log_info "User 2 reporting same event..."
response=$(http_post "$BASE_URL/v1/reports" \
"{\"target_type\":\"event\",\"target_id\":\"$EVENT_ID\",\"reason\":\"Spam\"}" "$USER2_TOKEN")
REPORT2_ID=$(extract_json "$response" "id")
if [ -n "$REPORT2_ID" ]; then
log_success "Second report created: $REPORT2_ID"
else
log_error "Failed to create report: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 3: Admin views all reports"
log_info "============================================================"
log_info "Admin getting all reports..."
response=$(http_get "$BASE_URL/v1/admin/reports" "$ADMIN_TOKEN")
REPORT_COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
if [ "$REPORT_COUNT" -ge 2 ]; then
log_success "Admin sees $REPORT_COUNT reports"
else
log_error "Admin should see reports, found $REPORT_COUNT"
fi
echo ""
log_info "============================================================"
log_info "TEST 4: Admin views reports for specific event"
log_info "============================================================"
log_info "Admin getting reports for event..."
response=$(http_get "$BASE_URL/v1/admin/reports?target_type=event&target_id=$EVENT_ID" "$ADMIN_TOKEN")
EVENT_REPORT_COUNT=$(echo "$response" | grep -o "\"id\"" | wc -l)
if [ "$EVENT_REPORT_COUNT" -eq 2 ]; then
log_success "Admin sees $EVENT_REPORT_COUNT reports for event"
else
log_error "Expected 2 reports, found $EVENT_REPORT_COUNT"
fi
echo ""
log_info "============================================================"
log_info "TEST 5: Auto-freeze by reports (threshold 3)"
log_info "============================================================"
log_info "User 3 creating third report for event..."
response=$(http_post "$BASE_URL/v1/reports" \
"{\"target_type\":\"event\",\"target_id\":\"$EVENT_ID\",\"reason\":\"Bad content\"}" "$USER3_TOKEN")
REPORT3_ID=$(extract_json "$response" "id")
if [ -n "$REPORT3_ID" ]; then
log_success "Third report created: $REPORT3_ID"
else
log_error "Failed to create third report"
fi
sleep 1
log_info "Checking if event was auto-frozen..."
response=$(http_get "$BASE_URL/v1/events/$EVENT_ID" "$OWNER_TOKEN")
EVENT_STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$EVENT_STATUS" = "frozen" ]; then
log_success "Event auto-frozen after 3 reports"
else
log_error "Event not auto-frozen: status=$EVENT_STATUS"
fi
echo ""
log_info "============================================================"
log_info "TEST 6: Admin resolves report (review)"
log_info "============================================================"
log_info "Admin reviewing first report..."
response=$(http_put "$BASE_URL/v1/admin/reports/$REPORT1_ID" \
"{\"action\":\"review\"}" "$ADMIN_TOKEN")
STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$STATUS" = "reviewed" ]; then
log_success "Report marked as reviewed"
else
log_error "Failed to review report: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 7: Admin resolves report (dismiss)"
log_info "============================================================"
log_info "Admin dismissing second report..."
response=$(http_put "$BASE_URL/v1/admin/reports/$REPORT2_ID" \
"{\"action\":\"dismiss\"}" "$ADMIN_TOKEN")
STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$STATUS" = "dismissed" ]; then
log_success "Report dismissed"
else
log_error "Failed to dismiss report: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 8: Admin adds banned words"
log_info "============================================================"
log_info "Admin adding banned word 'spam'..."
response=$(http_post "$BASE_URL/v1/admin/banned-words" \
"{\"word\":\"spam\"}" "$ADMIN_TOKEN")
if echo "$response" | grep -q "added"; then
log_success "Banned word added"
else
log_error "Failed to add banned word: $response"
fi
log_info "Admin adding banned word 'inappropriate'..."
http_post "$BASE_URL/v1/admin/banned-words" "{\"word\":\"inappropriate\"}" "$ADMIN_TOKEN" > /dev/null
echo ""
log_info "============================================================"
log_info "TEST 9: Admin lists banned words"
log_info "============================================================"
log_info "Admin getting banned words..."
response=$(http_get "$BASE_URL/v1/admin/banned-words" "$ADMIN_TOKEN")
if echo "$response" | grep -q "spam"; then
log_success "Banned words retrieved"
else
log_error "Failed to get banned words: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 10: Admin removes banned word"
log_info "============================================================"
log_info "Admin removing banned word 'inappropriate'..."
response=$(http_delete "$BASE_URL/v1/admin/banned-words/inappropriate" "$ADMIN_TOKEN")
if echo "$response" | grep -q "removed"; then
log_success "Banned word removed"
else
log_error "Failed to remove banned word: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 11: Admin freezes calendar"
log_info "============================================================"
log_info "Admin freezing calendar..."
response=$(http_put "$BASE_URL/v1/admin/calendars/$CALENDAR_ID" \
"{\"action\":\"freeze\"}" "$ADMIN_TOKEN")
CAL_STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$CAL_STATUS" = "frozen" ]; then
log_success "Calendar frozen"
else
log_error "Failed to freeze calendar: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 12: Admin unfreezes calendar"
log_info "============================================================"
log_info "Admin unfreezing calendar..."
response=$(http_put "$BASE_URL/v1/admin/calendars/$CALENDAR_ID" \
"{\"action\":\"unfreeze\"}" "$ADMIN_TOKEN")
CAL_STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$CAL_STATUS" = "active" ]; then
log_success "Calendar unfrozen"
else
log_error "Failed to unfreeze calendar: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 13: Admin freezes event"
log_info "============================================================"
log_info "Admin freezing event..."
response=$(http_put "$BASE_URL/v1/admin/events/$EVENT_ID" \
"{\"action\":\"freeze\"}" "$ADMIN_TOKEN")
EVENT_STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$EVENT_STATUS" = "frozen" ]; then
log_success "Event frozen"
else
log_error "Failed to freeze event: $response"
fi
echo ""
log_info "============================================================"
log_info "TEST 14: Admin unfreezes event"
log_info "============================================================"
log_info "Admin unfreezing event..."
response=$(http_put "$BASE_URL/v1/admin/events/$EVENT_ID" \
"{\"action\":\"unfreeze\"}" "$ADMIN_TOKEN")
EVENT_STATUS=$(echo "$response" | grep -o "\"status\":\"[^\"]*\"" | sed 's/"status":"//;s/"//')
if [ "$EVENT_STATUS" = "active" ]; then
log_success "Event unfrozen"
else
log_error "Failed to unfreeze event: $response"
fi
echo ""
echo "============================================================"
log_success "MODERATION API TESTS COMPLETED!"
echo "============================================================"
echo ""
echo "Summary of created resources:"
echo " Admin: $ADMIN_EMAIL"
echo " Owner: $OWNER_EMAIL"
echo " Calendar: $CALENDAR_ID"
echo " Event: $EVENT_ID"
echo ""