Files
EventHubBack/test/api/users/user_events_tests.erl
T
aleksey f4746df4a2
Deploy IFT (core) / deploy-ift-core (push) Failing after 22m58s
CI / test (push) Failing after 22m59s
CI/CD: ci, deploy-ift и deploy-stage через EventHubDevOps; фиксы calendar view, archive, API-тесты, traefik-coraza
2026-07-08 14:50:59 +03:00

83 lines
3.3 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.
%%%-------------------------------------------------------------------
%%% @doc Тесты клиентского API для событий.
%%% Покрывает POST /v1/calendars/:id/events и GET /v1/events/:id/occurrences
%%% @end
%%%-------------------------------------------------------------------
-module(user_events_tests).
-include_lib("eunit/include/eunit.hrl").
-export([test/0]).
-spec test() -> ok.
test() ->
ct:pal("=== User Events Tests ==="),
Token = api_test_runner:get_user_token(),
% Создаём календарь
CalId = api_test_runner:create_calendar(Token, #{title => <<"EventsTest">>}),
% Тесты
test_create_single_event(Token, CalId),
test_list_events_with_dates(Token, CalId),
test_create_recurring_event(Token, CalId),
ct:pal("=== All user events tests passed ==="),
ok.
%% @doc POST /v1/calendars/:calendar_id/events одиночное событие.
test_create_single_event(Token, CalId) ->
ct:pal(" TEST: Create single event"),
Path = <<"/v1/calendars/", CalId/binary, "/events">>,
Body = jsx:encode(#{
title => <<"Single Event">>,
start_time => api_test_runner:future_date_iso8601(),
duration => 60
}),
Resp = api_test_runner:client_request(post, Path, Token, Body),
{ok, 201, _, RespBody} = Resp,
#{<<"id">> := EventId, <<"title">> := Title} = jsx:decode(list_to_binary(RespBody), [return_maps]),
?assert(is_binary(EventId)),
?assertEqual(<<"Single Event">>, Title),
ct:pal(" OK: created event ~s", [EventId]).
%% @doc GET /v1/calendars/:calendar_id/events?from=...&to=... список с фильтром.
test_list_events_with_dates(Token, CalId) ->
ct:pal(" TEST: List events with date range"),
{From, To} = api_test_runner:future_month_range_iso8601(),
Path = <<"/v1/calendars/", CalId/binary, "/events?from=", From/binary,
"&to=", To/binary>>,
Events = api_test_runner:client_get(Path, Token),
?assert(is_list(Events)),
?assert(length(Events) >= 1),
First = hd(Events),
?assert(maps:is_key(<<"id">>, First)),
?assert(maps:is_key(<<"title">>, First)),
ct:pal(" OK: ~p events found", [length(Events)]).
%% @doc POST /v1/calendars/:calendar_id/events повторяющееся событие и проверка вхождений.
test_create_recurring_event(Token, CalId) ->
ct:pal(" TEST: Create recurring event and check occurrences"),
Path = <<"/v1/calendars/", CalId/binary, "/events">>,
Body = jsx:encode(#{
title => <<"Weekly Meeting">>,
start_time => api_test_runner:next_month_start_iso8601(),
duration => 60,
recurrence => #{
freq => <<"WEEKLY">>,
interval => 1
}
}),
Resp = api_test_runner:client_request(post, Path, Token, Body),
{ok, 201, _, RespBody} = Resp,
#{<<"id">> := RecurringId} = jsx:decode(list_to_binary(RespBody), [return_maps]),
ct:pal(" Created recurring event ~s", [RecurringId]),
{From, To} = api_test_runner:next_month_range_iso8601(),
OccPath = <<"/v1/events/", RecurringId/binary, "/occurrences?from=", From/binary,
"&to=", To/binary>>,
Occs = api_test_runner:client_get(OccPath, Token),
?assert(is_list(Occs)),
?assert(length(Occs) >= 4), % минимум 4 недели в полном месяце
FirstOcc = hd(Occs),
?assert(maps:is_key(<<"start_time">>, FirstOcc)),
ct:pal(" OK: ~p occurrences found", [length(Occs)]).