1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-24 08:54:08 +00:00
mobilizon/test/service/activity/discussion_test.exs
Thomas Citharel e4467ec4ad
Fix timeouts in tests by removing async: true for DB tests
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2022-03-23 15:22:14 +01:00

119 lines
3.5 KiB
Elixir

defmodule Mobilizon.Service.Activity.DiscussionTest do
@moduledoc """
Test the Discussion activity provider module
"""
alias Mobilizon.Actors.Actor
alias Mobilizon.Discussions.{Comment, Discussion}
alias Mobilizon.Mention
alias Mobilizon.Service.Activity.Discussion, as: DiscussionActivity
alias Mobilizon.Service.Workers.{ActivityBuilder, LegacyNotifierBuilder}
alias Mobilizon.Users.User
use Mobilizon.DataCase
use Oban.Testing, repo: Mobilizon.Storage.Repo
import Mobilizon.Factory
describe "handle discussion with mentions" do
test "with no mentions" do
%Comment{} = comment = insert(:comment)
%Discussion{
id: discussion_id,
actor_id: group_id,
creator_id: author_id,
title: discussion_title,
slug: discussion_slug
} = discussion = insert(:discussion)
assert {:ok, _} =
DiscussionActivity.insert_activity(%Discussion{discussion | last_comment: comment},
subject: "discussion_created"
)
refute_enqueued(
worker: LegacyNotifierBuilder,
args: %{op: :discussion_mention}
)
assert_enqueued(
worker: ActivityBuilder,
args: %{
"group_id" => group_id,
"author_id" => author_id,
"object_id" => to_string(discussion_id),
"object_type" => "discussion",
"op" => "build_activity",
"subject" => "discussion_created",
"subject_params" => %{
"discussion_slug" => discussion_slug,
"discussion_title" => discussion_title
},
"type" => "discussion"
}
)
end
test "with some mentions" do
%User{} = user = insert(:user)
%Actor{id: actor_id} = actor = insert(:actor, user: user)
%Comment{actor_id: author_id} = comment = insert(:comment, text: "Hey @you")
comment = %Comment{
comment
| mentions: [
%Mention{actor: actor, comment: comment, actor_id: actor_id}
]
}
%Discussion{
id: discussion_id,
actor_id: group_id,
creator_id: discussion_author_id,
title: discussion_title,
slug: discussion_slug
} = discussion = insert(:discussion)
assert {:ok, _} =
DiscussionActivity.insert_activity(%Discussion{discussion | last_comment: comment},
subject: "discussion_created"
)
assert_enqueued(
worker: LegacyNotifierBuilder,
args: %{
"author_id" => author_id,
"group_id" => group_id,
"mentions" => [actor_id],
"object_id" => to_string(discussion_id),
"object_type" => "discussion",
"op" => "legacy_notify",
"subject" => "discussion_mention",
"subject_params" => %{
"discussion_slug" => discussion_slug,
"discussion_title" => discussion_title
},
"type" => "discussion"
}
)
assert_enqueued(
worker: ActivityBuilder,
args: %{
"group_id" => group_id,
"author_id" => discussion_author_id,
"object_id" => to_string(discussion_id),
"object_type" => "discussion",
"op" => "build_activity",
"subject" => "discussion_created",
"subject_params" => %{
"discussion_slug" => discussion_slug,
"discussion_title" => discussion_title
},
"type" => "discussion"
}
)
end
end
end