Merge branch 'poll-notification' into 'develop'
MastodonAPI: Support poll notification See merge request pleroma/pleroma!3484
This commit is contained in:
commit
901204df22
17 changed files with 314 additions and 28 deletions
|
|
@ -129,6 +129,19 @@ defmodule Pleroma.NotificationTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "create_poll_notifications/1" do
|
||||
[user1, user2, user3, _, _] = insert_list(5, :user)
|
||||
question = insert(:question, user: user1)
|
||||
activity = insert(:question_activity, question: question)
|
||||
|
||||
{:ok, _, _} = CommonAPI.vote(user2, question, [0])
|
||||
{:ok, _, _} = CommonAPI.vote(user3, question, [1])
|
||||
|
||||
{:ok, notifications} = Notification.create_poll_notifications(activity)
|
||||
|
||||
assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
|
||||
end
|
||||
|
||||
describe "CommonApi.post/2 notification-related functionality" do
|
||||
test_with_mock "creates but does NOT send notification to blocker user",
|
||||
Push,
|
||||
|
|
|
|||
|
|
@ -157,6 +157,30 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Question objects" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
question = build(:question, user: user)
|
||||
question_activity = build(:question_activity, question: question)
|
||||
activity_data = Map.put(question_activity.data, "object", question.data["id"])
|
||||
meta = [object_data: question.data, local: false]
|
||||
|
||||
{:ok, activity, meta} = ActivityPub.persist(activity_data, meta)
|
||||
|
||||
%{activity: activity, meta: meta}
|
||||
end
|
||||
|
||||
test "enqueues the poll end", %{activity: activity, meta: meta} do
|
||||
{:ok, activity, meta} = SideEffects.handle(activity, meta)
|
||||
|
||||
assert_enqueued(
|
||||
worker: Pleroma.Workers.PollWorker,
|
||||
args: %{op: "poll_end", activity_id: activity.id},
|
||||
scheduled_at: NaiveDateTime.from_iso8601!(meta[:object_data]["closed"])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete users with confirmation pending" do
|
||||
setup do
|
||||
user = insert(:user, is_confirmed: false)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.PollWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
|
@ -48,6 +49,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
assert object.data["type"] == "Question"
|
||||
assert object.data["oneOf"] |> length() == 2
|
||||
|
||||
assert_enqueued(
|
||||
worker: PollWorker,
|
||||
args: %{op: "poll_end", activity_id: activity.id},
|
||||
scheduled_at: NaiveDateTime.from_iso8601!(object.data["closed"])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.ScheduledActivityWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -705,11 +706,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert {:ok, %{id: activity_id}} =
|
||||
perform_job(Pleroma.Workers.ScheduledActivityWorker, %{
|
||||
perform_job(ScheduledActivityWorker, %{
|
||||
activity_id: scheduled_id
|
||||
})
|
||||
|
||||
assert Repo.all(Oban.Job) == []
|
||||
refute_enqueued(worker: ScheduledActivityWorker)
|
||||
|
||||
object =
|
||||
Activity
|
||||
|
|
|
|||
|
|
@ -196,6 +196,27 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Poll notification" do
|
||||
user = insert(:user)
|
||||
activity = insert(:question_activity, user: user)
|
||||
{:ok, [notification]} = Notification.create_poll_notifications(activity)
|
||||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false, is_muted: false},
|
||||
type: "poll",
|
||||
account:
|
||||
AccountView.render("show.json", %{
|
||||
user: user,
|
||||
for: user
|
||||
}),
|
||||
status: StatusView.render("show.json", %{activity: activity, for: user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Report notification" do
|
||||
reporting_user = insert(:user)
|
||||
reported_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -213,6 +213,38 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def question_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"type" => "Question",
|
||||
"actor" => user.ap_id,
|
||||
"attributedTo" => user.ap_id,
|
||||
"attachment" => [],
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [user.follower_address],
|
||||
"context" => Pleroma.Web.ActivityPub.Utils.generate_context_id(),
|
||||
"closed" => DateTime.utc_now() |> DateTime.add(86_400) |> DateTime.to_iso8601(),
|
||||
"oneOf" => [
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "chocolate",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"}
|
||||
},
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "vanilla",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
%Pleroma.Object{
|
||||
data: merge_attributes(data, Map.get(attrs, :data, %{}))
|
||||
}
|
||||
end
|
||||
|
||||
def direct_note_activity_factory do
|
||||
dm = insert(:direct_note)
|
||||
|
||||
|
|
@ -428,6 +460,33 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def question_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
question = attrs[:question] || insert(:question, user: user)
|
||||
|
||||
data_attrs = attrs[:data_attrs] || %{}
|
||||
attrs = Map.drop(attrs, [:user, :question, :data_attrs])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Create",
|
||||
"actor" => question.data["actor"],
|
||||
"to" => question.data["to"],
|
||||
"object" => question.data["id"],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"context" => question.data["context"]
|
||||
}
|
||||
|> Map.merge(data_attrs)
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data,
|
||||
actor: data["actor"],
|
||||
recipients: data["to"]
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
|
||||
def oauth_app_factory do
|
||||
%Pleroma.Web.OAuth.App{
|
||||
client_name: sequence(:client_name, &"Some client #{&1}"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue