feat: discovery tops for empty GET /v1/search. Refs EventHub/EventHubBack#50
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user