feat: discovery tops for empty GET /v1/search. Refs EventHub/EventHubBack#50
CI / test (push) Successful in 22m57s
CI / deploy-ift (push) Successful in 3m22s
CI / e2e-ift (push) Successful in 1m12s
CI / deploy-stage (push) Successful in 4m21s
CI / e2e-stage (push) Successful in 1m27s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-20 12:17:36 +03:00
parent e94c94d1a6
commit 6d52bc3a8e
3 changed files with 96 additions and 2 deletions
+34 -1
View File
@@ -29,7 +29,9 @@ logic_search_test_() ->
{"Pagination", fun test_pagination/0},
{"Sorting", fun test_sorting/0},
{"Access control in search", fun test_access_control/0},
{"Empty search results", fun test_empty_search/0}
{"Empty search results", fun test_empty_search/0},
{"Discovery tops without filters", fun test_discovery_returns_tops/0},
{"Query switches to filtered search", fun test_discovery_with_q_uses_filter/0}
]}.
%% Вспомогательные функции
@@ -239,3 +241,34 @@ test_empty_search() ->
{Total, Results} = events_from(logic_search:search(<<"event">>, <<"nonexistent">>, OwnerId, #{})),
?assertEqual(0, Total),
?assertEqual([], Results).
test_discovery_returns_tops() ->
OwnerId = create_test_user(user),
ViewerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, commercial, []),
StartTime = eh_test_support:future_start(),
LowId = create_test_event(CalendarId, <<"Low Rated">>, <<"">>, StartTime, [], undefined),
HighId = create_test_event(CalendarId, <<"High Rated">>, <<"">>, StartTime, [], undefined),
{ok, _} = core_event:update(LowId, [{rating_avg, 1.0}, {rating_count, 1}]),
{ok, _} = core_event:update(HighId, [{rating_avg, 5.0}, {rating_count, 10}]),
stats_tops:init_tables(),
stats_tops:rebuild(),
{Total, [First | _]} = events_from(logic_search:search(<<"event">>, undefined, ViewerId, #{})),
?assertEqual(2, Total),
?assertMatch(#{title := <<"High Rated">>}, First).
test_discovery_with_q_uses_filter() ->
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, personal, []),
StartTime = eh_test_support:future_start(),
LowId = create_test_event(CalendarId, <<"Alpha">>, <<"">>, StartTime, [], undefined),
HighId = create_test_event(CalendarId, <<"Beta">>, <<"">>, StartTime, [], undefined),
{ok, _} = core_event:update(LowId, [{rating_avg, 1.0}]),
{ok, _} = core_event:update(HighId, [{rating_avg, 5.0}]),
stats_tops:init_tables(),
stats_tops:rebuild(),
{Total, Results} = events_from(logic_search:search(<<"event">>, <<"Alpha">>, OwnerId, #{})),
?assertEqual(1, Total),
?assertMatch([#{title := <<"Alpha">>}], Results).