Rewrite and expand EUnit suite; run unit tests in CI from shared test image. Refs EventHub/EventHubBack#36 [skip ci]

This commit is contained in:
2026-07-17 15:16:46 +03:00
parent 9d2780fef4
commit 4fa802702f
54 changed files with 4240 additions and 2281 deletions
+21 -24
View File
@@ -2,22 +2,16 @@
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
-define(TABLES, [event, recurrence_exception]).
setup() ->
mnesia:start(),
mnesia:create_table(event, [
{attributes, record_info(fields, event)},
{ram_copies, [node()]}
]),
mnesia:create_table(recurrence_exception, [
{attributes, record_info(fields, recurrence_exception)},
{ram_copies, [node()]}
]),
eh_test_support:start_mnesia(),
eh_test_support:ensure_tables(?TABLES),
ok.
cleanup(_) ->
mnesia:delete_table(recurrence_exception),
mnesia:delete_table(event),
mnesia:stop(),
eh_test_support:delete_tables(?TABLES),
eh_test_support:stop_mnesia(),
ok.
core_event_recurring_test_() ->
@@ -31,10 +25,14 @@ core_event_recurring_test_() ->
{"Materialize non-recurring test", fun test_materialize_non_recurring/0}
]}.
add_days(DateTime, Days) ->
Sec = calendar:datetime_to_gregorian_seconds(DateTime) + Days * 86400,
calendar:gregorian_seconds_to_datetime(Sec).
test_create_recurring() ->
CalendarId = <<"calendar123">>,
Title = <<"Weekly Meeting">>,
StartTime = {{2026, 4, 20}, {10, 0, 0}},
StartTime = eh_test_support:future_start(),
Duration = 60,
RRule = #{<<"freq">> => <<"WEEKLY">>, <<"interval">> => 1},
@@ -46,7 +44,6 @@ test_create_recurring() ->
?assertEqual(false, Event#event.is_instance),
?assert(is_binary(Event#event.recurrence_rule)),
% Проверяем, что правило сохранилось
Decoded = jsx:decode(Event#event.recurrence_rule, [return_maps]),
RRuleMap = case Decoded of
Map when is_map(Map) -> Map;
@@ -56,8 +53,8 @@ test_create_recurring() ->
test_materialize_occurrence() ->
CalendarId = <<"calendar123">>,
MasterId = create_recurring_event(CalendarId),
OccurrenceStart = {{2026, 4, 27}, {10, 0, 0}},
{MasterId, StartTime} = create_recurring_event(CalendarId),
OccurrenceStart = add_days(StartTime, 7),
SpecialistId = <<"specialist123">>,
{ok, Instance} = core_event:materialize_occurrence(MasterId, OccurrenceStart, SpecialistId),
@@ -71,15 +68,13 @@ test_materialize_occurrence() ->
test_materialize_existing() ->
CalendarId = <<"calendar123">>,
MasterId = create_recurring_event(CalendarId),
OccurrenceStart = {{2026, 4, 27}, {10, 0, 0}},
{MasterId, StartTime} = create_recurring_event(CalendarId),
OccurrenceStart = add_days(StartTime, 7),
SpecialistId1 = <<"specialist1">>,
SpecialistId2 = <<"specialist2">>,
% Первая материализация
{ok, Instance1} = core_event:materialize_occurrence(MasterId, OccurrenceStart, SpecialistId1),
% Вторая материализация - должна вернуть существующий экземпляр
{ok, Instance2} = core_event:materialize_occurrence(MasterId, OccurrenceStart, SpecialistId2),
?assertEqual(Instance1#event.id, Instance2#event.id),
@@ -87,18 +82,20 @@ test_materialize_existing() ->
test_materialize_non_recurring() ->
CalendarId = <<"calendar123">>,
{ok, SingleEvent} = core_event:create(CalendarId, <<"Single">>, {{2026, 4, 20}, {10, 0, 0}}, 60),
StartTime = eh_test_support:future_start(),
{ok, SingleEvent} = core_event:create(CalendarId, <<"Single">>, StartTime, 60),
{error, not_recurring} = core_event:materialize_occurrence(
SingleEvent#event.id, {{2026, 4, 27}, {10, 0, 0}}, <<"spec">>
SingleEvent#event.id, add_days(StartTime, 7), <<"spec">>
).
create_recurring_event(CalendarId) ->
StartTime = eh_test_support:future_start(),
{ok, Event} = core_event:create_recurring(
CalendarId,
<<"Weekly Meeting">>,
{{2026, 4, 20}, {10, 0, 0}},
StartTime,
60,
#{<<"freq">> => <<"WEEKLY">>, <<"interval">> => 1}
),
Event#event.id.
{Event#event.id, StartTime}.