feat: calendar follow API (POST/DELETE follow, GET following). Refs EventHub/EventHubFront#9
This commit is contained in:
Executable
+49
@@ -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">>))).
|
||||
Reference in New Issue
Block a user