Expire past-pending bookings to expired status. Fixes EventHub/EventHubBack#60
CI / test (push) Successful in 7m14s
CI / deploy-ift (push) Successful in 3m40s
CI / e2e-ift (push) Successful in 1m43s
CI / deploy-stage (push) Successful in 3m8s
CI / e2e-stage (push) Successful in 1m12s

This commit is contained in:
2026-07-27 16:45:30 +03:00
parent 1d9752bb69
commit edb7c20f70
6 changed files with 181 additions and 36 deletions
+69 -1
View File
@@ -42,7 +42,12 @@ logic_booking_test_() ->
{"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}
{"List booking requests stranger empty", fun test_list_booking_requests_stranger/0},
{"Past pending expires on list", fun test_past_pending_expires_on_list/0},
{"Past pending excluded from booking requests", fun test_past_pending_excluded_from_requests/0},
{"Past pending confirm denied", fun test_past_pending_confirm_denied/0},
{"Future pending still confirmable", fun test_future_pending_still_confirmable/0},
{"Process timeout expires past pending", fun test_process_timeout_expires_past/0}
]}.
%% Вспомогательные функции
@@ -83,6 +88,14 @@ create_test_event(CalendarId) ->
{ok, Event} = core_event:create(CalendarId, <<"Test Event">>, StartTime, 60),
Event#event.id.
create_test_event_at(CalendarId, StartTime) ->
{ok, Event} = core_event:create(CalendarId, <<"Test Event">>, StartTime, 60),
Event#event.id.
past_start() ->
Sec = calendar:datetime_to_gregorian_seconds(calendar:universal_time()) - 3600,
calendar:gregorian_seconds_to_datetime(Sec).
create_test_event_with_capacity(CalendarId, Capacity) ->
StartTime = eh_test_support:future_start(),
{ok, Event} = core_event:create(CalendarId, <<"Test Event">>, StartTime, 60),
@@ -355,3 +368,58 @@ test_list_booking_requests_stranger() ->
EventId = create_test_event(CalendarId),
{ok, _} = logic_booking:create_booking(ParticipantId, EventId),
{ok, []} = logic_booking:list_user_booking_requests(StrangerId).
test_past_pending_expires_on_list() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
EventId = create_test_event_at(CalendarId, past_start()),
{ok, Booking} = core_booking:create(EventId, ParticipantId, pending),
{ok, [Listed]} = logic_booking:list_user_bookings(ParticipantId),
?assertEqual(Booking#booking.id, Listed#booking.id),
?assertEqual(expired, Listed#booking.status),
{ok, Stored} = core_booking:get_by_id(Booking#booking.id),
?assertEqual(expired, Stored#booking.status).
test_past_pending_excluded_from_requests() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
PastId = create_test_event_at(CalendarId, past_start()),
FutureId = create_test_event(CalendarId),
{ok, _} = core_booking:create(PastId, ParticipantId, pending),
{ok, FutureBooking} = logic_booking:create_booking(ParticipantId, FutureId),
{ok, Items} = logic_booking:list_user_booking_requests(OwnerId),
?assertEqual(1, length(Items)),
[{B, Event, owner}] = Items,
?assertEqual(FutureBooking#booking.id, B#booking.id),
?assertEqual(FutureId, Event#event.id).
test_past_pending_confirm_denied() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
EventId = create_test_event_at(CalendarId, past_start()),
{ok, Booking} = core_booking:create(EventId, ParticipantId, pending),
{error, expired} = logic_booking:confirm_booking(Booking#booking.id, OwnerId),
{ok, Stored} = core_booking:get_by_id(Booking#booking.id),
?assertEqual(expired, Stored#booking.status).
test_future_pending_still_confirmable() ->
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, Confirmed} = logic_booking:confirm_booking(Booking#booking.id, OwnerId),
?assertEqual(confirmed, Confirmed#booking.status).
test_process_timeout_expires_past() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, manual),
EventId = create_test_event_at(CalendarId, past_start()),
{ok, Booking} = core_booking:create(EventId, ParticipantId, pending),
ok = logic_booking:process_timeout_bookings(),
{ok, Stored} = core_booking:get_by_id(Booking#booking.id),
?assertEqual(expired, Stored#booking.status).