fix(ct): adapt API tests to sole Default personal
Default create_calendar to commercial; reuse existing personal on 409; assert verify title Default; cover personal_exists / default_calendar. Refs EventHub/EventHubBack#64
This commit is contained in:
@@ -25,7 +25,9 @@
|
||||
future_date/0,
|
||||
register_and_login/2,
|
||||
create_calendar/2,
|
||||
create_event/3
|
||||
create_event/3,
|
||||
ensure_commercial_subscription/1,
|
||||
existing_personal_calendar_id/1
|
||||
, get_admin_refresh_token/0
|
||||
, admin_super_email/0
|
||||
, admin_super_password/0]).
|
||||
@@ -409,14 +411,39 @@ register_and_login(Email, Password) ->
|
||||
|
||||
-spec create_calendar(binary(), map()) -> binary().
|
||||
create_calendar(Token, Params) ->
|
||||
Type = maps:get(type, Params, maps:get(<<"type">>, Params, <<"personal">>)),
|
||||
%% Default commercial: user already has sole personal Default after verify.
|
||||
Type = maps:get(type, Params, maps:get(<<"type">>, Params, <<"commercial">>)),
|
||||
Params1 =
|
||||
case maps:is_key(type, Params) orelse maps:is_key(<<"type">>, Params) of
|
||||
true -> Params;
|
||||
false -> Params#{type => Type}
|
||||
end,
|
||||
case Type of
|
||||
<<"commercial">> -> ensure_commercial_subscription(Token);
|
||||
commercial -> ensure_commercial_subscription(Token);
|
||||
_ -> ok
|
||||
<<"personal">> -> ok;
|
||||
personal -> ok;
|
||||
_ -> ensure_commercial_subscription(Token)
|
||||
end,
|
||||
#{<<"id">> := CalId} = client_post(<<"/v1/calendars">>, Token, Params),
|
||||
CalId.
|
||||
Body = jsx:encode(Params1),
|
||||
case client_request(post, <<"/v1/calendars">>, Token, Body) of
|
||||
{ok, 201, _, RespBody} ->
|
||||
#{<<"id">> := CalId} = jsx:decode(list_to_binary(RespBody), [return_maps]),
|
||||
CalId;
|
||||
{ok, 409, _, _} when Type =:= <<"personal">>; Type =:= personal ->
|
||||
%% Sole Default personal already exists — reuse it.
|
||||
existing_personal_calendar_id(Token);
|
||||
Other ->
|
||||
error({create_calendar_failed, Other})
|
||||
end.
|
||||
|
||||
-spec existing_personal_calendar_id(binary()) -> binary().
|
||||
existing_personal_calendar_id(Token) ->
|
||||
Cals = client_get(<<"/v1/calendars">>, Token),
|
||||
case [Id || #{<<"id">> := Id, <<"type">> := <<"personal">>} <- Cals] of
|
||||
[Id | _] -> Id;
|
||||
[] -> error(no_personal_calendar)
|
||||
end.
|
||||
|
||||
-spec ensure_commercial_subscription(binary()) -> ok.
|
||||
ensure_commercial_subscription(Token) ->
|
||||
|
||||
Reference in New Issue
Block a user