fix(event): store multiple recurrence cancel exceptions
Use bag table for recurrence_exception so canceling several WEEKLY occurrences keeps all exceptions (set key was only master_id). Refs EventHub/EventHubFront#42
This commit is contained in:
@@ -137,7 +137,7 @@ table_opts(specialist_invite) ->
|
||||
table_opts(event) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, event)}];
|
||||
table_opts(recurrence_exception) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, recurrence_exception)}];
|
||||
[{ram_copies, [node()]}, {type, bag}, {attributes, record_info(fields, recurrence_exception)}];
|
||||
table_opts(booking) ->
|
||||
[{ram_copies, [node()]}, {attributes, record_info(fields, booking)}];
|
||||
table_opts(review) ->
|
||||
|
||||
@@ -24,6 +24,7 @@ logic_event_recurring_test_() ->
|
||||
{"Get occurrences test", fun test_get_occurrences/0},
|
||||
{"Cancel occurrence test", fun test_cancel_occurrence/0},
|
||||
{"Get occurrences with cancelled test", fun test_occurrences_with_cancelled/0},
|
||||
{"Cancel multiple occurrences keeps all exceptions", fun test_cancel_multiple_occurrences/0},
|
||||
{"Materialize for booking test", fun test_materialize_for_booking/0}
|
||||
]}.
|
||||
|
||||
@@ -117,6 +118,28 @@ test_occurrences_with_cancelled() ->
|
||||
Starts = [O || {virtual, O} <- Occurrences],
|
||||
?assertNot(lists:member(CancelTime, Starts)).
|
||||
|
||||
test_cancel_multiple_occurrences() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
StartTime = eh_test_support:future_start(),
|
||||
RRule = #{<<"freq">> => <<"WEEKLY">>, <<"interval">> => 1, <<"count">> => 4},
|
||||
|
||||
{ok, Event} = logic_event:create_recurring_event(
|
||||
UserId, CalendarId, <<"WeeklyFill">>, StartTime, 60, RRule
|
||||
),
|
||||
|
||||
C1 = StartTime,
|
||||
C2 = add_days(StartTime, 7),
|
||||
C3 = add_days(StartTime, 14),
|
||||
{ok, cancelled} = logic_event:cancel_occurrence(UserId, Event#event.id, C1),
|
||||
{ok, cancelled} = logic_event:cancel_occurrence(UserId, Event#event.id, C2),
|
||||
{ok, cancelled} = logic_event:cancel_occurrence(UserId, Event#event.id, C3),
|
||||
|
||||
RangeEnd = add_days(StartTime, 28),
|
||||
{ok, Occurrences} = logic_event:get_occurrences(UserId, Event#event.id, RangeEnd),
|
||||
Starts = [O || {virtual, O} <- Occurrences],
|
||||
?assertEqual(1, length(Starts)),
|
||||
?assertEqual([add_days(StartTime, 21)], Starts).
|
||||
|
||||
test_materialize_for_booking() ->
|
||||
{UserId, CalendarId} = create_test_user_and_calendar(),
|
||||
StartTime = eh_test_support:future_start(),
|
||||
|
||||
Reference in New Issue
Block a user