51 lines
1.9 KiB
Erlang
51 lines
1.9 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @doc Тесты клиентского API для управления календарями.
|
|
%%% Покрывает POST /v1/calendars (создание) и GET /v1/calendars (список).
|
|
%%% @end
|
|
%%%-------------------------------------------------------------------
|
|
-module(user_calendars_tests).
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
-export([test/0]).
|
|
|
|
-spec test() -> ok.
|
|
test() ->
|
|
ct:pal("=== User Calendars Tests ==="),
|
|
Token = api_test_runner:get_user_token(),
|
|
|
|
% Создаём один календарь для тестов
|
|
#{<<"id">> := CalId} = api_test_runner:client_post(<<"/v1/calendars">>, Token,
|
|
#{title => <<"TestCal">>, type => <<"personal">>}),
|
|
|
|
test_create_calendar(Token),
|
|
test_list_calendars(Token),
|
|
test_list_calendars_unauthorized(),
|
|
|
|
ct:pal("=== All user calendars tests passed ==="),
|
|
ok.
|
|
|
|
test_create_calendar(Token) ->
|
|
ct:pal(" TEST: Create a new calendar"),
|
|
Resp = api_test_runner:client_request(post, <<"/v1/calendars">>, Token,
|
|
jsx:encode(#{title => <<"NewCal">>, type => <<"personal">>})),
|
|
{ok, 201, _, Body} = Resp,
|
|
#{<<"id">> := Id, <<"title">> := Title} = jsx:decode(list_to_binary(Body), [return_maps]),
|
|
?assert(is_binary(Id)),
|
|
?assertEqual(<<"NewCal">>, Title),
|
|
ct:pal(" OK: created calendar ~s", [Id]).
|
|
|
|
test_list_calendars(Token) ->
|
|
ct:pal(" TEST: List user calendars"),
|
|
Calendars = api_test_runner:client_get(<<"/v1/calendars">>, Token),
|
|
?assert(is_list(Calendars)),
|
|
?assert(length(Calendars) >= 1),
|
|
First = hd(Calendars),
|
|
?assert(maps:is_key(<<"id">>, First)),
|
|
?assert(maps:is_key(<<"title">>, First)),
|
|
ct:pal(" OK: ~p calendars found", [length(Calendars)]).
|
|
|
|
test_list_calendars_unauthorized() ->
|
|
ct:pal(" TEST: List calendars without token (401)"),
|
|
Resp = api_test_runner:client_request(get, <<"/v1/calendars">>, <<>>),
|
|
?assertMatch({ok, 401, _, _}, Resp),
|
|
ct:pal(" OK: got 401"). |