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:
@@ -0,0 +1,76 @@
|
||||
-module(admin_handler_calendars_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
-define(TABLES, [admin, admin_audit, calendar, ticket]).
|
||||
-define(ADMIN_ID, <<"adm_test_1">>).
|
||||
-define(OWNER_ID, <<"owner_cal_1">>).
|
||||
|
||||
setup() ->
|
||||
eh_test_support:start_mnesia(),
|
||||
eh_test_support:ensure_tables(?TABLES),
|
||||
eh_test_support:ensure_jwt(),
|
||||
eh_test_support:seed_admin(#{id => ?ADMIN_ID}),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
eh_test_support:unload_cowboy(),
|
||||
eh_test_support:delete_tables(?TABLES),
|
||||
eh_test_support:stop_mnesia(),
|
||||
ok.
|
||||
|
||||
admin_calendars_test_() ->
|
||||
{foreach, fun setup/0, fun cleanup/1, [
|
||||
{"GET list – success", {timeout, 60, fun test_list/0}},
|
||||
{"GET list – filter by status", {timeout, 60, fun test_list_filter/0}},
|
||||
{"GET – unauthorized", {timeout, 60, fun test_unauthorized/0}},
|
||||
{"POST – method not allowed", {timeout, 60, fun test_wrong_method/0}}
|
||||
]}.
|
||||
|
||||
seed_calendars() ->
|
||||
{ok, C1} = core_calendar:create(?OWNER_ID, <<"Alpha">>, <<"desc a">>, auto, personal),
|
||||
{ok, C2} = core_calendar:create(?OWNER_ID, <<"Beta">>, <<"desc b">>, manual, commercial),
|
||||
{ok, _} = core_calendar:update(C2#calendar.id, [{status, frozen}]),
|
||||
{C1, C2}.
|
||||
|
||||
test_list() ->
|
||||
seed_calendars(),
|
||||
{Status, _, Body} = eh_test_support:call(admin_handler_calendars, #{
|
||||
method => <<"GET">>,
|
||||
path => <<"/v1/admin/calendars">>,
|
||||
auth => ?ADMIN_ID
|
||||
}),
|
||||
?assertEqual(200, Status),
|
||||
Result = jsx:decode(Body, [return_maps]),
|
||||
?assertEqual(2, length(Result)).
|
||||
|
||||
test_list_filter() ->
|
||||
seed_calendars(),
|
||||
{Status, _, Body} = eh_test_support:call(admin_handler_calendars, #{
|
||||
method => <<"GET">>,
|
||||
path => <<"/v1/admin/calendars">>,
|
||||
auth => ?ADMIN_ID,
|
||||
qs => [{<<"status">>, <<"active">>}]
|
||||
}),
|
||||
?assertEqual(200, Status),
|
||||
Result = jsx:decode(Body, [return_maps]),
|
||||
?assertEqual(1, length(Result)),
|
||||
[Only] = Result,
|
||||
?assertEqual(<<"Alpha">>, maps:get(<<"title">>, Only)),
|
||||
?assertEqual(<<"active">>, maps:get(<<"status">>, Only)).
|
||||
|
||||
test_unauthorized() ->
|
||||
{Status, _, _} = eh_test_support:call(admin_handler_calendars, #{
|
||||
method => <<"GET">>,
|
||||
path => <<"/v1/admin/calendars">>,
|
||||
auth => none
|
||||
}),
|
||||
?assertEqual(401, Status).
|
||||
|
||||
test_wrong_method() ->
|
||||
{Status, _, _} = eh_test_support:call(admin_handler_calendars, #{
|
||||
method => <<"POST">>,
|
||||
path => <<"/v1/admin/calendars">>,
|
||||
auth => ?ADMIN_ID
|
||||
}),
|
||||
?assertEqual(405, Status).
|
||||
Reference in New Issue
Block a user