feat(notify): Web Push subscriptions and email/push prefs.
Prefs in user.preferences; push_subscription table; VAPID send on reminder/waitlist. Refs EventHub/EventHubBack#75
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
-module(logic_notification_prefs_tests).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("records.hrl").
|
||||
|
||||
prefs_test_() ->
|
||||
{setup, fun setup/0, fun cleanup/1, [
|
||||
{"defaults true", fun test_defaults/0},
|
||||
{"put and get", fun test_put_get/0},
|
||||
{"web_push no-op without vapid", fun test_push_noop/0}
|
||||
]}.
|
||||
|
||||
setup() ->
|
||||
application:load(eventhub),
|
||||
ok.
|
||||
|
||||
cleanup(_) ->
|
||||
application:unset_env(eventhub, web_push_deliver),
|
||||
application:unset_env(eventhub, vapid_public_key),
|
||||
application:unset_env(eventhub, vapid_private_key),
|
||||
ok.
|
||||
|
||||
test_defaults() ->
|
||||
%% without user in mnesia — email_enabled falls back true
|
||||
?assertEqual(true, logic_notification_prefs:email_enabled(<<"missing-user">>)),
|
||||
?assertEqual(true, logic_notification_prefs:push_enabled(<<"missing-user">>)).
|
||||
|
||||
test_put_get() ->
|
||||
case whereis(mnesia_sup) of
|
||||
undefined ->
|
||||
%% skip if no mnesia in unit env
|
||||
ok;
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
test_push_noop() ->
|
||||
application:unset_env(eventhub, vapid_public_key),
|
||||
application:unset_env(eventhub, vapid_private_key),
|
||||
?assertEqual(ok, logic_web_push:send(<<"u1">>, <<"t">>, <<"b">>, <<"/x">>)),
|
||||
?assertEqual({error, missing}, logic_web_push:vapid_public_key()).
|
||||
Reference in New Issue
Block a user