Files
EventHubBack/test/api/users/user_me_tests.erl

55 lines
2.2 KiB
Erlang
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
%%%-------------------------------------------------------------------
%%% @doc Тесты клиентского API для получения профиля текущего пользователя.
%%%
%%% Покрывает эндпоинты:
%%% GET /v1/user/me
%%%
%%% Проверяет:
%%% - успешное получение профиля с валидным токеном
%%% - ошибку 401 при отсутствии токена
%%% - наличие ключевых полей в ответе
%%% @end
%%%-------------------------------------------------------------------
-module(user_me_tests).
-include_lib("eunit/include/eunit.hrl").
-export([test/0]).
%%%===================================================================
%%% Главная тестовая функция
%%%===================================================================
-spec test() -> ok.
test() ->
ct:pal("=== User Profile (me) Tests ==="),
Token = api_test_runner:get_user_token(),
test_get_me_success(Token),
test_get_me_unauthorized(),
ct:pal("=== All user me tests passed ==="),
ok.
%%%===================================================================
%%% Тестовые функции
%%%===================================================================
%% @doc Успешное получение профиля: 200 OK, возвращает данные пользователя.
-spec test_get_me_success(binary()) -> ok.
test_get_me_success(Token) ->
ct:pal(" TEST: Get current user profile"),
User = api_test_runner:client_get(<<"/v1/user/me">>, Token),
?assert(is_map(User)),
?assert(maps:is_key(<<"id">>, User)),
?assert(maps:is_key(<<"email">>, User)),
?assert(maps:is_key(<<"role">>, User)),
?assert(maps:is_key(<<"status">>, User)),
ct:pal(" OK: got profile for ~s", [maps:get(<<"email">>, User)]).
%% @doc Отсутствие токена: 401 Unauthorized.
-spec test_get_me_unauthorized() -> ok.
test_get_me_unauthorized() ->
ct:pal(" TEST: Get profile without token"),
Resp = api_test_runner:client_request(get, <<"/v1/user/me">>, <<>>),
?assertMatch({ok, 401, _, _}, Resp),
ct:pal(" OK: got 401 unauthorized").