feat: calendar follow API (POST/DELETE follow, GET following). Refs EventHub/EventHubFront#9
CI / test (push) Failing after 6m39s
CI / deploy-ift (push) Has been skipped
CI / e2e-ift (push) Has been skipped
CI / deploy-stage (push) Has been skipped
CI / e2e-stage (push) Has been skipped

This commit is contained in:
2026-07-20 22:10:48 +03:00
parent 4932f9abae
commit 59220b955e
16 changed files with 599 additions and 4 deletions
+49
View File
@@ -0,0 +1,49 @@
-module(core_calendar_follow_tests).
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
-define(TABLES, [calendar_follow]).
setup() ->
eh_test_support:start_mnesia(),
eh_test_support:ensure_tables(?TABLES),
ok.
cleanup(_) ->
eh_test_support:delete_tables(?TABLES),
eh_test_support:stop_mnesia(),
ok.
core_calendar_follow_test_() ->
{foreach, fun setup/0, fun cleanup/1, [
{"follow and is_following", fun test_follow/0},
{"follow idempotent", fun test_follow_idempotent/0},
{"unfollow", fun test_unfollow/0},
{"list_by_user", fun test_list_by_user/0}
]}.
test_follow() ->
{ok, F} = core_calendar_follow:follow(<<"cal1">>, <<"u1">>),
?assertEqual(<<"cal1">>, F#calendar_follow.calendar_id),
?assertEqual(<<"u1">>, F#calendar_follow.user_id),
?assert(core_calendar_follow:is_following(<<"u1">>, <<"cal1">>)),
?assertNot(core_calendar_follow:is_following(<<"u2">>, <<"cal1">>)).
test_follow_idempotent() ->
{ok, F1} = core_calendar_follow:follow(<<"cal1">>, <<"u1">>),
{ok, F2} = core_calendar_follow:follow(<<"cal1">>, <<"u1">>),
?assertEqual(F1#calendar_follow.id, F2#calendar_follow.id),
?assertEqual(1, length(core_calendar_follow:list_by_user(<<"u1">>))).
test_unfollow() ->
{ok, _} = core_calendar_follow:follow(<<"cal1">>, <<"u1">>),
ok = core_calendar_follow:unfollow(<<"cal1">>, <<"u1">>),
?assertNot(core_calendar_follow:is_following(<<"u1">>, <<"cal1">>)),
ok = core_calendar_follow:unfollow(<<"cal1">>, <<"u1">>).
test_list_by_user() ->
{ok, _} = core_calendar_follow:follow(<<"cal1">>, <<"u1">>),
{ok, _} = core_calendar_follow:follow(<<"cal2">>, <<"u1">>),
{ok, _} = core_calendar_follow:follow(<<"cal1">>, <<"u2">>),
?assertEqual(2, length(core_calendar_follow:list_by_user(<<"u1">>))),
?assertEqual(2, length(core_calendar_follow:list_by_calendar(<<"cal1">>))).