Count and display post quotes
This commit is contained in:
parent
4c5b45ed73
commit
9a063deacc
14 changed files with 292 additions and 3 deletions
|
|
@ -770,6 +770,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
end
|
||||
|
||||
test "increates quotes count", %{user: user} do
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "1", visibility: "public"})
|
||||
ap_id = activity.data["id"]
|
||||
quote_data = %{status: "1", quote_id: activity.id}
|
||||
|
||||
# public
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "public"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 1
|
||||
|
||||
# unlisted
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "unlisted"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 2
|
||||
|
||||
# private
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "private"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 2
|
||||
|
||||
# direct
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(quote_data, :visibility, "direct"))
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["quotesCount"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch activities for recipients" do
|
||||
|
|
|
|||
|
|
@ -337,7 +337,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
thread_muted: false,
|
||||
emoji_reactions: [],
|
||||
parent_visible: false,
|
||||
pinned_at: nil
|
||||
pinned_at: nil,
|
||||
quotes_count: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.StatusControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "getting quotes of a specified post" do
|
||||
setup do
|
||||
[current_user, user] = insert_pair(:user)
|
||||
%{user: current_user, conn: conn} = oauth_access(["read:statuses"], user: current_user)
|
||||
[current_user: current_user, user: user, conn: conn]
|
||||
end
|
||||
|
||||
test "shows quotes of a post", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
|
||||
{:ok, quote_post} = CommonAPI.post(user, %{status: "quoat", quote_id: activity.id})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/#{activity.id}/quotes")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
[status] = response
|
||||
|
||||
assert length(response) == 1
|
||||
assert status["id"] == quote_post.id
|
||||
end
|
||||
|
||||
test "returns 404 error when a post can't be seen", %{conn: conn} do
|
||||
activity = insert(:direct_note_activity)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/#{activity.id}/quotes")
|
||||
|
||||
assert json_response_and_validate_schema(response, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
|
||||
test "returns 404 error when a post does not exist", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/idontexist/quotes")
|
||||
|
||||
assert json_response_and_validate_schema(response, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue