Перенести все админские эндпоинты на порт 8445 и добавить отдельную авторизацию для админов. Часть 1
This commit is contained in:
49
test/unit/admin_handler_health_tests.erl
Normal file
49
test/unit/admin_handler_health_tests.erl
Normal file
@@ -0,0 +1,49 @@
|
||||
-module(admin_handler_health_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
%% ------------------------------------------------------------------
|
||||
%% Фикстуры
|
||||
%% ------------------------------------------------------------------
|
||||
setup() ->
|
||||
ok = meck:new(cowboy_req, [non_strict]),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
meck:unload(cowboy_req).
|
||||
|
||||
%% ------------------------------------------------------------------
|
||||
%% Тесты
|
||||
%% ------------------------------------------------------------------
|
||||
admin_handler_health_test_() ->
|
||||
{setup, fun setup/0, fun cleanup/1, [
|
||||
{"GET /admin/health returns 200 with status ok",
|
||||
fun test_health_get/0},
|
||||
{"POST /admin/health returns 405 Method not allowed",
|
||||
fun test_health_post/0}
|
||||
]}.
|
||||
|
||||
%% ── Успешный GET ─────────────────────────────────────────────
|
||||
test_health_get() ->
|
||||
% Мокаем method → <<"GET">>
|
||||
ok = meck:expect(cowboy_req, method, fun(_) -> <<"GET">> end),
|
||||
% reply/4 будем перехватывать
|
||||
ok = meck:expect(cowboy_req, reply,
|
||||
fun(Code, Headers, Body, Req) ->
|
||||
put(test_reply, {Code, Headers, Body, Req})
|
||||
end),
|
||||
{ok, _, _} = admin_handler_health:init(req, []),
|
||||
{Status, _, RespBody, _} = erase(test_reply),
|
||||
?assertEqual(200, Status),
|
||||
?assertEqual(#{<<"status">> => <<"ok">>}, jsx:decode(RespBody, [return_maps])).
|
||||
|
||||
%% ── Метод не разрешён ───────────────────────────────────────
|
||||
test_health_post() ->
|
||||
ok = meck:expect(cowboy_req, method, fun(_) -> <<"POST">> end),
|
||||
ok = meck:expect(cowboy_req, reply,
|
||||
fun(Code, Headers, Body, Req) ->
|
||||
put(test_reply, {Code, Headers, Body, Req})
|
||||
end),
|
||||
{ok, _, _} = admin_handler_health:init(req, []),
|
||||
{Status, _, RespBody, _} = erase(test_reply),
|
||||
?assertEqual(405, Status),
|
||||
?assertEqual(#{<<"error">> => <<"Method not allowed">>}, jsx:decode(RespBody, [return_maps])).
|
||||
Reference in New Issue
Block a user