feat: GET /v1/user/booking-requests + search image_url. Fixes EventHub/EventHubBack#59
CI / test (push) Successful in 7m1s
CI / deploy-ift (push) Successful in 5m59s
CI / e2e-ift (push) Successful in 1m34s
CI / deploy-stage (push) Successful in 2m47s
CI / e2e-stage (push) Successful in 1m18s

This commit is contained in:
2026-07-27 14:53:25 +03:00
parent b25c0447cd
commit 1d9752bb69
8 changed files with 263 additions and 8 deletions
+55 -1
View File
@@ -39,7 +39,10 @@ logic_booking_test_() ->
{"List event bookings", fun test_list_event_bookings/0},
{"List event bookings as owner", fun test_list_event_bookings_owner/0},
{"List event bookings non-owner denied", fun test_list_event_bookings_non_owner/0},
{"List user bookings", fun test_list_user_bookings/0}
{"List user bookings", fun test_list_user_bookings/0},
{"List booking requests as owner", fun test_list_booking_requests_owner/0},
{"List booking requests as specialist", fun test_list_booking_requests_specialist/0},
{"List booking requests stranger empty", fun test_list_booking_requests_stranger/0}
]}.
%% Вспомогательные функции
@@ -301,3 +304,54 @@ test_list_user_bookings() ->
{ok, Bookings} = logic_booking:list_user_bookings(ParticipantId),
?assertEqual(2, length(Bookings)).
test_list_booking_requests_owner() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
EventId = create_test_event(CalendarId),
{ok, Booking} = logic_booking:create_booking(ParticipantId, EventId),
{ok, Items} = logic_booking:list_user_booking_requests(OwnerId),
?assertEqual(1, length(Items)),
[{B, Event, Role}] = Items,
?assertEqual(Booking#booking.id, B#booking.id),
?assertEqual(EventId, Event#event.id),
?assertEqual(owner, Role),
%% participant inbox is separate — no manage requests for own booking
{ok, []} = logic_booking:list_user_booking_requests(ParticipantId).
test_list_booking_requests_specialist() ->
OwnerId = create_test_user(user),
SpecId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
{ok, _} = core_calendar_specialist:create(CalendarId, SpecId, <<"Spec">>, []),
SpecEventId = create_test_event(CalendarId),
OtherEventId = create_test_event(CalendarId),
{ok, _} = core_event:update(SpecEventId, [{specialist_id, SpecId}]),
{ok, SpecBooking} = logic_booking:create_booking(ParticipantId, SpecEventId),
OtherParticipant = create_test_user(user),
{ok, _} = logic_booking:create_booking(OtherParticipant, OtherEventId),
{ok, SpecItems} = logic_booking:list_user_booking_requests(SpecId),
?assertEqual(1, length(SpecItems)),
[{B, Event, Role}] = SpecItems,
?assertEqual(SpecBooking#booking.id, B#booking.id),
?assertEqual(SpecEventId, Event#event.id),
?assertEqual(specialist, Role),
%% owner sees both pending
{ok, OwnerItems} = logic_booking:list_user_booking_requests(OwnerId),
?assertEqual(2, length(OwnerItems)).
test_list_booking_requests_stranger() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
StrangerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
EventId = create_test_event(CalendarId),
{ok, _} = logic_booking:create_booking(ParticipantId, EventId),
{ok, []} = logic_booking:list_user_booking_requests(StrangerId).
+9
View File
@@ -25,6 +25,7 @@ logic_search_test_() ->
{"Search events by location", fun test_search_events_by_location/0},
{"Combined search", fun test_combined_search/0},
{"Search calendars", fun test_search_calendars/0},
{"Search calendars include image_url", fun test_search_calendars_image_url/0},
{"Search all", fun test_search_all/0},
{"Pagination", fun test_pagination/0},
{"Sorting", fun test_sorting/0},
@@ -175,6 +176,14 @@ test_search_calendars() ->
{Total2, _} = calendars_from(logic_search:search(<<"calendar">>, <<"Calendar">>, OwnerId, #{})),
?assertEqual(2, Total2).
test_search_calendars_image_url() ->
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, commercial, [<<"cover">>]),
{ok, _} = core_calendar:update(CalendarId, [{image_url, <<"https://cdn.example/cal.jpg">>}]),
{_, Cals} = calendars_from(logic_search:search(<<"calendar">>, <<"Calendar">>, OwnerId, #{})),
[Hit | _] = [C || C <- Cals, maps:get(id, C) =:= CalendarId],
?assertEqual(<<"https://cdn.example/cal.jpg">>, maps:get(image_url, Hit)).
test_search_all() ->
OwnerId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, personal, []),