Implement commercial calendars: booking_open, specialists, expire without type downgrade.
CI / test (push) Successful in 6m44s
CI / deploy-ift (push) Successful in 4m2s
CI / e2e-ift (push) Successful in 1m25s
CI / deploy-stage (push) Successful in 2m25s
CI / e2e-stage (push) Successful in 1m12s

Refs EventHub/EventHubBack#54
This commit is contained in:
2026-07-22 16:12:52 +03:00
parent fdb08eb453
commit af5f506866
35 changed files with 978 additions and 207 deletions
+48 -8
View File
@@ -2,7 +2,7 @@
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
-define(TABLES, [user, calendar, event, booking, admin]).
-define(TABLES, [user, calendar, event, booking, admin, subscription, calendar_specialist]).
setup() ->
eh_test_support:start_mnesia(),
@@ -19,14 +19,17 @@ logic_booking_test_() ->
fun setup/0,
fun cleanup/1,
[
{"Create booking returns pending", fun test_create_booking_pending/0},
{"Create booking auto confirms", fun test_create_booking_auto/0},
{"Create booking manual pending", fun test_create_booking_pending/0},
{"Create booking personal denied", fun test_booking_personal_denied/0},
{"Create duplicate booking", fun test_create_duplicate_booking/0},
{"Create booking for missing event", fun test_booking_missing_event/0},
{"Create booking when event is full", fun test_booking_event_full/0},
{"Pending bookings do not fill capacity", fun test_pending_does_not_fill/0},
{"Pending bookings fill capacity", fun test_pending_fills_capacity/0},
{"Confirm booking", fun test_confirm_booking/0},
{"Confirm booking as booker denied", fun test_confirm_booker_denied/0},
{"Confirm booking as stranger denied", fun test_confirm_stranger_denied/0},
{"Confirm booking as specialist", fun test_confirm_booking_specialist/0},
{"Confirm booking as admin", fun test_confirm_booking_admin/0},
{"Decline booking by owner", fun test_decline_booking/0},
{"Decline booking as booker denied", fun test_decline_booker_denied/0},
@@ -59,8 +62,17 @@ create_test_admin() ->
Admin = eh_test_support:seed_admin(#{id => AdminId, email => <<AdminId/binary, "@admin.test">>}),
Admin#admin.id.
ensure_subscription(OwnerId) ->
{ok, _} = core_subscription:create(OwnerId, monthly, true),
ok.
create_test_calendar(OwnerId, Confirmation) ->
{ok, Calendar} = core_calendar:create(OwnerId, <<"Test Calendar">>, <<"">>, Confirmation),
ensure_subscription(OwnerId),
{ok, Calendar} = core_calendar:create(OwnerId, <<"Test Calendar">>, <<"">>, Confirmation, commercial),
Calendar#calendar.id.
create_personal_calendar(OwnerId) ->
{ok, Calendar} = core_calendar:create(OwnerId, <<"Personal">>, <<"">>, manual, personal),
Calendar#calendar.id.
create_test_event(CalendarId) ->
@@ -75,18 +87,34 @@ create_test_event_with_capacity(CalendarId, Capacity) ->
Updated#event.id.
%% Тесты
test_create_booking_pending() ->
test_create_booking_auto() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_test_calendar(OwnerId, auto),
EventId = create_test_event(CalendarId),
{ok, Booking} = logic_booking:create_booking(ParticipantId, EventId),
?assertEqual(confirmed, Booking#booking.status).
test_create_booking_pending() ->
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),
?assertEqual(pending, Booking#booking.status),
{ok, Stored} = core_booking:get_by_id(Booking#booking.id),
?assertEqual(pending, Stored#booking.status).
test_booking_personal_denied() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
CalendarId = create_personal_calendar(OwnerId),
EventId = create_test_event(CalendarId),
{error, personal_calendar} = logic_booking:create_booking(ParticipantId, EventId).
test_create_duplicate_booking() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
@@ -111,7 +139,7 @@ test_booking_event_full() ->
{ok, _} = logic_booking:confirm_booking(OwnerId, B1#booking.id, confirm),
{error, full} = logic_booking:create_booking(Participant2Id, EventId).
test_pending_does_not_fill() ->
test_pending_fills_capacity() ->
OwnerId = create_test_user(user),
Participant1Id = create_test_user(user),
Participant2Id = create_test_user(user),
@@ -119,8 +147,7 @@ test_pending_does_not_fill() ->
EventId = create_test_event_with_capacity(CalendarId, 1),
{ok, _} = logic_booking:create_booking(Participant1Id, EventId),
{ok, B2} = logic_booking:create_booking(Participant2Id, EventId),
?assertEqual(pending, B2#booking.status).
{error, full} = logic_booking:create_booking(Participant2Id, EventId).
test_confirm_booking() ->
OwnerId = create_test_user(user),
@@ -151,6 +178,19 @@ test_confirm_stranger_denied() ->
{ok, Booking} = logic_booking:create_booking(ParticipantId, EventId),
{error, access_denied} = logic_booking:confirm_booking(StrangerId, Booking#booking.id, confirm).
test_confirm_booking_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">>, []),
EventId = create_test_event(CalendarId),
{ok, _} = core_event:update(EventId, [{specialist_id, SpecId}]),
{ok, Booking} = logic_booking:create_booking(ParticipantId, EventId),
{ok, Confirmed} = logic_booking:confirm_booking(SpecId, Booking#booking.id, confirm),
?assertEqual(confirmed, Confirmed#booking.status).
test_confirm_booking_admin() ->
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),