Merge remote-tracking branch 'origin/develop' into reactions
This commit is contained in:
commit
d9aaea44ff
89 changed files with 1242 additions and 841 deletions
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
test "getting a participation will also preload things" do
|
||||
|
|
@ -30,6 +31,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(user.id)
|
||||
[participation] = Participation.for_user(user)
|
||||
participation = Pleroma.Repo.preload(participation, :recipients)
|
||||
|
||||
|
|
@ -155,6 +158,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
[participation] = Participation.for_user_with_last_activity_id(user)
|
||||
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert participation.recipients |> length() == 1
|
||||
assert user in participation.recipients
|
||||
|
|
|
|||
|
|
@ -9,7 +9,14 @@ defmodule Pleroma.HealthcheckTest do
|
|||
test "system_info/0" do
|
||||
result = Healthcheck.system_info() |> Map.from_struct()
|
||||
|
||||
assert Map.keys(result) == [:active, :healthy, :idle, :memory_used, :pool_size]
|
||||
assert Map.keys(result) == [
|
||||
:active,
|
||||
:healthy,
|
||||
:idle,
|
||||
:job_queue_stats,
|
||||
:memory_used,
|
||||
:pool_size
|
||||
]
|
||||
end
|
||||
|
||||
describe "check_health/1" do
|
||||
|
|
|
|||
70
test/job_queue_monitor_test.exs
Normal file
70
test/job_queue_monitor_test.exs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.JobQueueMonitorTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pleroma.JobQueueMonitor
|
||||
|
||||
@success {:process_event, :success, 1337,
|
||||
%{
|
||||
args: %{"op" => "refresh_subscriptions"},
|
||||
attempt: 1,
|
||||
id: 339,
|
||||
max_attempts: 5,
|
||||
queue: "federator_outgoing",
|
||||
worker: "Pleroma.Workers.SubscriberWorker"
|
||||
}}
|
||||
|
||||
@failure {:process_event, :failure, 22_521_134,
|
||||
%{
|
||||
args: %{"op" => "force_password_reset", "user_id" => "9nJG6n6Nbu7tj9GJX6"},
|
||||
attempt: 1,
|
||||
error: %RuntimeError{message: "oops"},
|
||||
id: 345,
|
||||
kind: :exception,
|
||||
max_attempts: 1,
|
||||
queue: "background",
|
||||
stack: [
|
||||
{Pleroma.Workers.BackgroundWorker, :perform, 2,
|
||||
[file: 'lib/pleroma/workers/background_worker.ex', line: 31]},
|
||||
{Oban.Queue.Executor, :safe_call, 1,
|
||||
[file: 'lib/oban/queue/executor.ex', line: 42]},
|
||||
{:timer, :tc, 3, [file: 'timer.erl', line: 197]},
|
||||
{Oban.Queue.Executor, :call, 2, [file: 'lib/oban/queue/executor.ex', line: 23]},
|
||||
{Task.Supervised, :invoke_mfa, 2, [file: 'lib/task/supervised.ex', line: 90]},
|
||||
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
|
||||
],
|
||||
worker: "Pleroma.Workers.BackgroundWorker"
|
||||
}}
|
||||
|
||||
test "stats/0" do
|
||||
assert %{processed_jobs: _, queues: _, workers: _} = JobQueueMonitor.stats()
|
||||
end
|
||||
|
||||
test "handle_cast/2" do
|
||||
state = %{workers: %{}, queues: %{}, processed_jobs: 0}
|
||||
|
||||
assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
|
||||
assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
|
||||
assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
|
||||
assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
|
||||
|
||||
assert state == %{
|
||||
processed_jobs: 4,
|
||||
queues: %{
|
||||
"background" => %{failure: 2, processed_jobs: 2, success: 0},
|
||||
"federator_outgoing" => %{failure: 0, processed_jobs: 2, success: 2}
|
||||
},
|
||||
workers: %{
|
||||
"Pleroma.Workers.BackgroundWorker" => %{
|
||||
"force_password_reset" => %{failure: 2, processed_jobs: 2, success: 0}
|
||||
},
|
||||
"Pleroma.Workers.SubscriberWorker" => %{
|
||||
"refresh_subscriptions" => %{failure: 0, processed_jobs: 2, success: 2}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -1725,4 +1725,61 @@ defmodule Pleroma.UserTest do
|
|||
assert %{info: %{hide_follows: true}} = Repo.get(User, user.id)
|
||||
assert {:ok, %{info: %{hide_follows: true}}} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||
end
|
||||
|
||||
describe "get_cached_by_nickname_or_id" do
|
||||
setup do
|
||||
limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||
local_user = insert(:user)
|
||||
remote_user = insert(:user, nickname: "nickname@example.com", local: false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
|
||||
end)
|
||||
|
||||
[local_user: local_user, remote_user: remote_user]
|
||||
end
|
||||
|
||||
test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
|
||||
remote_user: remote_user
|
||||
} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], true)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
|
||||
end
|
||||
|
||||
test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
|
||||
%{remote_user: remote_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
|
||||
end
|
||||
|
||||
test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
|
||||
%{remote_user: remote_user, local_user: local_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
|
||||
end
|
||||
|
||||
test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
|
||||
%{remote_user: remote_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], true)
|
||||
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
|
||||
end
|
||||
|
||||
test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
|
||||
%{local_user: local_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], true)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -225,69 +225,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "/object/:uuid/likes" do
|
||||
setup do
|
||||
like = insert(:like_activity)
|
||||
like_object_ap_id = Object.normalize(like).data["id"]
|
||||
|
||||
uuid =
|
||||
like_object_ap_id
|
||||
|> String.split("/")
|
||||
|> List.last()
|
||||
|
||||
[id: like.data["id"], uuid: uuid]
|
||||
end
|
||||
|
||||
test "it returns the like activities in a collection", %{conn: conn, id: id, uuid: uuid} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}/likes")
|
||||
|> json_response(200)
|
||||
|
||||
assert List.first(result["first"]["orderedItems"])["id"] == id
|
||||
assert result["type"] == "OrderedCollection"
|
||||
assert result["totalItems"] == 1
|
||||
refute result["first"]["next"]
|
||||
end
|
||||
|
||||
test "it does not crash when page number is exceeded total pages", %{conn: conn, uuid: uuid} do
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}/likes?page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["type"] == "OrderedCollectionPage"
|
||||
assert result["totalItems"] == 1
|
||||
refute result["next"]
|
||||
assert Enum.empty?(result["orderedItems"])
|
||||
end
|
||||
|
||||
test "it contains the next key when likes count is more than 10", %{conn: conn} do
|
||||
note = insert(:note_activity)
|
||||
insert_list(11, :like_activity, note_activity: note)
|
||||
|
||||
uuid =
|
||||
note
|
||||
|> Object.normalize()
|
||||
|> Map.get(:data)
|
||||
|> Map.get("id")
|
||||
|> String.split("/")
|
||||
|> List.last()
|
||||
|
||||
result =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}/likes?page=1")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["totalItems"] == 11
|
||||
assert length(result["orderedItems"]) == 10
|
||||
assert result["next"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "/activities/:uuid" do
|
||||
test "it returns a json representation of the activity", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
|
|
|||
|
|
@ -883,10 +883,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, _, _, object} = ActivityPub.unlike(user, object)
|
||||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
assert Activity.get_by_id(like_activity.id) == nil
|
||||
assert note_activity.actor in unlike_activity.recipients
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -962,7 +963,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
assert unannounce_activity.data["to"] == [
|
||||
User.ap_followers(user),
|
||||
announce_activity.data["actor"]
|
||||
object.data["actor"]
|
||||
]
|
||||
|
||||
assert unannounce_activity.data["type"] == "Undo"
|
||||
|
|
|
|||
|
|
@ -106,11 +106,13 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
user = insert(:user)
|
||||
like_activity = insert(:like_activity, data_attrs: %{"context" => "test context"})
|
||||
|
||||
object = Object.normalize(like_activity.data["object"])
|
||||
|
||||
assert Utils.make_unlike_data(user, like_activity, nil) == %{
|
||||
"type" => "Undo",
|
||||
"actor" => user.ap_id,
|
||||
"object" => like_activity.data,
|
||||
"to" => [user.follower_address, like_activity.data["actor"]],
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => [Pleroma.Constants.as_public()],
|
||||
"context" => like_activity.data["context"]
|
||||
}
|
||||
|
|
@ -119,7 +121,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
"type" => "Undo",
|
||||
"actor" => user.ap_id,
|
||||
"object" => like_activity.data,
|
||||
"to" => [user.follower_address, like_activity.data["actor"]],
|
||||
"to" => [user.follower_address, object.data["actor"]],
|
||||
"cc" => [Pleroma.Constants.as_public()],
|
||||
"context" => like_activity.data["context"],
|
||||
"id" => "9mJEZK0tky1w2xD2vY"
|
||||
|
|
|
|||
84
test/web/masto_fe_controller_test.exs
Normal file
84
test/web/masto_fe_controller_test.exs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.MastoFEController do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:instance, :public])
|
||||
|
||||
test "put settings", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||
|
||||
assert _result = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.info.settings == %{"programming" => "socks"}
|
||||
end
|
||||
|
||||
describe "index/2 redirections" do
|
||||
setup %{conn: conn} do
|
||||
session_opts = [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> Plug.Session.call(Plug.Session.init(session_opts))
|
||||
|> fetch_session()
|
||||
|
||||
test_path = "/web/statuses/test"
|
||||
%{conn: conn, path: test_path}
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page on private instances", %{
|
||||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
||||
token = insert(:oauth_token)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, token.user)
|
||||
|> put_session(:oauth_token, token.token)
|
||||
|> get(path)
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "saves referer path to session", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
return_to = Plug.Conn.get_session(conn, :return_to)
|
||||
|
||||
assert return_to == path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -10,19 +10,23 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "Conversations", %{conn: conn} do
|
||||
test "returns a list of conversations", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 0
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 1
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
|
|
@ -52,23 +56,100 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
assert is_binary(res_id)
|
||||
assert unread == true
|
||||
assert res_last_status["id"] == direct.id
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
end
|
||||
|
||||
test "updates the last_status on reply", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, direct_reply} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "reply",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
[%{"last_status" => res_last_status}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
assert res_last_status["id"] == direct_reply.id
|
||||
end
|
||||
|
||||
test "the user marks a conversation as read", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
[%{"id" => direct_conversation_id, "unread" => true}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
%{"unread" => false} =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> post("/api/v1/conversations/#{direct_conversation_id}/read")
|
||||
|> json_response(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 0
|
||||
|
||||
# The conversation is marked as unread on reply
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "reply",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
[%{"unread" => true}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
|
||||
# A reply doesn't increment the user's unread_conversation_count if the conversation is unread
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "reply",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
end
|
||||
|
||||
test "(vanilla) Mastodon frontend behaviour", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
# Apparently undocumented API endpoint
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> post("/api/v1/conversations/#{res_id}/read")
|
||||
|
||||
assert response = json_response(res_conn, 200)
|
||||
assert length(response["accounts"]) == 2
|
||||
assert response["last_status"]["id"] == direct.id
|
||||
assert response["unread"] == false
|
||||
|
||||
# (vanilla) Mastodon frontend behaviour
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/statuses/#{res_last_status["id"]}/context")
|
||||
|> get("/api/v1/statuses/#{direct.id}/context")
|
||||
|
||||
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
test "with tags", %{conn: conn} do
|
||||
[emoji | _body] =
|
||||
conn
|
||||
|> get("/api/v1/custom_emojis")
|
||||
|> json_response(200)
|
||||
|
||||
assert Map.has_key?(emoji, "shortcode")
|
||||
assert Map.has_key?(emoji, "static_url")
|
||||
assert Map.has_key?(emoji, "tags")
|
||||
assert is_list(emoji["tags"])
|
||||
assert Map.has_key?(emoji, "category")
|
||||
assert Map.has_key?(emoji, "url")
|
||||
assert Map.has_key?(emoji, "visible_in_picker")
|
||||
end
|
||||
end
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
|
@ -19,7 +18,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :public])
|
||||
clear_config([:rich_media, :enabled])
|
||||
|
||||
test "getting a list of mutes", %{conn: conn} do
|
||||
|
|
@ -113,20 +111,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert [] = json_response(third_conn, 200)
|
||||
end
|
||||
|
||||
test "put settings", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||
|
||||
assert _result = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.info.settings == %{"programming" => "socks"}
|
||||
end
|
||||
|
||||
describe "link headers" do
|
||||
test "preserves parameters in link headers", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
@ -159,79 +143,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "custom emoji" do
|
||||
test "with tags", %{conn: conn} do
|
||||
[emoji | _body] =
|
||||
conn
|
||||
|> get("/api/v1/custom_emojis")
|
||||
|> json_response(200)
|
||||
|
||||
assert Map.has_key?(emoji, "shortcode")
|
||||
assert Map.has_key?(emoji, "static_url")
|
||||
assert Map.has_key?(emoji, "tags")
|
||||
assert is_list(emoji["tags"])
|
||||
assert Map.has_key?(emoji, "category")
|
||||
assert Map.has_key?(emoji, "url")
|
||||
assert Map.has_key?(emoji, "visible_in_picker")
|
||||
end
|
||||
end
|
||||
|
||||
describe "index/2 redirections" do
|
||||
setup %{conn: conn} do
|
||||
session_opts = [
|
||||
store: :cookie,
|
||||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> Plug.Session.call(Plug.Session.init(session_opts))
|
||||
|> fetch_session()
|
||||
|
||||
test_path = "/web/statuses/test"
|
||||
%{conn: conn, path: test_path}
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "redirects not logged-in users to the login page on private instances", %{
|
||||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "/web/login"
|
||||
end
|
||||
|
||||
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
|
||||
token = insert(:oauth_token)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, token.user)
|
||||
|> put_session(:oauth_token, token.token)
|
||||
|> get(path)
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "saves referer path to session", %{conn: conn, path: path} do
|
||||
conn = get(conn, path)
|
||||
return_to = Plug.Conn.get_session(conn, :return_to)
|
||||
|
||||
assert return_to == path
|
||||
end
|
||||
end
|
||||
|
||||
describe "empty_array, stubs for mastodon api" do
|
||||
test "GET /api/v1/accounts/:id/identity_proofs", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -418,6 +418,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
following_count: 1
|
||||
} = AccountView.render("show.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "shows unread_conversation_count only to the account owner" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "Hey @#{other_user.nickname}.",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert AccountView.render("show.json", %{user: user, for: other_user})[:pleroma][
|
||||
:unread_conversation_count
|
||||
] == nil
|
||||
|
||||
assert AccountView.render("show.json", %{user: user, for: user})[:pleroma][
|
||||
:unread_conversation_count
|
||||
] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow requests counter" do
|
||||
|
|
|
|||
|
|
@ -100,5 +100,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
NotificationView.render("index.json", %{notifications: [notification], for: followed})
|
||||
|
||||
assert [expected] == result
|
||||
|
||||
User.perform(:delete, follower)
|
||||
notification = Notification |> Repo.one() |> Repo.preload(:activity)
|
||||
|
||||
assert [] ==
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: followed})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -133,6 +134,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert [user] == participation.recipients
|
||||
assert other_user not in participation.recipients
|
||||
|
||||
|
|
|
|||
|
|
@ -233,30 +233,68 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "it doesn't send to blocked users" do
|
||||
user = insert(:user)
|
||||
blocked_user = insert(:user)
|
||||
{:ok, user} = User.block(user, blocked_user)
|
||||
describe "blocks" do
|
||||
test "it doesn't send messages involving blocked users" do
|
||||
user = insert(:user)
|
||||
blocked_user = insert(:user)
|
||||
{:ok, user} = User.block(user, blocked_user)
|
||||
|
||||
task =
|
||||
Task.async(fn ->
|
||||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
task =
|
||||
Task.async(fn ->
|
||||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
user: user
|
||||
}
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
user: user
|
||||
}
|
||||
|
||||
{:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
|
||||
{:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
|
||||
|
||||
topics = %{
|
||||
"public" => [fake_socket]
|
||||
}
|
||||
topics = %{
|
||||
"public" => [fake_socket]
|
||||
}
|
||||
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it doesn't send messages transitively involving blocked users" do
|
||||
blocker = insert(:user)
|
||||
blockee = insert(:user)
|
||||
friend = insert(:user)
|
||||
|
||||
task =
|
||||
Task.async(fn ->
|
||||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
user: blocker
|
||||
}
|
||||
|
||||
topics = %{
|
||||
"public" => [fake_socket]
|
||||
}
|
||||
|
||||
{:ok, blocker} = User.block(blocker, blockee)
|
||||
|
||||
{:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
|
||||
|
||||
Worker.push_to_socket(topics, "public", activity_one)
|
||||
|
||||
{:ok, activity_two} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"})
|
||||
|
||||
Worker.push_to_socket(topics, "public", activity_two)
|
||||
|
||||
{:ok, activity_three} = CommonAPI.post(blockee, %{"status" => "hey! @#{blocker.nickname}"})
|
||||
|
||||
Worker.push_to_socket(topics, "public", activity_three)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
end
|
||||
|
||||
test "it doesn't send unwanted DMs to list" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue