61 lines
2.5 KiB
Erlang
61 lines
2.5 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @doc Тесты клиентского API для HTML-представления календаря.
|
|
%%%
|
|
%%% Покрывает эндпоинты:
|
|
%%% GET /v1/calendars/:calendar_id/view
|
|
%%%
|
|
%%% Проверяет:
|
|
%%% - успешное получение HTML-страницы (200, text/html)
|
|
%%% - ошибку 401 без токена
|
|
%%% @end
|
|
%%%-------------------------------------------------------------------
|
|
-module(user_calendar_view_tests).
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
-export([test/0]).
|
|
|
|
%%%===================================================================
|
|
%%% Главная тестовая функция
|
|
%%%===================================================================
|
|
|
|
-spec test() -> ok.
|
|
test() ->
|
|
ct:pal("=== User Calendar View Tests ==="),
|
|
Token = api_test_runner:get_user_token(),
|
|
|
|
% Создаём календарь
|
|
CalId = api_test_runner:create_calendar(Token, #{title => <<"ViewCal">>}),
|
|
|
|
test_get_calendar_view(Token, CalId),
|
|
test_get_calendar_view_unauthorized(CalId),
|
|
|
|
ct:pal("=== All user calendar view tests passed ==="),
|
|
ok.
|
|
|
|
%%%===================================================================
|
|
%%% Тестовые функции
|
|
%%%===================================================================
|
|
|
|
%% @doc Успешный запрос HTML-представления: 200 OK, тип text/html.
|
|
-spec test_get_calendar_view(binary(), binary()) -> ok.
|
|
test_get_calendar_view(Token, CalId) ->
|
|
ct:pal(" TEST: Get calendar HTML view"),
|
|
Path = <<"/v1/calendars/", CalId/binary, "/view?month=2026-06">>,
|
|
Resp = api_test_runner:client_request(get, Path, Token),
|
|
{ok, 200, Headers, Body} = Resp,
|
|
?assert(lists:keymember("content-type", 1, Headers)),
|
|
{"content-type", CT} = lists:keyfind("content-type", 1, Headers),
|
|
?assert(string:str(CT, "text/html") > 0),
|
|
% Body может быть строкой или binary, приводим к binary и проверяем непустоту
|
|
BodyBin = iolist_to_binary(Body),
|
|
?assert(byte_size(BodyBin) > 0),
|
|
ct:pal(" OK: got HTML of ~p bytes", [byte_size(BodyBin)]).
|
|
|
|
%% @doc Запрос без токена: 401 Unauthorized.
|
|
-spec test_get_calendar_view_unauthorized(binary()) -> ok.
|
|
test_get_calendar_view_unauthorized(CalId) ->
|
|
ct:pal(" TEST: Get calendar view without token"),
|
|
Path = <<"/v1/calendars/", CalId/binary, "/view?month=2026-06">>,
|
|
Resp = api_test_runner:client_request(get, Path, <<>>),
|
|
?assertMatch({ok, 401, _, _}, Resp),
|
|
ct:pal(" OK: got 401"). |