test(notify): prefs gate email/push on reminder and waitlist.
CI / test (push) Successful in 7m47s
CI / deploy-ift (push) Successful in 3m5s
CI / e2e-ift (push) Successful in 1m26s
CI / deploy-stage (push) Successful in 2m13s
CI / e2e-stage (push) Failing after 3m23s

Assert email=false skips SMTP; push=true hits web_push_deliver.
Refs EventHub/EventHubBack#75
This commit is contained in:
2026-08-15 21:50:08 +03:00
parent 12274f9ed0
commit 00bf72e4d1
3 changed files with 124 additions and 3 deletions
+75 -2
View File
@@ -3,7 +3,7 @@
-include("records.hrl").
-define(TABLES, [user, calendar, event, booking, admin, subscription, calendar_specialist,
recurrence_exception, notification]).
recurrence_exception, notification, push_subscription]).
setup() ->
eh_test_support:start_mnesia(),
@@ -57,7 +57,9 @@ logic_booking_test_() ->
{"Process timeout expires past pending", fun test_process_timeout_expires_past/0},
{"Reminder sends once within lead window", fun test_reminder_within_window/0},
{"Reminder skipped outside lead window", fun test_reminder_outside_window/0},
{"Reminder skipped for pending", fun test_reminder_skips_pending/0}
{"Reminder skipped for pending", fun test_reminder_skips_pending/0},
{"Reminder skips email when prefs email=false", fun test_reminder_email_pref_off/0},
{"Reminder calls web_push when prefs push=true", fun test_reminder_web_push/0}
]}.
%% Вспомогательные функции
@@ -598,3 +600,74 @@ test_reminder_skips_pending() ->
{ok, Stored} = core_booking:get_by_id(Booking#booking.id),
?assertEqual(false, Stored#booking.reminder_sent),
application:unset_env(eventhub, reminder_lead_hours).
test_reminder_email_pref_off() ->
application:set_env(eventhub, reminder_lead_hours, 24),
Self = self(),
application:set_env(eventhub, smtp_host, "smtp.test"),
application:set_env(eventhub, smtp_deliver,
fun(_From, To, Raw, _Opts) ->
Self ! {smtp, To, Raw},
{ok, mock}
end),
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
{ok, _} = logic_notification_prefs:put_prefs(ParticipantId, #{email => false, push => true}),
CalendarId = create_test_calendar(OwnerId, auto),
EventId = create_test_event_at(CalendarId, hours_from_now(2)),
{ok, Booking} = logic_booking:create_booking(ParticipantId, EventId),
ok = logic_booking:process_reminders(),
receive
{smtp, _, _} -> error(unexpected_email_when_pref_off)
after 300 ->
ok
end,
{ok, Stored} = core_booking:get_by_id(Booking#booking.id),
?assertEqual(true, Stored#booking.reminder_sent),
Notifs = core_notification:list_by_user(ParticipantId),
?assert(lists:any(fun(#notification{type = event_reminder}) -> true; (_) -> false end,
Notifs)),
application:unset_env(eventhub, smtp_host),
application:unset_env(eventhub, smtp_deliver),
application:unset_env(eventhub, reminder_lead_hours).
test_reminder_web_push() ->
application:set_env(eventhub, reminder_lead_hours, 24),
application:set_env(eventhub, vapid_public_key, <<"BKtestpublickey0123456789abcdef">>),
application:set_env(eventhub, vapid_private_key, <<"testprivatekey0123456789abcdef">>),
Self = self(),
application:set_env(eventhub, web_push_deliver,
fun(Ep, _P256, _Auth, Payload, _Pub, _Priv) ->
Self ! {push, Ep, Payload},
ok
end),
OwnerId = create_test_user(user),
ParticipantId = create_test_user(user),
{ok, _} = logic_notification_prefs:put_prefs(ParticipantId, #{email => false, push => true}),
{ok, _} = core_push_subscription:upsert(
ParticipantId,
<<"https://push.example/endpoint-reminder">>,
<<"p256dh-test">>,
<<"auth-test">>),
CalendarId = create_test_calendar(OwnerId, auto),
EventId = create_test_event_at(CalendarId, hours_from_now(2)),
{ok, _} = logic_booking:create_booking(ParticipantId, EventId),
ok = logic_booking:process_reminders(),
receive
{push, Ep, Payload} ->
?assertEqual(<<"https://push.example/endpoint-reminder">>, Ep),
?assert(binary:match(Payload, <<"Напоминание"/utf8>>) =/= nomatch)
after 1000 ->
error(timeout_web_push)
end,
{ok, _} = logic_notification_prefs:put_prefs(ParticipantId, #{email => false, push => false}),
ok = logic_web_push:send(ParticipantId, <<"t">>, <<"b">>, <<"/x">>),
receive
{push, _, _} -> error(push_should_be_skipped)
after 300 ->
ok
end,
application:unset_env(eventhub, web_push_deliver),
application:unset_env(eventhub, vapid_public_key),
application:unset_env(eventhub, vapid_private_key),
application:unset_env(eventhub, reminder_lead_hours).