X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fmastodon_api%2Fcontrollers%2Fpoll_controller_test.exs;h=da0a631a93de7d657c2b046133b09e319b4a53e7;hb=7372609c5b5063d177715d5067654888f7075403;hp=95e27623d7111358784cb804edc7d9d9b7ab11bc;hpb=4134abef63e1165f5701741c1012e64cb908654c;p=akkoma
diff --git a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
index 95e27623d..da0a631a9 100644
--- a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
@@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn = get(conn, "/api/v1/polls/#{object.id}")
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
visibility: "private"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn = get(conn, "/api/v1/polls/#{object.id}")
@@ -47,6 +47,78 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
end
end
+ test "own_votes" do
+ %{conn: conn} = oauth_access(["write:statuses", "read:statuses"])
+
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(other_user, %{
+ status: "A very delicious sandwich",
+ poll: %{
+ options: ["Lettuce", "Grilled Bacon", "Tomato"],
+ expires_in: 20,
+ multiple: true
+ }
+ })
+
+ object = Object.normalize(activity, fetch: false)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 2]})
+ |> json_response_and_validate_schema(200)
+
+ object = Object.get_by_id(object.id)
+
+ assert [
+ %{
+ "name" => "Lettuce",
+ "replies" => %{"totalItems" => 1, "type" => "Collection"},
+ "type" => "Note"
+ },
+ %{
+ "name" => "Grilled Bacon",
+ "replies" => %{"totalItems" => 0, "type" => "Collection"},
+ "type" => "Note"
+ },
+ %{
+ "name" => "Tomato",
+ "replies" => %{"totalItems" => 1, "type" => "Collection"},
+ "type" => "Note"
+ }
+ ] == object.data["anyOf"]
+
+ assert %{"replies" => %{"totalItems" => 0}} =
+ Enum.find(object.data["anyOf"], fn %{"name" => name} -> name == "Grilled Bacon" end)
+
+ Enum.each(["Lettuce", "Tomato"], fn title ->
+ %{"replies" => %{"totalItems" => total_items}} =
+ Enum.find(object.data["anyOf"], fn %{"name" => name} -> name == title end)
+
+ assert total_items == 1
+ end)
+
+ assert %{
+ "own_votes" => own_votes,
+ "voted" => true
+ } =
+ conn
+ |> get("/api/v1/polls/#{object.id}")
+ |> json_response_and_validate_schema(200)
+
+ assert 0 in own_votes
+ assert 2 in own_votes
+ # for non authenticated user
+ response =
+ build_conn()
+ |> get("/api/v1/polls/#{object.id}")
+ |> json_response_and_validate_schema(200)
+
+ refute Map.has_key?(response, "own_votes")
+ refute Map.has_key?(response, "voted")
+ end
+
describe "POST /api/v1/polls/:id/votes" do
setup do: oauth_access(["write:statuses"])
@@ -63,14 +135,13 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
- conn =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
+ |> json_response_and_validate_schema(200)
- assert json_response_and_validate_schema(conn, 200)
object = Object.get_by_id(object.id)
assert Enum.all?(object.data["anyOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
@@ -85,7 +156,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["Yes", "No"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert conn
|> put_req_header("content-type", "application/json")
@@ -106,7 +177,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["half empty", "half full"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
assert conn
|> put_req_header("content-type", "application/json")
@@ -129,7 +200,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
poll: %{options: ["Yes", "No"], expires_in: 20}
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn =
conn
@@ -158,7 +229,7 @@ defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
visibility: "private"
})
- object = Object.normalize(activity)
+ object = Object.normalize(activity, fetch: false)
conn =
conn