Статистика для дашборда, расширенная #7

This commit is contained in:
2026-04-28 23:04:17 +03:00
parent c87d56bb49
commit 3da4ee28d4
11 changed files with 261 additions and 70 deletions

View File

@@ -1,4 +1,6 @@
-module(api_admin_tests).
-include_lib("eunit/include/eunit.hrl").
-export([test/0]).
test() ->
@@ -25,17 +27,23 @@ test() ->
%% TEST 3: Admin stats (superadmin)
io:format(" TEST 3: Admin stats (superadmin)... "),
% Логинимся под суперадмином (данные из api_test_runner)
LoginBody = jsx:encode(#{<<"email">> => <<"admin@eventhub.local">>, <<"password">> => <<"123456">>}),
{ok, {{_, 200, _}, _, LoginResp}} = httpc:request(post,
{AdminURL ++ "/v1/admin/login", [], "application/json", LoginBody}, [], []),
#{<<"token">> := SuperToken} = jsx:decode(list_to_binary(LoginResp), [return_maps]),
% Запрашиваем статистику
{ok, {{_, 200, _}, _, StatsResp}} = httpc:request(get,
% Без дат
{ok, {{_, 200, _}, _, StatsResp1}} = httpc:request(get,
{AdminURL ++ "/v1/admin/stats", [{"Authorization", "Bearer " ++ binary_to_list(SuperToken)}]}, [], []),
Stats = jsx:decode(list_to_binary(StatsResp), [return_maps]),
io:format(" OK (keys: ~p)~n", [maps:keys(Stats)]),
Stats1 = jsx:decode(list_to_binary(StatsResp1), [return_maps]),
io:format(" OK (keys: ~p)~n", [maps:keys(Stats1)]),
% С датами
{ok, {{_, 200, _}, _, StatsResp2}} = httpc:request(get,
{AdminURL ++ "/v1/admin/stats?from=2026-01-01T00:00:00&to=2026-12-31T23:59:59",
[{"Authorization", "Bearer " ++ binary_to_list(SuperToken)}]}, [], []),
Stats2 = jsx:decode(list_to_binary(StatsResp2), [return_maps]),
io:format(" (with dates, keys: ~p)~n", [maps:keys(Stats2)]),
%% TEST 4: List users
io:format(" TEST 4: List users... "),