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:
@@ -2,27 +2,16 @@
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
-define(TABLES, [user, calendar, event]).
|
||||
|
||||
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()]}
|
||||
]),
|
||||
eh_test_support:start_mnesia(),
|
||||
eh_test_support:ensure_tables(?TABLES),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
mnesia:delete_table(event),
|
||||
mnesia:delete_table(calendar),
|
||||
mnesia:delete_table(user),
|
||||
mnesia:stop(),
|
||||
eh_test_support:delete_tables(?TABLES),
|
||||
eh_test_support:stop_mnesia(),
|
||||
ok.
|
||||
|
||||
logic_event_test_() ->
|
||||
@@ -54,10 +43,14 @@ create_test_user_and_calendar() ->
|
||||
{ok, Calendar} = logic_calendar:create_calendar(UserId, <<"Test Calendar">>, <<"">>, manual),
|
||||
{UserId, Calendar#calendar.id}.
|
||||
|
||||
add_days(DateTime, Days) ->
|
||||
Sec = calendar:datetime_to_gregorian_seconds(DateTime) + Days * 86400,
|
||||
calendar:gregorian_seconds_to_datetime(Sec).
|
||||
|
||||
test_create_event() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
Title = <<"Test Event">>,
|
||||
StartTime = {{2026, 5, 1}, {10, 0, 0}},
|
||||
StartTime = eh_test_support:future_start(),
|
||||
Duration = 60,
|
||||
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, Title, StartTime, Duration),
|
||||
@@ -67,22 +60,26 @@ test_create_event() ->
|
||||
|
||||
test_get_event() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, <<"Test">>, {{2026, 5, 1}, {10, 0, 0}}, 60),
|
||||
StartTime = eh_test_support:future_start(),
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, <<"Test">>, StartTime, 60),
|
||||
|
||||
{ok, Found} = logic_event:get_event(UserId, Event#event.id),
|
||||
?assertEqual(Event#event.id, Found#event.id).
|
||||
|
||||
test_list_events() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
{ok, _} = logic_event:create_event(UserId, CalendarId, <<"Event 1">>, {{2026, 5, 1}, {10, 0, 0}}, 60),
|
||||
{ok, _} = logic_event:create_event(UserId, CalendarId, <<"Event 2">>, {{2026, 5, 2}, {11, 0, 0}}, 90),
|
||||
Start1 = eh_test_support:future_start(),
|
||||
Start2 = add_days(Start1, 1),
|
||||
{ok, _} = logic_event:create_event(UserId, CalendarId, <<"Event 1">>, Start1, 60),
|
||||
{ok, _} = logic_event:create_event(UserId, CalendarId, <<"Event 2">>, Start2, 90),
|
||||
|
||||
{ok, Events} = logic_event:list_events(UserId, CalendarId),
|
||||
?assertEqual(2, length(Events)).
|
||||
|
||||
test_update_event() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, <<"Original">>, {{2026, 5, 1}, {10, 0, 0}}, 60),
|
||||
StartTime = eh_test_support:future_start(),
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, <<"Original">>, StartTime, 60),
|
||||
|
||||
Updates = [{title, <<"Updated">>}, {capacity, 50}],
|
||||
{ok, Updated} = logic_event:update_event(UserId, Event#event.id, Updates),
|
||||
@@ -91,7 +88,8 @@ test_update_event() ->
|
||||
|
||||
test_delete_event() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, <<"Test">>, {{2026, 5, 1}, {10, 0, 0}}, 60),
|
||||
StartTime = eh_test_support:future_start(),
|
||||
{ok, Event} = logic_event:create_event(UserId, CalendarId, <<"Test">>, StartTime, 60),
|
||||
|
||||
{ok, Deleted} = logic_event:delete_event(UserId, Event#event.id),
|
||||
?assertEqual(deleted, Deleted#event.status).
|
||||
@@ -102,5 +100,5 @@ test_time_validation() ->
|
||||
PastTime = {{2020, 1, 1}, {10, 0, 0}},
|
||||
{error, event_in_past} = logic_event:create_event(UserId, CalendarId, <<"Past">>, PastTime, 60),
|
||||
|
||||
FutureTime = {{2030, 1, 1}, {10, 0, 0}},
|
||||
?assertEqual(ok, logic_event:validate_event_time(FutureTime)).
|
||||
FutureTime = eh_test_support:future_start(),
|
||||
?assertEqual(ok, logic_event:validate_event_time(FutureTime)).
|
||||
|
||||
Reference in New Issue
Block a user