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
+46 -1
View File
@@ -3,7 +3,7 @@
-include("records.hrl").
-define(TABLES, [user, calendar, event, booking, waitlist_entry, subscription,
notification, calendar_specialist]).
notification, calendar_specialist, push_subscription]).
setup() ->
eh_test_support:start_mnesia(),
@@ -21,6 +21,7 @@ logic_waitlist_test_() ->
{"join when full and enabled", fun test_join_full/0},
{"join rejected when not full", fun test_not_full/0},
{"promote on cancel", fun test_promote_on_cancel/0},
{"promote respects email=false and sends push", fun test_promote_prefs_push/0},
{"leave waitlist", fun test_leave/0}
]}.
@@ -94,6 +95,50 @@ test_promote_on_cancel() ->
?assertEqual(1, length(Active)),
?assertEqual({error, not_found}, core_waitlist:get_waiting(EventId, Waiter)).
test_promote_prefs_push() ->
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),
application:set_env(eventhub, vapid_public_key, <<"BKtestpublic">>),
application:set_env(eventhub, vapid_private_key, <<"testprivate">>),
application:set_env(eventhub, web_push_deliver,
fun(Ep, _P, _A, Payload, _Pub, _Priv) ->
Self ! {push, Ep, Payload},
ok
end),
Owner = create_user(),
Guest = create_user(),
Waiter = create_user(),
{ok, _} = logic_notification_prefs:put_prefs(Waiter, #{email => false, push => true}),
{ok, _} = core_push_subscription:upsert(
Waiter, <<"https://push.example/waitlist">>, <<"p256">>, <<"auth">>),
Cal = create_cal(Owner, true),
EventId = create_event(Cal#calendar.id, 1),
{ok, Booking} = logic_booking:create_booking(Guest, EventId),
{ok, _} = logic_waitlist:join(Waiter, EventId),
{ok, _} = logic_booking:cancel_booking(Booking#booking.id, Guest),
receive
{smtp, _, _} -> error(unexpected_waitlist_email)
after 300 ->
ok
end,
receive
{push, Ep, Payload} ->
?assertEqual(<<"https://push.example/waitlist">>, Ep),
?assert(binary:match(Payload, <<"листа ожидания"/utf8>>) =/= nomatch)
after 1000 ->
error(timeout_waitlist_push)
end,
application:unset_env(eventhub, smtp_host),
application:unset_env(eventhub, smtp_deliver),
application:unset_env(eventhub, web_push_deliver),
application:unset_env(eventhub, vapid_public_key),
application:unset_env(eventhub, vapid_private_key).
test_leave() ->
Owner = create_user(),
Guest = create_user(),