2021-03-23 14:18:03 +00:00
|
|
|
defmodule Mobilizon.Service.Workers.ActivityBuilderTest do
|
|
|
|
@moduledoc """
|
|
|
|
Test the ActivityBuilder module
|
|
|
|
"""
|
|
|
|
|
|
|
|
alias Mobilizon.Activities.Activity
|
|
|
|
alias Mobilizon.Actors.Actor
|
2021-06-03 15:17:13 +00:00
|
|
|
alias Mobilizon.Service.Notifier.Mock, as: NotifierMock
|
2021-03-23 14:18:03 +00:00
|
|
|
alias Mobilizon.Service.Workers.ActivityBuilder
|
|
|
|
alias Mobilizon.Users.User
|
|
|
|
|
|
|
|
use Mobilizon.DataCase
|
|
|
|
|
|
|
|
import Mobilizon.Factory
|
2021-06-03 15:17:13 +00:00
|
|
|
import Mox
|
|
|
|
|
|
|
|
setup :verify_on_exit!
|
2021-03-23 14:18:03 +00:00
|
|
|
|
|
|
|
describe "Sends direct email notification to users" do
|
|
|
|
test "if the user has a profile member of a group" do
|
|
|
|
%User{} = user = insert(:user)
|
|
|
|
|
|
|
|
%Actor{} = actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
insert(:member, parent: group, actor: actor, role: :member)
|
|
|
|
|
|
|
|
%Activity{} =
|
|
|
|
activity = insert(:mobilizon_activity, group: group, inserted_at: DateTime.utc_now())
|
|
|
|
|
2021-06-03 15:17:13 +00:00
|
|
|
NotifierMock
|
|
|
|
|> expect(:ready?, 1, fn -> true end)
|
|
|
|
|> expect(:send, 1, fn %User{},
|
|
|
|
%Activity{
|
|
|
|
type: :event,
|
|
|
|
subject: :event_created,
|
|
|
|
object_type: :event
|
|
|
|
},
|
|
|
|
[single_activity: true] ->
|
|
|
|
{:ok, :sent}
|
|
|
|
end)
|
2021-03-23 14:18:03 +00:00
|
|
|
|
2021-06-03 15:17:13 +00:00
|
|
|
assert :ok == ActivityBuilder.notify_activity(activity)
|
2021-03-23 14:18:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "unless if the user has a profile member of a group" do
|
|
|
|
%User{} = user = insert(:user)
|
|
|
|
|
|
|
|
%Actor{} = actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
%Actor{type: :Group} = group = insert(:group)
|
|
|
|
insert(:member, parent: group, actor: actor, role: :member)
|
|
|
|
|
|
|
|
%Activity{} =
|
|
|
|
activity =
|
|
|
|
insert(:mobilizon_activity, group: group, inserted_at: DateTime.utc_now(), author: actor)
|
|
|
|
|
|
|
|
assert :ok == ActivityBuilder.notify_activity(activity)
|
|
|
|
|
2021-06-03 15:17:13 +00:00
|
|
|
NotifierMock
|
|
|
|
|> expect(:ready?, 0, fn -> true end)
|
|
|
|
|> expect(:send, 0, fn %User{},
|
|
|
|
%Activity{
|
|
|
|
type: :event,
|
|
|
|
subject: :event_created,
|
|
|
|
object_type: :event
|
|
|
|
},
|
|
|
|
[single_activity: true] ->
|
|
|
|
{:ok, :sent}
|
|
|
|
end)
|
2021-03-23 14:18:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|