Handle poll votes

This commit is contained in:
rinpatch 2019-05-21 14:12:10 +03:00
commit aafe30d94e
4 changed files with 87 additions and 0 deletions

16
test/fixtures/mastodon-vote.json vendored Normal file
View file

@ -0,0 +1,16 @@
{
"@context": "https://www.w3.org/ns/activitystreams",
"actor": "https://mastodon.sdf.org/users/rinpatch",
"id": "https://mastodon.sdf.org/users/rinpatch#votes/387/activity",
"nickname": "rin",
"object": {
"attributedTo": "https://mastodon.sdf.org/users/rinpatch",
"id": "https://mastodon.sdf.org/users/rinpatch#votes/387",
"inReplyTo": "https://testing.uguu.ltd/objects/9d300947-2dcb-445d-8978-9a3b4b84fa14",
"name": "suya..",
"to": "https://testing.uguu.ltd/users/rin",
"type": "Note"
},
"to": "https://testing.uguu.ltd/users/rin",
"type": "Create"
}

View file

@ -130,6 +130,37 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end)
end
test "in increments vote counters on question activities" do
user = insert(:user)
{:ok, activity} =
CommonAPI.post(user, %{
"status" => "suya...",
"poll" => %{"options" => ["suya", "suya.", "suya.."], "expires_in" => 10}
})
object = Object.normalize(activity)
data =
File.read!("test/fixtures/mastodon-vote.json")
|> Poison.decode!()
|> Kernel.put_in(["to"], user.ap_id)
|> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
|> Kernel.put_in(["object", "to"], user.ap_id)
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
object = Object.get_by_ap_id(object.data["id"])
assert Enum.any?(
object.data["oneOf"],
fn
%{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
_ -> false
end
)
end
test "it works for incoming notices with contentMap" do
data =
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()