1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-23 00:14:48 +00:00
mobilizon/test/service/notifier/push_test.exs
Thomas Citharel e841fb6fbb
Move mailer from Bamboo to Swoosh
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2022-04-05 12:38:02 +02:00

63 lines
1.8 KiB
Elixir

defmodule Mobilizon.Service.Notifier.PushTest do
@moduledoc """
Test the Push notifier module
"""
alias Mobilizon.Activities.Activity
alias Mobilizon.Config
alias Mobilizon.Service.Notifier.Push
alias Mobilizon.Users.{ActivitySetting, Setting, User}
use Mobilizon.DataCase
import Mobilizon.Factory
describe "Returns if the module is loaded" do
test "Loaded by default" do
assert Push.ready?() == true
end
test "If disabled" do
Config.put([Push, :enabled], false)
assert Push.ready?() == false
Config.put([Push, :enabled], true)
end
end
describe "sending push notification for activities" do
test "when the user doesn't allow it" do
%Activity{} = activity = insert(:mobilizon_activity, inserted_at: DateTime.utc_now())
%User{} = user = insert(:user, activity_settings: [])
%Setting{} = user_settings = insert(:settings, user_id: user.id)
user = %User{user | settings: user_settings}
assert {:ok, :skipped} == Push.send(user, activity)
end
test "when the user allows it" do
event = insert(:event)
%Activity{} =
activity =
insert(:mobilizon_activity,
inserted_at: DateTime.utc_now(),
object_id: to_string(event.id),
subject_params: %{
"event_title" => event.title,
"event_uuid" => event.uuid,
"event_id" => event.id
}
)
%User{} = user = insert(:user)
%Setting{} = user_settings = insert(:settings, user_id: user.id)
%ActivitySetting{} =
activity_setting =
insert(:mobilizon_activity_setting, user_id: user.id, user: user, method: "push")
user = %User{user | settings: user_settings, activity_settings: [activity_setting]}
assert {:ok, :sent} == Push.send(user, activity)
end
end
end