7d39c004a1
Default create_calendar to commercial; reuse existing personal on 409; assert verify title Default; cover personal_exists / default_calendar. Refs EventHub/EventHubBack#64
58 lines
2.2 KiB
Erlang
58 lines
2.2 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(),
|
|
|
|
_CalId = api_test_runner:create_calendar(Token, #{title => <<"TestCal">>}),
|
|
|
|
test_create_calendar(Token),
|
|
test_second_personal_rejected(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 studio calendar"),
|
|
api_test_runner:ensure_commercial_subscription(Token),
|
|
Resp = api_test_runner:client_request(post, <<"/v1/calendars">>, Token,
|
|
jsx:encode(#{title => <<"NewCal">>, type => <<"commercial">>})),
|
|
{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_second_personal_rejected(Token) ->
|
|
ct:pal(" TEST: Second personal calendar rejected (409)"),
|
|
Resp = api_test_runner:client_request(post, <<"/v1/calendars">>, Token,
|
|
jsx:encode(#{title => <<"AnotherPersonal">>, type => <<"personal">>})),
|
|
?assertMatch({ok, 409, _, _}, Resp),
|
|
ct:pal(" OK: got 409 personal_exists").
|
|
|
|
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"). |