feat(booking): materialize occurrence on POST bookings. Refs EventHub/EventHubBack#67

This commit is contained in:
2026-08-14 10:52:24 +03:00
parent e3403f6ed6
commit 8a5f254c2a
5 changed files with 220 additions and 35 deletions
+28 -1
View File
@@ -47,6 +47,7 @@ test() ->
test_cancel_booking(ParticipantToken, EventId),
test_duplicate_booking(ParticipantToken, EventId),
test_booking_unauthorized(EventId),
test_recurring_booking(OwnerToken, ParticipantToken),
ct:pal("=== All user bookings tests passed ==="),
ok.
@@ -116,4 +117,30 @@ test_booking_unauthorized(EventId) ->
Path = <<"/v1/events/", EventId/binary, "/bookings">>,
Resp = api_test_runner:client_request(post, Path, <<>>, <<"{}">>),
?assertMatch({ok, 401, _, _}, Resp),
ct:pal(" OK: got 401").
ct:pal(" OK: got 401").
%% @doc Серия: без occurrence_start — 400; с датой вхождения — 201 на instance.
-spec test_recurring_booking(binary(), binary()) -> ok.
test_recurring_booking(OwnerToken, ParticipantToken) ->
ct:pal(" TEST: Recurring booking occurrence_start"),
CalId = api_test_runner:create_calendar(OwnerToken, #{
title => <<"SeriesBooking">>,
type => <<"commercial">>,
confirmation => <<"auto">>
}),
Start = api_test_runner:future_date(),
StartIso = api_test_runner:iso8601_utc(Start),
#{<<"id">> := MasterId} = api_test_runner:client_post(
<<"/v1/calendars/", CalId/binary, "/events">>, OwnerToken,
#{title => <<"Weekly slot">>,
start_time => StartIso,
duration => 60,
recurrence => #{freq => <<"WEEKLY">>, interval => 1}}),
Path = <<"/v1/events/", MasterId/binary, "/bookings">>,
{ok, 400, _, _} = api_test_runner:client_request(post, Path, ParticipantToken, <<"{}">>),
OccSec = calendar:datetime_to_gregorian_seconds(Start) + 7 * 86400,
OccIso = api_test_runner:iso8601_utc(calendar:gregorian_seconds_to_datetime(OccSec)),
#{<<"id">> := _Bid, <<"event_id">> := InstId} =
api_test_runner:client_post(Path, ParticipantToken, #{occurrence_start => OccIso}),
?assertNotEqual(MasterId, InstId),
ct:pal(" OK: booked instance ~s", [InstId]).