fix(api): resolve public calendar GET by unique short_name.
CI / test (push) Successful in 7m28s
CI / deploy-ift (push) Successful in 2m46s
CI / e2e-ift (push) Successful in 1m26s
CI / deploy-stage (push) Successful in 2m4s
CI / e2e-stage (push) Successful in 2m4s

This commit is contained in:
2026-08-14 15:00:41 +03:00
parent 658cbda4fe
commit 3d7ae0d372
8 changed files with 67 additions and 18 deletions
@@ -20,6 +20,7 @@ test() ->
test_get_calendar(Token, CalId),
test_get_calendar_guest(Token, CalId),
test_get_calendar_guest_short_name(Token, CalId),
test_get_calendar_not_found(Token),
test_update_calendar(Token, CalId),
test_update_calendar_settings(Token, CalId),
@@ -49,6 +50,20 @@ test_get_calendar_guest(Token, CalId) ->
{ok, 403, _, _} = api_test_runner:client_request(get, PPath, <<>>),
ct:pal(" OK: guest commercial 200, personal 403").
test_get_calendar_guest_short_name(Token, CalId) ->
ct:pal(" TEST: Guest GET commercial by short_name"),
PathId = <<"/v1/calendars/", CalId/binary>>,
Slug2 = <<"sn", (integer_to_binary(erlang:unique_integer([positive])))/binary>>,
_ = api_test_runner:client_put(PathId, Token, #{short_name => Slug2}),
PathSlug = <<"/v1/calendars/", Slug2/binary>>,
{ok, 200, _, Body} = api_test_runner:client_request(get, PathSlug, <<>>),
Dec = jsx:decode(list_to_binary(Body), [return_maps]),
?assertEqual(CalId, maps:get(<<"id">>, Dec)),
?assertEqual(Slug2, maps:get(<<"short_name">>, Dec)),
EvPath = <<"/v1/calendars/", Slug2/binary, "/events">>,
{ok, 200, _, _} = api_test_runner:client_request(get, EvPath, <<>>),
ct:pal(" OK: guest GET by short_name").
test_get_calendar_not_found(Token) ->
ct:pal(" TEST: Get non-existent calendar (404)"),
Resp = api_test_runner:client_request(get, <<"/v1/calendars/fakeid">>, Token),
+14
View File
@@ -12,6 +12,7 @@ setup() ->
{attributes, record_info(fields, calendar)},
{ram_copies, [node()]}
]),
{atomic, ok} = mnesia:add_table_index(calendar, short_name),
mnesia:create_table(subscription, [
{attributes, record_info(fields, subscription)},
{ram_copies, [node()]}
@@ -38,6 +39,7 @@ logic_calendar_test_() ->
{"Create calendar test", fun test_create_calendar/0},
{"Create commercial requires subscription", fun test_create_commercial_gate/0},
{"Get calendar test", fun test_get_calendar/0},
{"Get calendar by short_name", fun test_get_calendar_by_short_name/0},
{"List calendars test", fun test_list_calendars/0},
{"Update calendar test", fun test_update_calendar/0},
{"Persist calendar settings (week_patterns)", fun test_update_settings/0},
@@ -104,6 +106,18 @@ test_get_calendar() ->
?assertMatch({error, access_denied},
logic_calendar:get_calendar(OtherUserId, Calendar#calendar.id)).
test_get_calendar_by_short_name() ->
UserId = create_test_user(),
{ok, _} = logic_subscription:start_trial(UserId),
{ok, Cal} = logic_calendar:create_calendar(UserId, <<"Studio">>, <<>>, manual, commercial),
Slug = <<"bizcal-unit-", (Cal#calendar.id)/binary>>,
{ok, _} = core_calendar:update(Cal#calendar.id, [{short_name, Slug}]),
{ok, Found} = logic_calendar:get_calendar(<<>>, Slug),
?assertEqual(Cal#calendar.id, Found#calendar.id),
{ok, Found2} = logic_calendar:get_calendar(UserId, Slug),
?assertEqual(Cal#calendar.id, Found2#calendar.id),
?assertEqual({error, not_found}, logic_calendar:get_calendar(<<>>, <<"no-such-slug">>)).
test_list_calendars() ->
UserId = create_test_user(),
{ok, _} = logic_calendar:create_calendar(UserId, <<"Calendar 1">>, <<"">>, manual),