fix: persist specialist_id on event create; 402 commercial without active sub. Fixes EventHub/EventHubBack#61
CI / test (push) Failing after 6m52s
CI / deploy-ift (push) Has been skipped
CI / e2e-ift (push) Has been skipped
CI / deploy-stage (push) Has been skipped
CI / e2e-stage (push) Has been skipped

This commit is contained in:
2026-07-27 21:17:15 +03:00
parent edb7c20f70
commit 81728301e2
9 changed files with 115 additions and 54 deletions
+34 -2
View File
@@ -2,7 +2,7 @@
-include_lib("eunit/include/eunit.hrl").
-include("records.hrl").
-define(TABLES, [user, calendar, event]).
-define(TABLES, [user, calendar, event, calendar_specialist, subscription]).
setup() ->
eh_test_support:start_mnesia(),
@@ -24,7 +24,8 @@ logic_event_test_() ->
{"List events test", fun test_list_events/0},
{"Update event test", fun test_update_event/0},
{"Delete event test", fun test_delete_event/0},
{"Event time validation test", fun test_time_validation/0}
{"Event time validation test", fun test_time_validation/0},
{"Persist specialist_id on update", fun test_specialist_id_persist/0}
]}.
create_test_user_and_calendar() ->
@@ -43,6 +44,26 @@ create_test_user_and_calendar() ->
{ok, Calendar} = logic_calendar:create_calendar(UserId, <<"Test Calendar">>, <<"">>, manual),
{UserId, Calendar#calendar.id}.
create_commercial_with_specialist() ->
OwnerId = base64:encode(crypto:strong_rand_bytes(12), #{padding => false}),
SpecId = base64:encode(crypto:strong_rand_bytes(12), #{padding => false}),
Owner = #user{
id = OwnerId, email = <<"owner@ex.com">>, password_hash = <<"hash">>,
role = user, status = active,
created_at = calendar:universal_time(), updated_at = calendar:universal_time()
},
Spec = #user{
id = SpecId, email = <<"spec@ex.com">>, password_hash = <<"hash">>,
role = user, status = active,
created_at = calendar:universal_time(), updated_at = calendar:universal_time()
},
mnesia:dirty_write(Owner),
mnesia:dirty_write(Spec),
{ok, _} = logic_subscription:start_trial(OwnerId),
{ok, Cal} = logic_calendar:create_calendar(OwnerId, <<"Studio">>, <<>>, manual, commercial),
{ok, _} = core_calendar_specialist:create(Cal#calendar.id, SpecId, <<"Spec">>, []),
{OwnerId, SpecId, Cal#calendar.id}.
add_days(DateTime, Days) ->
Sec = calendar:datetime_to_gregorian_seconds(DateTime) + Days * 86400,
calendar:gregorian_seconds_to_datetime(Sec).
@@ -102,3 +123,14 @@ test_time_validation() ->
FutureTime = eh_test_support:future_start(),
?assertEqual(ok, logic_event:validate_event_time(FutureTime)).
test_specialist_id_persist() ->
{OwnerId, SpecId, CalendarId} = create_commercial_with_specialist(),
StartTime = eh_test_support:future_start(),
{ok, Event} = logic_event:create_event(OwnerId, CalendarId, <<"Slot">>, StartTime, 60),
?assertEqual(<<>>, Event#event.specialist_id),
{ok, Updated} = logic_event:update_event(OwnerId, Event#event.id, [{specialist_id, SpecId}]),
?assertEqual(SpecId, Updated#event.specialist_id),
BadSpec = base64:encode(crypto:strong_rand_bytes(12), #{padding => false}),
?assertMatch({error, invalid_specialist},
logic_event:update_event(OwnerId, Event#event.id, [{specialist_id, BadSpec}])).