From 23d279e03ee1f7a1285614754738711359bc4b81 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Thu, 1 Aug 2019 17:28:00 +0300
Subject: [#1149] Replaced RetryQueue with oban-based retries.
---
test/user_test.exs | 15 ++----
test/web/activity_pub/publisher_test.exs | 2 +-
test/web/federator_test.exs | 82 ++++++++++++++------------------
test/web/retry_queue_test.exs | 48 -------------------
test/web/salmon/salmon_test.exs | 2 +-
5 files changed, 43 insertions(+), 106 deletions(-)
delete mode 100644 test/web/retry_queue_test.exs
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 556df45fd..70c376384 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -12,9 +12,9 @@ defmodule Pleroma.UserTest do
alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory
- import Mock
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -1034,11 +1034,7 @@ defmodule Pleroma.UserTest do
refute Activity.get_by_id(repeat.id)
end
- test_with_mock "it sends out User Delete activity",
- %{user: user},
- Pleroma.Web.ActivityPub.Publisher,
- [:passthrough],
- [] do
+ test "it sends out User Delete activity", %{user: user} do
config_path = [:instance, :federating]
initial_setting = Pleroma.Config.get(config_path)
Pleroma.Config.put(config_path, true)
@@ -1048,11 +1044,8 @@ defmodule Pleroma.UserTest do
{:ok, _user} = User.delete(user)
- assert called(
- Pleroma.Web.ActivityPub.Publisher.publish_one(%{
- inbox: "http://mastodon.example.org/inbox"
- })
- )
+ assert [%{args: %{"params" => %{"inbox" => "http://mastodon.example.org/inbox"}}}] =
+ all_enqueued(worker: Pleroma.Workers.Publisher)
Pleroma.Config.put(config_path, initial_setting)
end
diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs
index 36a39c84c..26d019878 100644
--- a/test/web/activity_pub/publisher_test.exs
+++ b/test/web/activity_pub/publisher_test.exs
@@ -257,7 +257,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert called(
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
inbox: "https://domain.com/users/nick1/inbox",
- actor: actor,
+ actor_id: actor.id,
id: note_activity.data["id"]
})
)
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 6e143eee4..5c1704548 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -6,7 +6,10 @@ defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Instances
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
+
use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
+
import Pleroma.Factory
import Mock
@@ -22,15 +25,6 @@ defmodule Pleroma.Web.FederatorTest do
:ok
end
- describe "Publisher.perform" do
- test "call `perform` with unknown task" do
- assert {
- :error,
- "Don't know what to do with this"
- } = Pleroma.Web.Federator.Publisher.perform("test", :ok, :ok)
- end
- end
-
describe "Publish an activity" do
setup do
user = insert(:user)
@@ -73,10 +67,7 @@ defmodule Pleroma.Web.FederatorTest do
end
describe "Targets reachability filtering in `publish`" do
- test_with_mock "it federates only to reachable instances via AP",
- Pleroma.Web.ActivityPub.Publisher,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via AP" do
user = insert(:user)
{inbox1, inbox2} =
@@ -104,20 +95,13 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(
- Pleroma.Web.ActivityPub.Publisher.publish_one(%{
- inbox: inbox1,
- unreachable_since: dt
- })
- )
+ expected_dt = NaiveDateTime.to_iso8601(dt)
- refute called(Pleroma.Web.ActivityPub.Publisher.publish_one(%{inbox: inbox2}))
+ assert [%{args: %{"params" => %{"inbox" => ^inbox1, "unreachable_since" => ^expected_dt}}}] =
+ all_enqueued(worker: Pleroma.Workers.Publisher)
end
- test_with_mock "it federates only to reachable instances via Websub",
- Pleroma.Web.Websub,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via Websub" do
user = insert(:user)
websub_topic = Pleroma.Web.OStatus.feed_path(user)
@@ -142,23 +126,25 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
- assert called(
- Pleroma.Web.Websub.publish_one(%{
- callback: sub2.callback,
- unreachable_since: dt
- })
- )
-
- refute called(Pleroma.Web.Websub.publish_one(%{callback: sub1.callback}))
+ expected_callback = sub2.callback
+ expected_dt = NaiveDateTime.to_iso8601(dt)
+
+ assert [
+ %{
+ args: %{
+ "params" => %{
+ "callback" => ^expected_callback,
+ "unreachable_since" => ^expected_dt
+ }
+ }
+ }
+ ] = all_enqueued(worker: Pleroma.Workers.Publisher)
end
- test_with_mock "it federates only to reachable instances via Salmon",
- Pleroma.Web.Salmon,
- [:passthrough],
- [] do
+ test "it federates only to reachable instances via Salmon" do
user = insert(:user)
- remote_user1 =
+ _remote_user1 =
insert(:user, %{
local: false,
nickname: "nick1@domain.com",
@@ -174,6 +160,8 @@ defmodule Pleroma.Web.FederatorTest do
info: %{salmon: "https://domain2.com/salmon"}
})
+ remote_user2_id = remote_user2.id
+
dt = NaiveDateTime.utc_now()
Instances.set_unreachable(remote_user2.ap_id, dt)
@@ -182,14 +170,18 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(
- Pleroma.Web.Salmon.publish_one(%{
- recipient: remote_user2,
- unreachable_since: dt
- })
- )
-
- refute called(Pleroma.Web.Salmon.publish_one(%{recipient: remote_user1}))
+ expected_dt = NaiveDateTime.to_iso8601(dt)
+
+ assert [
+ %{
+ args: %{
+ "params" => %{
+ "recipient_id" => ^remote_user2_id,
+ "unreachable_since" => ^expected_dt
+ }
+ }
+ }
+ ] = all_enqueued(worker: Pleroma.Workers.Publisher)
end
end
diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs
deleted file mode 100644
index ecb3ce5d0..000000000
--- a/test/web/retry_queue_test.exs
+++ /dev/null
@@ -1,48 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule MockActivityPub do
- def publish_one({ret, waiter}) do
- send(waiter, :complete)
- {ret, "success"}
- end
-end
-
-defmodule Pleroma.Web.Federator.RetryQueueTest do
- use Pleroma.DataCase
- alias Pleroma.Web.Federator.RetryQueue
-
- @small_retry_count 0
- @hopeless_retry_count 10
-
- setup do
- RetryQueue.reset_stats()
- end
-
- test "RetryQueue responds to stats request" do
- assert %{delivered: 0, dropped: 0} == RetryQueue.get_stats()
- end
-
- test "failed posts are retried" do
- {:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count)
-
- wait_task =
- Task.async(fn ->
- receive do
- :complete -> :ok
- end
- end)
-
- RetryQueue.enqueue({:ok, wait_task.pid}, MockActivityPub, @small_retry_count)
- Task.await(wait_task)
- assert %{delivered: 1, dropped: 0} == RetryQueue.get_stats()
- end
-
- test "posts that have been tried too many times are dropped" do
- {:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count)
-
- RetryQueue.enqueue({:ok, nil}, MockActivityPub, @hopeless_retry_count)
- assert %{delivered: 0, dropped: 1} == RetryQueue.get_stats()
- end
-end
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index e86e76fe9..0186f3fef 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -96,6 +96,6 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
Salmon.publish(user, activity)
- assert called(Publisher.enqueue_one(Salmon, %{recipient: mentioned_user}))
+ assert called(Publisher.enqueue_one(Salmon, %{recipient_id: mentioned_user.id}))
end
end
--
cgit v1.2.3
From b7fad8d395c2bd1afe445a370e539571f5ec0c18 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 9 Aug 2019 20:08:01 +0300
Subject: [#1149] Oban jobs implementation for :federator_incoming and
:federator_outgoing queues.
---
test/activity_test.exs | 4 +-
test/support/oban_helpers.ex | 36 ++++++++++++++
test/user_test.exs | 11 ++++-
.../activity_pub/activity_pub_controller_test.exs | 14 ++++--
test/web/federator_test.exs | 57 ++++++++++++++--------
test/web/websub/websub_test.exs | 4 ++
6 files changed, 101 insertions(+), 25 deletions(-)
create mode 100644 test/support/oban_helpers.ex
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index b27f6fd36..b9c12adb2 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.ActivityTest do
use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.Bookmark
+ alias Pleroma.ObanHelpers
alias Pleroma.Object
alias Pleroma.ThreadMute
import Pleroma.Factory
@@ -125,7 +126,8 @@ defmodule Pleroma.ActivityTest do
}
{:ok, local_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "find me!"})
- {:ok, remote_activity} = Pleroma.Web.Federator.incoming_ap_doc(params)
+ {:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params)
+ {:ok, remote_activity} = ObanHelpers.perform(job)
%{local_activity: local_activity, remote_activity: remote_activity, user: user}
end
diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex
new file mode 100644
index 000000000..54b5a9566
--- /dev/null
+++ b/test/support/oban_helpers.ex
@@ -0,0 +1,36 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ObanHelpers do
+ @moduledoc """
+ Oban test helpers.
+ """
+
+ alias Pleroma.Repo
+
+ def perform(%Oban.Job{} = job) do
+ res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
+ Repo.delete(job)
+ res
+ end
+
+ def perform(jobs) when is_list(jobs) do
+ for job <- jobs, do: perform(job)
+ end
+
+ def member?(%{} = job_args, jobs) when is_list(jobs) do
+ Enum.any?(jobs, fn job ->
+ member?(job_args, job.args)
+ end)
+ end
+
+ def member?(%{} = test_attrs, %{} = attrs) do
+ Enum.all?(
+ test_attrs,
+ fn {k, _v} -> member?(test_attrs[k], attrs[k]) end
+ )
+ end
+
+ def member?(x, y), do: x == y
+end
diff --git a/test/user_test.exs b/test/user_test.exs
index 70c376384..ee6d8e8f3 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.UserTest do
alias Pleroma.Activity
alias Pleroma.Builders.UserBuilder
+ alias Pleroma.ObanHelpers
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
@@ -1044,8 +1045,16 @@ defmodule Pleroma.UserTest do
{:ok, _user} = User.delete(user)
- assert [%{args: %{"params" => %{"inbox" => "http://mastodon.example.org/inbox"}}}] =
+ assert ObanHelpers.member?(
+ %{
+ "op" => "publish_one",
+ "params" => %{
+ "inbox" => "http://mastodon.example.org/inbox",
+ "id" => "pleroma:fakeid"
+ }
+ },
all_enqueued(worker: Pleroma.Workers.Publisher)
+ )
Pleroma.Config.put(config_path, initial_setting)
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 40344f17e..1d809164f 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -4,15 +4,19 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
+ use Oban.Testing, repo: Pleroma.Repo
+
import Pleroma.Factory
alias Pleroma.Activity
alias Pleroma.Instances
+ alias Pleroma.ObanHelpers
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.UserView
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Workers.Receiver, as: ReceiverWorker
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -232,7 +236,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/inbox", data)
assert "ok" == json_response(conn, 200)
- :timer.sleep(500)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
assert Activity.get_by_ap_id(data["id"])
end
@@ -274,7 +279,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/users/#{user.nickname}/inbox", data)
assert "ok" == json_response(conn, 200)
- :timer.sleep(500)
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
assert Activity.get_by_ap_id(data["id"])
end
@@ -303,7 +308,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/users/#{recipient.nickname}/inbox", data)
assert "ok" == json_response(conn, 200)
- :timer.sleep(500)
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
assert Activity.get_by_ap_id(data["id"])
end
@@ -382,6 +387,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/users/#{recipient.nickname}/inbox", data)
|> json_response(200)
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+
activity = Activity.get_by_ap_id(data["id"])
assert activity.id
@@ -457,6 +464,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> post("/users/#{user.nickname}/outbox", data)
result = json_response(conn, 201)
+
assert Activity.get_by_ap_id(result["id"])
end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 5c1704548..ebe962da2 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -4,8 +4,10 @@
defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Instances
+ alias Pleroma.ObanHelpers
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
+ alias Pleroma.Workers.Publisher, as: PublisherWorker
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
@@ -45,6 +47,7 @@ defmodule Pleroma.Web.FederatorTest do
} do
with_mocks([relay_mock]) do
Federator.publish(activity)
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
end
assert_received :relay_publish
@@ -58,6 +61,7 @@ defmodule Pleroma.Web.FederatorTest do
with_mocks([relay_mock]) do
Federator.publish(activity)
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
end
refute_received :relay_publish
@@ -97,8 +101,15 @@ defmodule Pleroma.Web.FederatorTest do
expected_dt = NaiveDateTime.to_iso8601(dt)
- assert [%{args: %{"params" => %{"inbox" => ^inbox1, "unreachable_since" => ^expected_dt}}}] =
- all_enqueued(worker: Pleroma.Workers.Publisher)
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
+
+ assert ObanHelpers.member?(
+ %{
+ "op" => "publish_one",
+ "params" => %{"inbox" => inbox1, "unreachable_since" => expected_dt}
+ },
+ all_enqueued(worker: PublisherWorker)
+ )
end
test "it federates only to reachable instances via Websub" do
@@ -129,16 +140,18 @@ defmodule Pleroma.Web.FederatorTest do
expected_callback = sub2.callback
expected_dt = NaiveDateTime.to_iso8601(dt)
- assert [
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
+
+ assert ObanHelpers.member?(
%{
- args: %{
- "params" => %{
- "callback" => ^expected_callback,
- "unreachable_since" => ^expected_dt
- }
+ "op" => "publish_one",
+ "params" => %{
+ "callback" => expected_callback,
+ "unreachable_since" => expected_dt
}
- }
- ] = all_enqueued(worker: Pleroma.Workers.Publisher)
+ },
+ all_enqueued(worker: PublisherWorker)
+ )
end
test "it federates only to reachable instances via Salmon" do
@@ -172,16 +185,18 @@ defmodule Pleroma.Web.FederatorTest do
expected_dt = NaiveDateTime.to_iso8601(dt)
- assert [
+ ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
+
+ assert ObanHelpers.member?(
%{
- args: %{
- "params" => %{
- "recipient_id" => ^remote_user2_id,
- "unreachable_since" => ^expected_dt
- }
+ "op" => "publish_one",
+ "params" => %{
+ "recipient_id" => remote_user2_id,
+ "unreachable_since" => expected_dt
}
- }
- ] = all_enqueued(worker: Pleroma.Workers.Publisher)
+ },
+ all_enqueued(worker: PublisherWorker)
+ )
end
end
@@ -201,7 +216,8 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- {:ok, _activity} = Federator.incoming_ap_doc(params)
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert {:ok, _activity} = ObanHelpers.perform(job)
end
test "rejects incoming AP docs with incorrect origin" do
@@ -219,7 +235,8 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- :error = Federator.incoming_ap_doc(params)
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert :error = ObanHelpers.perform(job)
end
end
end
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 74386d7db..b704a558a 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -4,11 +4,14 @@
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
+ alias Pleroma.ObanHelpers
alias Pleroma.Web.Router.Helpers
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.Web.Websub.WebsubServerSubscription
+ alias Pleroma.Workers.Subscriber, as: SubscriberWorker
import Pleroma.Factory
import Tesla.Mock
@@ -224,6 +227,7 @@ defmodule Pleroma.Web.WebsubTest do
})
_refresh = Websub.refresh_subscriptions()
+ ObanHelpers.perform(all_enqueued(worker: SubscriberWorker))
assert still_good == Repo.get(WebsubClientSubscription, still_good.id)
refute needs_refresh == Repo.get(WebsubClientSubscription, needs_refresh.id)
--
cgit v1.2.3
From 33a5fc4a70b6f9b8c2d8c03a412d7eec8d5b3db1 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 10 Aug 2019 20:38:31 +0300
Subject: [#1149] Fixed failing tests. Ensured Instance.set_unreachable/2
supports ISO 8601 datetime.
---
test/conversation_test.exs | 2 ++
test/support/oban_helpers.ex | 6 ++++++
test/web/federator_test.exs | 3 ++-
test/web/instances/instance_test.exs | 3 ++-
4 files changed, 12 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/conversation_test.exs b/test/conversation_test.exs
index aa193e0d4..2ebbcab76 100644
--- a/test/conversation_test.exs
+++ b/test/conversation_test.exs
@@ -28,6 +28,8 @@ defmodule Pleroma.ConversationTest do
{:ok, _activity} =
CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"})
+ Pleroma.ObanHelpers.perform_all()
+
Repo.delete_all(Conversation)
Repo.delete_all(Conversation.Participation)
diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex
index 54b5a9566..ecc03ba1a 100644
--- a/test/support/oban_helpers.ex
+++ b/test/support/oban_helpers.ex
@@ -9,6 +9,12 @@ defmodule Pleroma.ObanHelpers do
alias Pleroma.Repo
+ def perform_all do
+ Oban.Job
+ |> Repo.all()
+ |> perform()
+ end
+
def perform(%Oban.Job{} = job) do
res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
Repo.delete(job)
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index d3a28d50e..e0be4342b 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -249,7 +249,8 @@ defmodule Pleroma.Web.FederatorTest do
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
- assert Federator.incoming_ap_doc(params) == :error
+ assert {:ok, job} = Federator.incoming_ap_doc(params)
+ assert :error = ObanHelpers.perform(job)
Pleroma.Config.put([:instance, :rewrite_policy], policies)
Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
index d28730994..a1bdd45d3 100644
--- a/test/web/instances/instance_test.exs
+++ b/test/web/instances/instance_test.exs
@@ -22,7 +22,8 @@ defmodule Pleroma.Instances.InstanceTest do
describe "set_reachable/1" do
test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
- instance = insert(:instance, unreachable_since: NaiveDateTime.utc_now())
+ unreachable_since = NaiveDateTime.to_iso8601(NaiveDateTime.utc_now())
+ instance = insert(:instance, unreachable_since: unreachable_since)
assert {:ok, instance} = Instance.set_reachable(instance.host)
refute instance.unreachable_since
--
cgit v1.2.3
From 0e1c481a94392b69833fbe6afc184ebbd90e1330 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 13 Aug 2019 20:20:26 +0300
Subject: [#1149] Added more oban workers. Refactoring.
---
test/activity_test.exs | 2 +-
test/conversation_test.exs | 2 +-
test/notification_test.exs | 5 ++-
test/support/oban_helpers.ex | 2 +-
test/user_test.exs | 19 +++++++---
.../activity_pub/activity_pub_controller_test.exs | 2 +-
.../mrf/mediaproxy_warming_policy_test.exs | 6 +++
test/web/activity_pub/transmogrifier_test.exs | 4 ++
test/web/federator_test.exs | 2 +-
test/web/twitter_api/util_controller_test.exs | 43 ++++++++++++----------
test/web/websub/websub_test.exs | 2 +-
11 files changed, 56 insertions(+), 33 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index b9c12adb2..658c47837 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -6,8 +6,8 @@ defmodule Pleroma.ActivityTest do
use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.Bookmark
- alias Pleroma.ObanHelpers
alias Pleroma.Object
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.ThreadMute
import Pleroma.Factory
diff --git a/test/conversation_test.exs b/test/conversation_test.exs
index 2ebbcab76..f917aa691 100644
--- a/test/conversation_test.exs
+++ b/test/conversation_test.exs
@@ -28,7 +28,7 @@ defmodule Pleroma.ConversationTest do
{:ok, _activity} =
CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"})
- Pleroma.ObanHelpers.perform_all()
+ Pleroma.Tests.ObanHelpers.perform_all()
Repo.delete_all(Conversation)
Repo.delete_all(Conversation.Participation)
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 80ea2a085..e1c9f4f93 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.NotificationTest do
import Pleroma.Factory
alias Pleroma.Notification
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
@@ -621,7 +622,8 @@ defmodule Pleroma.NotificationTest do
refute Enum.empty?(Notification.for_user(other_user))
- User.delete(user)
+ {:ok, job} = User.delete(user)
+ ObanHelpers.perform(job)
assert Enum.empty?(Notification.for_user(other_user))
end
@@ -666,6 +668,7 @@ defmodule Pleroma.NotificationTest do
}
{:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
+ ObanHelpers.perform_all()
assert Enum.empty?(Notification.for_user(local_user))
end
diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex
index ecc03ba1a..d379c9ec7 100644
--- a/test/support/oban_helpers.ex
+++ b/test/support/oban_helpers.ex
@@ -2,7 +2,7 @@
# Copyright © 2017-2018 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.ObanHelpers do
+defmodule Pleroma.Tests.ObanHelpers do
@moduledoc """
Oban test helpers.
"""
diff --git a/test/user_test.exs b/test/user_test.exs
index 8617752d7..9c2117a0b 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -5,9 +5,9 @@
defmodule Pleroma.UserTest do
alias Pleroma.Activity
alias Pleroma.Builders.UserBuilder
- alias Pleroma.ObanHelpers
alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
@@ -676,7 +676,9 @@ defmodule Pleroma.UserTest do
user3.nickname
]
- result = User.follow_import(user1, identifiers)
+ {:ok, job} = User.follow_import(user1, identifiers)
+ result = ObanHelpers.perform(job)
+
assert is_list(result)
assert result == [user2, user3]
end
@@ -887,7 +889,9 @@ defmodule Pleroma.UserTest do
user3.nickname
]
- result = User.blocks_import(user1, identifiers)
+ {:ok, job} = User.blocks_import(user1, identifiers)
+ result = ObanHelpers.perform(job)
+
assert is_list(result)
assert result == [user2, user3]
end
@@ -1013,7 +1017,8 @@ defmodule Pleroma.UserTest do
{:ok, like_two, _} = CommonAPI.favorite(activity.id, follower)
{:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
- {:ok, _} = User.delete(user)
+ {:ok, job} = User.delete(user)
+ {:ok, _user} = ObanHelpers.perform(job)
follower = User.get_cached_by_id(follower.id)
@@ -1043,7 +1048,8 @@ defmodule Pleroma.UserTest do
{:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
{:ok, _} = User.follow(follower, user)
- {:ok, _user} = User.delete(user)
+ {:ok, job} = User.delete(user)
+ {:ok, _user} = ObanHelpers.perform(job)
assert ObanHelpers.member?(
%{
@@ -1100,7 +1106,8 @@ defmodule Pleroma.UserTest do
test "User.delete() plugs any possible zombie objects" do
user = insert(:user)
- {:ok, _} = User.delete(user)
+ {:ok, job} = User.delete(user)
+ {:ok, _} = ObanHelpers.perform(job)
{:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index d7f0a8264..f46353fdd 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -9,8 +9,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
import Pleroma.Factory
alias Pleroma.Activity
alias Pleroma.Instances
- alias Pleroma.ObanHelpers
alias Pleroma.Object
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.UserView
diff --git a/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs b/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs
index 372e789be..95a809d25 100644
--- a/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs
+++ b/test/web/activity_pub/mrf/mediaproxy_warming_policy_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
use Pleroma.DataCase
alias Pleroma.HTTP
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
import Mock
@@ -24,6 +25,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
test "it prefetches media proxy URIs" do
with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
MediaProxyWarmingPolicy.filter(@message)
+
+ ObanHelpers.perform_all()
+ # Performing jobs which has been just enqueued
+ ObanHelpers.perform_all()
+
assert called(HTTP.get(:_, :_, :_))
end
end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index e7498e005..52f46c141 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.Object
alias Pleroma.Object.Fetcher
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier
@@ -563,6 +564,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|> Poison.decode!()
{:ok, _} = Transmogrifier.handle_incoming(data)
+ ObanHelpers.perform_all()
refute User.get_cached_by_ap_id(ap_id)
end
@@ -1132,6 +1134,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.info.note_count == 1
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
+ ObanHelpers.perform_all()
+
assert user.info.ap_enabled
assert user.info.note_count == 1
assert user.follower_address == "https://niu.moe/users/rye/followers"
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index e0be4342b..9ca341b6d 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -4,7 +4,7 @@
defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Instances
- alias Pleroma.ObanHelpers
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
alias Pleroma.Workers.Publisher, as: PublisherWorker
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 640579c09..e3f129f72 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -4,9 +4,11 @@
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
use Pleroma.Web.ConnCase
+ use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Notification
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -50,8 +52,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
{File, [],
read!: fn "follow_list.txt" ->
"Account address,Show boosts\n#{user2.ap_id},true"
- end},
- {PleromaJobQueue, [:passthrough], []}
+ end}
]) do
response =
conn
@@ -59,15 +60,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|> post("/api/pleroma/follow_import", %{"list" => %Plug.Upload{path: "follow_list.txt"}})
|> json_response(:ok)
- assert called(
- PleromaJobQueue.enqueue(
- :background,
- User,
- [:follow_import, user1, [user2.ap_id]]
- )
- )
-
assert response == "job started"
+
+ assert ObanHelpers.member?(
+ %{
+ "op" => "follow_import",
+ "follower_id" => user1.id,
+ "followed_identifiers" => [user2.ap_id]
+ },
+ all_enqueued(worker: Pleroma.Workers.BackgroundWorker)
+ )
end
end
@@ -126,8 +128,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user3 = insert(:user)
with_mocks([
- {File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end},
- {PleromaJobQueue, [:passthrough], []}
+ {File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
]) do
response =
conn
@@ -135,15 +136,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|> post("/api/pleroma/blocks_import", %{"list" => %Plug.Upload{path: "blocks_list.txt"}})
|> json_response(:ok)
- assert called(
- PleromaJobQueue.enqueue(
- :background,
- User,
- [:blocks_import, user1, [user2.ap_id, user3.ap_id]]
- )
- )
-
assert response == "job started"
+
+ assert ObanHelpers.member?(
+ %{
+ "op" => "blocks_import",
+ "blocker_id" => user1.id,
+ "blocked_identifiers" => [user2.ap_id, user3.ap_id]
+ },
+ all_enqueued(worker: Pleroma.Workers.BackgroundWorker)
+ )
end
end
end
@@ -607,6 +609,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|> json_response(:ok)
assert response == %{"status" => "success"}
+ ObanHelpers.perform_all()
user = User.get_cached_by_id(user.id)
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index b704a558a..414610879 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
- alias Pleroma.ObanHelpers
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.Router.Helpers
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.WebsubClientSubscription
--
cgit v1.2.3
From a180c1360ecdbed76eccf3435bb2c831356746bc Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Wed, 14 Aug 2019 21:42:21 +0300
Subject: [#1149] Oban mailer job. Adjusted tests.
---
test/mix/tasks/pleroma.digest_test.exs | 3 +++
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 ++++
test/web/twitter_api/twitter_api_controller_test.exs | 4 ++++
test/web/twitter_api/twitter_api_test.exs | 2 ++
4 files changed, 13 insertions(+)
(limited to 'test')
diff --git a/test/mix/tasks/pleroma.digest_test.exs b/test/mix/tasks/pleroma.digest_test.exs
index 595f64ed7..5fbeac0d6 100644
--- a/test/mix/tasks/pleroma.digest_test.exs
+++ b/test/mix/tasks/pleroma.digest_test.exs
@@ -4,6 +4,7 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
import Pleroma.Factory
import Swoosh.TestAssertions
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
setup_all do
@@ -39,6 +40,8 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
:ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
+ ObanHelpers.perform_all()
+
assert_receive {:mix_shell, :info, [message]}
assert message =~ "Digest email have been sent"
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e49c4cc22..be9ff2568 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
@@ -3871,6 +3872,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "it sends an email to user", %{user: user} do
+ ObanHelpers.perform_all()
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
@@ -3934,6 +3936,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/pleroma/accounts/confirmation_resend?email=#{user.email}")
|> json_response(:no_content)
+ ObanHelpers.perform_all()
+
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
notify_email = Pleroma.Config.get([:instance, :notify_email])
instance_name = Pleroma.Config.get([:instance, :name])
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 8bb8aa36d..9ac4ff929 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
@@ -1099,6 +1100,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
test "it sends an email to user", %{user: user} do
+ ObanHelpers.perform_all()
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
@@ -1209,6 +1211,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/account/resend_confirmation_email?email=#{user.email}")
+ ObanHelpers.perform_all()
+
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
notify_email = Pleroma.Config.get([:instance, :notify_email])
instance_name = Pleroma.Config.get([:instance, :name])
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index cbe83852e..bf063a0de 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -321,6 +322,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
+ ObanHelpers.perform_all()
assert user.info.confirmation_pending
--
cgit v1.2.3
From c29686309eaf2cdae039ce813755c0e23cdc4a03 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 23 Aug 2019 09:23:10 +0300
Subject: [#1149] Upgraded `oban` from 0.6.0 to 0.7.1.
---
test/support/oban_helpers.ex | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex
index d379c9ec7..989770926 100644
--- a/test/support/oban_helpers.ex
+++ b/test/support/oban_helpers.ex
@@ -16,7 +16,7 @@ defmodule Pleroma.Tests.ObanHelpers do
end
def perform(%Oban.Job{} = job) do
- res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
+ res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job.args, job])
Repo.delete(job)
res
end
--
cgit v1.2.3
From 71700ea6d4104ecd2cc0afb0ac103e722b30fbb5 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 24 Aug 2019 09:27:32 +0300
Subject: [#1149] Updated docs & tests.
---
test/web/admin_api/admin_api_controller_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 844cd0732..a867ac998 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1861,7 +1861,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
post(conn, "/api/pleroma/admin/config", %{
configs: [
%{
- "group" => "pleroma_job_queue",
+ "group" => "oban",
"key" => ":queues",
"value" => [
%{"tuple" => [":federator_incoming", 50]},
@@ -1879,7 +1879,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, 200) == %{
"configs" => [
%{
- "group" => "pleroma_job_queue",
+ "group" => "oban",
"key" => ":queues",
"value" => [
%{"tuple" => [":federator_incoming", 50]},
--
cgit v1.2.3
From 45e21a9df4a7b58d28624534fdde3dc9e31c6813 Mon Sep 17 00:00:00 2001
From: kPherox
Date: Sun, 25 Aug 2019 06:51:05 +0900
Subject: Rename fields to fields_attributes
---
.../mastodon_api_controller/update_credentials_test.exs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index 87ee82050..b1a5c2aea 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -313,7 +313,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
account =
conn
|> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(200)
assert account["fields"] == [
@@ -339,7 +339,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert %{"error" => "Invalid request"} ==
conn
|> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
@@ -349,7 +349,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert %{"error" => "Invalid request"} ==
conn
|> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
Pleroma.Config.put([:instance, :max_account_fields], 1)
@@ -362,7 +362,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert %{"error" => "Invalid request"} ==
conn
|> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
end
end
--
cgit v1.2.3
From b8777b01aeb4656e74437c1ac4916d2fcbe7f39e Mon Sep 17 00:00:00 2001
From: kPherox
Date: Mon, 26 Aug 2019 03:25:06 +0900
Subject: Update test for custom fields when name empty string
---
.../mastodon_api_controller/update_credentials_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index b1a5c2aea..21dae98fa 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -364,6 +364,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
+
+ fields = [
+ %{"name" => "foo", "value" => ""},
+ %{"name" => "", "value" => "bar"}
+ ]
+
+ account =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
+ |> json_response(200)
+
+ assert account["fields"] == [
+ %{"name" => "foo", "value" => ""}
+ ]
end
end
end
--
cgit v1.2.3
From eb75ea502d9c608ef892feeda02fa49578e9c369 Mon Sep 17 00:00:00 2001
From: kPherox
Date: Mon, 26 Aug 2019 03:49:47 +0900
Subject: Update test for custom fields when content-type urlencoded
---
.../update_credentials_test.exs | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index 21dae98fa..56a8f1716 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -329,6 +329,35 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
%{"name" => "link", "value" => "cofe.io"}
]
+ fields =
+ [
+ "fields_attributes[1][name]=link",
+ "fields_attributes[1][value]=cofe.io",
+ "fields_attributes[0][name]=foo",
+ "fields_attributes[0][value]=bar"
+ ]
+ |> Enum.join("&")
+
+ account =
+ conn
+ |> put_req_header("content-type", "application/x-www-form-urlencoded")
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", fields)
+ |> json_response(200)
+
+ assert account["fields"] == [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ assert account["source"]["fields"] == [
+ %{
+ "name" => "foo",
+ "value" => "bar"
+ },
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
--
cgit v1.2.3
From eb1739c59699754297149c92ea3d03ec688ae16a Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Tue, 27 Aug 2019 12:29:19 +0300
Subject: Remove most of TwitterAPIController
---
.../twitter_api/twitter_api_controller_test.exs | 2150 --------------------
1 file changed, 2150 deletions(-)
delete mode 100644 test/web/twitter_api/twitter_api_controller_test.exs
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
deleted file mode 100644
index 8ef14b4c5..000000000
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ /dev/null
@@ -1,2150 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.TwitterAPI.ControllerTest do
- use Pleroma.Web.ConnCase
- alias Comeonin.Pbkdf2
- alias Ecto.Changeset
- alias Pleroma.Activity
- alias Pleroma.Builders.ActivityBuilder
- alias Pleroma.Builders.UserBuilder
- alias Pleroma.Notification
- alias Pleroma.Object
- alias Pleroma.Repo
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.OAuth.Token
- alias Pleroma.Web.TwitterAPI.ActivityView
- alias Pleroma.Web.TwitterAPI.Controller
- alias Pleroma.Web.TwitterAPI.NotificationView
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.TwitterAPI.UserView
-
- import Mock
- import Pleroma.Factory
- import Swoosh.TestAssertions
-
- @banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
-
- describe "POST /api/account/update_profile_banner" do
- test "it updates the banner", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => @banner})
- |> json_response(200)
-
- user = refresh_record(user)
- assert user.info.banner["type"] == "Image"
- end
-
- test "profile banner can be reset", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => ""})
- |> json_response(200)
-
- user = refresh_record(user)
- assert user.info.banner == %{}
- end
- end
-
- describe "POST /api/qvitter/update_background_image" do
- test "it updates the background", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => @banner})
- |> json_response(200)
-
- user = refresh_record(user)
- assert user.info.background["type"] == "Image"
- end
-
- test "background can be reset", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => ""})
- |> json_response(200)
-
- user = refresh_record(user)
- assert user.info.background == %{}
- end
- end
-
- describe "POST /api/account/verify_credentials" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/account/verify_credentials.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: user} do
- response =
- conn
- |> with_credentials(user.nickname, "test")
- |> post("/api/account/verify_credentials.json")
- |> json_response(200)
-
- assert response ==
- UserView.render("show.json", %{user: user, token: response["token"], for: user})
- end
- end
-
- describe "POST /statuses/update.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/statuses/update.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: user} do
- conn_with_creds = conn |> with_credentials(user.nickname, "test")
- request_path = "/api/statuses/update.json"
-
- error_response = %{
- "request" => request_path,
- "error" => "Client must provide a 'status' parameter with a value."
- }
-
- conn =
- conn_with_creds
- |> post(request_path)
-
- assert json_response(conn, 400) == error_response
-
- conn =
- conn_with_creds
- |> post(request_path, %{status: ""})
-
- assert json_response(conn, 400) == error_response
-
- conn =
- conn_with_creds
- |> post(request_path, %{status: " "})
-
- assert json_response(conn, 400) == error_response
-
- # we post with visibility private in order to avoid triggering relay
- conn =
- conn_with_creds
- |> post(request_path, %{status: "Nice meme.", visibility: "private"})
-
- assert json_response(conn, 200) ==
- ActivityView.render("activity.json", %{
- activity: Repo.one(Activity),
- user: user,
- for: user
- })
- end
- end
-
- describe "GET /statuses/public_timeline.json" do
- setup [:valid_user]
- clear_config([:instance, :public])
-
- test "returns statuses", %{conn: conn} do
- user = insert(:user)
- activities = ActivityBuilder.insert_list(30, %{}, %{user: user})
- ActivityBuilder.insert_list(10, %{}, %{user: user})
- since_id = List.last(activities).id
-
- conn =
- conn
- |> get("/api/statuses/public_timeline.json", %{since_id: since_id})
-
- response = json_response(conn, 200)
-
- assert length(response) == 10
- end
-
- test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
- Pleroma.Config.put([:instance, :public], false)
-
- conn
- |> get("/api/statuses/public_timeline.json")
- |> json_response(403)
- end
-
- test "returns 200 to authenticated request when the instance is not public",
- %{conn: conn, user: user} do
- Pleroma.Config.put([:instance, :public], false)
-
- conn
- |> with_credentials(user.nickname, "test")
- |> get("/api/statuses/public_timeline.json")
- |> json_response(200)
- end
-
- test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
- conn
- |> get("/api/statuses/public_timeline.json")
- |> json_response(200)
- end
-
- test "returns 200 to authenticated request when the instance is public",
- %{conn: conn, user: user} do
- conn
- |> with_credentials(user.nickname, "test")
- |> get("/api/statuses/public_timeline.json")
- |> json_response(200)
- end
-
- test_with_mock "treats user as unauthenticated if `assigns[:token]` is present but lacks `read` permission",
- Controller,
- [:passthrough],
- [] do
- token = insert(:oauth_token, scopes: ["write"])
-
- build_conn()
- |> put_req_header("authorization", "Bearer #{token.token}")
- |> get("/api/statuses/public_timeline.json")
- |> json_response(200)
-
- assert called(Controller.public_timeline(%{assigns: %{user: nil}}, :_))
- end
- end
-
- describe "GET /statuses/public_and_external_timeline.json" do
- setup [:valid_user]
- clear_config([:instance, :public])
-
- test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
- Pleroma.Config.put([:instance, :public], false)
-
- conn
- |> get("/api/statuses/public_and_external_timeline.json")
- |> json_response(403)
- end
-
- test "returns 200 to authenticated request when the instance is not public",
- %{conn: conn, user: user} do
- Pleroma.Config.put([:instance, :public], false)
-
- conn
- |> with_credentials(user.nickname, "test")
- |> get("/api/statuses/public_and_external_timeline.json")
- |> json_response(200)
- end
-
- test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
- conn
- |> get("/api/statuses/public_and_external_timeline.json")
- |> json_response(200)
- end
-
- test "returns 200 to authenticated request when the instance is public",
- %{conn: conn, user: user} do
- conn
- |> with_credentials(user.nickname, "test")
- |> get("/api/statuses/public_and_external_timeline.json")
- |> json_response(200)
- end
- end
-
- describe "GET /statuses/show/:id.json" do
- test "returns one status", %{conn: conn} do
- user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
- actor = User.get_cached_by_ap_id(activity.data["actor"])
-
- conn =
- conn
- |> get("/api/statuses/show/#{activity.id}.json")
-
- response = json_response(conn, 200)
-
- assert response == ActivityView.render("activity.json", %{activity: activity, user: actor})
- end
- end
-
- describe "GET /users/show.json" do
- test "gets user with screen_name", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> get("/api/users/show.json", %{"screen_name" => user.nickname})
-
- response = json_response(conn, 200)
-
- assert response["id"] == user.id
- end
-
- test "gets user with user_id", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> get("/api/users/show.json", %{"user_id" => user.id})
-
- response = json_response(conn, 200)
-
- assert response["id"] == user.id
- end
-
- test "gets a user for a logged in user", %{conn: conn} do
- user = insert(:user)
- logged_in = insert(:user)
-
- {:ok, logged_in, user, _activity} = TwitterAPI.follow(logged_in, %{"user_id" => user.id})
-
- conn =
- conn
- |> with_credentials(logged_in.nickname, "test")
- |> get("/api/users/show.json", %{"user_id" => user.id})
-
- response = json_response(conn, 200)
-
- assert response["following"] == true
- end
- end
-
- describe "GET /statusnet/conversation/:id.json" do
- test "returns the statuses in the conversation", %{conn: conn} do
- {:ok, _user} = UserBuilder.insert()
- {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
- {:ok, _activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
- {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
-
- conn =
- conn
- |> get("/api/statusnet/conversation/#{activity.data["context_id"]}.json")
-
- response = json_response(conn, 200)
-
- assert length(response) == 2
- end
- end
-
- describe "GET /statuses/friends_timeline.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = get(conn, "/api/statuses/friends_timeline.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- user = insert(:user)
-
- activities =
- ActivityBuilder.insert_list(30, %{"to" => [User.ap_followers(user)]}, %{user: user})
-
- returned_activities =
- ActivityBuilder.insert_list(10, %{"to" => [User.ap_followers(user)]}, %{user: user})
-
- other_user = insert(:user)
- ActivityBuilder.insert_list(10, %{}, %{user: other_user})
- since_id = List.last(activities).id
-
- current_user =
- Changeset.change(current_user, following: [User.ap_followers(user)])
- |> Repo.update!()
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/friends_timeline.json", %{since_id: since_id})
-
- response = json_response(conn, 200)
-
- assert length(response) == 10
-
- assert response ==
- Enum.map(returned_activities, fn activity ->
- ActivityView.render("activity.json", %{
- activity: activity,
- user: User.get_cached_by_ap_id(activity.data["actor"]),
- for: current_user
- })
- end)
- end
- end
-
- describe "GET /statuses/dm_timeline.json" do
- test "it show direct messages", %{conn: conn} do
- user_one = insert(:user)
- user_two = insert(:user)
-
- {:ok, user_two} = User.follow(user_two, user_one)
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
- })
-
- {:ok, direct_two} =
- CommonAPI.post(user_two, %{
- "status" => "Hi @#{user_one.nickname}!",
- "visibility" => "direct"
- })
-
- {:ok, _follower_only} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "private"
- })
-
- # Only direct should be visible here
- res_conn =
- conn
- |> assign(:user, user_two)
- |> get("/api/statuses/dm_timeline.json")
-
- [status, status_two] = json_response(res_conn, 200)
- assert status["id"] == direct_two.id
- assert status_two["id"] == direct.id
- end
-
- test "doesn't include DMs from blocked users", %{conn: conn} do
- blocker = insert(:user)
- blocked = insert(:user)
- user = insert(:user)
- {:ok, blocker} = User.block(blocker, blocked)
-
- {:ok, _blocked_direct} =
- CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}!",
- "visibility" => "direct"
- })
-
- {:ok, direct} =
- CommonAPI.post(user, %{
- "status" => "Hi @#{blocker.nickname}!",
- "visibility" => "direct"
- })
-
- res_conn =
- conn
- |> assign(:user, blocker)
- |> get("/api/statuses/dm_timeline.json")
-
- [status] = json_response(res_conn, 200)
- assert status["id"] == direct.id
- end
- end
-
- describe "GET /statuses/mentions.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = get(conn, "/api/statuses/mentions.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- {:ok, activity} =
- CommonAPI.post(current_user, %{
- "status" => "why is tenshi eating a corndog so cute?",
- "visibility" => "public"
- })
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/mentions.json")
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{
- user: current_user,
- for: current_user,
- activity: activity
- })
- end
-
- test "does not show DMs in mentions timeline", %{conn: conn, user: current_user} do
- {:ok, _activity} =
- CommonAPI.post(current_user, %{
- "status" => "Have you guys ever seen how cute tenshi eating a corndog is?",
- "visibility" => "direct"
- })
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/mentions.json")
-
- response = json_response(conn, 200)
-
- assert Enum.empty?(response)
- end
- end
-
- describe "GET /api/qvitter/statuses/notifications.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = get(conn, "/api/qvitter/statuses/notifications.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- other_user = insert(:user)
-
- {:ok, _activity} =
- ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/qvitter/statuses/notifications.json")
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert response ==
- NotificationView.render("notification.json", %{
- notifications: Notification.for_user(current_user),
- for: current_user
- })
- end
-
- test "muted user", %{conn: conn, user: current_user} do
- other_user = insert(:user)
-
- {:ok, current_user} = User.mute(current_user, other_user)
-
- {:ok, _activity} =
- ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/qvitter/statuses/notifications.json")
-
- assert json_response(conn, 200) == []
- end
-
- test "muted user with with_muted parameter", %{conn: conn, user: current_user} do
- other_user = insert(:user)
-
- {:ok, current_user} = User.mute(current_user, other_user)
-
- {:ok, _activity} =
- ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/qvitter/statuses/notifications.json", %{"with_muted" => "true"})
-
- assert length(json_response(conn, 200)) == 1
- end
- end
-
- describe "POST /api/qvitter/statuses/notifications/read" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials, without any params", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/qvitter/statuses/notifications/read")
-
- assert json_response(conn, 400) == %{
- "error" => "You need to specify latest_id",
- "request" => "/api/qvitter/statuses/notifications/read"
- }
- end
-
- test "with credentials, with params", %{conn: conn, user: current_user} do
- other_user = insert(:user)
-
- {:ok, _activity} =
- ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
-
- response_conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/qvitter/statuses/notifications.json")
-
- [notification] = response = json_response(response_conn, 200)
-
- assert length(response) == 1
-
- assert notification["is_seen"] == 0
-
- response_conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
-
- [notification] = response = json_response(response_conn, 200)
-
- assert length(response) == 1
-
- assert notification["is_seen"] == 1
- end
- end
-
- describe "GET /statuses/user_timeline.json" do
- setup [:valid_user]
-
- test "without any params", %{conn: conn} do
- conn = get(conn, "/api/statuses/user_timeline.json")
-
- assert json_response(conn, 400) == %{
- "error" => "You need to specify screen_name or user_id",
- "request" => "/api/statuses/user_timeline.json"
- }
- end
-
- test "with user_id", %{conn: conn} do
- user = insert(:user)
- {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
-
- conn = get(conn, "/api/statuses/user_timeline.json", %{"user_id" => user.id})
- response = json_response(conn, 200)
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{user: user, activity: activity})
- end
-
- test "with screen_name", %{conn: conn} do
- user = insert(:user)
- {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
-
- conn = get(conn, "/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
- response = json_response(conn, 200)
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{user: user, activity: activity})
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: current_user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/user_timeline.json")
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{
- user: current_user,
- for: current_user,
- activity: activity
- })
- end
-
- test "with credentials with user_id", %{conn: conn, user: current_user} do
- user = insert(:user)
- {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/user_timeline.json", %{"user_id" => user.id})
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{user: user, activity: activity})
- end
-
- test "with credentials screen_name", %{conn: conn, user: current_user} do
- user = insert(:user)
- {:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{user: user, activity: activity})
- end
-
- test "with credentials with user_id, excluding RTs", %{conn: conn, user: current_user} do
- user = insert(:user)
- {:ok, activity} = ActivityBuilder.insert(%{"id" => 1, "type" => "Create"}, %{user: user})
- {:ok, _} = ActivityBuilder.insert(%{"id" => 2, "type" => "Announce"}, %{user: user})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/statuses/user_timeline.json", %{
- "user_id" => user.id,
- "include_rts" => "false"
- })
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{user: user, activity: activity})
-
- conn =
- conn
- |> get("/api/statuses/user_timeline.json", %{"user_id" => user.id, "include_rts" => "0"})
-
- response = json_response(conn, 200)
-
- assert length(response) == 1
-
- assert Enum.at(response, 0) ==
- ActivityView.render("activity.json", %{user: user, activity: activity})
- end
- end
-
- describe "POST /friendships/create.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/friendships/create.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- followed = insert(:user)
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/friendships/create.json", %{user_id: followed.id})
-
- current_user = User.get_cached_by_id(current_user.id)
- assert User.ap_followers(followed) in current_user.following
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: followed, for: current_user})
- end
-
- test "for restricted account", %{conn: conn, user: current_user} do
- followed = insert(:user, info: %User.Info{locked: true})
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/friendships/create.json", %{user_id: followed.id})
-
- current_user = User.get_cached_by_id(current_user.id)
- followed = User.get_cached_by_id(followed.id)
-
- refute User.ap_followers(followed) in current_user.following
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: followed, for: current_user})
- end
- end
-
- describe "POST /friendships/destroy.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/friendships/destroy.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- followed = insert(:user)
-
- {:ok, current_user} = User.follow(current_user, followed)
- assert User.ap_followers(followed) in current_user.following
- ActivityPub.follow(current_user, followed)
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/friendships/destroy.json", %{user_id: followed.id})
-
- current_user = User.get_cached_by_id(current_user.id)
- assert current_user.following == [current_user.ap_id]
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: followed, for: current_user})
- end
- end
-
- describe "POST /blocks/create.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/blocks/create.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- blocked = insert(:user)
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/blocks/create.json", %{user_id: blocked.id})
-
- current_user = User.get_cached_by_id(current_user.id)
- assert User.blocks?(current_user, blocked)
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: blocked, for: current_user})
- end
- end
-
- describe "POST /blocks/destroy.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/blocks/destroy.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- blocked = insert(:user)
-
- {:ok, current_user, blocked} = TwitterAPI.block(current_user, %{"user_id" => blocked.id})
- assert User.blocks?(current_user, blocked)
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/blocks/destroy.json", %{user_id: blocked.id})
-
- current_user = User.get_cached_by_id(current_user.id)
- assert current_user.info.blocks == []
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: blocked, for: current_user})
- end
- end
-
- describe "GET /help/test.json" do
- test "returns \"ok\"", %{conn: conn} do
- conn = get(conn, "/api/help/test.json")
- assert json_response(conn, 200) == "ok"
- end
- end
-
- describe "POST /api/qvitter/update_avatar.json" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/qvitter/update_avatar.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- avatar_image = File.read!("test/fixtures/avatar_data_uri")
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
-
- current_user = User.get_cached_by_id(current_user.id)
- assert is_map(current_user.avatar)
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: current_user, for: current_user})
- end
-
- test "user avatar can be reset", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/qvitter/update_avatar.json", %{img: ""})
-
- current_user = User.get_cached_by_id(current_user.id)
- assert current_user.avatar == nil
-
- assert json_response(conn, 200) ==
- UserView.render("show.json", %{user: current_user, for: current_user})
- end
- end
-
- describe "GET /api/qvitter/mutes.json" do
- setup [:valid_user]
-
- test "unimplemented mutes without valid credentials", %{conn: conn} do
- conn = get(conn, "/api/qvitter/mutes.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
- response =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> get("/api/qvitter/mutes.json")
- |> json_response(200)
-
- assert [] = response
- end
- end
-
- describe "POST /api/favorites/create/:id" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = post(conn, "/api/favorites/create/#{note_activity.id}.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- note_activity = insert(:note_activity)
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/favorites/create/#{note_activity.id}.json")
-
- assert json_response(conn, 200)
- end
-
- test "with credentials, invalid param", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/favorites/create/wrong.json")
-
- assert json_response(conn, 400)
- end
-
- test "with credentials, invalid activity", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/favorites/create/1.json")
-
- assert json_response(conn, 400)
- end
- end
-
- describe "POST /api/favorites/destroy/:id" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = post(conn, "/api/favorites/destroy/#{note_activity.id}.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
- ActivityPub.like(current_user, object)
-
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/favorites/destroy/#{note_activity.id}.json")
-
- assert json_response(conn, 200)
- end
- end
-
- describe "POST /api/statuses/retweet/:id" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = post(conn, "/api/statuses/retweet/#{note_activity.id}.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- note_activity = insert(:note_activity)
-
- request_path = "/api/statuses/retweet/#{note_activity.id}.json"
-
- response =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post(request_path)
-
- activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- assert json_response(response, 200) ==
- ActivityView.render("activity.json", %{
- user: activity_user,
- for: current_user,
- activity: activity
- })
- end
- end
-
- describe "POST /api/statuses/unretweet/:id" do
- setup [:valid_user]
-
- test "without valid credentials", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = post(conn, "/api/statuses/unretweet/#{note_activity.id}.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: current_user} do
- note_activity = insert(:note_activity)
-
- request_path = "/api/statuses/retweet/#{note_activity.id}.json"
-
- _response =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post(request_path)
-
- request_path = String.replace(request_path, "retweet", "unretweet")
-
- response =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post(request_path)
-
- activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- assert json_response(response, 200) ==
- ActivityView.render("activity.json", %{
- user: activity_user,
- for: current_user,
- activity: activity
- })
- end
- end
-
- describe "POST /api/account/register" do
- test "it creates a new user", %{conn: conn} do
- data = %{
- "nickname" => "lain",
- "email" => "lain@wired.jp",
- "fullname" => "lain iwakura",
- "bio" => "close the world.",
- "password" => "bear",
- "confirm" => "bear"
- }
-
- conn =
- conn
- |> post("/api/account/register", data)
-
- user = json_response(conn, 200)
-
- fetched_user = User.get_cached_by_nickname("lain")
- assert user == UserView.render("show.json", %{user: fetched_user})
- end
-
- test "it returns errors on a problem", %{conn: conn} do
- data = %{
- "email" => "lain@wired.jp",
- "fullname" => "lain iwakura",
- "bio" => "close the world.",
- "password" => "bear",
- "confirm" => "bear"
- }
-
- conn =
- conn
- |> post("/api/account/register", data)
-
- errors = json_response(conn, 400)
-
- assert is_binary(errors["error"])
- end
- end
-
- describe "POST /api/account/password_reset, with valid parameters" do
- setup %{conn: conn} do
- user = insert(:user)
- conn = post(conn, "/api/account/password_reset?email=#{user.email}")
- %{conn: conn, user: user}
- end
-
- test "it returns 204", %{conn: conn} do
- assert json_response(conn, :no_content)
- end
-
- test "it creates a PasswordResetToken record for user", %{user: user} do
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
- assert token_record
- end
-
- test "it sends an email to user", %{user: user} do
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
-
- email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
- notify_email = Pleroma.Config.get([:instance, :notify_email])
- instance_name = Pleroma.Config.get([:instance, :name])
-
- assert_email_sent(
- from: {instance_name, notify_email},
- to: {user.name, user.email},
- html_body: email.html_body
- )
- end
- end
-
- describe "POST /api/account/password_reset, with invalid parameters" do
- setup [:valid_user]
-
- test "it returns 404 when user is not found", %{conn: conn, user: user} do
- conn = post(conn, "/api/account/password_reset?email=nonexisting_#{user.email}")
- assert conn.status == 404
- assert conn.resp_body == ""
- end
-
- test "it returns 400 when user is not local", %{conn: conn, user: user} do
- {:ok, user} = Repo.update(Changeset.change(user, local: false))
- conn = post(conn, "/api/account/password_reset?email=#{user.email}")
- assert conn.status == 400
- assert conn.resp_body == ""
- end
- end
-
- describe "GET /api/account/confirm_email/:id/:token" do
- setup do
- user = insert(:user)
- info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
-
- {:ok, user} =
- user
- |> Changeset.change()
- |> Changeset.put_embed(:info, info_change)
- |> Repo.update()
-
- assert user.info.confirmation_pending
-
- [user: user]
- end
-
- test "it redirects to root url", %{conn: conn, user: user} do
- conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
-
- assert 302 == conn.status
- end
-
- test "it confirms the user account", %{conn: conn, user: user} do
- get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
-
- user = User.get_cached_by_id(user.id)
-
- refute user.info.confirmation_pending
- refute user.info.confirmation_token
- end
-
- test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
- conn = get(conn, "/api/account/confirm_email/0/#{user.info.confirmation_token}")
-
- assert 500 == conn.status
- end
-
- test "it returns 500 if token is invalid", %{conn: conn, user: user} do
- conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
-
- assert 500 == conn.status
- end
- end
-
- describe "POST /api/account/resend_confirmation_email" do
- setup do
- user = insert(:user)
- info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
-
- {:ok, user} =
- user
- |> Changeset.change()
- |> Changeset.put_embed(:info, info_change)
- |> Repo.update()
-
- assert user.info.confirmation_pending
-
- [user: user]
- end
-
- clear_config([:instance, :account_activation_required]) do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- end
-
- test "it returns 204 No Content", %{conn: conn, user: user} do
- conn
- |> assign(:user, user)
- |> post("/api/account/resend_confirmation_email?email=#{user.email}")
- |> json_response(:no_content)
- end
-
- test "it sends confirmation email", %{conn: conn, user: user} do
- conn
- |> assign(:user, user)
- |> post("/api/account/resend_confirmation_email?email=#{user.email}")
-
- email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
- notify_email = Pleroma.Config.get([:instance, :notify_email])
- instance_name = Pleroma.Config.get([:instance, :name])
-
- assert_email_sent(
- from: {instance_name, notify_email},
- to: {user.name, user.email},
- html_body: email.html_body
- )
- end
- end
-
- describe "GET /api/externalprofile/show" do
- test "it returns the user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
-
- assert json_response(conn, 200) == UserView.render("show.json", %{user: other_user})
- end
- end
-
- describe "GET /api/statuses/followers" do
- test "it returns a user's followers", %{conn: conn} do
- user = insert(:user)
- follower_one = insert(:user)
- follower_two = insert(:user)
- _not_follower = insert(:user)
-
- {:ok, follower_one} = User.follow(follower_one, user)
- {:ok, follower_two} = User.follow(follower_two, user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/followers")
-
- expected = UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
- result = json_response(conn, 200)
- assert Enum.sort(expected) == Enum.sort(result)
- end
-
- test "it returns 20 followers per page", %{conn: conn} do
- user = insert(:user)
- followers = insert_list(21, :user)
-
- Enum.each(followers, fn follower ->
- User.follow(follower, user)
- end)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/followers")
-
- result = json_response(res_conn, 200)
- assert length(result) == 20
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/followers?page=2")
-
- result = json_response(res_conn, 200)
- assert length(result) == 1
- end
-
- test "it returns a given user's followers with user_id", %{conn: conn} do
- user = insert(:user)
- follower_one = insert(:user)
- follower_two = insert(:user)
- not_follower = insert(:user)
-
- {:ok, follower_one} = User.follow(follower_one, user)
- {:ok, follower_two} = User.follow(follower_two, user)
-
- conn =
- conn
- |> assign(:user, not_follower)
- |> get("/api/statuses/followers", %{"user_id" => user.id})
-
- assert MapSet.equal?(
- MapSet.new(json_response(conn, 200)),
- MapSet.new(
- UserView.render("index.json", %{
- users: [follower_one, follower_two],
- for: not_follower
- })
- )
- )
- end
-
- test "it returns empty when hide_followers is set to true", %{conn: conn} do
- user = insert(:user, %{info: %{hide_followers: true}})
- follower_one = insert(:user)
- follower_two = insert(:user)
- not_follower = insert(:user)
-
- {:ok, _follower_one} = User.follow(follower_one, user)
- {:ok, _follower_two} = User.follow(follower_two, user)
-
- response =
- conn
- |> assign(:user, not_follower)
- |> get("/api/statuses/followers", %{"user_id" => user.id})
- |> json_response(200)
-
- assert [] == response
- end
-
- test "it returns the followers when hide_followers is set to true if requested by the user themselves",
- %{
- conn: conn
- } do
- user = insert(:user, %{info: %{hide_followers: true}})
- follower_one = insert(:user)
- follower_two = insert(:user)
- _not_follower = insert(:user)
-
- {:ok, _follower_one} = User.follow(follower_one, user)
- {:ok, _follower_two} = User.follow(follower_two, user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/followers", %{"user_id" => user.id})
-
- refute [] == json_response(conn, 200)
- end
- end
-
- describe "GET /api/statuses/blocks" do
- test "it returns the list of users blocked by requester", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, user} = User.block(user, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/blocks")
-
- expected = UserView.render("index.json", %{users: [other_user], for: user})
- result = json_response(conn, 200)
- assert Enum.sort(expected) == Enum.sort(result)
- end
- end
-
- describe "GET /api/statuses/friends" do
- test "it returns the logged in user's friends", %{conn: conn} do
- user = insert(:user)
- followed_one = insert(:user)
- followed_two = insert(:user)
- _not_followed = insert(:user)
-
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends")
-
- expected = UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
- result = json_response(conn, 200)
- assert Enum.sort(expected) == Enum.sort(result)
- end
-
- test "it returns 20 friends per page, except if 'export' is set to true", %{conn: conn} do
- user = insert(:user)
- followeds = insert_list(21, :user)
-
- {:ok, user} =
- Enum.reduce(followeds, {:ok, user}, fn followed, {:ok, user} ->
- User.follow(user, followed)
- end)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends")
-
- result = json_response(res_conn, 200)
- assert length(result) == 20
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends", %{page: 2})
-
- result = json_response(res_conn, 200)
- assert length(result) == 1
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends", %{all: true})
-
- result = json_response(res_conn, 200)
- assert length(result) == 21
- end
-
- test "it returns a given user's friends with user_id", %{conn: conn} do
- user = insert(:user)
- followed_one = insert(:user)
- followed_two = insert(:user)
- _not_followed = insert(:user)
-
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends", %{"user_id" => user.id})
-
- assert MapSet.equal?(
- MapSet.new(json_response(conn, 200)),
- MapSet.new(
- UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
- )
- )
- end
-
- test "it returns empty when hide_follows is set to true", %{conn: conn} do
- user = insert(:user, %{info: %{hide_follows: true}})
- followed_one = insert(:user)
- followed_two = insert(:user)
- not_followed = insert(:user)
-
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
-
- conn =
- conn
- |> assign(:user, not_followed)
- |> get("/api/statuses/friends", %{"user_id" => user.id})
-
- assert [] == json_response(conn, 200)
- end
-
- test "it returns friends when hide_follows is set to true if the user themselves request it",
- %{
- conn: conn
- } do
- user = insert(:user, %{info: %{hide_follows: true}})
- followed_one = insert(:user)
- followed_two = insert(:user)
- _not_followed = insert(:user)
-
- {:ok, _user} = User.follow(user, followed_one)
- {:ok, _user} = User.follow(user, followed_two)
-
- response =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends", %{"user_id" => user.id})
- |> json_response(200)
-
- refute [] == response
- end
-
- test "it returns a given user's friends with screen_name", %{conn: conn} do
- user = insert(:user)
- followed_one = insert(:user)
- followed_two = insert(:user)
- _not_followed = insert(:user)
-
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/statuses/friends", %{"screen_name" => user.nickname})
-
- assert MapSet.equal?(
- MapSet.new(json_response(conn, 200)),
- MapSet.new(
- UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
- )
- )
- end
- end
-
- describe "GET /friends/ids" do
- test "it returns a user's friends", %{conn: conn} do
- user = insert(:user)
- followed_one = insert(:user)
- followed_two = insert(:user)
- _not_followed = insert(:user)
-
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/friends/ids")
-
- expected = [followed_one.id, followed_two.id]
-
- assert MapSet.equal?(
- MapSet.new(Poison.decode!(json_response(conn, 200))),
- MapSet.new(expected)
- )
- end
- end
-
- describe "POST /api/account/update_profile.json" do
- test "it updates a user's profile", %{conn: conn} do
- user = insert(:user)
- user2 = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "name" => "new name",
- "description" => "hi @#{user2.nickname}"
- })
-
- user = Repo.get!(User, user.id)
- assert user.name == "new name"
-
- assert user.bio ==
- "hi @#{user2.nickname}"
-
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- test "it sets and un-sets hide_follows", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "hide_follows" => "true"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.hide_follows == true
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "hide_follows" => "false"
- })
-
- user = refresh_record(user)
- assert user.info.hide_follows == false
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- test "it sets and un-sets hide_followers", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "hide_followers" => "true"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.hide_followers == true
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "hide_followers" => "false"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.hide_followers == false
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- test "it sets and un-sets show_role", %{conn: conn} do
- user = insert(:user)
-
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "show_role" => "true"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.show_role == true
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "show_role" => "false"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.show_role == false
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- test "it sets and un-sets skip_thread_containment", %{conn: conn} do
- user = insert(:user)
-
- response =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "true"})
- |> json_response(200)
-
- assert response["pleroma"]["skip_thread_containment"] == true
- user = refresh_record(user)
- assert user.info.skip_thread_containment
-
- response =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "false"})
- |> json_response(200)
-
- assert response["pleroma"]["skip_thread_containment"] == false
- refute refresh_record(user).info.skip_thread_containment
- end
-
- test "it locks an account", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "locked" => "true"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.locked == true
-
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- test "it unlocks an account", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "locked" => "false"
- })
-
- user = Repo.get!(User, user.id)
- assert user.info.locked == false
-
- assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
- end
-
- # Broken before the change to class="emoji" and non-
in the DB
- @tag :skip
- test "it formats emojos", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "bio" => "I love our :moominmamma:"
- })
-
- assert response = json_response(conn, 200)
-
- assert %{
- "description" => "I love our :moominmamma:",
- "description_html" =>
- ~s{I love our
Base.encode64("#{username}:#{password}")
- put_req_header(conn, "authorization", header_content)
- end
-
- describe "GET /api/search.json" do
- test "it returns search results", %{conn: conn} do
- user = insert(:user)
- user_two = insert(:user, %{nickname: "shp@shitposter.club"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
- {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
-
- conn =
- conn
- |> get("/api/search.json", %{"q" => "2hu", "page" => "1", "rpp" => "1"})
-
- assert [status] = json_response(conn, 200)
- assert status["id"] == activity.id
- end
- end
-
- describe "GET /api/statusnet/tags/timeline/:tag.json" do
- test "it returns the tags timeline", %{conn: conn} do
- user = insert(:user)
- user_two = insert(:user, %{nickname: "shp@shitposter.club"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about #2hu"})
- {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
-
- conn =
- conn
- |> get("/api/statusnet/tags/timeline/2hu.json")
-
- assert [status] = json_response(conn, 200)
- assert status["id"] == activity.id
- end
- end
-
- test "Convert newlines to
in bio", %{conn: conn} do
- user = insert(:user)
-
- _conn =
- conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{
- "description" => "Hello,\r\nWorld! I\n am a test."
- })
-
- user = Repo.get!(User, user.id)
- assert user.bio == "Hello,
World! I
am a test."
- end
-
- describe "POST /api/pleroma/change_password" do
- setup [:valid_user]
-
- test "without credentials", %{conn: conn} do
- conn = post(conn, "/api/pleroma/change_password")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials and invalid password", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/pleroma/change_password", %{
- "password" => "hi",
- "new_password" => "newpass",
- "new_password_confirmation" => "newpass"
- })
-
- assert json_response(conn, 200) == %{"error" => "Invalid password."}
- end
-
- test "with credentials, valid password and new password and confirmation not matching", %{
- conn: conn,
- user: current_user
- } do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/pleroma/change_password", %{
- "password" => "test",
- "new_password" => "newpass",
- "new_password_confirmation" => "notnewpass"
- })
-
- assert json_response(conn, 200) == %{
- "error" => "New password does not match confirmation."
- }
- end
-
- test "with credentials, valid password and invalid new password", %{
- conn: conn,
- user: current_user
- } do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/pleroma/change_password", %{
- "password" => "test",
- "new_password" => "",
- "new_password_confirmation" => ""
- })
-
- assert json_response(conn, 200) == %{
- "error" => "New password can't be blank."
- }
- end
-
- test "with credentials, valid password and matching new password and confirmation", %{
- conn: conn,
- user: current_user
- } do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/pleroma/change_password", %{
- "password" => "test",
- "new_password" => "newpass",
- "new_password_confirmation" => "newpass"
- })
-
- assert json_response(conn, 200) == %{"status" => "success"}
- fetched_user = User.get_cached_by_id(current_user.id)
- assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
- end
- end
-
- describe "POST /api/pleroma/delete_account" do
- setup [:valid_user]
-
- test "without credentials", %{conn: conn} do
- conn = post(conn, "/api/pleroma/delete_account")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials and invalid password", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/pleroma/delete_account", %{"password" => "hi"})
-
- assert json_response(conn, 200) == %{"error" => "Invalid password."}
- end
-
- test "with credentials and valid password", %{conn: conn, user: current_user} do
- conn =
- conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/pleroma/delete_account", %{"password" => "test"})
-
- assert json_response(conn, 200) == %{"status" => "success"}
- # Wait a second for the started task to end
- :timer.sleep(1000)
- end
- end
-
- describe "GET /api/pleroma/friend_requests" do
- test "it lists friend requests" do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} = ActivityPub.follow(other_user, user)
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == false
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> get("/api/pleroma/friend_requests")
-
- assert [relationship] = json_response(conn, 200)
- assert other_user.id == relationship["id"]
- end
-
- test "requires 'read' permission", %{conn: conn} do
- token1 = insert(:oauth_token, scopes: ["write"])
- token2 = insert(:oauth_token, scopes: ["read"])
-
- for token <- [token1, token2] do
- conn =
- conn
- |> put_req_header("authorization", "Bearer #{token.token}")
- |> get("/api/pleroma/friend_requests")
-
- if token == token1 do
- assert %{"error" => "Insufficient permissions: read."} == json_response(conn, 403)
- else
- assert json_response(conn, 200)
- end
- end
- end
- end
-
- describe "POST /api/pleroma/friendships/approve" do
- test "it approves a friend request" do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} = ActivityPub.follow(other_user, user)
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == false
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
-
- assert relationship = json_response(conn, 200)
- assert other_user.id == relationship["id"]
- assert relationship["follows_you"] == true
- end
- end
-
- describe "POST /api/pleroma/friendships/deny" do
- test "it denies a friend request" do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} = ActivityPub.follow(other_user, user)
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == false
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
-
- assert relationship = json_response(conn, 200)
- assert other_user.id == relationship["id"]
- assert relationship["follows_you"] == false
- end
- end
-
- describe "GET /api/pleroma/search_user" do
- test "it returns users, ordered by similarity", %{conn: conn} do
- user = insert(:user, %{name: "eal"})
- user_two = insert(:user, %{name: "eal me"})
- _user_three = insert(:user, %{name: "zzz"})
-
- resp =
- conn
- |> get(twitter_api_search__path(conn, :search_user), query: "eal me")
- |> json_response(200)
-
- assert length(resp) == 2
- assert [user_two.id, user.id] == Enum.map(resp, fn %{"id" => id} -> id end)
- end
- end
-
- describe "POST /api/media/upload" do
- setup context do
- Pleroma.DataCase.ensure_local_uploader(context)
- end
-
- test "it performs the upload and sets `data[actor]` with AP id of uploader user", %{
- conn: conn
- } do
- user = insert(:user)
-
- upload_filename = "test/fixtures/image_tmp.jpg"
- File.cp!("test/fixtures/image.jpg", upload_filename)
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname(upload_filename),
- filename: "image.jpg"
- }
-
- response =
- conn
- |> assign(:user, user)
- |> put_req_header("content-type", "application/octet-stream")
- |> post("/api/media/upload", %{
- "media" => file
- })
- |> json_response(:ok)
-
- assert response["media_id"]
- object = Repo.get(Object, response["media_id"])
- assert object
- assert object.data["actor"] == User.ap_id(user)
- end
- end
-
- describe "POST /api/media/metadata/create" do
- setup do
- object = insert(:note)
- user = User.get_cached_by_ap_id(object.data["actor"])
- %{object: object, user: user}
- end
-
- test "it returns :forbidden status on attempt to modify someone else's upload", %{
- conn: conn,
- object: object
- } do
- initial_description = object.data["name"]
- another_user = insert(:user)
-
- conn
- |> assign(:user, another_user)
- |> post("/api/media/metadata/create", %{"media_id" => object.id})
- |> json_response(:forbidden)
-
- object = Repo.get(Object, object.id)
- assert object.data["name"] == initial_description
- end
-
- test "it updates `data[name]` of referenced Object with provided value", %{
- conn: conn,
- object: object,
- user: user
- } do
- description = "Informative description of the image. Initial value: #{object.data["name"]}}"
-
- conn
- |> assign(:user, user)
- |> post("/api/media/metadata/create", %{
- "media_id" => object.id,
- "alt_text" => %{"text" => description}
- })
- |> json_response(:no_content)
-
- object = Repo.get(Object, object.id)
- assert object.data["name"] == description
- end
- end
-
- describe "POST /api/statuses/user_timeline.json?user_id=:user_id&pinned=true" do
- test "it returns a list of pinned statuses", %{conn: conn} do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
-
- user = insert(:user, %{name: "egor"})
- {:ok, %{id: activity_id}} = CommonAPI.post(user, %{"status" => "HI!!!"})
- {:ok, _} = CommonAPI.pin(activity_id, user)
-
- resp =
- conn
- |> get("/api/statuses/user_timeline.json", %{user_id: user.id, pinned: true})
- |> json_response(200)
-
- assert length(resp) == 1
- assert [%{"id" => ^activity_id, "pinned" => true}] = resp
- end
- end
-
- describe "POST /api/statuses/pin/:id" do
- setup do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- [user: insert(:user)]
- end
-
- test "without valid credentials", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = post(conn, "/api/statuses/pin/#{note_activity.id}.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test!"})
-
- request_path = "/api/statuses/pin/#{activity.id}.json"
-
- response =
- conn
- |> with_credentials(user.nickname, "test")
- |> post(request_path)
-
- user = refresh_record(user)
-
- assert json_response(response, 200) ==
- ActivityView.render("activity.json", %{user: user, for: user, activity: activity})
- end
- end
-
- describe "POST /api/statuses/unpin/:id" do
- setup do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- [user: insert(:user)]
- end
-
- test "without valid credentials", %{conn: conn} do
- note_activity = insert(:note_activity)
- conn = post(conn, "/api/statuses/unpin/#{note_activity.id}.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
-
- test "with credentials", %{conn: conn, user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test!"})
- {:ok, activity} = CommonAPI.pin(activity.id, user)
-
- request_path = "/api/statuses/unpin/#{activity.id}.json"
-
- response =
- conn
- |> with_credentials(user.nickname, "test")
- |> post(request_path)
-
- user = refresh_record(user)
-
- assert json_response(response, 200) ==
- ActivityView.render("activity.json", %{user: user, for: user, activity: activity})
- end
- end
-
- describe "GET /api/oauth_tokens" do
- setup do
- token = insert(:oauth_token) |> Repo.preload(:user)
-
- %{token: token}
- end
-
- test "renders list", %{token: token} do
- response =
- build_conn()
- |> assign(:user, token.user)
- |> get("/api/oauth_tokens")
-
- keys =
- json_response(response, 200)
- |> hd()
- |> Map.keys()
-
- assert keys -- ["id", "app_name", "valid_until"] == []
- end
-
- test "revoke token", %{token: token} do
- response =
- build_conn()
- |> assign(:user, token.user)
- |> delete("/api/oauth_tokens/#{token.id}")
-
- tokens = Token.get_user_tokens(token.user)
-
- assert tokens == []
- assert response.status == 201
- end
- end
-end
--
cgit v1.2.3
From 5e4fde1d3d49ec56fae3b199fb4af51057e2dffd Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 27 Aug 2019 20:48:16 +0300
Subject: Filter logs by date
---
test/web/admin_api/admin_api_controller_test.exs | 46 ++++++++++++++++++++++++
1 file changed, 46 insertions(+)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 4e2c27431..a7269aee9 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -2348,6 +2348,52 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert second_entry["message"] ==
"@#{admin.nickname} followed relay: https://example.org/relay"
end
+
+ test "filters log by date", %{conn: conn, admin: admin} do
+ first_date = "2017-08-15T15:47:06Z"
+ second_date = "2017-08-20T15:47:06Z"
+
+ Repo.insert(%ModerationLog{
+ data: %{
+ actor: %{
+ "id" => admin.id,
+ "nickname" => admin.nickname,
+ "type" => "user"
+ },
+ action: "relay_follow",
+ target: "https://example.org/relay"
+ },
+ inserted_at: NaiveDateTime.from_iso8601!(first_date)
+ })
+
+ Repo.insert(%ModerationLog{
+ data: %{
+ actor: %{
+ "id" => admin.id,
+ "nickname" => admin.nickname,
+ "type" => "user"
+ },
+ action: "relay_unfollow",
+ target: "https://example.org/relay"
+ },
+ inserted_at: NaiveDateTime.from_iso8601!(second_date)
+ })
+
+ conn1 =
+ get(
+ conn,
+ "/api/pleroma/admin/moderation_log?start_date=#{second_date}"
+ )
+
+ response1 = json_response(conn1, 200)
+ [first_entry] = response1
+
+ assert response1 |> length() == 1
+ assert first_entry["data"]["action"] == "relay_unfollow"
+
+ assert first_entry["message"] ==
+ "@#{admin.nickname} unfollowed relay: https://example.org/relay"
+ end
end
end
--
cgit v1.2.3
From cef2e980b1f6b07c2bdb01030559aca83257bd7e Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 28 Aug 2019 21:32:44 +0300
Subject: division emoji.ex on loader.ex and emoji.ex
---
test/emoji/loader_test.exs | 83 ++++++++++++++++++++++++++++++++++++++++++++++
test/emoji_test.exs | 75 -----------------------------------------
2 files changed, 83 insertions(+), 75 deletions(-)
create mode 100644 test/emoji/loader_test.exs
(limited to 'test')
diff --git a/test/emoji/loader_test.exs b/test/emoji/loader_test.exs
new file mode 100644
index 000000000..045eef150
--- /dev/null
+++ b/test/emoji/loader_test.exs
@@ -0,0 +1,83 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Emoji.LoaderTest do
+ use ExUnit.Case, async: true
+ alias Pleroma.Emoji.Loader
+
+ describe "match_extra/2" do
+ setup do
+ groups = [
+ "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
+ "wildcard folder": "/emoji/custom/*/file.png",
+ "wildcard files": "/emoji/custom/folder/*.png",
+ "special file": "/emoji/custom/special.png"
+ ]
+
+ {:ok, groups: groups}
+ end
+
+ test "config for list of files", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/custom/first_file.png")
+ |> to_string()
+
+ assert group == "list of files"
+ end
+
+ test "config with wildcard folder", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/custom/some_folder/file.png")
+ |> to_string()
+
+ assert group == "wildcard folder"
+ end
+
+ test "config with wildcard folder and subfolders", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/custom/some_folder/another_folder/file.png")
+ |> to_string()
+
+ assert group == "wildcard folder"
+ end
+
+ test "config with wildcard files", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/custom/folder/some_file.png")
+ |> to_string()
+
+ assert group == "wildcard files"
+ end
+
+ test "config with wildcard files and subfolders", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/custom/folder/another_folder/some_file.png")
+ |> to_string()
+
+ assert group == "wildcard files"
+ end
+
+ test "config for special file", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/custom/special.png")
+ |> to_string()
+
+ assert group == "special file"
+ end
+
+ test "no mathing returns nil", %{groups: groups} do
+ group =
+ groups
+ |> Loader.match_extra("/emoji/some_undefined.png")
+
+ refute group
+ end
+ end
+end
diff --git a/test/emoji_test.exs b/test/emoji_test.exs
index 07ac6ff1d..32a828cc9 100644
--- a/test/emoji_test.exs
+++ b/test/emoji_test.exs
@@ -32,79 +32,4 @@ defmodule Pleroma.EmojiTest do
assert is_list(tags)
end
end
-
- describe "match_extra/2" do
- setup do
- groups = [
- "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
- "wildcard folder": "/emoji/custom/*/file.png",
- "wildcard files": "/emoji/custom/folder/*.png",
- "special file": "/emoji/custom/special.png"
- ]
-
- {:ok, groups: groups}
- end
-
- test "config for list of files", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/custom/first_file.png")
- |> to_string()
-
- assert group == "list of files"
- end
-
- test "config with wildcard folder", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/custom/some_folder/file.png")
- |> to_string()
-
- assert group == "wildcard folder"
- end
-
- test "config with wildcard folder and subfolders", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/custom/some_folder/another_folder/file.png")
- |> to_string()
-
- assert group == "wildcard folder"
- end
-
- test "config with wildcard files", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/custom/folder/some_file.png")
- |> to_string()
-
- assert group == "wildcard files"
- end
-
- test "config with wildcard files and subfolders", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/custom/folder/another_folder/some_file.png")
- |> to_string()
-
- assert group == "wildcard files"
- end
-
- test "config for special file", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/custom/special.png")
- |> to_string()
-
- assert group == "special file"
- end
-
- test "no mathing returns nil", %{groups: groups} do
- group =
- groups
- |> Emoji.match_extra("/emoji/some_undefined.png")
-
- refute group
- end
- end
end
--
cgit v1.2.3
From d7808b5db437b3300122127cef4c7ad076de7bda Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Thu, 29 Aug 2019 06:22:18 +0300
Subject: added code\path fields without html tags in ets
---
test/emoji_test.exs | 8 ++--
test/formatter_test.exs | 104 +++++++++++++++++++++++++-----------------------
2 files changed, 58 insertions(+), 54 deletions(-)
(limited to 'test')
diff --git a/test/emoji_test.exs b/test/emoji_test.exs
index 32a828cc9..82f9c52ff 100644
--- a/test/emoji_test.exs
+++ b/test/emoji_test.exs
@@ -14,9 +14,9 @@ defmodule Pleroma.EmojiTest do
test "first emoji", %{emoji_list: emoji_list} do
[emoji | _others] = emoji_list
- {code, path, tags} = emoji
+ {code, path, tags, _, _} = emoji
- assert tuple_size(emoji) == 3
+ assert tuple_size(emoji) == 5
assert is_binary(code)
assert is_binary(path)
assert is_list(tags)
@@ -24,9 +24,9 @@ defmodule Pleroma.EmojiTest do
test "random emoji", %{emoji_list: emoji_list} do
emoji = Enum.random(emoji_list)
- {code, path, tags} = emoji
+ {code, path, tags, _, _} = emoji
- assert tuple_size(emoji) == 3
+ assert tuple_size(emoji) == 5
assert is_binary(code)
assert is_binary(path)
assert is_list(tags)
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index bfa673049..7a5bd0f9f 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -217,6 +217,27 @@ defmodule Pleroma.FormatterTest do
assert expected_text =~ "how are you doing?"
end
+
+ test "it can parse mentions and return the relevant users" do
+ text =
+ "@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm"
+
+ o = insert(:user, %{nickname: "o"})
+ jimm = insert(:user, %{nickname: "jimm"})
+ gsimg = insert(:user, %{nickname: "gsimg"})
+ archaeme = insert(:user, %{nickname: "archaeme"})
+ archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
+
+ expected_mentions = [
+ {"@archaeme", archaeme},
+ {"@archaeme@archae.me", archaeme_remote},
+ {"@gsimg", gsimg},
+ {"@jimm", jimm},
+ {"@o", o}
+ ]
+
+ assert {_text, ^expected_mentions, []} = Formatter.linkify(text)
+ end
end
describe ".parse_tags" do
@@ -234,67 +255,50 @@ defmodule Pleroma.FormatterTest do
end
end
- test "it can parse mentions and return the relevant users" do
- text =
- "@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm"
-
- o = insert(:user, %{nickname: "o"})
- jimm = insert(:user, %{nickname: "jimm"})
- gsimg = insert(:user, %{nickname: "gsimg"})
- archaeme = insert(:user, %{nickname: "archaeme"})
- archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
-
- expected_mentions = [
- {"@archaeme", archaeme},
- {"@archaeme@archae.me", archaeme_remote},
- {"@gsimg", gsimg},
- {"@jimm", jimm},
- {"@o", o}
- ]
-
- assert {_text, ^expected_mentions, []} = Formatter.linkify(text)
- end
+ describe "emojify" do
+ test "it adds cool emoji" do
+ text = "I love :firefox:"
- test "it adds cool emoji" do
- text = "I love :firefox:"
+ expected_result =
+ "I love
"
- expected_result =
- "I love
"
-
- assert Formatter.emojify(text) == expected_result
- end
+ assert Formatter.emojify(text) == expected_result
+ end
- test "it does not add XSS emoji" do
- text =
- "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
+ test "it does not add XSS emoji" do
+ text =
+ "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
- custom_emoji = %{
- "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" =>
- "https://placehold.it/1x1"
- }
+ custom_emoji = %{
+ "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" =>
+ "https://placehold.it/1x1"
+ }
- expected_result =
- "I love
"
+ expected_result =
+ "I love
"
- assert Formatter.emojify(text, custom_emoji) == expected_result
+ assert Formatter.emojify(text, custom_emoji) == expected_result
+ end
end
- test "it returns the emoji used in the text" do
- text = "I love :firefox:"
+ describe "get_emoji" do
+ test "it returns the emoji used in the text" do
+ text = "I love :firefox:"
- assert Formatter.get_emoji(text) == [
- {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"]}
- ]
- end
+ assert Formatter.get_emoji(text) == [
+ {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"], "firefox", "/emoji/Firefox.gif"}
+ ]
+ end
- test "it returns a nice empty result when no emojis are present" do
- text = "I love moominamma"
- assert Formatter.get_emoji(text) == []
- end
+ test "it returns a nice empty result when no emojis are present" do
+ text = "I love moominamma"
+ assert Formatter.get_emoji(text) == []
+ end
- test "it doesn't die when text is absent" do
- text = nil
- assert Formatter.get_emoji(text) == []
+ test "it doesn't die when text is absent" do
+ text = nil
+ assert Formatter.get_emoji(text) == []
+ end
end
test "it escapes HTML in plain text" do
--
cgit v1.2.3
From d8098d142a0e8412eabdf5fe63705c25bcb1be34 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Thu, 29 Aug 2019 22:01:37 +0300
Subject: added Emoji.Formatter
---
test/emoji/formatter_test.exs | 54 +++++++++++++++++++++++++++++++++++++++++++
test/formatter_test.exs | 46 ------------------------------------
2 files changed, 54 insertions(+), 46 deletions(-)
create mode 100644 test/emoji/formatter_test.exs
(limited to 'test')
diff --git a/test/emoji/formatter_test.exs b/test/emoji/formatter_test.exs
new file mode 100644
index 000000000..8b510f48b
--- /dev/null
+++ b/test/emoji/formatter_test.exs
@@ -0,0 +1,54 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Emoji.FormatterTest do
+ alias Pleroma.Emoji.Formatter
+ use Pleroma.DataCase
+
+ describe "emojify" do
+ test "it adds cool emoji" do
+ text = "I love :firefox:"
+
+ expected_result =
+ "I love
"
+
+ assert Formatter.emojify(text) == expected_result
+ end
+
+ test "it does not add XSS emoji" do
+ text =
+ "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
+
+ custom_emoji = %{
+ "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" =>
+ "https://placehold.it/1x1"
+ }
+
+ expected_result =
+ "I love
"
+
+ assert Formatter.emojify(text, custom_emoji) == expected_result
+ end
+ end
+
+ describe "get_emoji" do
+ test "it returns the emoji used in the text" do
+ text = "I love :firefox:"
+
+ assert Formatter.get_emoji(text) == [
+ {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"], "firefox", "/emoji/Firefox.gif"}
+ ]
+ end
+
+ test "it returns a nice empty result when no emojis are present" do
+ text = "I love moominamma"
+ assert Formatter.get_emoji(text) == []
+ end
+
+ test "it doesn't die when text is absent" do
+ text = nil
+ assert Formatter.get_emoji(text) == []
+ end
+ end
+end
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 7a5bd0f9f..c36681068 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -255,52 +255,6 @@ defmodule Pleroma.FormatterTest do
end
end
- describe "emojify" do
- test "it adds cool emoji" do
- text = "I love :firefox:"
-
- expected_result =
- "I love
"
-
- assert Formatter.emojify(text) == expected_result
- end
-
- test "it does not add XSS emoji" do
- text =
- "I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
-
- custom_emoji = %{
- "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" =>
- "https://placehold.it/1x1"
- }
-
- expected_result =
- "I love
"
-
- assert Formatter.emojify(text, custom_emoji) == expected_result
- end
- end
-
- describe "get_emoji" do
- test "it returns the emoji used in the text" do
- text = "I love :firefox:"
-
- assert Formatter.get_emoji(text) == [
- {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"], "firefox", "/emoji/Firefox.gif"}
- ]
- end
-
- test "it returns a nice empty result when no emojis are present" do
- text = "I love moominamma"
- assert Formatter.get_emoji(text) == []
- end
-
- test "it doesn't die when text is absent" do
- text = nil
- assert Formatter.get_emoji(text) == []
- end
- end
-
test "it escapes HTML in plain text" do
text = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"
expected = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"
--
cgit v1.2.3
From f182f0f6bd89a2f2e3c4a6000c772512b239fe54 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sat, 31 Aug 2019 00:57:15 +0300
Subject: Add ability to search moderation logs
---
test/moderation_log_test.exs | 36 +++++++-------
test/web/admin_api/admin_api_controller_test.exs | 61 +++++++++++++++++++++++-
2 files changed, 76 insertions(+), 21 deletions(-)
(limited to 'test')
diff --git a/test/moderation_log_test.exs b/test/moderation_log_test.exs
index c78708471..a39a00e02 100644
--- a/test/moderation_log_test.exs
+++ b/test/moderation_log_test.exs
@@ -30,8 +30,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
- "@#{moderator.nickname} deleted user @#{subject1.nickname}"
+ assert log.data["message"] == "@#{moderator.nickname} deleted user @#{subject1.nickname}"
end
test "logging user creation by moderator", %{
@@ -48,7 +47,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} created users: @#{subject1.nickname}, @#{subject2.nickname}"
end
@@ -63,7 +62,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{admin.nickname} made @#{subject2.nickname} follow @#{subject1.nickname}"
end
@@ -78,7 +77,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{admin.nickname} made @#{subject2.nickname} unfollow @#{subject1.nickname}"
end
@@ -100,8 +99,7 @@ defmodule Pleroma.ModerationLogTest do
tags = ["foo", "bar"] |> Enum.join(", ")
- assert ModerationLog.get_log_entry_message(log) ==
- "@#{admin.nickname} added tags: #{tags} to users: #{users}"
+ assert log.data["message"] == "@#{admin.nickname} added tags: #{tags} to users: #{users}"
end
test "logging user untagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
@@ -122,7 +120,7 @@ defmodule Pleroma.ModerationLogTest do
tags = ["foo", "bar"] |> Enum.join(", ")
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
end
@@ -137,8 +135,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
- "@#{moderator.nickname} made @#{subject1.nickname} moderator"
+ assert log.data["message"] == "@#{moderator.nickname} made @#{subject1.nickname} moderator"
end
test "logging user revoke by moderator", %{moderator: moderator, subject1: subject1} do
@@ -152,7 +149,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} revoked moderator role from @#{subject1.nickname}"
end
@@ -166,7 +163,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} followed relay: https://example.org/relay"
end
@@ -180,7 +177,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
end
@@ -202,7 +199,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} updated report ##{report.id} with 'resolved' state"
end
@@ -224,7 +221,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} responded with 'look at this' to report ##{report.id}"
end
@@ -242,7 +239,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true'"
end
@@ -260,7 +257,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} updated status ##{note.id}, set visibility: 'private'"
end
@@ -278,7 +275,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
+ assert log.data["message"] ==
"@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true', visibility: 'private'"
end
@@ -294,8 +291,7 @@ defmodule Pleroma.ModerationLogTest do
log = Repo.one(ModerationLog)
- assert ModerationLog.get_log_entry_message(log) ==
- "@#{moderator.nickname} deleted status ##{note.id}"
+ assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"
end
end
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index a7269aee9..eaf847b25 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -2251,8 +2251,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "GET /api/pleroma/admin/moderation_log" do
setup %{conn: conn} do
admin = insert(:user, info: %{is_admin: true})
+ moderator = insert(:user, info: %{is_moderator: true})
- %{conn: assign(conn, :user, admin), admin: admin}
+ %{conn: assign(conn, :user, admin), admin: admin, moderator: moderator}
end
test "returns the log", %{conn: conn, admin: admin} do
@@ -2394,6 +2395,64 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert first_entry["message"] ==
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
end
+
+ test "returns log filtered by user", %{conn: conn, admin: admin, moderator: moderator} do
+ Repo.insert(%ModerationLog{
+ data: %{
+ actor: %{
+ "id" => admin.id,
+ "nickname" => admin.nickname,
+ "type" => "user"
+ },
+ action: "relay_follow",
+ target: "https://example.org/relay"
+ }
+ })
+
+ Repo.insert(%ModerationLog{
+ data: %{
+ actor: %{
+ "id" => moderator.id,
+ "nickname" => moderator.nickname,
+ "type" => "user"
+ },
+ action: "relay_unfollow",
+ target: "https://example.org/relay"
+ }
+ })
+
+ conn1 = get(conn, "/api/pleroma/admin/moderation_log?user_id=#{moderator.id}")
+
+ response1 = json_response(conn1, 200)
+ [first_entry] = response1
+
+ assert response1 |> length() == 1
+ assert get_in(first_entry, ["data", "actor", "id"]) == moderator.id
+ end
+
+ test "returns log filtered by search", %{conn: conn, moderator: moderator} do
+ ModerationLog.insert_log(%{
+ actor: moderator,
+ action: "relay_follow",
+ target: "https://example.org/relay"
+ })
+
+ ModerationLog.insert_log(%{
+ actor: moderator,
+ action: "relay_unfollow",
+ target: "https://example.org/relay"
+ })
+
+ conn1 = get(conn, "/api/pleroma/admin/moderation_log?search=unfo")
+
+ response1 = json_response(conn1, 200)
+ [first_entry] = response1
+
+ assert response1 |> length() == 1
+
+ assert get_in(first_entry, ["data", "message"]) ==
+ "@#{moderator.nickname} unfollowed relay: https://example.org/relay"
+ end
end
end
--
cgit v1.2.3
From 6ef0103ca0b194971a2e6f61685316536b742a11 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Sat, 31 Aug 2019 10:14:53 +0300
Subject: added Emoji struct
---
test/emoji/formatter_test.exs | 20 +++++++++++++++-----
test/emoji_test.exs | 8 ++++----
2 files changed, 19 insertions(+), 9 deletions(-)
(limited to 'test')
diff --git a/test/emoji/formatter_test.exs b/test/emoji/formatter_test.exs
index 8b510f48b..6d25fc453 100644
--- a/test/emoji/formatter_test.exs
+++ b/test/emoji/formatter_test.exs
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emoji.FormatterTest do
+ alias Pleroma.Emoji
alias Pleroma.Emoji.Formatter
use Pleroma.DataCase
@@ -20,15 +21,17 @@ defmodule Pleroma.Emoji.FormatterTest do
text =
"I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
- custom_emoji = %{
- "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" =>
+ custom_emoji =
+ {
+ "'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)",
"https://placehold.it/1x1"
- }
+ }
+ |> Pleroma.Emoji.build()
expected_result =
"I love
"
- assert Formatter.emojify(text, custom_emoji) == expected_result
+ assert Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) == expected_result
end
end
@@ -37,7 +40,14 @@ defmodule Pleroma.Emoji.FormatterTest do
text = "I love :firefox:"
assert Formatter.get_emoji(text) == [
- {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"], "firefox", "/emoji/Firefox.gif"}
+ {"firefox",
+ %Emoji{
+ code: "firefox",
+ file: "/emoji/Firefox.gif",
+ tags: ["Gif", "Fun"],
+ safe_code: "firefox",
+ safe_file: "/emoji/Firefox.gif"
+ }}
]
end
diff --git a/test/emoji_test.exs b/test/emoji_test.exs
index 82f9c52ff..1fdbd0fdf 100644
--- a/test/emoji_test.exs
+++ b/test/emoji_test.exs
@@ -14,9 +14,9 @@ defmodule Pleroma.EmojiTest do
test "first emoji", %{emoji_list: emoji_list} do
[emoji | _others] = emoji_list
- {code, path, tags, _, _} = emoji
+ {code, %Emoji{file: path, tags: tags}} = emoji
- assert tuple_size(emoji) == 5
+ assert tuple_size(emoji) == 2
assert is_binary(code)
assert is_binary(path)
assert is_list(tags)
@@ -24,9 +24,9 @@ defmodule Pleroma.EmojiTest do
test "random emoji", %{emoji_list: emoji_list} do
emoji = Enum.random(emoji_list)
- {code, path, tags, _, _} = emoji
+ {code, %Emoji{file: path, tags: tags}} = emoji
- assert tuple_size(emoji) == 5
+ assert tuple_size(emoji) == 2
assert is_binary(code)
assert is_binary(path)
assert is_list(tags)
--
cgit v1.2.3
From 90c2dae9a4d5fd7e7c1f0d0f532ce95fbc4c69f9 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 31 Aug 2019 10:20:34 +0300
Subject: Remove most of Pleroma.Web.TwitterAPI.TwitterAPI
---
test/notification_test.exs | 87 ++---
test/user_test.exs | 22 +-
.../mastodon_api/mastodon_api_controller_test.exs | 8 +-
test/web/mastodon_api/mastodon_api_test.exs | 7 +-
test/web/twitter_api/twitter_api_test.exs | 265 --------------
test/web/twitter_api/views/activity_view_test.exs | 384 ---------------------
.../twitter_api/views/notification_view_test.exs | 112 ------
test/web/twitter_api/views/user_view_test.exs | 323 -----------------
8 files changed, 42 insertions(+), 1166 deletions(-)
delete mode 100644 test/web/twitter_api/views/activity_view_test.exs
delete mode 100644 test/web/twitter_api/views/notification_view_test.exs
delete mode 100644 test/web/twitter_api/views/user_view_test.exs
(limited to 'test')
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 80ea2a085..2a52dad8d 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -12,7 +12,6 @@ defmodule Pleroma.NotificationTest do
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Streamer
- alias Pleroma.Web.TwitterAPI.TwitterAPI
describe "create_notifications" do
test "notifies someone when they are directly addressed" do
@@ -21,7 +20,7 @@ defmodule Pleroma.NotificationTest do
third_user = insert(:user)
{:ok, activity} =
- TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
})
@@ -39,7 +38,7 @@ defmodule Pleroma.NotificationTest do
User.subscribe(subscriber, user)
- {:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
+ {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
{:ok, [notification]} = Notification.create_notifications(status)
assert notification.user_id == subscriber.id
@@ -184,47 +183,20 @@ defmodule Pleroma.NotificationTest do
test "it doesn't create a notification for follow-unfollow-follow chains" do
user = insert(:user)
followed_user = insert(:user)
- {:ok, _, _, activity} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
+ {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
Notification.create_notification(activity, followed_user)
- TwitterAPI.unfollow(user, %{"user_id" => followed_user.id})
- {:ok, _, _, activity_dupe} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
+ CommonAPI.unfollow(user, followed_user)
+ {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
refute Notification.create_notification(activity_dupe, followed_user)
end
- test "it doesn't create a notification for like-unlike-like chains" do
- user = insert(:user)
- liked_user = insert(:user)
- {:ok, status} = TwitterAPI.create_status(liked_user, %{"status" => "Yui is best yuru"})
- {:ok, fav_status} = TwitterAPI.fav(user, status.id)
- Notification.create_notification(fav_status, liked_user)
- TwitterAPI.unfav(user, status.id)
- {:ok, dupe} = TwitterAPI.fav(user, status.id)
- refute Notification.create_notification(dupe, liked_user)
- end
-
- test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
- user = insert(:user)
- retweeted_user = insert(:user)
-
- {:ok, status} =
- TwitterAPI.create_status(retweeted_user, %{
- "status" => "Send dupe notifications to the shadow realm"
- })
-
- {:ok, retweeted_activity} = TwitterAPI.repeat(user, status.id)
- Notification.create_notification(retweeted_activity, retweeted_user)
- TwitterAPI.unrepeat(user, status.id)
- {:ok, dupe} = TwitterAPI.repeat(user, status.id)
- refute Notification.create_notification(dupe, retweeted_user)
- end
-
test "it doesn't create duplicate notifications for follow+subscribed users" do
user = insert(:user)
subscriber = insert(:user)
- {:ok, _, _, _} = TwitterAPI.follow(subscriber, %{"user_id" => user.id})
+ {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
User.subscribe(subscriber, user)
- {:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
+ {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
{:ok, [_notif]} = Notification.create_notifications(status)
end
@@ -234,8 +206,7 @@ defmodule Pleroma.NotificationTest do
User.subscribe(subscriber, user)
- {:ok, status} =
- TwitterAPI.create_status(user, %{"status" => "inwisible", "visibility" => "direct"})
+ {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
assert {:ok, []} == Notification.create_notifications(status)
end
@@ -246,8 +217,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, notification} = Notification.get(other_user, notification.id)
@@ -259,8 +229,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:error, _notification} = Notification.get(user, notification.id)
@@ -272,8 +241,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, notification} = Notification.dismiss(other_user, notification.id)
@@ -285,8 +253,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
{:error, _notification} = Notification.dismiss(user, notification.id)
@@ -300,14 +267,14 @@ defmodule Pleroma.NotificationTest do
third_user = insert(:user)
{:ok, activity} =
- TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
})
{:ok, _notifs} = Notification.create_notifications(activity)
{:ok, activity} =
- TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
})
@@ -325,12 +292,12 @@ defmodule Pleroma.NotificationTest do
other_user = insert(:user)
{:ok, _activity} =
- TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey @#{other_user.nickname}!"
})
{:ok, _activity} =
- TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey again @#{other_user.nickname}!"
})
@@ -340,7 +307,7 @@ defmodule Pleroma.NotificationTest do
assert n2.id > n1.id
{:ok, _activity} =
- TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey yet again @#{other_user.nickname}!"
})
@@ -677,7 +644,7 @@ defmodule Pleroma.NotificationTest do
muted = insert(:user)
{:ok, user} = User.mute(user, muted, false)
- {:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
assert length(Notification.for_user(user)) == 1
end
@@ -687,7 +654,7 @@ defmodule Pleroma.NotificationTest do
muted = insert(:user)
{:ok, user} = User.mute(user, muted)
- {:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
assert Notification.for_user(user) == []
end
@@ -697,7 +664,7 @@ defmodule Pleroma.NotificationTest do
blocked = insert(:user)
{:ok, user} = User.block(user, blocked)
- {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
assert Notification.for_user(user) == []
end
@@ -707,7 +674,7 @@ defmodule Pleroma.NotificationTest do
blocked = insert(:user, ap_id: "http://some-domain.com")
{:ok, user} = User.block_domain(user, "some-domain.com")
- {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
assert Notification.for_user(user) == []
end
@@ -716,8 +683,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
another_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
assert Notification.for_user(user) == []
@@ -728,7 +694,7 @@ defmodule Pleroma.NotificationTest do
muted = insert(:user)
{:ok, user} = User.mute(user, muted)
- {:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
assert length(Notification.for_user(user, %{with_muted: true})) == 1
end
@@ -738,7 +704,7 @@ defmodule Pleroma.NotificationTest do
blocked = insert(:user)
{:ok, user} = User.block(user, blocked)
- {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
assert length(Notification.for_user(user, %{with_muted: true})) == 1
end
@@ -748,7 +714,7 @@ defmodule Pleroma.NotificationTest do
blocked = insert(:user, ap_id: "http://some-domain.com")
{:ok, user} = User.block_domain(user, "some-domain.com")
- {:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
assert length(Notification.for_user(user, %{with_muted: true})) == 1
end
@@ -757,8 +723,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
another_user = insert(:user)
- {:ok, activity} =
- TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
+ {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
assert length(Notification.for_user(user, %{with_muted: true})) == 1
diff --git a/test/user_test.exs b/test/user_test.exs
index 2cbc1f525..a25b72f4e 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -69,8 +69,8 @@ defmodule Pleroma.UserTest do
locked = insert(:user, %{info: %{locked: true}})
follower = insert(:user)
- Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => unlocked.id})
- Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => locked.id})
+ CommonAPI.follow(follower, unlocked)
+ CommonAPI.follow(follower, locked)
assert {:ok, []} = User.get_follow_requests(unlocked)
assert {:ok, [activity]} = User.get_follow_requests(locked)
@@ -83,9 +83,9 @@ defmodule Pleroma.UserTest do
pending_follower = insert(:user)
accepted_follower = insert(:user)
- Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
- Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
- Pleroma.Web.TwitterAPI.TwitterAPI.follow(accepted_follower, %{"user_id" => locked.id})
+ CommonAPI.follow(pending_follower, locked)
+ CommonAPI.follow(pending_follower, locked)
+ CommonAPI.follow(accepted_follower, locked)
User.follow(accepted_follower, locked)
assert {:ok, [activity]} = User.get_follow_requests(locked)
@@ -1279,11 +1279,9 @@ defmodule Pleroma.UserTest do
{:ok, _follower2} = User.follow(follower2, user)
{:ok, _follower3} = User.follow(follower3, user)
- {:ok, _} = User.block(user, follower)
+ {:ok, user} = User.block(user, follower)
- user_show = Pleroma.Web.TwitterAPI.UserView.render("show.json", %{user: user})
-
- assert Map.get(user_show, "followers_count") == 2
+ assert User.user_info(user).follower_count == 2
end
describe "list_inactive_users_query/1" do
@@ -1327,7 +1325,7 @@ defmodule Pleroma.UserTest do
to = Enum.random(users -- [user])
{:ok, _} =
- Pleroma.Web.TwitterAPI.TwitterAPI.create_status(user, %{
+ CommonAPI.post(user, %{
"status" => "hey @#{to.nickname}"
})
end)
@@ -1359,12 +1357,12 @@ defmodule Pleroma.UserTest do
Enum.each(recipients, fn to ->
{:ok, _} =
- Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
+ CommonAPI.post(sender, %{
"status" => "hey @#{to.nickname}"
})
{:ok, _} =
- Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
+ CommonAPI.post(sender, %{
"status" => "hey again @#{to.nickname}"
})
end)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6fcdc19aa..66588c891 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -21,7 +21,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.OStatus
alias Pleroma.Web.Push
- alias Pleroma.Web.TwitterAPI.TwitterAPI
import Pleroma.Factory
import ExUnit.CaptureLog
import Tesla.Mock
@@ -1583,12 +1582,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
filename: "an_image.jpg"
}
- media =
- TwitterAPI.upload(file, user, "json")
- |> Jason.decode!()
+ {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
- {:ok, image_post} =
- CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
+ {:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
conn =
conn
diff --git a/test/web/mastodon_api/mastodon_api_test.exs b/test/web/mastodon_api/mastodon_api_test.exs
index b4c0427c9..7fcb2bd55 100644
--- a/test/web/mastodon_api/mastodon_api_test.exs
+++ b/test/web/mastodon_api/mastodon_api_test.exs
@@ -8,8 +8,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
alias Pleroma.Notification
alias Pleroma.ScheduledActivity
alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.MastodonAPI
- alias Pleroma.Web.TwitterAPI.TwitterAPI
import Pleroma.Factory
@@ -75,8 +75,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
User.subscribe(subscriber, user)
- {:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
- {:ok, status1} = TwitterAPI.create_status(user, %{"status" => "Magi"})
+ {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
+
+ {:ok, status1} = CommonAPI.post(user, %{"status" => "Magi"})
{:ok, [notification]} = Notification.create_notifications(status)
{:ok, [notification1]} = Notification.create_notifications(status1)
res = MastodonAPI.get_notifications(subscriber)
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index cbe83852e..ac9c0c27e 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -4,12 +4,9 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
- alias Pleroma.Activity
- alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.UserInviteToken
- alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.UserView
@@ -21,253 +18,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
:ok
end
- test "create a status" do
- user = insert(:user)
- mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
-
- object_data = %{
- "type" => "Image",
- "url" => [
- %{
- "type" => "Link",
- "mediaType" => "image/jpg",
- "href" => "http://example.org/image.jpg"
- }
- ],
- "uuid" => 1
- }
-
- object = Repo.insert!(%Object{data: object_data})
-
- input = %{
- "status" =>
- "Hello again, @shp.\nThis is on another :firefox: line. #2hu #epic #phantasmagoric",
- "media_ids" => [object.id]
- }
-
- {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
- object = Object.normalize(activity)
-
- expected_text =
- "Hello again, @shp.<script></script>
This is on another :firefox: line. #2hu #epic #phantasmagoric
image.jpg"
-
- assert get_in(object.data, ["content"]) == expected_text
- assert get_in(object.data, ["type"]) == "Note"
- assert get_in(object.data, ["actor"]) == user.ap_id
- assert get_in(activity.data, ["actor"]) == user.ap_id
- assert Enum.member?(get_in(activity.data, ["cc"]), User.ap_followers(user))
-
- assert Enum.member?(
- get_in(activity.data, ["to"]),
- "https://www.w3.org/ns/activitystreams#Public"
- )
-
- assert Enum.member?(get_in(activity.data, ["to"]), "shp")
- assert activity.local == true
-
- assert %{"firefox" => "http://localhost:4001/emoji/Firefox.gif"} = object.data["emoji"]
-
- # hashtags
- assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
-
- # Add a context
- assert is_binary(get_in(activity.data, ["context"]))
- assert is_binary(get_in(object.data, ["context"]))
-
- assert is_list(object.data["attachment"])
-
- assert activity.data["object"] == object.data["id"]
-
- user = User.get_cached_by_ap_id(user.ap_id)
-
- assert user.info.note_count == 1
- end
-
- test "create a status that is a reply" do
- user = insert(:user)
-
- input = %{
- "status" => "Hello again."
- }
-
- {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
- object = Object.normalize(activity)
-
- input = %{
- "status" => "Here's your (you).",
- "in_reply_to_status_id" => activity.id
- }
-
- {:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
- reply_object = Object.normalize(reply)
-
- assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
-
- assert get_in(reply_object.data, ["context"]) == get_in(object.data, ["context"])
-
- assert get_in(reply_object.data, ["inReplyTo"]) == get_in(activity.data, ["object"])
- assert Activity.get_in_reply_to_activity(reply).id == activity.id
- end
-
- test "Follow another user using user_id" do
- user = insert(:user)
- followed = insert(:user)
-
- {:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
- assert User.ap_followers(followed) in user.following
-
- {:ok, _, _, _} = TwitterAPI.follow(user, %{"user_id" => followed.id})
- end
-
- test "Follow another user using screen_name" do
- user = insert(:user)
- followed = insert(:user)
-
- {:ok, user, followed, _activity} =
- TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
-
- assert User.ap_followers(followed) in user.following
-
- followed = User.get_cached_by_ap_id(followed.ap_id)
- assert followed.info.follower_count == 1
-
- {:ok, _, _, _} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
- end
-
- test "Unfollow another user using user_id" do
- unfollowed = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
- ActivityPub.follow(user, unfollowed)
-
- {:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
- assert user.following == []
-
- {:error, msg} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
- assert msg == "Not subscribed!"
- end
-
- test "Unfollow another user using screen_name" do
- unfollowed = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
-
- ActivityPub.follow(user, unfollowed)
-
- {:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
- assert user.following == []
-
- {:error, msg} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
- assert msg == "Not subscribed!"
- end
-
- test "Block another user using user_id" do
- user = insert(:user)
- blocked = insert(:user)
-
- {:ok, user, blocked} = TwitterAPI.block(user, %{"user_id" => blocked.id})
- assert User.blocks?(user, blocked)
- end
-
- test "Block another user using screen_name" do
- user = insert(:user)
- blocked = insert(:user)
-
- {:ok, user, blocked} = TwitterAPI.block(user, %{"screen_name" => blocked.nickname})
- assert User.blocks?(user, blocked)
- end
-
- test "Unblock another user using user_id" do
- unblocked = insert(:user)
- user = insert(:user)
- {:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})
-
- {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
- assert user.info.blocks == []
- end
-
- test "Unblock another user using screen_name" do
- unblocked = insert(:user)
- user = insert(:user)
- {:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})
-
- {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
- assert user.info.blocks == []
- end
-
- test "upload a file" do
- user = insert(:user)
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- response = TwitterAPI.upload(file, user)
-
- assert is_binary(response)
- end
-
- test "it favorites a status, returns the updated activity" do
- user = insert(:user)
- other_user = insert(:user)
- note_activity = insert(:note_activity)
-
- {:ok, status} = TwitterAPI.fav(user, note_activity.id)
- updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
- assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 1
-
- object = Object.normalize(note_activity)
-
- assert object.data["like_count"] == 1
-
- assert status == updated_activity
-
- {:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
-
- object = Object.normalize(note_activity)
-
- assert object.data["like_count"] == 2
-
- updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
- assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 2
- end
-
- test "it unfavorites a status, returns the updated activity" do
- user = insert(:user)
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
-
- {:ok, _like_activity, _object} = ActivityPub.like(user, object)
- updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
-
- assert ActivityView.render("activity.json", activity: updated_activity)["fave_num"] == 1
-
- {:ok, activity} = TwitterAPI.unfav(user, note_activity.id)
-
- assert ActivityView.render("activity.json", activity: activity)["fave_num"] == 0
- end
-
- test "it retweets a status and returns the retweet" do
- user = insert(:user)
- note_activity = insert(:note_activity)
-
- {:ok, status} = TwitterAPI.repeat(user, note_activity.id)
- updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
-
- assert status == updated_activity
- end
-
- test "it unretweets an already retweeted status" do
- user = insert(:user)
- note_activity = insert(:note_activity)
-
- {:ok, _status} = TwitterAPI.repeat(user, note_activity.id)
- {:ok, status} = TwitterAPI.unrepeat(user, note_activity.id)
- updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
-
- assert status == updated_activity
- end
-
test "it registers a new user and returns the user." do
data = %{
"nickname" => "lain",
@@ -701,19 +451,4 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
:ok
end
-
- describe "fetching a user by uri" do
- test "fetches a user by uri" do
- id = "https://mastodon.social/users/lambadalambda"
- user = insert(:user)
- {:ok, represented} = TwitterAPI.get_external_profile(user, id)
- remote = User.get_cached_by_ap_id(id)
-
- assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
-
- # Also fetches the feed.
- # assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
- # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
- end
- end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
deleted file mode 100644
index 56d861efb..000000000
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ /dev/null
@@ -1,384 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
- use Pleroma.DataCase
-
- alias Pleroma.Activity
- alias Pleroma.Object
- alias Pleroma.Repo
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.TwitterAPI.ActivityView
- alias Pleroma.Web.TwitterAPI.UserView
-
- import Pleroma.Factory
- import Tesla.Mock
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- import Mock
-
- test "returns a temporary ap_id based user for activities missing db users" do
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
-
- Repo.delete(user)
- Cachex.clear(:user_cache)
-
- %{"user" => tw_user} = ActivityView.render("activity.json", activity: activity)
-
- assert tw_user["screen_name"] == "erroruser@example.com"
- assert tw_user["name"] == user.ap_id
- assert tw_user["statusnet_profile_url"] == user.ap_id
- end
-
- test "tries to get a user by nickname if fetching by ap_id doesn't work" do
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
-
- {:ok, user} =
- user
- |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
- |> Repo.update()
-
- Cachex.clear(:user_cache)
-
- result = ActivityView.render("activity.json", activity: activity)
- assert result["user"]["id"] == user.id
- end
-
- test "tells if the message is muted for some reason" do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, user} = User.mute(user, other_user)
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
- status = ActivityView.render("activity.json", %{activity: activity})
-
- assert status["muted"] == false
-
- status = ActivityView.render("activity.json", %{activity: activity, for: user})
-
- assert status["muted"] == true
- end
-
- test "a create activity with a html status" do
- text = """
- #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
- """
-
- {:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
-
- result = ActivityView.render("activity.json", activity: activity)
-
- assert result["statusnet_html"] ==
- "#Bike log - Commute Tuesday
https://pla.bike/posts/20181211/
#cycling #CHScycling #commute
MVIMG_20181211_054020.jpg"
-
- assert result["text"] ==
- "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
- end
-
- test "a create activity with a summary containing emoji" do
- {:ok, activity} =
- CommonAPI.post(insert(:user), %{
- "spoiler_text" => ":firefox: meow",
- "status" => "."
- })
-
- result = ActivityView.render("activity.json", activity: activity)
-
- expected = ":firefox: meow"
-
- expected_html =
- "
meow"
-
- assert result["summary"] == expected
- assert result["summary_html"] == expected_html
- end
-
- test "a create activity with a summary containing invalid HTML" do
- {:ok, activity} =
- CommonAPI.post(insert(:user), %{
- "spoiler_text" => "meow",
- "status" => "."
- })
-
- result = ActivityView.render("activity.json", activity: activity)
-
- expected = "meow"
-
- assert result["summary"] == expected
- assert result["summary_html"] == expected
- end
-
- test "a create activity with a note" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
- object = Object.normalize(activity)
-
- result = ActivityView.render("activity.json", activity: activity)
-
- convo_id = Utils.context_to_conversation_id(object.data["context"])
-
- expected = %{
- "activity_type" => "post",
- "attachments" => [],
- "attentions" => [
- UserView.render("show.json", %{user: other_user})
- ],
- "created_at" => object.data["published"] |> Utils.date_to_asctime(),
- "external_url" => object.data["id"],
- "fave_num" => 0,
- "favorited" => false,
- "id" => activity.id,
- "in_reply_to_status_id" => nil,
- "in_reply_to_screen_name" => nil,
- "in_reply_to_user_id" => nil,
- "in_reply_to_profileurl" => nil,
- "in_reply_to_ostatus_uri" => nil,
- "is_local" => true,
- "is_post_verb" => true,
- "possibly_sensitive" => false,
- "repeat_num" => 0,
- "repeated" => false,
- "pinned" => false,
- "statusnet_conversation_id" => convo_id,
- "summary" => "",
- "summary_html" => "",
- "statusnet_html" =>
- "Hey @shp!",
- "tags" => [],
- "text" => "Hey @shp!",
- "uri" => object.data["id"],
- "user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct",
- "card" => nil,
- "muted" => false
- }
-
- assert result == expected
- end
-
- test "a list of activities" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- object = Object.normalize(activity)
-
- convo_id = Utils.context_to_conversation_id(object.data["context"])
-
- mocks = [
- {
- Utils,
- [:passthrough],
- [context_to_conversation_id: fn _ -> false end]
- },
- {
- User,
- [:passthrough],
- [get_cached_by_ap_id: fn _ -> nil end]
- }
- ]
-
- with_mocks mocks do
- [result] = ActivityView.render("index.json", activities: [activity])
-
- assert result["statusnet_conversation_id"] == convo_id
- assert result["user"]
- refute called(Utils.context_to_conversation_id(:_))
- refute called(User.get_cached_by_ap_id(user.ap_id))
- refute called(User.get_cached_by_ap_id(other_user.ap_id))
- end
- end
-
- test "an activity that is a reply" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
-
- {:ok, answer} =
- CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
-
- result = ActivityView.render("activity.json", %{activity: answer})
-
- assert result["in_reply_to_status_id"] == activity.id
- end
-
- test "a like activity" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
-
- result = ActivityView.render("activity.json", activity: like)
- activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
-
- expected = %{
- "activity_type" => "like",
- "created_at" => like.data["published"] |> Utils.date_to_asctime(),
- "external_url" => like.data["id"],
- "id" => like.id,
- "in_reply_to_status_id" => activity.id,
- "is_local" => true,
- "is_post_verb" => false,
- "favorited_status" => ActivityView.render("activity.json", activity: activity),
- "statusnet_html" => "shp favorited a status.",
- "text" => "shp favorited a status.",
- "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
- "user" => UserView.render("show.json", user: other_user)
- }
-
- assert result == expected
- end
-
- test "a like activity for deleted post" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
- CommonAPI.delete(activity.id, user)
-
- result = ActivityView.render("activity.json", activity: like)
-
- expected = %{
- "activity_type" => "like",
- "created_at" => like.data["published"] |> Utils.date_to_asctime(),
- "external_url" => like.data["id"],
- "id" => like.id,
- "in_reply_to_status_id" => nil,
- "is_local" => true,
- "is_post_verb" => false,
- "favorited_status" => nil,
- "statusnet_html" => "shp favorited a status.",
- "text" => "shp favorited a status.",
- "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
- "user" => UserView.render("show.json", user: other_user)
- }
-
- assert result == expected
- end
-
- test "an announce activity" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- {:ok, announce, object} = CommonAPI.repeat(activity.id, other_user)
-
- convo_id = Utils.context_to_conversation_id(object.data["context"])
-
- activity = Activity.get_by_id(activity.id)
-
- result = ActivityView.render("activity.json", activity: announce)
-
- expected = %{
- "activity_type" => "repeat",
- "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
- "external_url" => announce.data["id"],
- "id" => announce.id,
- "is_local" => true,
- "is_post_verb" => false,
- "statusnet_html" => "shp repeated a status.",
- "text" => "shp repeated a status.",
- "uri" => "tag:#{announce.data["id"]}:objectType=note",
- "user" => UserView.render("show.json", user: other_user),
- "retweeted_status" => ActivityView.render("activity.json", activity: activity),
- "statusnet_conversation_id" => convo_id
- }
-
- assert result == expected
- end
-
- test "A follow activity" do
- user = insert(:user)
- other_user = insert(:user, %{nickname: "shp"})
-
- {:ok, follower} = User.follow(user, other_user)
- {:ok, follow} = ActivityPub.follow(follower, other_user)
-
- result = ActivityView.render("activity.json", activity: follow)
-
- expected = %{
- "activity_type" => "follow",
- "attentions" => [],
- "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
- "external_url" => follow.data["id"],
- "id" => follow.id,
- "in_reply_to_status_id" => nil,
- "is_local" => true,
- "is_post_verb" => false,
- "statusnet_html" => "#{user.nickname} started following shp",
- "text" => "#{user.nickname} started following shp",
- "user" => UserView.render("show.json", user: user)
- }
-
- assert result == expected
- end
-
- test "a delete activity" do
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- {:ok, delete} = CommonAPI.delete(activity.id, user)
-
- result = ActivityView.render("activity.json", activity: delete)
-
- expected = %{
- "activity_type" => "delete",
- "attentions" => [],
- "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
- "external_url" => delete.data["id"],
- "id" => delete.id,
- "in_reply_to_status_id" => nil,
- "is_local" => true,
- "is_post_verb" => false,
- "statusnet_html" => "deleted notice {{tag",
- "text" => "deleted notice {{tag",
- "uri" => Object.normalize(delete).data["id"],
- "user" => UserView.render("show.json", user: user)
- }
-
- assert result == expected
- end
-
- test "a peertube video" do
- {:ok, object} =
- Pleroma.Object.Fetcher.fetch_object_from_id(
- "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
- )
-
- %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
-
- result = ActivityView.render("activity.json", activity: activity)
-
- assert length(result["attachments"]) == 1
- assert result["summary"] == "Friday Night"
- end
-
- test "special characters are not escaped in text field for status created" do
- text = "<3 is on the way"
-
- {:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
-
- result = ActivityView.render("activity.json", activity: activity)
-
- assert result["text"] == text
- end
-end
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
deleted file mode 100644
index 6baeeaf63..000000000
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ /dev/null
@@ -1,112 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
- use Pleroma.DataCase
-
- alias Pleroma.Notification
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.TwitterAPI.ActivityView
- alias Pleroma.Web.TwitterAPI.NotificationView
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.TwitterAPI.UserView
-
- import Pleroma.Factory
-
- setup do
- user = insert(:user, bio: "Here's some html")
- [user: user]
- end
-
- test "A follow notification" do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
- follower = insert(:user)
-
- {:ok, follower} = User.follow(follower, user)
- {:ok, activity} = ActivityPub.follow(follower, user)
- Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
- [follow_notif] = Notification.for_user(user)
-
- represented = %{
- "created_at" => follow_notif.inserted_at |> Utils.format_naive_asctime(),
- "from_profile" => UserView.render("show.json", %{user: follower, for: user}),
- "id" => follow_notif.id,
- "is_seen" => 0,
- "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
- "ntype" => "follow"
- }
-
- assert represented ==
- NotificationView.render("notification.json", %{notification: follow_notif, for: user})
- end
-
- test "A mention notification" do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
-
- [notification] = Notification.for_user(user)
-
- represented = %{
- "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
- "from_profile" => UserView.render("show.json", %{user: other_user, for: user}),
- "id" => notification.id,
- "is_seen" => 0,
- "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
- "ntype" => "mention"
- }
-
- assert represented ==
- NotificationView.render("notification.json", %{notification: notification, for: user})
- end
-
- test "A retweet notification" do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
- repeater = insert(:user)
-
- {:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
- [notification] = Notification.for_user(user)
-
- represented = %{
- "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
- "from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
- "id" => notification.id,
- "is_seen" => 0,
- "notice" =>
- ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
- "ntype" => "repeat"
- }
-
- assert represented ==
- NotificationView.render("notification.json", %{notification: notification, for: user})
- end
-
- test "A like notification" do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
- liker = insert(:user)
-
- {:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
- [notification] = Notification.for_user(user)
-
- represented = %{
- "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
- "from_profile" => UserView.render("show.json", %{user: liker, for: user}),
- "id" => notification.id,
- "is_seen" => 0,
- "notice" =>
- ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
- "ntype" => "like"
- }
-
- assert represented ==
- NotificationView.render("notification.json", %{notification: notification, for: user})
- end
-end
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
deleted file mode 100644
index 70c5a0b7f..000000000
--- a/test/web/twitter_api/views/user_view_test.exs
+++ /dev/null
@@ -1,323 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.TwitterAPI.UserViewTest do
- use Pleroma.DataCase
-
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.TwitterAPI.UserView
-
- import Pleroma.Factory
-
- setup do
- user = insert(:user, bio: "Here's some html")
- [user: user]
- end
-
- test "A user with only a nickname", %{user: user} do
- user = %{user | name: nil, nickname: "scarlett@catgirl.science"}
- represented = UserView.render("show.json", %{user: user})
- assert represented["name"] == user.nickname
- assert represented["name_html"] == user.nickname
- end
-
- test "A user with an avatar object", %{user: user} do
- image = "image"
- user = %{user | avatar: %{"url" => [%{"href" => image}]}}
- represented = UserView.render("show.json", %{user: user})
- assert represented["profile_image_url"] == image
- end
-
- test "A user with emoji in username" do
- expected =
- "
man"
-
- user =
- insert(:user, %{
- info: %{
- source_data: %{
- "tag" => [
- %{
- "type" => "Emoji",
- "icon" => %{"url" => "/file.png"},
- "name" => ":karjalanpiirakka:"
- }
- ]
- }
- },
- name: ":karjalanpiirakka: man"
- })
-
- represented = UserView.render("show.json", %{user: user})
- assert represented["name_html"] == expected
- end
-
- test "A user" do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
- {:ok, user} = User.update_note_count(user)
- follower = insert(:user)
- second_follower = insert(:user)
-
- User.follow(follower, user)
- User.follow(second_follower, user)
- User.follow(user, follower)
- {:ok, user} = User.update_follower_count(user)
- Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
-
- image = "http://localhost:4001/images/avi.png"
- banner = "http://localhost:4001/images/banner.png"
-
- represented = %{
- "id" => user.id,
- "name" => user.name,
- "screen_name" => user.nickname,
- "name_html" => user.name,
- "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("
", "\n")),
- "description_html" => HtmlSanitizeEx.basic_html(user.bio),
- "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
- "favourites_count" => 0,
- "statuses_count" => 1,
- "friends_count" => 1,
- "followers_count" => 2,
- "profile_image_url" => image,
- "profile_image_url_https" => image,
- "profile_image_url_profile_size" => image,
- "profile_image_url_original" => image,
- "following" => false,
- "follows_you" => false,
- "statusnet_blocking" => false,
- "statusnet_profile_url" => user.ap_id,
- "cover_photo" => banner,
- "background_image" => nil,
- "is_local" => true,
- "locked" => false,
- "hide_follows" => false,
- "hide_followers" => false,
- "fields" => [],
- "pleroma" => %{
- "confirmation_pending" => false,
- "tags" => [],
- "skip_thread_containment" => false
- },
- "rights" => %{"admin" => false, "delete_others_notice" => false},
- "role" => "member"
- }
-
- assert represented == UserView.render("show.json", %{user: user})
- end
-
- test "User exposes settings for themselves and only for themselves", %{user: user} do
- as_user = UserView.render("show.json", %{user: user, for: user})
- assert as_user["default_scope"] == user.info.default_scope
- assert as_user["no_rich_text"] == user.info.no_rich_text
- assert as_user["pleroma"]["notification_settings"] == user.info.notification_settings
- as_stranger = UserView.render("show.json", %{user: user})
- refute as_stranger["default_scope"]
- refute as_stranger["no_rich_text"]
- refute as_stranger["pleroma"]["notification_settings"]
- end
-
- test "A user for a given other follower", %{user: user} do
- follower = insert(:user, %{following: [User.ap_followers(user)]})
- {:ok, user} = User.update_follower_count(user)
- image = "http://localhost:4001/images/avi.png"
- banner = "http://localhost:4001/images/banner.png"
-
- represented = %{
- "id" => user.id,
- "name" => user.name,
- "screen_name" => user.nickname,
- "name_html" => user.name,
- "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("
", "\n")),
- "description_html" => HtmlSanitizeEx.basic_html(user.bio),
- "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
- "favourites_count" => 0,
- "statuses_count" => 0,
- "friends_count" => 0,
- "followers_count" => 1,
- "profile_image_url" => image,
- "profile_image_url_https" => image,
- "profile_image_url_profile_size" => image,
- "profile_image_url_original" => image,
- "following" => true,
- "follows_you" => false,
- "statusnet_blocking" => false,
- "statusnet_profile_url" => user.ap_id,
- "cover_photo" => banner,
- "background_image" => nil,
- "is_local" => true,
- "locked" => false,
- "hide_follows" => false,
- "hide_followers" => false,
- "fields" => [],
- "pleroma" => %{
- "confirmation_pending" => false,
- "tags" => [],
- "skip_thread_containment" => false
- },
- "rights" => %{"admin" => false, "delete_others_notice" => false},
- "role" => "member"
- }
-
- assert represented == UserView.render("show.json", %{user: user, for: follower})
- end
-
- test "A user that follows you", %{user: user} do
- follower = insert(:user)
- {:ok, follower} = User.follow(follower, user)
- {:ok, user} = User.update_follower_count(user)
- image = "http://localhost:4001/images/avi.png"
- banner = "http://localhost:4001/images/banner.png"
-
- represented = %{
- "id" => follower.id,
- "name" => follower.name,
- "screen_name" => follower.nickname,
- "name_html" => follower.name,
- "description" => HtmlSanitizeEx.strip_tags(follower.bio |> String.replace("
", "\n")),
- "description_html" => HtmlSanitizeEx.basic_html(follower.bio),
- "created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
- "favourites_count" => 0,
- "statuses_count" => 0,
- "friends_count" => 1,
- "followers_count" => 0,
- "profile_image_url" => image,
- "profile_image_url_https" => image,
- "profile_image_url_profile_size" => image,
- "profile_image_url_original" => image,
- "following" => false,
- "follows_you" => true,
- "statusnet_blocking" => false,
- "statusnet_profile_url" => follower.ap_id,
- "cover_photo" => banner,
- "background_image" => nil,
- "is_local" => true,
- "locked" => false,
- "hide_follows" => false,
- "hide_followers" => false,
- "fields" => [],
- "pleroma" => %{
- "confirmation_pending" => false,
- "tags" => [],
- "skip_thread_containment" => false
- },
- "rights" => %{"admin" => false, "delete_others_notice" => false},
- "role" => "member"
- }
-
- assert represented == UserView.render("show.json", %{user: follower, for: user})
- end
-
- test "a user that is a moderator" do
- user = insert(:user, %{info: %{is_moderator: true}})
- represented = UserView.render("show.json", %{user: user, for: user})
-
- assert represented["rights"]["delete_others_notice"]
- assert represented["role"] == "moderator"
- end
-
- test "a user that is a admin" do
- user = insert(:user, %{info: %{is_admin: true}})
- represented = UserView.render("show.json", %{user: user, for: user})
-
- assert represented["rights"]["admin"]
- assert represented["role"] == "admin"
- end
-
- test "A moderator with hidden role for another user", %{user: user} do
- admin = insert(:user, %{info: %{is_moderator: true, show_role: false}})
- represented = UserView.render("show.json", %{user: admin, for: user})
-
- assert represented["role"] == nil
- end
-
- test "An admin with hidden role for another user", %{user: user} do
- admin = insert(:user, %{info: %{is_admin: true, show_role: false}})
- represented = UserView.render("show.json", %{user: admin, for: user})
-
- assert represented["role"] == nil
- end
-
- test "A regular user for the admin", %{user: user} do
- admin = insert(:user, %{info: %{is_admin: true}})
- represented = UserView.render("show.json", %{user: user, for: admin})
-
- assert represented["pleroma"]["deactivated"] == false
- end
-
- test "A blocked user for the blocker" do
- user = insert(:user)
- blocker = insert(:user)
- User.block(blocker, user)
- image = "http://localhost:4001/images/avi.png"
- banner = "http://localhost:4001/images/banner.png"
-
- represented = %{
- "id" => user.id,
- "name" => user.name,
- "screen_name" => user.nickname,
- "name_html" => user.name,
- "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("
", "\n")),
- "description_html" => HtmlSanitizeEx.basic_html(user.bio),
- "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
- "favourites_count" => 0,
- "statuses_count" => 0,
- "friends_count" => 0,
- "followers_count" => 0,
- "profile_image_url" => image,
- "profile_image_url_https" => image,
- "profile_image_url_profile_size" => image,
- "profile_image_url_original" => image,
- "following" => false,
- "follows_you" => false,
- "statusnet_blocking" => true,
- "statusnet_profile_url" => user.ap_id,
- "cover_photo" => banner,
- "background_image" => nil,
- "is_local" => true,
- "locked" => false,
- "hide_follows" => false,
- "hide_followers" => false,
- "fields" => [],
- "pleroma" => %{
- "confirmation_pending" => false,
- "tags" => [],
- "skip_thread_containment" => false
- },
- "rights" => %{"admin" => false, "delete_others_notice" => false},
- "role" => "member"
- }
-
- blocker = User.get_cached_by_id(blocker.id)
- assert represented == UserView.render("show.json", %{user: user, for: blocker})
- end
-
- test "a user with mastodon fields" do
- fields = [
- %{
- "name" => "Pronouns",
- "value" => "she/her"
- },
- %{
- "name" => "Website",
- "value" => "https://example.org/"
- }
- ]
-
- user =
- insert(:user, %{
- info: %{
- source_data: %{
- "attachment" =>
- Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end)
- }
- }
- })
-
- userview = UserView.render("show.json", %{user: user})
- assert userview["fields"] == fields
- end
-end
--
cgit v1.2.3
From 985122cc03380b8e3decd4ac7180ea5b0f7ab30d Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 31 Aug 2019 10:31:15 +0300
Subject: Remove Activity, User and Notification views from TwitterAPI
---
test/web/twitter_api/twitter_api_test.exs | 38 ++++++++++++-------------------
1 file changed, 15 insertions(+), 23 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index ac9c0c27e..50ed43c15 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -7,9 +7,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.UserInviteToken
- alias Pleroma.Web.TwitterAPI.ActivityView
alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Web.MastodonAPI.AccountView
import Pleroma.Factory
@@ -31,8 +30,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
fetched_user = User.get_cached_by_nickname("lain")
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
end
test "it registers a new user with empty string in bio and returns the user." do
@@ -49,8 +48,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
fetched_user = User.get_cached_by_nickname("lain")
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
end
test "it sends confirmation email if :account_activation_required is specified in instance config" do
@@ -147,8 +146,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert invite.used == true
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
end
test "returns error on invalid token" do
@@ -212,8 +211,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
fetched_user = User.get_cached_by_nickname("vinny")
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
end
{:ok, data: data, check_fn: check_fn}
@@ -287,8 +286,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert invite.used == true
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
data = %{
"nickname" => "GrimReaper",
@@ -338,8 +337,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
refute invite.used
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
end
test "error after max uses" do
@@ -362,8 +361,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
- assert UserView.render("show.json", %{user: user}) ==
- UserView.render("show.json", %{user: fetched_user})
+ assert AccountView.render("account.json", %{user: user}) ==
+ AccountView.render("account.json", %{user: fetched_user})
data = %{
"nickname" => "GrimReaper",
@@ -439,13 +438,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
refute User.get_cached_by_nickname("lain")
end
- test "it assigns an integer conversation_id" do
- note_activity = insert(:note_activity)
- status = ActivityView.render("activity.json", activity: note_activity)
-
- assert is_number(status["statusnet_conversation_id"])
- end
-
setup do
Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
--
cgit v1.2.3
From 64410497d20869f9b6c1c92a48761157048b0cb9 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 31 Aug 2019 10:41:15 +0300
Subject: Remove TwitterAPI representers
---
.../representers/object_representer_test.exs | 60 ----------------------
1 file changed, 60 deletions(-)
delete mode 100644 test/web/twitter_api/representers/object_representer_test.exs
(limited to 'test')
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
deleted file mode 100644
index c3cf330f1..000000000
--- a/test/web/twitter_api/representers/object_representer_test.exs
+++ /dev/null
@@ -1,60 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
- use Pleroma.DataCase
-
- alias Pleroma.Object
- alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
-
- test "represent an image attachment" do
- object = %Object{
- id: 5,
- data: %{
- "type" => "Image",
- "url" => [
- %{
- "mediaType" => "sometype",
- "href" => "someurl"
- }
- ],
- "uuid" => 6
- }
- }
-
- expected_object = %{
- id: 6,
- url: "someurl",
- mimetype: "sometype",
- oembed: false,
- description: nil
- }
-
- assert expected_object == ObjectRepresenter.to_map(object)
- end
-
- test "represents mastodon-style attachments" do
- object = %Object{
- id: nil,
- data: %{
- "mediaType" => "image/png",
- "name" => "blabla",
- "type" => "Document",
- "url" =>
- "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
- }
- }
-
- expected_object = %{
- url:
- "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
- mimetype: "image/png",
- oembed: false,
- id: nil,
- description: "blabla"
- }
-
- assert expected_object == ObjectRepresenter.to_map(object)
- end
-end
--
cgit v1.2.3
From dbfcba85ec2d3336219c75a32adbcff93a684309 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 31 Aug 2019 10:45:37 +0300
Subject: Add a changelog entry for twitterapi removal and fix credo issues
---
test/web/twitter_api/twitter_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 50ed43c15..0a57e174f 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -7,8 +7,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.UserInviteToken
- alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
import Pleroma.Factory
--
cgit v1.2.3
From 9cabc02864ff33b76f424a342732ef8039dfd73d Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 31 Aug 2019 10:57:35 +0300
Subject: Remove a useless import
---
test/web/twitter_api/twitter_api_test.exs | 2 --
1 file changed, 2 deletions(-)
(limited to 'test')
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 0a57e174f..c5b18234e 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -10,8 +10,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.TwitterAPI.TwitterAPI
- import Pleroma.Factory
-
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
--
cgit v1.2.3
From a90ea8ba1562818b025f677ffeea35f7ca08ddf2 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 31 Aug 2019 19:08:56 +0300
Subject: [#1149] Addressed code review comments (code style, jobs pruning
etc.).
---
test/user_test.exs | 2 +-
test/web/activity_pub/activity_pub_controller_test.exs | 2 +-
test/web/federator_test.exs | 2 +-
test/web/websub/websub_test.exs | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 86232de99..0acd0db4e 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1123,7 +1123,7 @@ defmodule Pleroma.UserTest do
"id" => "pleroma:fakeid"
}
},
- all_enqueued(worker: Pleroma.Workers.Publisher)
+ all_enqueued(worker: Pleroma.Workers.PublisherWorker)
)
end
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index a1b567a46..f1c1bb503 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -17,7 +17,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.Web.ActivityPub.UserView
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
- alias Pleroma.Workers.Receiver, as: ReceiverWorker
+ alias Pleroma.Workers.ReceiverWorker
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 5724672fd..4096d4690 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
- alias Pleroma.Workers.Publisher, as: PublisherWorker
+ alias Pleroma.Workers.PublisherWorker
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 414610879..929acf5a2 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.WebsubTest do
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.Web.Websub.WebsubServerSubscription
- alias Pleroma.Workers.Subscriber, as: SubscriberWorker
+ alias Pleroma.Workers.SubscriberWorker
import Pleroma.Factory
import Tesla.Mock
--
cgit v1.2.3
From 6c2fd1b78bbbb4486a5dddeffa053199ba8cc015 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sun, 1 Sep 2019 21:38:15 +0300
Subject: Fix tests
---
test/web/admin_api/admin_api_controller_test.exs | 26 +++++++++++++-----------
1 file changed, 14 insertions(+), 12 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index eaf847b25..b87fffc34 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -2286,9 +2286,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn = get(conn, "/api/pleroma/admin/moderation_log")
response = json_response(conn, 200)
- [first_entry, second_entry] = response
+ [first_entry, second_entry] = response["items"]
- assert response |> length() == 2
+ assert response["total"] == 2
assert first_entry["data"]["action"] == "relay_unfollow"
assert first_entry["message"] ==
@@ -2330,9 +2330,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn1 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=1")
response1 = json_response(conn1, 200)
- [first_entry] = response1
+ [first_entry] = response1["items"]
- assert response1 |> length() == 1
+ assert response1["total"] == 2
+ assert response1["items"] |> length() == 1
assert first_entry["data"]["action"] == "relay_unfollow"
assert first_entry["message"] ==
@@ -2341,9 +2342,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn2 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=2")
response2 = json_response(conn2, 200)
- [second_entry] = response2
+ [second_entry] = response2["items"]
- assert response2 |> length() == 1
+ assert response2["total"] == 2
+ assert response2["items"] |> length() == 1
assert second_entry["data"]["action"] == "relay_follow"
assert second_entry["message"] ==
@@ -2387,9 +2389,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
)
response1 = json_response(conn1, 200)
- [first_entry] = response1
+ [first_entry] = response1["items"]
- assert response1 |> length() == 1
+ assert response1["total"] == 1
assert first_entry["data"]["action"] == "relay_unfollow"
assert first_entry["message"] ==
@@ -2424,9 +2426,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn1 = get(conn, "/api/pleroma/admin/moderation_log?user_id=#{moderator.id}")
response1 = json_response(conn1, 200)
- [first_entry] = response1
+ [first_entry] = response1["items"]
- assert response1 |> length() == 1
+ assert response1["total"] == 1
assert get_in(first_entry, ["data", "actor", "id"]) == moderator.id
end
@@ -2446,9 +2448,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn1 = get(conn, "/api/pleroma/admin/moderation_log?search=unfo")
response1 = json_response(conn1, 200)
- [first_entry] = response1
+ [first_entry] = response1["items"]
- assert response1 |> length() == 1
+ assert response1["total"] == 1
assert get_in(first_entry, ["data", "message"]) ==
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
--
cgit v1.2.3
From 35ef470d000c53e21c6f867d53ca3a83260d93b8 Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Mon, 2 Sep 2019 12:15:21 +0100
Subject: truncate fields for remote users instead
---
test/user_test.exs | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 2cbc1f525..68a469fe3 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1117,11 +1117,20 @@ defmodule Pleroma.UserTest do
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end
- test "insert or update a user from given data" do
- user = insert(:user, %{nickname: "nick@name.de"})
- data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
+ describe "insert or update a user from given data" do
+ test "with normal data" do
+ user = insert(:user, %{nickname: "nick@name.de"})
+ data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
- assert {:ok, %User{}} = User.insert_or_update_user(data)
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
+
+ test "with overly long fields" do
+ current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
+ user = insert(:user, nickname: "nickname@supergood.domain")
+ data = %{ap_id: user.ap_id, info: %{ fields: [%{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}] }}
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
end
describe "per-user rich-text filtering" do
--
cgit v1.2.3
From 05c935c3961e4c1a20c7713611920318d45d4b57 Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Mon, 2 Sep 2019 12:15:40 +0100
Subject: mix format
---
test/user_test.exs | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 68a469fe3..0ca310331 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1119,17 +1119,26 @@ defmodule Pleroma.UserTest do
describe "insert or update a user from given data" do
test "with normal data" do
- user = insert(:user, %{nickname: "nick@name.de"})
- data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
+ user = insert(:user, %{nickname: "nick@name.de"})
+ data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
- assert {:ok, %User{}} = User.insert_or_update_user(data)
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
end
test "with overly long fields" do
- current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
- user = insert(:user, nickname: "nickname@supergood.domain")
- data = %{ap_id: user.ap_id, info: %{ fields: [%{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}] }}
- assert {:ok, %User{}} = User.insert_or_update_user(data)
+ current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
+ user = insert(:user, nickname: "nickname@supergood.domain")
+
+ data = %{
+ ap_id: user.ap_id,
+ info: %{
+ fields: [
+ %{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
+ ]
+ }
+ }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
end
end
--
cgit v1.2.3
From e73685834c1797404c943f66417ffa30add87e04 Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Mon, 2 Sep 2019 12:35:55 +0100
Subject: add mandatory fields for user update
---
test/user_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 0ca310331..92a48f630 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1131,6 +1131,8 @@ defmodule Pleroma.UserTest do
data = %{
ap_id: user.ap_id,
+ name: user.name,
+ nickname: user.nickname,
info: %{
fields: [
%{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
--
cgit v1.2.3
From b49085c156a6a4449c95c2c315f6250317122735 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Mon, 2 Sep 2019 14:57:40 +0300
Subject: [#1149] Refactoring: GenServer workers renamed to daemons, `use
Oban.Worker` moved to helper.
---
test/activity_expiration_worker_test.exs | 17 ------------
test/daemons/activity_expiration_daemon_test.exs | 17 ++++++++++++
test/daemons/digest_email_daemon_test.exs | 35 ++++++++++++++++++++++++
test/daemons/scheduled_activity_daemon_test.exs | 19 +++++++++++++
test/scheduled_activity_worker_test.exs | 19 -------------
test/web/digest_email_worker_test.exs | 35 ------------------------
6 files changed, 71 insertions(+), 71 deletions(-)
delete mode 100644 test/activity_expiration_worker_test.exs
create mode 100644 test/daemons/activity_expiration_daemon_test.exs
create mode 100644 test/daemons/digest_email_daemon_test.exs
create mode 100644 test/daemons/scheduled_activity_daemon_test.exs
delete mode 100644 test/scheduled_activity_worker_test.exs
delete mode 100644 test/web/digest_email_worker_test.exs
(limited to 'test')
diff --git a/test/activity_expiration_worker_test.exs b/test/activity_expiration_worker_test.exs
deleted file mode 100644
index 939d912f1..000000000
--- a/test/activity_expiration_worker_test.exs
+++ /dev/null
@@ -1,17 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.ActivityExpirationWorkerTest do
- use Pleroma.DataCase
- alias Pleroma.Activity
- import Pleroma.Factory
-
- test "deletes an activity" do
- activity = insert(:note_activity)
- expiration = insert(:expiration_in_the_past, %{activity_id: activity.id})
- Pleroma.ActivityExpirationWorker.perform(:execute, expiration.id)
-
- refute Repo.get(Activity, activity.id)
- end
-end
diff --git a/test/daemons/activity_expiration_daemon_test.exs b/test/daemons/activity_expiration_daemon_test.exs
new file mode 100644
index 000000000..31f4a70a6
--- /dev/null
+++ b/test/daemons/activity_expiration_daemon_test.exs
@@ -0,0 +1,17 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ActivityExpirationWorkerTest do
+ use Pleroma.DataCase
+ alias Pleroma.Activity
+ import Pleroma.Factory
+
+ test "deletes an activity" do
+ activity = insert(:note_activity)
+ expiration = insert(:expiration_in_the_past, %{activity_id: activity.id})
+ Pleroma.Daemons.ActivityExpirationDaemon.perform(:execute, expiration.id)
+
+ refute Repo.get(Activity, activity.id)
+ end
+end
diff --git a/test/daemons/digest_email_daemon_test.exs b/test/daemons/digest_email_daemon_test.exs
new file mode 100644
index 000000000..3168f3b9a
--- /dev/null
+++ b/test/daemons/digest_email_daemon_test.exs
@@ -0,0 +1,35 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.DigestEmailDaemonTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.Daemons.DigestEmailDaemon
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ test "it sends digest emails" do
+ user = insert(:user)
+
+ date =
+ Timex.now()
+ |> Timex.shift(days: -10)
+ |> Timex.to_naive_datetime()
+
+ user2 = insert(:user, last_digest_emailed_at: date)
+ User.switch_email_notifications(user2, "digest", true)
+ CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
+
+ DigestEmailDaemon.perform()
+ ObanHelpers.perform_all()
+ # Performing job(s) enqueued at previous step
+ ObanHelpers.perform_all()
+
+ assert_received {:email, email}
+ assert email.to == [{user2.name, user2.email}]
+ assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
+ end
+end
diff --git a/test/daemons/scheduled_activity_daemon_test.exs b/test/daemons/scheduled_activity_daemon_test.exs
new file mode 100644
index 000000000..32820b2b7
--- /dev/null
+++ b/test/daemons/scheduled_activity_daemon_test.exs
@@ -0,0 +1,19 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ScheduledActivityDaemonTest do
+ use Pleroma.DataCase
+ alias Pleroma.ScheduledActivity
+ import Pleroma.Factory
+
+ test "creates a status from the scheduled activity" do
+ user = insert(:user)
+ scheduled_activity = insert(:scheduled_activity, user: user, params: %{status: "hi"})
+ Pleroma.Daemons.ScheduledActivityDaemon.perform(:execute, scheduled_activity.id)
+
+ refute Repo.get(ScheduledActivity, scheduled_activity.id)
+ activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
+ assert Pleroma.Object.normalize(activity).data["content"] == "hi"
+ end
+end
diff --git a/test/scheduled_activity_worker_test.exs b/test/scheduled_activity_worker_test.exs
deleted file mode 100644
index e3ad1244e..000000000
--- a/test/scheduled_activity_worker_test.exs
+++ /dev/null
@@ -1,19 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.ScheduledActivityWorkerTest do
- use Pleroma.DataCase
- alias Pleroma.ScheduledActivity
- import Pleroma.Factory
-
- test "creates a status from the scheduled activity" do
- user = insert(:user)
- scheduled_activity = insert(:scheduled_activity, user: user, params: %{status: "hi"})
- Pleroma.ScheduledActivityWorker.perform(:execute, scheduled_activity.id)
-
- refute Repo.get(ScheduledActivity, scheduled_activity.id)
- activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
- assert Pleroma.Object.normalize(activity).data["content"] == "hi"
- end
-end
diff --git a/test/web/digest_email_worker_test.exs b/test/web/digest_email_worker_test.exs
deleted file mode 100644
index 5dfd920fa..000000000
--- a/test/web/digest_email_worker_test.exs
+++ /dev/null
@@ -1,35 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.DigestEmailWorkerTest do
- use Pleroma.DataCase
- import Pleroma.Factory
-
- alias Pleroma.DigestEmailWorker
- alias Pleroma.Tests.ObanHelpers
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI
-
- test "it sends digest emails" do
- user = insert(:user)
-
- date =
- Timex.now()
- |> Timex.shift(days: -10)
- |> Timex.to_naive_datetime()
-
- user2 = insert(:user, last_digest_emailed_at: date)
- User.switch_email_notifications(user2, "digest", true)
- CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
-
- DigestEmailWorker.perform()
- ObanHelpers.perform_all()
- # Performing job(s) enqueued at previous step
- ObanHelpers.perform_all()
-
- assert_received {:email, email}
- assert email.to == [{user2.name, user2.email}]
- assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
- end
-end
--
cgit v1.2.3
From 8cbad5500cefbba1e0bb67604960fc331b75b498 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 4 Sep 2019 15:25:12 +0300
Subject: add tests for activity_pub/utils.ex
---
test/web/activity_pub/utils_test.exs | 232 ++++++++++++++++++++++++++++++++++-
1 file changed, 228 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index eb429b2c4..b1c1d6f71 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -87,6 +87,18 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert Utils.determine_explicit_mentions(object) == []
end
+
+ test "works with an object has tags as map" do
+ object = %{
+ "tag" => %{
+ "type" => "Mention",
+ "href" => "https://example.com/~alyssa",
+ "name" => "Alyssa P. Hacker"
+ }
+ }
+
+ assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
+ end
end
describe "make_unlike_data/3" do
@@ -300,8 +312,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
{:ok, follow_activity_two} =
Utils.update_follow_state_for_all(follow_activity_two, "accept")
- assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
- assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
+ assert refresh_record(follow_activity).data["state"] == "accept"
+ assert refresh_record(follow_activity_two).data["state"] == "accept"
end
end
@@ -323,8 +335,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
{:ok, follow_activity_two} = Utils.update_follow_state(follow_activity_two, "reject")
- assert Repo.get(Activity, follow_activity.id).data["state"] == "pending"
- assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
+ assert refresh_record(follow_activity).data["state"] == "pending"
+ assert refresh_record(follow_activity_two).data["state"] == "reject"
end
end
@@ -401,4 +413,216 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert ^like_activity = Utils.get_existing_like(user.ap_id, object)
end
end
+
+ describe "get_get_existing_announce/2" do
+ test "returns nil if announce not found" do
+ actor = insert(:user)
+ refute Utils.get_existing_announce(actor.ap_id, %{data: %{"id" => "test"}})
+ end
+
+ test "fetches existing announce" do
+ note_activity = insert(:note_activity)
+ assert object = Object.normalize(note_activity)
+ actor = insert(:user)
+
+ {:ok, announce, _object} = ActivityPub.announce(actor, object)
+ assert Utils.get_existing_announce(actor.ap_id, object) == announce
+ end
+ end
+
+ describe "fetch_latest_block/2" do
+ test "fetches last block activities" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+
+ assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
+ assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
+ assert {:ok, %Activity{} = activity} = ActivityPub.block(user1, user2)
+
+ assert Utils.fetch_latest_block(user1, user2) == activity
+ end
+ end
+
+ describe "recipient_in_message/3" do
+ test "returns true when recipient in `to`" do
+ recipient = insert(:user)
+ actor = insert(:user)
+ assert Utils.recipient_in_message(recipient, actor, %{"to" => recipient.ap_id})
+
+ assert Utils.recipient_in_message(
+ recipient,
+ actor,
+ %{"to" => [recipient.ap_id], "cc" => ""}
+ )
+ end
+
+ test "returns true when recipient in `cc`" do
+ recipient = insert(:user)
+ actor = insert(:user)
+ assert Utils.recipient_in_message(recipient, actor, %{"cc" => recipient.ap_id})
+
+ assert Utils.recipient_in_message(
+ recipient,
+ actor,
+ %{"cc" => [recipient.ap_id], "to" => ""}
+ )
+ end
+
+ test "returns true when recipient in `bto`" do
+ recipient = insert(:user)
+ actor = insert(:user)
+ assert Utils.recipient_in_message(recipient, actor, %{"bto" => recipient.ap_id})
+
+ assert Utils.recipient_in_message(
+ recipient,
+ actor,
+ %{"bcc" => "", "bto" => [recipient.ap_id]}
+ )
+ end
+
+ test "returns true when recipient in `bcc`" do
+ recipient = insert(:user)
+ actor = insert(:user)
+ assert Utils.recipient_in_message(recipient, actor, %{"bcc" => recipient.ap_id})
+
+ assert Utils.recipient_in_message(
+ recipient,
+ actor,
+ %{"bto" => "", "bcc" => [recipient.ap_id]}
+ )
+ end
+
+ test "returns true when message without addresses fields" do
+ recipient = insert(:user)
+ actor = insert(:user)
+ assert Utils.recipient_in_message(recipient, actor, %{"bccc" => recipient.ap_id})
+
+ assert Utils.recipient_in_message(
+ recipient,
+ actor,
+ %{"btod" => "", "bccc" => [recipient.ap_id]}
+ )
+ end
+
+ test "returns false" do
+ recipient = insert(:user)
+ actor = insert(:user)
+ refute Utils.recipient_in_message(recipient, actor, %{"to" => "ap_id"})
+ end
+ end
+
+ describe "lazy_put_activity_defaults/2" do
+ test "returns map with id and published data" do
+ note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
+ res = Utils.lazy_put_activity_defaults(%{"context" => object.data["id"]})
+ assert res["context"] == object.data["id"]
+ assert res["context_id"] == object.id
+ assert res["id"]
+ assert res["published"]
+ end
+
+ test "returns map with fake id and published data" do
+ assert %{
+ "context" => "pleroma:fakecontext",
+ "context_id" => -1,
+ "id" => "pleroma:fakeid",
+ "published" => _
+ } = Utils.lazy_put_activity_defaults(%{}, true)
+ end
+
+ test "returns activity data with object" do
+ note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
+
+ res =
+ Utils.lazy_put_activity_defaults(%{
+ "context" => object.data["id"],
+ "object" => %{}
+ })
+
+ assert res["context"] == object.data["id"]
+ assert res["context_id"] == object.id
+ assert res["id"]
+ assert res["published"]
+ assert res["object"]["id"]
+ assert res["object"]["published"]
+ assert res["object"]["context"] == object.data["id"]
+ assert res["object"]["context_id"] == object.id
+ end
+ end
+
+ describe "make_flag_data" do
+ test "returns empty map when params is invalid" do
+ assert Utils.make_flag_data(%{}, %{}) == %{}
+ end
+
+ test "returns map with Flag object" do
+ reporter = insert(:user)
+ target_account = insert(:user)
+ {:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"})
+ context = Utils.generate_context_id()
+ content = "foobar"
+
+ target_ap_id = target_account.ap_id
+ activity_ap_id = activity.data["id"]
+
+ res =
+ Utils.make_flag_data(
+ %{
+ actor: reporter,
+ context: context,
+ account: target_account,
+ statuses: [%{"id" => activity.data["id"]}],
+ content: content
+ },
+ %{}
+ )
+
+ assert %{
+ "type" => "Flag",
+ "content" => ^content,
+ "context" => ^context,
+ "object" => [^target_ap_id, ^activity_ap_id],
+ "state" => "open"
+ } = res
+ end
+ end
+
+ describe "add_announce_to_object/2" do
+ test "adds actor to announcement" do
+ user = insert(:user)
+ object = insert(:note)
+
+ activity =
+ insert(:note_activity,
+ data: %{
+ "actor" => user.ap_id,
+ "cc" => [Pleroma.Constants.as_public()]
+ }
+ )
+
+ assert {:ok, updated_object} = Utils.add_announce_to_object(activity, object)
+ assert updated_object.data["announcements"] == [user.ap_id]
+ assert updated_object.data["announcement_count"] == 1
+ end
+ end
+
+ describe "remove_announce_from_object/2" do
+ test "removes actor from announcements" do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ object =
+ insert(:note,
+ data: %{"announcements" => [user.ap_id, user2.ap_id], "announcement_count" => 2}
+ )
+
+ activity = insert(:note_activity, data: %{"actor" => user.ap_id})
+
+ assert {:ok, updated_object} = Utils.remove_announce_from_object(activity, object)
+ assert updated_object.data["announcements"] == [user2.ap_id]
+ assert updated_object.data["announcement_count"] == 1
+ end
+ end
end
--
cgit v1.2.3
From 2975da284b75c846a99a56ce70a91ebc3cc43f33 Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Wed, 4 Sep 2019 15:45:40 +0100
Subject: truncate remote user bio/display name
---
test/user_test.exs | 45 +++++++++++++++++++++++++++++----------------
1 file changed, 29 insertions(+), 16 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 92a48f630..45f998ff8 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -570,22 +570,6 @@ defmodule Pleroma.UserTest do
refute cs.valid?
end)
end
-
- test "it restricts some sizes" do
- bio_limit = Pleroma.Config.get([:instance, :user_bio_length], 5000)
- name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
-
- [bio: bio_limit, name: name_limit]
- |> Enum.each(fn {field, size} ->
- string = String.pad_leading(".", size)
- cs = User.remote_user_creation(Map.put(@valid_remote, field, string))
- assert cs.valid?
-
- string = String.pad_leading(".", size + 1)
- cs = User.remote_user_creation(Map.put(@valid_remote, field, string))
- refute cs.valid?
- end)
- end
end
describe "followers and friends" do
@@ -1142,6 +1126,35 @@ defmodule Pleroma.UserTest do
assert {:ok, %User{}} = User.insert_or_update_user(data)
end
+
+ test "with an overly long bio" do
+ current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
+ user = insert(:user, nickname: "nickname@supergood.domain")
+
+ data = %{
+ ap_id: user.ap_id,
+ name: user.name,
+ nickname: user.nickname,
+ bio: String.duplicate("h", current_max_length + 1),
+ info: %{}
+ }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
+
+ test "with an overly long display name" do
+ current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
+ user = insert(:user, nickname: "nickname@supergood.domain")
+
+ data = %{
+ ap_id: user.ap_id,
+ name: String.duplicate("h", current_max_length + 1),
+ nickname: user.nickname,
+ info: %{}
+ }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
end
describe "per-user rich-text filtering" do
--
cgit v1.2.3
From af746fa4a814dbacd4fe4a3e58b1ee1732363d22 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Wed, 4 Sep 2019 20:08:13 +0300
Subject: Return total for reports
---
test/web/admin_api/admin_api_controller_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 4e2c27431..b1ddd898b 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1309,6 +1309,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> json_response(:ok)
assert Enum.empty?(response["reports"])
+ assert response["total"] == 0
end
test "returns reports", %{conn: conn} do
@@ -1331,6 +1332,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert length(response["reports"]) == 1
assert report["id"] == report_id
+
+ assert response["total"] == 1
end
test "returns reports with specified state", %{conn: conn} do
@@ -1364,6 +1367,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert length(response["reports"]) == 1
assert open_report["id"] == first_report_id
+ assert response["total"] == 1
+
response =
conn
|> get("/api/pleroma/admin/reports", %{
@@ -1376,6 +1381,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert length(response["reports"]) == 1
assert closed_report["id"] == second_report_id
+ assert response["total"] == 1
+
response =
conn
|> get("/api/pleroma/admin/reports", %{
@@ -1384,6 +1391,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> json_response(:ok)
assert Enum.empty?(response["reports"])
+ assert response["total"] == 0
end
test "returns 403 when requested by a non-admin" do
--
cgit v1.2.3
From ab2f21e470f349f783f895f26da3041afcc3d73e Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 6 Sep 2019 21:50:00 +0300
Subject: tests for mastodon_api_controller.ex
---
.../mastodon_api/mastodon_api_controller_test.exs | 370 +++++++++++++++++----
test/web/oauth/app_test.exs | 33 ++
2 files changed, 340 insertions(+), 63 deletions(-)
create mode 100644 test/web/oauth/app_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e18f8f0d1..a331d6455 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1551,6 +1551,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(other_user.id) == relationship["id"]
end
+
+ test "returns an empty list when bad request", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/relationships", %{})
+
+ assert [] = json_response(conn, 200)
+ end
end
describe "media upload" do
@@ -1752,70 +1763,72 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- test "mascot upload", %{conn: conn} do
- user = insert(:user)
+ describe "/api/v1/pleroma/mascot" do
+ test "mascot upload", %{conn: conn} do
+ user = insert(:user)
- non_image_file = %Plug.Upload{
- content_type: "audio/mpeg",
- path: Path.absname("test/fixtures/sound.mp3"),
- filename: "sound.mp3"
- }
+ non_image_file = %Plug.Upload{
+ content_type: "audio/mpeg",
+ path: Path.absname("test/fixtures/sound.mp3"),
+ filename: "sound.mp3"
+ }
- conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
- assert json_response(conn, 415)
+ assert json_response(conn, 415)
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
- conn =
- build_conn()
- |> assign(:user, user)
- |> put("/api/v1/pleroma/mascot", %{"file" => file})
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> put("/api/v1/pleroma/mascot", %{"file" => file})
- assert %{"id" => _, "type" => image} = json_response(conn, 200)
- end
+ assert %{"id" => _, "type" => image} = json_response(conn, 200)
+ end
- test "mascot retrieving", %{conn: conn} do
- user = insert(:user)
- # When user hasn't set a mascot, we should just get pleroma tan back
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/pleroma/mascot")
+ test "mascot retrieving", %{conn: conn} do
+ user = insert(:user)
+ # When user hasn't set a mascot, we should just get pleroma tan back
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/pleroma/mascot")
- assert %{"url" => url} = json_response(conn, 200)
- assert url =~ "pleroma-fox-tan-smol"
+ assert %{"url" => url} = json_response(conn, 200)
+ assert url =~ "pleroma-fox-tan-smol"
- # When a user sets their mascot, we should get that back
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
+ # When a user sets their mascot, we should get that back
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
- conn =
- build_conn()
- |> assign(:user, user)
- |> put("/api/v1/pleroma/mascot", %{"file" => file})
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> put("/api/v1/pleroma/mascot", %{"file" => file})
- assert json_response(conn, 200)
+ assert json_response(conn, 200)
- user = User.get_cached_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
- conn =
- build_conn()
- |> assign(:user, user)
- |> get("/api/v1/pleroma/mascot")
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/pleroma/mascot")
- assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
- assert url =~ "an_image"
+ assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
+ assert url =~ "an_image"
+ end
end
test "hashtag timeline", %{conn: conn} do
@@ -2183,23 +2196,51 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- test "subscribing / unsubscribing to a user", %{conn: conn} do
- user = insert(:user)
- subscription_target = insert(:user)
+ describe "subscribing / unsubscribing" do
+ test "subscribing / unsubscribing to a user", %{conn: conn} do
+ user = insert(:user)
+ subscription_target = insert(:user)
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
- assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
+ assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
+
+ assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
+ end
+ end
+
+ describe "subscribing" do
+ test "returns 404 when subscription_target not found", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/target_id/subscribe")
+
+ assert %{"error" => "Record not found"} = json_response(conn, 404)
+ end
+ end
+
+ describe "unsubscribing" do
+ test "returns 404 when subscription_target not found", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/target_id/unsubscribe")
- assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
+ assert %{"error" => "Record not found"} = json_response(conn, 404)
+ end
end
test "getting a list of mutes", %{conn: conn} do
@@ -2814,6 +2855,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
}
end
+
+ test "returns empty object when id invalid", %{conn: conn} do
+ response =
+ conn
+ |> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card")
+ |> json_response(200)
+
+ assert response == %{}
+ end
end
test "bookmarks" do
@@ -3133,6 +3183,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert conn.status == 302
assert redirected_to(conn) == path
end
+ end
+
+ describe "GET /web/login" do
+ test "redirects to /oauth/authorize", %{conn: conn} do
+ app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
+ conn = get(conn, "/web/login", %{})
+
+ assert conn.status == 302
+
+ assert redirected_to(conn) ==
+ "/oauth/authorize?response_type=code&client_id=#{app.client_id}&redirect_uri=.&scope=read+write+follow+push"
+ end
test "redirects to the getting-started page when referer is not present", %{conn: conn} do
app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
@@ -3143,6 +3205,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert conn.status == 302
assert redirected_to(conn) == "/web/getting-started"
end
+
+ test "redirects to the getting-started page when user assigned", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/web/login", %{})
+
+ assert conn.status == 302
+ assert redirected_to(conn) == "/web/getting-started"
+ end
end
describe "scheduled activities" do
@@ -3401,6 +3475,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
describe "create account by app" do
+ setup do
+ valid_params = %{
+ username: "lain",
+ email: "lain@example.org",
+ password: "PlzDontHackLain",
+ agreement: true
+ }
+
+ [valid_params: valid_params]
+ end
+
test "Account registration via Application", %{conn: conn} do
conn =
conn
@@ -3444,6 +3529,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
username: "lain",
email: "lain@example.org",
password: "PlzDontHackLain",
+ bio: "Test Bio",
agreement: true
})
@@ -3462,6 +3548,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert token_from_db.user.info.confirmation_pending
end
+ test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
+ _user = insert(:user, email: "lain@example.org")
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+
+ res = post(conn, "/api/v1/accounts", valid_params)
+ assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}
+ end
+
test "rate limit", %{conn: conn} do
app_token = insert(:oauth_token, user: nil)
@@ -3505,6 +3603,41 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert json_response(conn, :too_many_requests) == %{"error" => "Throttled"}
end
+
+ test "returns bad_request if missing required params", %{
+ conn: conn,
+ valid_params: valid_params
+ } do
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+
+ res = post(conn, "/api/v1/accounts", valid_params)
+ assert json_response(res, 200)
+
+ Enum.each(valid_params, fn {attr, _} ->
+ res =
+ conn
+ |> Map.put(
+ :remote_ip,
+ {:rand.uniform(15), :rand.uniform(15), :rand.uniform(15), :rand.uniform(15)}
+ )
+ |> post("/api/v1/accounts", Map.delete(valid_params, attr))
+
+ assert json_response(res, 400) == %{"error" => "Missing parameters"}
+ end)
+ end
+
+ test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> "invalid-token")
+
+ res = post(conn, "/api/v1/accounts", valid_params)
+ assert json_response(res, 403) == %{"error" => "Invalid credentials"}
+ end
end
describe "GET /api/v1/polls/:id" do
@@ -3988,4 +4121,115 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
]
end
end
+
+ describe "PUT /api/v1/media/:id" do
+ setup do
+ actor = insert(:user)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, %Object{} = object} =
+ ActivityPub.upload(
+ file,
+ actor: User.ap_id(actor),
+ description: "test-m"
+ )
+
+ [actor: actor, object: object]
+ end
+
+ test "updates name of media", %{conn: conn, actor: actor, object: object} do
+ media =
+ conn
+ |> assign(:user, actor)
+ |> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
+ |> json_response(:ok)
+
+ assert media["description"] == "test-media"
+ assert refresh_record(object).data["name"] == "test-media"
+ end
+
+ test "returns error wheb request is bad", %{conn: conn, actor: actor, object: object} do
+ media =
+ conn
+ |> assign(:user, actor)
+ |> put("/api/v1/media/#{object.id}", %{})
+ |> json_response(400)
+
+ assert media == %{"error" => "bad_request"}
+ end
+ end
+
+ describe "DELETE /auth/sign_out" do
+ test "redirect to root page", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/auth/sign_out")
+
+ assert conn.status == 302
+ assert redirected_to(conn) == "/"
+ end
+ end
+
+ describe "GET /api/v1/accounts/:id/lists - account_lists" do
+ test "returns lists to which the account belongs", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ assert {:ok, %Pleroma.List{} = list} = Pleroma.List.create("Test List", user)
+ {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{other_user.id}/lists")
+ |> json_response(200)
+
+ assert res == [%{"id" => to_string(list.id), "title" => "Test List"}]
+ end
+ end
+
+ describe "empty_array, stubs for mastodon api" do
+ test "GET /api/v1/accounts/:id/identity_proofs", %{conn: conn} do
+ user = insert(:user)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/identity_proofs")
+ |> json_response(200)
+
+ assert res == []
+ end
+
+ test "GET /api/v1/endorsements", %{conn: conn} do
+ user = insert(:user)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/endorsements")
+ |> json_response(200)
+
+ assert res == []
+ end
+
+ test "GET /api/v1/trends", %{conn: conn} do
+ user = insert(:user)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/trends")
+ |> json_response(200)
+
+ assert res == []
+ end
+ end
end
diff --git a/test/web/oauth/app_test.exs b/test/web/oauth/app_test.exs
new file mode 100644
index 000000000..195b8c17f
--- /dev/null
+++ b/test/web/oauth/app_test.exs
@@ -0,0 +1,33 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.OAuth.AppTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.OAuth.App
+ import Pleroma.Factory
+
+ describe "get_or_make/2" do
+ test "gets exist app" do
+ attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
+ app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
+ {:ok, %App{} = exist_app} = App.get_or_make(attrs, [])
+ assert exist_app == app
+ end
+
+ test "make app" do
+ attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
+ {:ok, %App{} = app} = App.get_or_make(attrs, ["write"])
+ assert app.scopes == ["write"]
+ end
+
+ test "gets exist app and updates scopes" do
+ attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
+ app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
+ {:ok, %App{} = exist_app} = App.get_or_make(attrs, ["read", "write", "follow", "push"])
+ assert exist_app.id == app.id
+ assert exist_app.scopes == ["read", "write", "follow", "push"]
+ end
+ end
+end
--
cgit v1.2.3
From b63faf9819c2c49d2e9b63e7f37136eb03d8b4e8 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sun, 8 Sep 2019 15:00:03 +0300
Subject: [#1234] Mastodon 2.4.3 hierarchical scopes initial support (WIP).
---
test/plugs/oauth_scopes_plug_test.exs | 38 +++++++++++++++++++++++++--
test/web/twitter_api/util_controller_test.exs | 10 ++++---
2 files changed, 42 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/plugs/oauth_scopes_plug_test.exs b/test/plugs/oauth_scopes_plug_test.exs
index f328026df..9b0a2e702 100644
--- a/test/plugs/oauth_scopes_plug_test.exs
+++ b/test/plugs/oauth_scopes_plug_test.exs
@@ -84,7 +84,8 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
refute conn.assigns[:user]
end
- test "returns 403 and halts in case of no :fallback option and `token.scopes` not fulfilling specified 'any of' conditions",
+ test "returns 403 and halts " <>
+ "in case of no :fallback option and `token.scopes` not fulfilling specified 'any of' conditions",
%{conn: conn} do
token = insert(:oauth_token, scopes: ["read", "write"])
any_of_scopes = ["follow"]
@@ -101,7 +102,8 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
assert Jason.encode!(%{error: expected_error}) == conn.resp_body
end
- test "returns 403 and halts in case of no :fallback option and `token.scopes` not fulfilling specified 'all of' conditions",
+ test "returns 403 and halts " <>
+ "in case of no :fallback option and `token.scopes` not fulfilling specified 'all of' conditions",
%{conn: conn} do
token = insert(:oauth_token, scopes: ["read", "write"])
all_of_scopes = ["write", "follow"]
@@ -119,4 +121,36 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
assert Jason.encode!(%{error: expected_error}) == conn.resp_body
end
+
+ describe "with hierarchical scopes, " do
+ test "proceeds with no op if `token.scopes` fulfill specified 'any of' conditions", %{
+ conn: conn
+ } do
+ token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: ["read:something"]})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+ end
+
+ test "proceeds with no op if `token.scopes` fulfill specified 'all of' conditions", %{
+ conn: conn
+ } do
+ token = insert(:oauth_token, scopes: ["scope1", "scope2", "scope3"]) |> Repo.preload(:user)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: ["scope1:subscope", "scope2:subscope"], op: :&})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+ end
+ end
end
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index cf8e69d2b..685e48270 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -78,19 +78,21 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert response == "job started"
end
- test "requires 'follow' permission", %{conn: conn} do
+ test "requires 'follow' or 'write:follows' permissions", %{conn: conn} do
token1 = insert(:oauth_token, scopes: ["read", "write"])
token2 = insert(:oauth_token, scopes: ["follow"])
+ token3 = insert(:oauth_token, scopes: ["something"])
another_user = insert(:user)
- for token <- [token1, token2] do
+ for token <- [token1, token2, token3] do
conn =
conn
|> put_req_header("authorization", "Bearer #{token.token}")
|> post("/api/pleroma/follow_import", %{"list" => "#{another_user.ap_id}"})
- if token == token1 do
- assert %{"error" => "Insufficient permissions: follow."} == json_response(conn, 403)
+ if token == token3 do
+ assert %{"error" => "Insufficient permissions: follow | write:follows."} ==
+ json_response(conn, 403)
else
assert json_response(conn, 200)
end
--
cgit v1.2.3
From e0f84d0043d922f7cc88875a0bc52f2db8972b76 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 10 Sep 2019 01:11:57 +0700
Subject: Fix `ActivityPubController.read_inbox/2`
---
test/web/activity_pub/activity_pub_controller_test.exs | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 5192e734f..4388538c2 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -365,6 +365,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 403)
end
+ test "it doesn't crash without an authenticated user", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}/inbox")
+
+ assert json_response(conn, 403)
+ end
+
test "it returns a note activity in a collection", %{conn: conn} do
note_activity = insert(:direct_note_activity)
note_object = Object.normalize(note_activity)
--
cgit v1.2.3
From 11e12b5761bcd67aa609d91f6f8d1f6755b2312b Mon Sep 17 00:00:00 2001
From: minibikini
Date: Mon, 9 Sep 2019 18:53:08 +0000
Subject: Add Pleroma.Plugs.Cache
---
test/object_test.exs | 3 +
test/plugs/cache_test.exs | 186 +++++++++++++++++++++
.../activity_pub/activity_pub_controller_test.exs | 88 ++++++++++
3 files changed, 277 insertions(+)
create mode 100644 test/plugs/cache_test.exs
(limited to 'test')
diff --git a/test/object_test.exs b/test/object_test.exs
index d138ee091..ba96aeea4 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -53,9 +53,12 @@ defmodule Pleroma.ObjectTest do
assert object == cached_object
+ Cachex.put(:web_resp_cache, URI.parse(object.data["id"]).path, "cofe")
+
Object.delete(cached_object)
{:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
+ {:ok, nil} = Cachex.get(:web_resp_cache, URI.parse(object.data["id"]).path)
cached_object = Object.get_cached_by_ap_id(object.data["id"])
diff --git a/test/plugs/cache_test.exs b/test/plugs/cache_test.exs
new file mode 100644
index 000000000..e6e7f409e
--- /dev/null
+++ b/test/plugs/cache_test.exs
@@ -0,0 +1,186 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.CacheTest do
+ use ExUnit.Case, async: true
+ use Plug.Test
+
+ alias Pleroma.Plugs.Cache
+
+ @miss_resp {200,
+ [
+ {"cache-control", "max-age=0, private, must-revalidate"},
+ {"content-type", "cofe/hot; charset=utf-8"},
+ {"x-cache", "MISS from Pleroma"}
+ ], "cofe"}
+
+ @hit_resp {200,
+ [
+ {"cache-control", "max-age=0, private, must-revalidate"},
+ {"content-type", "cofe/hot; charset=utf-8"},
+ {"x-cache", "HIT from Pleroma"}
+ ], "cofe"}
+
+ @ttl 5
+
+ setup do
+ Cachex.clear(:web_resp_cache)
+ :ok
+ end
+
+ test "caches a response" do
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert_raise(Plug.Conn.AlreadySentError, fn ->
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end)
+
+ assert @hit_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> sent_resp()
+ end
+
+ test "ttl is set" do
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: @ttl})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert @hit_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: @ttl})
+ |> sent_resp()
+
+ :timer.sleep(@ttl + 1)
+
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: @ttl})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end
+
+ test "set ttl via conn.assigns" do
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> assign(:cache_ttl, @ttl)
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert @hit_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> sent_resp()
+
+ :timer.sleep(@ttl + 1)
+
+ assert @miss_resp ==
+ conn(:get, "/")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end
+
+ test "ignore query string when `query_params` is false" do
+ assert @miss_resp ==
+ conn(:get, "/?cofe")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert @hit_resp ==
+ conn(:get, "/?cofefe")
+ |> Cache.call(%{query_params: false, ttl: nil})
+ |> sent_resp()
+ end
+
+ test "take query string into account when `query_params` is true" do
+ assert @miss_resp ==
+ conn(:get, "/?cofe")
+ |> Cache.call(%{query_params: true, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert @miss_resp ==
+ conn(:get, "/?cofefe")
+ |> Cache.call(%{query_params: true, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end
+
+ test "take specific query params into account when `query_params` is list" do
+ assert @miss_resp ==
+ conn(:get, "/?a=1&b=2&c=3&foo=bar")
+ |> fetch_query_params()
+ |> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+
+ assert @hit_resp ==
+ conn(:get, "/?bar=foo&c=3&b=2&a=1")
+ |> fetch_query_params()
+ |> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
+ |> sent_resp()
+
+ assert @miss_resp ==
+ conn(:get, "/?bar=foo&c=3&b=2&a=2")
+ |> fetch_query_params()
+ |> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end
+
+ test "ignore not GET requests" do
+ expected =
+ {200,
+ [
+ {"cache-control", "max-age=0, private, must-revalidate"},
+ {"content-type", "cofe/hot; charset=utf-8"}
+ ], "cofe"}
+
+ assert expected ==
+ conn(:post, "/")
+ |> Cache.call(%{query_params: true, ttl: nil})
+ |> put_resp_content_type("cofe/hot")
+ |> send_resp(:ok, "cofe")
+ |> sent_resp()
+ end
+
+ test "ignore non-successful responses" do
+ expected =
+ {418,
+ [
+ {"cache-control", "max-age=0, private, must-revalidate"},
+ {"content-type", "tea/iced; charset=utf-8"}
+ ], "🥤"}
+
+ assert expected ==
+ conn(:get, "/cofe")
+ |> Cache.call(%{query_params: true, ttl: nil})
+ |> put_resp_content_type("tea/iced")
+ |> send_resp(:im_a_teapot, "🥤")
+ |> sent_resp()
+ end
+end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 4388538c2..9698c7099 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -175,6 +175,49 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+
+ test "it caches a response", %{conn: conn} do
+ note = insert(:note)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+
+ conn1 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn1, :ok)
+ assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
+
+ conn2 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn1, :ok) == json_response(conn2, :ok)
+ assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
+ end
+
+ test "cached purged after object deletion", %{conn: conn} do
+ note = insert(:note)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+
+ conn1 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn1, :ok)
+ assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
+
+ Object.delete(note)
+
+ conn2 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ assert "Not found" == json_response(conn2, :not_found)
+ end
end
describe "/object/:uuid/likes" do
@@ -264,6 +307,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 404)
end
+
+ test "it caches a response", %{conn: conn} do
+ activity = insert(:note_activity)
+ uuid = String.split(activity.data["id"], "/") |> List.last()
+
+ conn1 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert json_response(conn1, :ok)
+ assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
+
+ conn2 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert json_response(conn1, :ok) == json_response(conn2, :ok)
+ assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
+ end
+
+ test "cached purged after activity deletion", %{conn: conn} do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "cofe"})
+
+ uuid = String.split(activity.data["id"], "/") |> List.last()
+
+ conn1 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert json_response(conn1, :ok)
+ assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
+
+ Activity.delete_by_ap_id(activity.object.data["id"])
+
+ conn2 =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/activities/#{uuid}")
+
+ assert "Not found" == json_response(conn2, :not_found)
+ end
end
describe "/inbox" do
--
cgit v1.2.3
From b40b10b53d00d13f24b5667acc02b1642abc6ec4 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 3 Sep 2019 16:23:03 +0700
Subject: Add an endpoint to get multiple statuses by IDs
---
test/activity_test.exs | 8 ++++++++
test/web/mastodon_api/mastodon_api_controller_test.exs | 10 ++++++++++
2 files changed, 18 insertions(+)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 785c4b3cf..49654bd67 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -173,4 +173,12 @@ defmodule Pleroma.ActivityTest do
|> where([a], a.activity_id == ^activity.id)
|> Repo.one!()
end
+
+ test "all_by_ids_with_object/1" do
+ %{id: id1} = insert(:note_activity)
+ %{id: id2} = insert(:note_activity)
+
+ assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] =
+ Activity.all_by_ids_with_object([id1, id2])
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e18f8f0d1..f4902d043 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -744,6 +744,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(activity.id)
end
+ test "get statuses by IDs", %{conn: conn} do
+ %{id: id1} = insert(:note_activity)
+ %{id: id2} = insert(:note_activity)
+
+ query_string = "ids[]=#{id1}&ids[]=#{id2}"
+ conn = get(conn, "/api/v1/statuses/?#{query_string}")
+
+ assert [%{"id" => ^id1}, %{"id" => ^id2}] = json_response(conn, :ok)
+ end
+
describe "deleting a status" do
test "when you created it", %{conn: conn} do
activity = insert(:note_activity)
--
cgit v1.2.3
From a31af93e1d10d9db8796d86ccda35873697b5a4c Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Tue, 10 Sep 2019 16:43:10 +0300
Subject: added tests /activity_pub/transmogrifier.ex
---
test/web/activity_pub/transmogrifier_test.exs | 162 ++++++++++++++++++++++++++
1 file changed, 162 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 0661d5d7c..63c869d35 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1451,4 +1451,166 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
refute recipient.follower_address in fixed_object["to"]
end
end
+
+ describe "fix_summary/1" do
+ test "returns fixed object" do
+ assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
+ assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
+ assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
+ end
+ end
+
+ describe "fix_in_reply_to/2" do
+ clear_config([:instance, :federation_incoming_replies_max_depth])
+
+ setup do
+ data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
+ [data: data]
+ end
+
+ test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
+ assert Transmogrifier.fix_in_reply_to(data) == data
+ end
+
+ test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
+ Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
+
+ object_with_reply =
+ Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
+
+ modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
+ assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
+ assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
+
+ object_with_reply =
+ Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
+
+ modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
+ assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
+ assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
+
+ object_with_reply =
+ Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
+
+ modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
+ assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
+ assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
+
+ object_with_reply = Map.put(data["object"], "inReplyTo", [])
+ modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
+ assert modified_object["inReplyTo"] == []
+ assert modified_object["inReplyToAtomUri"] == ""
+ end
+
+ test "returns modified object when allowed incoming reply", %{data: data} do
+ object_with_reply =
+ Map.put(
+ data["object"],
+ "inReplyTo",
+ "https://shitposter.club/notice/2827873"
+ )
+
+ Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
+ modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
+
+ assert modified_object["inReplyTo"] ==
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+
+ assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
+
+ assert modified_object["conversation"] ==
+ "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
+
+ assert modified_object["context"] ==
+ "tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
+ end
+ end
+
+ describe "fix_url/1" do
+ test "fixes data for object when url is map" do
+ object = %{
+ "url" => %{
+ "type" => "Link",
+ "mimeType" => "video/mp4",
+ "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
+ }
+ }
+
+ assert Transmogrifier.fix_url(object) == %{
+ "url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
+ }
+ end
+
+ test "fixes data for video object" do
+ object = %{
+ "type" => "Video",
+ "url" => [
+ %{
+ "type" => "Link",
+ "mimeType" => "video/mp4",
+ "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
+ },
+ %{
+ "type" => "Link",
+ "mimeType" => "video/mp4",
+ "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
+ },
+ %{
+ "type" => "Link",
+ "mimeType" => "text/html",
+ "href" => "https://peertube.-2d4c2d1630e3"
+ },
+ %{
+ "type" => "Link",
+ "mimeType" => "text/html",
+ "href" => "https://peertube.-2d4c2d16377-42"
+ }
+ ]
+ }
+
+ assert Transmogrifier.fix_url(object) == %{
+ "attachment" => [
+ %{
+ "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
+ "mimeType" => "video/mp4",
+ "type" => "Link"
+ }
+ ],
+ "type" => "Video",
+ "url" => "https://peertube.-2d4c2d1630e3"
+ }
+ end
+
+ test "fixes url for not Video object" do
+ object = %{
+ "type" => "Text",
+ "url" => [
+ %{
+ "type" => "Link",
+ "mimeType" => "text/html",
+ "href" => "https://peertube.-2d4c2d1630e3"
+ },
+ %{
+ "type" => "Link",
+ "mimeType" => "text/html",
+ "href" => "https://peertube.-2d4c2d16377-42"
+ }
+ ]
+ }
+
+ assert Transmogrifier.fix_url(object) == %{
+ "type" => "Text",
+ "url" => "https://peertube.-2d4c2d1630e3"
+ }
+
+ assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
+ "type" => "Text",
+ "url" => ""
+ }
+ end
+
+ test "retunrs not modified object" do
+ assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
+ end
+ end
end
--
cgit v1.2.3
From 3d12e05f43763d3ebc693e69f3f945044939bcc2 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 11 Sep 2019 01:08:37 +0700
Subject: Fix `Activity.all_by_ids_with_object/1` test
---
test/activity_test.exs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 49654bd67..4152aaa7e 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -178,7 +178,11 @@ defmodule Pleroma.ActivityTest do
%{id: id1} = insert(:note_activity)
%{id: id2} = insert(:note_activity)
- assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] =
- Activity.all_by_ids_with_object([id1, id2])
+ activities =
+ [id1, id2]
+ |> Activity.all_by_ids_with_object()
+ |> Enum.sort(&(&1.id < &2.id))
+
+ assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] = activities
end
end
--
cgit v1.2.3
From fcf604fa43031be747b33c05866a192d9651322c Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 11 Sep 2019 07:23:33 +0300
Subject: added tests
---
test/web/activity_pub/transmogrifier_test.exs | 74 +++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 63c869d35..ab6e76056 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1613,4 +1613,78 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
end
end
+
+ describe "get_obj_helper/2" do
+ test "returns nil when cannot normalize object" do
+ refute Transmogrifier.get_obj_helper("test-obj-id")
+ end
+
+ test "returns {:ok, %Object{}} for success case" do
+ assert {:ok, %Object{}} =
+ Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
+ end
+ end
+
+ describe "fix_attachments/1" do
+ test "returns not modified object" do
+ data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
+ assert Transmogrifier.fix_attachments(data) == data
+ end
+
+ test "returns modified object when attachment is map" do
+ assert Transmogrifier.fix_attachments(%{
+ "attachment" => %{
+ "mediaType" => "video/mp4",
+ "url" => "https://peertube.moe/stat-480.mp4"
+ }
+ }) == %{
+ "attachment" => [
+ %{
+ "mediaType" => "video/mp4",
+ "url" => [
+ %{
+ "href" => "https://peertube.moe/stat-480.mp4",
+ "mediaType" => "video/mp4",
+ "type" => "Link"
+ }
+ ]
+ }
+ ]
+ }
+ end
+
+ test "returns modified object when attachment is list" do
+ assert Transmogrifier.fix_attachments(%{
+ "attachment" => [
+ %{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
+ %{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
+ ]
+ }) == %{
+ "attachment" => [
+ %{
+ "mediaType" => "video/mp4",
+ "url" => [
+ %{
+ "href" => "https://pe.er/stat-480.mp4",
+ "mediaType" => "video/mp4",
+ "type" => "Link"
+ }
+ ]
+ },
+ %{
+ "href" => "https://pe.er/stat-480.mp4",
+ "mediaType" => "video/mp4",
+ "mimeType" => "video/mp4",
+ "url" => [
+ %{
+ "href" => "https://pe.er/stat-480.mp4",
+ "mediaType" => "video/mp4",
+ "type" => "Link"
+ }
+ ]
+ }
+ ]
+ }
+ end
+ end
end
--
cgit v1.2.3
From a1f2dfb10a777592ea85d4bf8c5f91c859ec225b Mon Sep 17 00:00:00 2001
From: Alex S
Date: Fri, 30 Aug 2019 14:04:21 +0300
Subject: expanding regex sigils to use modifiers
---
test/web/admin_api/admin_api_controller_test.exs | 12 ++++++++++--
test/web/admin_api/config_test.exs | 24 ++++++++++++++++++++++++
2 files changed, 34 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 4e2c27431..3b6d75a4c 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1779,7 +1779,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{"tuple" => [":seconds_valid", 60]},
%{"tuple" => [":path", ""]},
%{"tuple" => [":key1", nil]},
- %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
+ %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
+ %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
+ %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
+ %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
+ %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]}
]
}
]
@@ -1796,7 +1800,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{"tuple" => [":seconds_valid", 60]},
%{"tuple" => [":path", ""]},
%{"tuple" => [":key1", nil]},
- %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
+ %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
+ %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
+ %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
+ %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
+ %{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]}
]
}
]
diff --git a/test/web/admin_api/config_test.exs b/test/web/admin_api/config_test.exs
index 3190dc1c8..204446b79 100644
--- a/test/web/admin_api/config_test.exs
+++ b/test/web/admin_api/config_test.exs
@@ -103,6 +103,30 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
end
+ test "link sigil" do
+ binary = Config.transform("~r/https:\/\/example.com/")
+ assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/)
+ assert Config.from_binary(binary) == ~r/https:\/\/example.com/
+ end
+
+ test "link sigil with u modifier" do
+ binary = Config.transform("~r/https:\/\/example.com/u")
+ assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/u)
+ assert Config.from_binary(binary) == ~r/https:\/\/example.com/u
+ end
+
+ test "link sigil with i modifier" do
+ binary = Config.transform("~r/https:\/\/example.com/i")
+ assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i)
+ assert Config.from_binary(binary) == ~r/https:\/\/example.com/i
+ end
+
+ test "link sigil with s modifier" do
+ binary = Config.transform("~r/https:\/\/example.com/s")
+ assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s)
+ assert Config.from_binary(binary) == ~r/https:\/\/example.com/s
+ end
+
test "2 child tuple" do
binary = Config.transform(%{"tuple" => ["v1", ":v2"]})
assert binary == :erlang.term_to_binary({"v1", :v2})
--
cgit v1.2.3
From 007e0c1ce158bdfc11738a194944534837ae0258 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 11 Sep 2019 23:19:06 +0300
Subject: added tests
---
test/web/activity_pub/transmogrifier_test.exs | 31 ++++++++++++++++++++++++++
test/web/activity_pub/views/user_view_test.exs | 16 +++++++++++++
2 files changed, 47 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index ab6e76056..87ef843c6 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1687,4 +1687,35 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
}
end
end
+
+ describe "fix_emoji/1" do
+ test "returns not modified object when object not contains tags" do
+ data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
+ assert Transmogrifier.fix_emoji(data) == data
+ end
+
+ test "returns object with emoji when object contains list tags" do
+ assert Transmogrifier.fix_emoji(%{
+ "tag" => [
+ %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
+ %{"type" => "Hashtag"}
+ ]
+ }) == %{
+ "emoji" => %{"bib" => "/test"},
+ "tag" => [
+ %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
+ %{"type" => "Hashtag"}
+ ]
+ }
+ end
+
+ test "returns object with emoji when object contains map tag" do
+ assert Transmogrifier.fix_emoji(%{
+ "tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
+ }) == %{
+ "emoji" => %{"bib" => "/test"},
+ "tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}
+ }
+ end
+ end
end
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index fb7fd9e79..4390f9272 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -37,6 +37,22 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
} = UserView.render("user.json", %{user: user})
end
+ test "Renders with emoji tags" do
+ user = insert(:user, %{info: %{emoji: [%{"bib" => "/test"}]}})
+
+ assert %{
+ "tag" => [
+ %{
+ "icon" => %{"type" => "Image", "url" => "/test"},
+ "id" => "/test",
+ "name" => ":bib:",
+ "type" => "Emoji",
+ "updated" => "1970-01-01T00:00:00Z"
+ }
+ ]
+ } = UserView.render("user.json", %{user: user})
+ end
+
test "Does not add an avatar image if the user hasn't set one" do
user = insert(:user)
{:ok, user} = User.ensure_keys_present(user)
--
cgit v1.2.3
From 4f548cb2b7b4a16a956a4f4a0ff64d279777925e Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Thu, 12 Sep 2019 09:59:34 +0300
Subject: added test for Ostatus
---
test/web/ostatus/ostatus_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 803a97695..ff00c53ee 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -628,4 +628,18 @@ defmodule Pleroma.Web.OStatusTest do
refute OStatus.is_representable?(note_activity)
end
end
+
+ describe "make_user/2" do
+ test "creates new user" do
+ {:ok, user} = OStatus.make_user("https://social.heldscal.la/user/23211")
+
+ created_user =
+ User
+ |> Repo.get_by(ap_id: "https://social.heldscal.la/user/23211")
+ |> Map.put(:last_digest_emailed_at, nil)
+
+ assert user.info
+ assert user == created_user
+ end
+ end
end
--
cgit v1.2.3
From 102eb4455c6285378bf7c25822d82378c7024aa4 Mon Sep 17 00:00:00 2001
From: Mark Felder
Date: Thu, 12 Sep 2019 12:29:08 -0500
Subject: Fix associated test as well
---
test/web/activity_pub/transmogrifier_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 0661d5d7c..bebecce8d 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -102,7 +102,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert capture_log(fn ->
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
- end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil"
+ end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
end
test "it works for incoming notices" do
--
cgit v1.2.3
From 769fb778d41df77c2514b5e3c663f3f624c0a266 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Thu, 12 Sep 2019 21:37:36 +0300
Subject: Track object/create activity fetches
---
.../activity_pub/activity_pub_controller_test.exs | 83 ++++++++++++++++++++++
1 file changed, 83 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 9698c7099..0bab555b5 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Activity
+ alias Pleroma.Delivery
alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.User
@@ -885,4 +886,86 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert result["totalItems"] == 15
end
end
+
+ describe "delivery tracking" do
+ test "it tracks a signed object fetch", %{conn: conn} do
+ user = insert(:user, local: false)
+ activity = insert(:note_activity)
+ object = Object.normalize(activity)
+
+ object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
+
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, user)
+ |> get(object_path)
+ |> json_response(200)
+
+ assert Delivery.get(object.id, user.id)
+ end
+
+ test "it tracks a signed activity fetch", %{conn: conn} do
+ user = insert(:user, local: false)
+ activity = insert(:note_activity)
+ object = Object.normalize(activity)
+
+ activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
+
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, user)
+ |> get(activity_path)
+ |> json_response(200)
+
+ assert Delivery.get(object.id, user.id)
+ end
+
+ test "it tracks a signed object fetch when the json is cached", %{conn: conn} do
+ user = insert(:user, local: false)
+ other_user = insert(:user, local: false)
+ activity = insert(:note_activity)
+ object = Object.normalize(activity)
+
+ object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
+
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, user)
+ |> get(object_path)
+ |> json_response(200)
+
+ build_conn()
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, other_user)
+ |> get(object_path)
+ |> json_response(200)
+
+ assert Delivery.get(object.id, user.id)
+ assert Delivery.get(object.id, other_user.id)
+ end
+
+ test "it tracks a signed activity fetch when the json is cached", %{conn: conn} do
+ user = insert(:user, local: false)
+ other_user = insert(:user, local: false)
+ activity = insert(:note_activity)
+ object = Object.normalize(activity)
+
+ activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
+
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, user)
+ |> get(activity_path)
+ |> json_response(200)
+
+ build_conn()
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, other_user)
+ |> get(activity_path)
+ |> json_response(200)
+
+ assert Delivery.get(object.id, user.id)
+ assert Delivery.get(object.id, other_user.id)
+ end
+ end
end
--
cgit v1.2.3
From 58b17196fa3f2583db5ee0534766350ed25727e0 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Fri, 13 Sep 2019 03:58:58 +0000
Subject: Apply suggestion to
test/web/mastodon_api/mastodon_api_controller_test.exs
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index a331d6455..7b337044c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1552,7 +1552,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(other_user.id) == relationship["id"]
end
- test "returns an empty list when bad request", %{conn: conn} do
+ test "returns an empty list on a bad request", %{conn: conn} do
user = insert(:user)
conn =
--
cgit v1.2.3
From d8a178274bd1eb642270e52f207849014cba12bc Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 13 Sep 2019 07:12:34 +0300
Subject: fix Activity.get_by_id
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 7b337044c..35c2236c8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2864,6 +2864,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert response == %{}
end
+
+ test "returns empty object when id isn't FlakeID", %{conn: conn} do
+ response =
+ conn
+ |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
+ |> json_response(200)
+
+ assert response == %{}
+ end
end
test "bookmarks" do
--
cgit v1.2.3
From 39dc9b470c7ad8348a13f181039f11d14a42fa2b Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 3 Sep 2019 21:58:30 +0700
Subject: Cleanup Pleroma.Activity and Pleroma.Web.ActivityPub.Utils
---
test/user_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index a25b72f4e..206258fee 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1081,7 +1081,7 @@ defmodule Pleroma.UserTest do
user_activities =
user.ap_id
- |> Activity.query_by_actor()
+ |> Activity.Queries.by_actor()
|> Repo.all()
|> Enum.map(fn act -> act.data["type"] end)
--
cgit v1.2.3
From 5bfbad13ad4dd009b172748d81f56ead21c700de Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 3 Sep 2019 21:33:02 +0700
Subject: Add more tests for Pleroma.Activity
---
test/activity_test.exs | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 4152aaa7e..f9f789a76 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -185,4 +185,35 @@ defmodule Pleroma.ActivityTest do
assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] = activities
end
+
+ test "get_by_id_with_object/1" do
+ %{id: id} = insert(:note_activity)
+
+ assert %Activity{id: ^id, object: %Object{}} = Activity.get_by_id_with_object(id)
+ end
+
+ test "get_by_ap_id_with_object/1" do
+ %{data: %{"id" => ap_id}} = insert(:note_activity)
+
+ assert %Activity{data: %{"id" => ^ap_id}, object: %Object{}} =
+ Activity.get_by_ap_id_with_object(ap_id)
+ end
+
+ test "get_by_id/1" do
+ %{id: id} = insert(:note_activity)
+
+ assert %Activity{id: ^id} = Activity.get_by_id(id)
+ end
+
+ test "all_by_actor_and_id/2" do
+ user = insert(:user)
+
+ {:ok, %{id: id1}} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
+ {:ok, %{id: id2}} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofefe"})
+
+ assert [] == Activity.all_by_actor_and_id(user, [])
+
+ assert [%Activity{id: ^id2}, %Activity{id: ^id1}] =
+ Activity.all_by_actor_and_id(user.ap_id, [id1, id2])
+ end
end
--
cgit v1.2.3
From 25d8216804c7742cd8549799a7785723f2a70afa Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 13 Sep 2019 13:09:35 +0700
Subject: Add email change endpoint
---
test/user_test.exs | 27 +++++++
test/web/twitter_api/util_controller_test.exs | 107 ++++++++++++++++++++++++++
2 files changed, 134 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index a25b72f4e..ed8cdbe31 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1614,4 +1614,31 @@ defmodule Pleroma.UserTest do
assert User.user_info(other_user).following_count == 152
end
end
+
+ describe "change_email/2" do
+ setup do
+ [user: insert(:user)]
+ end
+
+ test "blank email returns error", %{user: user} do
+ assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
+ assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
+ end
+
+ test "non unique email returns error", %{user: user} do
+ %{email: email} = insert(:user)
+
+ assert {:error, %{errors: [email: {"has already been taken", _}]}} =
+ User.change_email(user, email)
+ end
+
+ test "invalid email returns error", %{user: user} do
+ assert {:error, %{errors: [email: {"has invalid format", _}]}} =
+ User.change_email(user, "cofe")
+ end
+
+ test "changes email", %{user: user} do
+ assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
+ end
+ end
end
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index cf8e69d2b..a3c6145c0 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -662,4 +662,111 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert called(Pleroma.Captcha.new())
end
end
+
+ defp with_credentials(conn, username, password) do
+ header_content = "Basic " <> Base.encode64("#{username}:#{password}")
+ put_req_header(conn, "authorization", header_content)
+ end
+
+ defp valid_user(_context) do
+ user = insert(:user)
+ [user: user]
+ end
+
+ describe "POST /api/pleroma/change_email" do
+ setup [:valid_user]
+
+ test "without credentials", %{conn: conn} do
+ conn = post(conn, "/api/pleroma/change_email")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials and invalid password", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_email", %{
+ "password" => "hi",
+ "email" => "test@test.com"
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ end
+
+ test "with credentials, valid password and invalid email", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_email", %{
+ "password" => "test",
+ "email" => "foobar"
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Email has invalid format."}
+ end
+
+ test "with credentials, valid password and no email", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_email", %{
+ "password" => "test"
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
+ end
+
+ test "with credentials, valid password and blank email", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_email", %{
+ "password" => "test",
+ "email" => ""
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
+ end
+
+ test "with credentials, valid password and non unique email", %{
+ conn: conn,
+ user: current_user
+ } do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_email", %{
+ "password" => "test",
+ "email" => user.email
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Email has already been taken."}
+ end
+
+ test "with credentials, valid password and valid email", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_email", %{
+ "password" => "test",
+ "email" => "cofe@foobar.com"
+ })
+
+ assert json_response(conn, 200) == %{"status" => "success"}
+ end
+ end
end
--
cgit v1.2.3
From ce23529d917c1830b270a29e774e4ed7768bfeff Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 13 Sep 2019 11:36:49 +0300
Subject: Use delivery info when federating deletes
---
test/web/activity_pub/publisher_test.exs | 68 +++++++++++++++++++++++++++++++-
1 file changed, 67 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs
index 36a39c84c..32b7a242c 100644
--- a/test/web/activity_pub/publisher_test.exs
+++ b/test/web/activity_pub/publisher_test.exs
@@ -3,15 +3,17 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.PublisherTest do
- use Pleroma.DataCase
+ use Pleroma.Web.ConnCase
import Pleroma.Factory
import Tesla.Mock
import Mock
alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.Instances
alias Pleroma.Web.ActivityPub.Publisher
+ alias Pleroma.Web.CommonAPI
@as_public "https://www.w3.org/ns/activitystreams#Public"
@@ -262,5 +264,69 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
})
)
end
+
+ test_with_mock "publishes a delete activity to peers who signed fetch requests to the create acitvity/object.",
+ Pleroma.Web.Federator.Publisher,
+ [:passthrough],
+ [] do
+ fetcher =
+ insert(:user,
+ local: false,
+ info: %{
+ ap_enabled: true,
+ source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
+ }
+ )
+
+ another_fetcher =
+ insert(:user,
+ local: false,
+ info: %{
+ ap_enabled: true,
+ source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"}
+ }
+ )
+
+ actor = insert(:user)
+
+ note_activity = insert(:note_activity, user: actor)
+ object = Object.normalize(note_activity)
+
+ activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url())
+ object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
+
+ build_conn()
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, fetcher)
+ |> get(object_path)
+ |> json_response(200)
+
+ build_conn()
+ |> put_req_header("accept", "application/activity+json")
+ |> assign(:user, another_fetcher)
+ |> get(activity_path)
+ |> json_response(200)
+
+ {:ok, delete} = CommonAPI.delete(note_activity.id, actor)
+
+ res = Publisher.publish(actor, delete)
+ assert res == :ok
+
+ assert called(
+ Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
+ inbox: "https://domain.com/users/nick1/inbox",
+ actor: actor,
+ id: delete.data["id"]
+ })
+ )
+
+ assert called(
+ Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
+ inbox: "https://domain2.com/users/nick1/inbox",
+ actor: actor,
+ id: delete.data["id"]
+ })
+ )
+ end
end
end
--
cgit v1.2.3
From fb96facc32fb275efffeefa2892a1098ecd68b77 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 13 Sep 2019 12:06:31 +0300
Subject: Remove unused functions and fix credo issues
---
test/web/activity_pub/publisher_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs
index 32b7a242c..0ef97464e 100644
--- a/test/web/activity_pub/publisher_test.exs
+++ b/test/web/activity_pub/publisher_test.exs
@@ -10,8 +10,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
import Mock
alias Pleroma.Activity
- alias Pleroma.Object
alias Pleroma.Instances
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.Publisher
alias Pleroma.Web.CommonAPI
--
cgit v1.2.3
From ec5aaf5bd72c91db93a9dbfbe73b58cf7ae5e566 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 13 Sep 2019 14:59:58 +0300
Subject: fix tests
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 35c2236c8..f899d77d9 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3626,16 +3626,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
res = post(conn, "/api/v1/accounts", valid_params)
assert json_response(res, 200)
- Enum.each(valid_params, fn {attr, _} ->
+ [{127,0,0,1}, {127,0,0,2}, {127,0,0,3}, {127,0,0,4}]
+ |> Stream.zip(valid_params)
+ |> Enum.each(fn {ip, {attr, _}} ->
res =
conn
- |> Map.put(
- :remote_ip,
- {:rand.uniform(15), :rand.uniform(15), :rand.uniform(15), :rand.uniform(15)}
- )
+ |> Map.put(:remote_ip, ip)
|> post("/api/v1/accounts", Map.delete(valid_params, attr))
+ |> json_response(400)
- assert json_response(res, 400) == %{"error" => "Missing parameters"}
+ assert res == %{"error" => "Missing parameters"}
end)
end
--
cgit v1.2.3
From bc3e8c033bbef303890ff6afa92d1fe365e530fb Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 13 Sep 2019 15:06:34 +0300
Subject: fix formatting
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f899d77d9..58efbba38 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3626,7 +3626,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
res = post(conn, "/api/v1/accounts", valid_params)
assert json_response(res, 200)
- [{127,0,0,1}, {127,0,0,2}, {127,0,0,3}, {127,0,0,4}]
+ [{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
|> Stream.zip(valid_params)
|> Enum.each(fn {ip, {attr, _}} ->
res =
--
cgit v1.2.3
From 0bd2b85edbf3b7062570778649cf2b77cc7a0bce Mon Sep 17 00:00:00 2001
From: Roman Chvanikov
Date: Fri, 13 Sep 2019 18:25:27 +0300
Subject: Separate Subscription Notifications from regular Notifications
---
test/notification_test.exs | 12 +-
.../mastodon_api/mastodon_api_controller_test.exs | 192 +++++++++++++++++++++
test/web/mastodon_api/mastodon_api_test.exs | 4 +-
3 files changed, 201 insertions(+), 7 deletions(-)
(limited to 'test')
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 2a52dad8d..0e2635aad 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -32,16 +32,16 @@ defmodule Pleroma.NotificationTest do
assert other_notification.activity_id == activity.id
end
- test "it creates a notification for subscribed users" do
+ test "it does not create a notification for subscribed users" do
user = insert(:user)
subscriber = insert(:user)
User.subscribe(subscriber, user)
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
- {:ok, [notification]} = Notification.create_notifications(status)
+ {:ok, notifications} = Notification.create_notifications(status)
- assert notification.user_id == subscriber.id
+ assert notifications == []
end
test "does not create a notification for subscribed users if status is a reply" do
@@ -190,14 +190,16 @@ defmodule Pleroma.NotificationTest do
refute Notification.create_notification(activity_dupe, followed_user)
end
- test "it doesn't create duplicate notifications for follow+subscribed users" do
+ test "it doesn't create notifications for follow+subscribed users" do
user = insert(:user)
subscriber = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(subscriber, user)
User.subscribe(subscriber, user)
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
- {:ok, [_notif]} = Notification.create_notifications(status)
+ {:ok, notifications} = Notification.create_notifications(status)
+
+ assert notifications == []
end
test "it doesn't create subscription notifications if the recipient cannot see the status" do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f4902d043..95fcecc52 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -13,6 +13,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
+ alias Pleroma.SubscriptionNotification
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
@@ -1273,6 +1274,197 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
+ describe "subscription_notifications" do
+ setup do
+ user = insert(:user)
+ subscriber = insert(:user)
+
+ User.subscribe(subscriber, user)
+
+ {:ok, %{user: user, subscriber: subscriber}}
+ end
+
+ test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
+ status_text = "Hello"
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> get("/api/v1/notifications/subscription")
+
+ assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
+ assert response == status_text
+ end
+
+ test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
+ status_text = "Hello"
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+ [notification] = Repo.all(SubscriptionNotification)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> get("/api/v1/notifications/subscription/#{notification.id}")
+
+ assert %{"status" => %{"content" => response}} = json_response(conn, 200)
+ assert response == status_text
+ end
+
+ test "dismissing a single notification also deletes it", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ status_text = "Hello"
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+
+ [notification] = Repo.all(SubscriptionNotification)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> post("/api/v1/notifications/subscription/dismiss", %{"id" => notification.id})
+
+ assert %{} = json_response(conn, 200)
+
+ assert Repo.all(SubscriptionNotification) == []
+ end
+
+ test "clearing all notifications also deletes them", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ status_text1 = "Hello"
+ status_text2 = "Hello again"
+ {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
+ {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> post("/api/v1/notifications/subscription/clear")
+
+ assert %{} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, subscriber)
+ |> get("/api/v1/notifications/subscription")
+
+ assert json_response(conn, 200) == []
+
+ assert Repo.all(SubscriptionNotification) == []
+ end
+
+ test "paginates notifications using min_id, since_id, max_id, and limit", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
+ {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
+ {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
+ {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
+
+ notification1_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
+
+ notification2_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
+
+ notification3_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
+
+ notification4_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
+
+ conn = assign(conn, :user, subscriber)
+
+ # min_id
+ conn_res =
+ get(conn, "/api/v1/notifications/subscription?limit=2&min_id=#{notification1_id}")
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+
+ # since_id
+ conn_res =
+ get(conn, "/api/v1/notifications/subscription?limit=2&since_id=#{notification1_id}")
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
+
+ # max_id
+ conn_res =
+ get(conn, "/api/v1/notifications/subscription?limit=2&max_id=#{notification4_id}")
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+ end
+
+ test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
+ # mutual subscription
+ User.subscribe(user1, user2)
+
+ {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
+ {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
+ {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
+ {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
+
+ notification1_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
+
+ notification2_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
+
+ notification3_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
+
+ notification4_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
+
+ conn = assign(conn, :user, user1)
+
+ conn_res = get(conn, "/api/v1/notifications/subscription")
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification3_id, notification4_id]
+ end)
+
+ conn2 = assign(conn, :user, user2)
+
+ conn_res = get(conn2, "/api/v1/notifications/subscription")
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification1_id, notification2_id]
+ end)
+
+ conn_destroy =
+ delete(conn, "/api/v1/notifications/subscription/destroy_multiple", %{
+ "ids" => [notification3_id, notification4_id]
+ })
+
+ assert json_response(conn_destroy, 200) == %{}
+
+ conn_res = get(conn2, "/api/v1/notifications/subscription")
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification1_id, notification2_id]
+ end)
+
+ assert length(Repo.all(SubscriptionNotification)) == 2
+ end
+ end
+
describe "reblogging" do
test "reblogs and returns the reblogged status", %{conn: conn} do
activity = insert(:note_activity)
diff --git a/test/web/mastodon_api/mastodon_api_test.exs b/test/web/mastodon_api/mastodon_api_test.exs
index 7fcb2bd55..848fce7ad 100644
--- a/test/web/mastodon_api/mastodon_api_test.exs
+++ b/test/web/mastodon_api/mastodon_api_test.exs
@@ -75,9 +75,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
User.subscribe(subscriber, user)
- {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
+ {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin @#{subscriber.nickname}"})
- {:ok, status1} = CommonAPI.post(user, %{"status" => "Magi"})
+ {:ok, status1} = CommonAPI.post(user, %{"status" => "Magi @#{subscriber.nickname}"})
{:ok, [notification]} = Notification.create_notifications(status)
{:ok, [notification1]} = Notification.create_notifications(status1)
res = MastodonAPI.get_notifications(subscriber)
--
cgit v1.2.3
From 25a64a4aa0a10bf06c2ccdf9a6c493f184170a89 Mon Sep 17 00:00:00 2001
From: stwf
Date: Fri, 13 Sep 2019 11:46:41 -0400
Subject: Capture test error messages where appropriate
---
test/integration/mastodon_websocket_test.exs | 29 ++++++++++++++++------
test/web/activity_pub/publisher_test.exs | 24 +++++++++++-------
test/web/activity_pub/relay_test.exs | 13 +++++++---
.../mastodon_api/mastodon_api_controller_test.exs | 16 ++++++------
test/web/twitter_api/util_controller_test.exs | 13 ++++++----
test/web/web_finger/web_finger_controller_test.exs | 13 ++++++----
6 files changed, 71 insertions(+), 37 deletions(-)
(limited to 'test')
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index 3975cdcd6..63bf73412 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Integration.MastodonWebsocketTest do
use Pleroma.DataCase
+ import ExUnit.CaptureLog
import Pleroma.Factory
alias Pleroma.Integration.WebsocketClient
@@ -39,13 +40,17 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end
test "refuses invalid requests" do
- assert {:error, {400, _}} = start_socket()
- assert {:error, {404, _}} = start_socket("?stream=ncjdk")
+ capture_log(fn ->
+ assert {:error, {400, _}} = start_socket()
+ assert {:error, {404, _}} = start_socket("?stream=ncjdk")
+ end)
end
test "requires authentication and a valid token for protected streams" do
- assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
- assert {:error, {403, _}} = start_socket("?stream=user")
+ capture_log(fn ->
+ assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
+ assert {:error, {403, _}} = start_socket("?stream=user")
+ end)
end
test "allows public streams without authentication" do
@@ -100,19 +105,27 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
test "accepts the 'user' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
- assert {:error, {403, "Forbidden"}} = start_socket("?stream=user")
+
+ assert capture_log(fn ->
+ assert {:error, {403, "Forbidden"}} = start_socket("?stream=user")
+ end) =~ ":badarg"
end
test "accepts the 'user:notification' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
- assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
+
+ assert capture_log(fn ->
+ assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
+ end) =~ ":badarg"
end
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
- assert {:error, {403, "Forbidden"}} =
- start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
+ assert capture_log(fn ->
+ assert {:error, {403, "Forbidden"}} =
+ start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
+ end) =~ ":badarg"
end
end
end
diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs
index 36a39c84c..381757e1b 100644
--- a/test/web/activity_pub/publisher_test.exs
+++ b/test/web/activity_pub/publisher_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.ActivityPub.PublisherTest do
use Pleroma.DataCase
+ import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
import Mock
@@ -188,7 +189,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
actor = insert(:user)
inbox = "http://connrefused.site/users/nick1/inbox"
- assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+ assert capture_log(fn ->
+ assert {:error, _} =
+ Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
+ end) =~ "connrefused"
assert called(Instances.set_unreachable(inbox))
end
@@ -212,14 +216,16 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
actor = insert(:user)
inbox = "http://connrefused.site/users/nick1/inbox"
- assert {:error, _} =
- Publisher.publish_one(%{
- inbox: inbox,
- json: "{}",
- actor: actor,
- id: 1,
- unreachable_since: NaiveDateTime.utc_now()
- })
+ assert capture_log(fn ->
+ assert {:error, _} =
+ Publisher.publish_one(%{
+ inbox: inbox,
+ json: "{}",
+ actor: actor,
+ id: 1,
+ unreachable_since: NaiveDateTime.utc_now()
+ })
+ end) =~ "connrefused"
refute called(Instances.set_unreachable(inbox))
end
diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs
index 4f7d592a6..9db4255d8 100644
--- a/test/web/activity_pub/relay_test.exs
+++ b/test/web/activity_pub/relay_test.exs
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay
+ import ExUnit.CaptureLog
import Pleroma.Factory
import Mock
@@ -20,7 +21,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
describe "follow/1" do
test "returns errors when user not found" do
- assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
+ assert capture_log(fn ->
+ assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
+ end) =~ "Could not fetch by AP id"
end
test "returns activity" do
@@ -37,7 +40,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
describe "unfollow/1" do
test "returns errors when user not found" do
- assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
+ assert capture_log(fn ->
+ assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
+ end) =~ "Could not fetch by AP id"
end
test "returns activity" do
@@ -78,7 +83,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
}
)
- assert Relay.publish(activity) == {:error, nil}
+ assert capture_log(fn ->
+ assert Relay.publish(activity) == {:error, nil}
+ end) =~ "[error] error: nil"
end
test_with_mock "returns announce activity and publish to federate",
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f4902d043..806ae7e69 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3963,13 +3963,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
Config.put([:suggestions, :enabled], true)
Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
- res =
- conn
- |> assign(:user, user)
- |> get("/api/v1/suggestions")
- |> json_response(500)
-
- assert res == "Something went wrong"
+ assert capture_log(fn ->
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(500)
+
+ assert res == "Something went wrong"
+ end) =~ "Could not retrieve suggestions"
end
test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index cf8e69d2b..e36d3130f 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
+ import ExUnit.CaptureLog
import Pleroma.Factory
import Mock
@@ -338,12 +339,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
user = insert(:user)
- response =
- conn
- |> assign(:user, user)
- |> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
+ assert capture_log(fn ->
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
- assert html_response(response, 200) =~ "Error fetching user"
+ assert html_response(response, 200) =~ "Error fetching user"
+ end) =~ "Object has been deleted"
end
end
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index e23086b2a..bd3ccaaf7 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
use Pleroma.Web.ConnCase
+ import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
@@ -75,11 +76,13 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
test "Sends a 404 when invalid format" do
user = insert(:user)
- assert_raise Phoenix.NotAcceptableError, fn ->
- build_conn()
- |> put_req_header("accept", "text/html")
- |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
- end
+ assert capture_log(fn ->
+ assert_raise Phoenix.NotAcceptableError, fn ->
+ build_conn()
+ |> put_req_header("accept", "text/html")
+ |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
+ end
+ end) =~ "no supported media type in accept header"
end
test "Sends a 400 when resource param is missing" do
--
cgit v1.2.3
From 5c5ebd38619bb853a58374918fd8983569ba7c0b Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 14 Sep 2019 01:50:15 +0300
Subject: Mastodon API: Respect post privacy in favourited/reblogged endpoints
---
.../mastodon_api/mastodon_api_controller_test.exs | 53 +++++++++++++++++++++-
1 file changed, 51 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 806ae7e69..c9bce1439 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3698,7 +3698,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
build_conn()
|> assign(:user, user)
- [conn: conn, activity: activity]
+ [conn: conn, activity: activity, user: user]
end
test "returns users who have favorited the status", %{conn: conn, activity: activity} do
@@ -3758,6 +3758,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[%{"id" => id}] = response
assert id == other_user.id
end
+
+ test "requires authentifucation for private posts", %{conn: conn, user: user} do
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} wanna get some #cofe together?",
+ "visibility" => "direct"
+ })
+
+ {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
+
+ conn
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(404)
+
+ response =
+ build_conn()
+ |> assign(:user, other_user)
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(200)
+
+ [%{"id" => id}] = response
+ assert id == other_user.id
+ end
end
describe "GET /api/v1/statuses/:id/reblogged_by" do
@@ -3769,7 +3795,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
build_conn()
|> assign(:user, user)
- [conn: conn, activity: activity]
+ [conn: conn, activity: activity, user: user]
end
test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
@@ -3829,6 +3855,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[%{"id" => id}] = response
assert id == other_user.id
end
+
+ test "requires authentifucation for private posts", %{conn: conn, user: user} do
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} wanna get some #cofe together?",
+ "visibility" => "direct"
+ })
+
+ conn
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(404)
+
+ response =
+ build_conn()
+ |> assign(:user, other_user)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(200)
+
+ assert [] == response
+ end
end
describe "POST /auth/password, with valid parameters" do
--
cgit v1.2.3
From 85b6144ffd9e96fc79608847fe739a40ca094207 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 14 Sep 2019 10:46:35 +0000
Subject: Apply suggestion to
test/web/mastodon_api/mastodon_api_controller_test.exs
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index c9bce1439..013a838b8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3759,7 +3759,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == other_user.id
end
- test "requires authentifucation for private posts", %{conn: conn, user: user} do
+ test "requires authentification for private posts", %{conn: conn, user: user} do
other_user = insert(:user)
{:ok, activity} =
--
cgit v1.2.3
From a78a7ee455c4e8f4c2aab15a15626237b2b90399 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 14 Sep 2019 10:50:08 +0000
Subject: Apply suggestion to
test/web/mastodon_api/mastodon_api_controller_test.exs
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 013a838b8..061c3a8ad 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3856,7 +3856,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == other_user.id
end
- test "requires authentifucation for private posts", %{conn: conn, user: user} do
+ test "requires authentification for private posts", %{conn: conn, user: user} do
other_user = insert(:user)
{:ok, activity} =
--
cgit v1.2.3
From b870ae08fd19acd7c40e4353e657e6a1ed1b34c5 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Sat, 14 Sep 2019 19:31:20 +0700
Subject: Fix `Activity.all_by_actor_and_id/2` test
---
test/activity_test.exs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index f9f789a76..275cab81e 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -213,7 +213,11 @@ defmodule Pleroma.ActivityTest do
assert [] == Activity.all_by_actor_and_id(user, [])
- assert [%Activity{id: ^id2}, %Activity{id: ^id1}] =
- Activity.all_by_actor_and_id(user.ap_id, [id1, id2])
+ activities =
+ user.ap_id
+ |> Activity.all_by_actor_and_id([id1, id2])
+ |> Enum.sort(&(&1.id < &2.id))
+
+ assert [%Activity{id: ^id1}, %Activity{id: ^id2}] = activities
end
end
--
cgit v1.2.3
From e6f43a831bdd2a381ed4de493344886f312f9a38 Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sun, 15 Sep 2019 18:22:08 +0300
Subject: [#1234] Permissions-related fixes / new functionality (Masto 2.4.3
scopes).
---
test/support/factory.ex | 1 +
.../controllers/mastodon_api_controller/update_credentials_test.exs | 5 +++--
test/web/oauth/oauth_controller_test.exs | 6 +++---
3 files changed, 7 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 719115003..c14c8ddb3 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -283,6 +283,7 @@ defmodule Pleroma.Factory do
%Pleroma.Web.OAuth.Token{
token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
+ scopes: ["read"],
refresh_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
user: build(:user),
app_id: oauth_app.id,
diff --git a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
index 87ee82050..1680ec122 100644
--- a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
@@ -257,7 +257,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert user_response["pleroma"]["background_image"]
end
- test "requires 'write' permission", %{conn: conn} do
+ test "requires 'write:accounts' permission", %{conn: conn} do
token1 = insert(:oauth_token, scopes: ["read"])
token2 = insert(:oauth_token, scopes: ["write", "follow"])
@@ -268,7 +268,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|> patch("/api/v1/accounts/update_credentials", %{})
if token == token1 do
- assert %{"error" => "Insufficient permissions: write."} == json_response(conn, 403)
+ assert %{"error" => "Insufficient permissions: write:accounts."} ==
+ json_response(conn, 403)
else
assert json_response(conn, 200)
end
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index b492c7794..e919ea112 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -556,7 +556,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
"password" => "test",
"client_id" => app.client_id,
"redirect_uri" => redirect_uri,
- "scope" => "read write",
+ "scope" => "read:subscope write",
"state" => "statepassed"
}
})
@@ -569,7 +569,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert %{"state" => "statepassed", "code" => code} = query
auth = Repo.get_by(Authorization, token: code)
assert auth
- assert auth.scopes == ["read", "write"]
+ assert auth.scopes == ["read:subscope", "write"]
end
test "returns 401 for wrong credentials", %{conn: conn} do
@@ -626,7 +626,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert result =~ "This action is outside the authorized scopes"
end
- test "returns 401 for scopes beyond app scopes", %{conn: conn} do
+ test "returns 401 for scopes beyond app scopes hierarchy", %{conn: conn} do
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
redirect_uri = OAuthController.default_redirect_uri(app)
--
cgit v1.2.3
From 43f17c2e67cfb85ae469eee39b526a5baf7c7408 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 12 Sep 2019 19:04:55 +0700
Subject: Restore tests for `change_password` and `delete_account`
---
test/web/twitter_api/util_controller_test.exs | 105 ++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
(limited to 'test')
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 0a2a48fb7..56e318182 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -775,4 +775,109 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert json_response(conn, 200) == %{"status" => "success"}
end
end
+
+ describe "POST /api/pleroma/change_password" do
+ setup [:valid_user]
+
+ test "without credentials", %{conn: conn} do
+ conn = post(conn, "/api/pleroma/change_password")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials and invalid password", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "hi",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "newpass"
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ end
+
+ test "with credentials, valid password and new password and confirmation not matching", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "test",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "notnewpass"
+ })
+
+ assert json_response(conn, 200) == %{
+ "error" => "New password does not match confirmation."
+ }
+ end
+
+ test "with credentials, valid password and invalid new password", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "test",
+ "new_password" => "",
+ "new_password_confirmation" => ""
+ })
+
+ assert json_response(conn, 200) == %{
+ "error" => "New password can't be blank."
+ }
+ end
+
+ test "with credentials, valid password and matching new password and confirmation", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "test",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "newpass"
+ })
+
+ assert json_response(conn, 200) == %{"status" => "success"}
+ fetched_user = User.get_cached_by_id(current_user.id)
+ assert Comeonin.Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
+ end
+ end
+
+ describe "POST /api/pleroma/delete_account" do
+ setup [:valid_user]
+
+ test "without credentials", %{conn: conn} do
+ conn = post(conn, "/api/pleroma/delete_account")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials and invalid password", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/delete_account", %{"password" => "hi"})
+
+ assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ end
+
+ test "with credentials and valid password", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/delete_account", %{"password" => "test"})
+
+ assert json_response(conn, 200) == %{"status" => "success"}
+ # Wait a second for the started task to end
+ :timer.sleep(1000)
+ end
+ end
end
--
cgit v1.2.3
From ca88e37a8f3b0b52771f94df676e26471fb44019 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 16 Sep 2019 12:55:05 +0700
Subject: Fix a race condition in tests
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 9c5322ccb..fb04748bb 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -752,7 +752,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
query_string = "ids[]=#{id1}&ids[]=#{id2}"
conn = get(conn, "/api/v1/statuses/?#{query_string}")
- assert [%{"id" => ^id1}, %{"id" => ^id2}] = json_response(conn, :ok)
+ assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"])
end
describe "deleting a status" do
--
cgit v1.2.3
From aab264db82054df470075c65ca25c42bbcc5d7a8 Mon Sep 17 00:00:00 2001
From: Steven Fuchs
Date: Mon, 16 Sep 2019 07:44:03 +0000
Subject: Streamer refactoring
---
test/activity/ir/topics_test.exs | 141 +++++++
test/integration/mastodon_websocket_test.exs | 16 +-
test/notification_test.exs | 11 +-
test/support/conn_case.ex | 4 +
test/support/data_case.ex | 4 +
test/web/activity_pub/activity_pub_test.exs | 4 +-
test/web/streamer/ping_test.exs | 36 ++
test/web/streamer/state_test.exs | 54 +++
test/web/streamer/streamer_test.exs | 515 ++++++++++++++++++++++++++
test/web/streamer_test.exs | 534 ---------------------------
10 files changed, 761 insertions(+), 558 deletions(-)
create mode 100644 test/activity/ir/topics_test.exs
create mode 100644 test/web/streamer/ping_test.exs
create mode 100644 test/web/streamer/state_test.exs
create mode 100644 test/web/streamer/streamer_test.exs
delete mode 100644 test/web/streamer_test.exs
(limited to 'test')
diff --git a/test/activity/ir/topics_test.exs b/test/activity/ir/topics_test.exs
new file mode 100644
index 000000000..e75f83586
--- /dev/null
+++ b/test/activity/ir/topics_test.exs
@@ -0,0 +1,141 @@
+defmodule Pleroma.Activity.Ir.TopicsTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Activity
+ alias Pleroma.Activity.Ir.Topics
+ alias Pleroma.Object
+
+ require Pleroma.Constants
+
+ describe "poll answer" do
+ test "produce no topics" do
+ activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
+
+ assert [] == Topics.get_activity_topics(activity)
+ end
+ end
+
+ describe "non poll answer" do
+ test "always add user and list topics" do
+ activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "user")
+ assert Enum.member?(topics, "list")
+ end
+ end
+
+ describe "public visibility" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Note"}},
+ data: %{"to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "produces public topic", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public")
+ end
+
+ test "local action produces public:local topic", %{activity: activity} do
+ activity = %{activity | local: true}
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:local")
+ end
+
+ test "non-local action does not produce public:local topic", %{activity: activity} do
+ activity = %{activity | local: false}
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:local")
+ end
+ end
+
+ describe "public visibility create events" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Create", "attachment" => []}},
+ data: %{"to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "with no attachments doesn't produce public:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:media")
+ refute Enum.member?(topics, "public:local:media")
+ end
+
+ test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
+ tagged_data = Map.put(data, "tag", ["foo", "bar"])
+ activity = %{activity | object: %{object | data: tagged_data}}
+
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "hashtag:foo")
+ assert Enum.member?(topics, "hashtag:bar")
+ end
+
+ test "only converts strinngs to hash tags", %{
+ activity: %{object: %{data: data} = object} = activity
+ } do
+ tagged_data = Map.put(data, "tag", [2])
+ activity = %{activity | object: %{object | data: tagged_data}}
+
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "hashtag:2")
+ end
+ end
+
+ describe "public visibility create events with attachments" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Create", "attachment" => ["foo"]}},
+ data: %{"to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "produce public:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:media")
+ end
+
+ test "local produces public:local:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:local:media")
+ end
+
+ test "non-local doesn't produce public:local:media topics", %{activity: activity} do
+ activity = %{activity | local: false}
+
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:local:media")
+ end
+ end
+
+ describe "non-public visibility" do
+ test "produces direct topic" do
+ activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "direct")
+ refute Enum.member?(topics, "public")
+ refute Enum.member?(topics, "public:local")
+ refute Enum.member?(topics, "public:media")
+ refute Enum.member?(topics, "public:local:media")
+ end
+ end
+end
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index 63bf73412..c04262808 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -11,7 +11,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
alias Pleroma.Integration.WebsocketClient
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth
- alias Pleroma.Web.Streamer
@path Pleroma.Web.Endpoint.url()
|> URI.parse()
@@ -19,16 +18,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|> Map.put(:path, "/api/v1/streaming")
|> URI.to_string()
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
- end
-
def start_socket(qs \\ nil, headers \\ []) do
path =
case qs do
@@ -53,12 +42,14 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end)
end
+ @tag needs_streamer: true
test "allows public streams without authentication" do
assert {:ok, _} = start_socket("?stream=public")
assert {:ok, _} = start_socket("?stream=public:local")
assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
end
+ @tag needs_streamer: true
test "receives well formatted events" do
user = insert(:user)
{:ok, _} = start_socket("?stream=public")
@@ -103,6 +94,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
end
+ @tag needs_streamer: true
test "accepts the 'user' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@@ -111,6 +103,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end) =~ ":badarg"
end
+ @tag needs_streamer: true
test "accepts the 'user:notification' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
@@ -119,6 +112,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end) =~ ":badarg"
end
+ @tag needs_streamer: true
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 3be9db09b..3d2f9a8fc 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -69,16 +69,7 @@ defmodule Pleroma.NotificationTest do
end
describe "create_notification" do
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
- end
-
+ @tag needs_streamer: true
test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
user = insert(:user)
task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index ec5892ff5..b39c70677 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -40,6 +40,10 @@ defmodule Pleroma.Web.ConnCase do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
+ if tags[:needs_streamer] do
+ start_supervised(Pleroma.Web.Streamer.supervisor())
+ end
+
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
end
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index f3d98e7e3..17fa15214 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -39,6 +39,10 @@ defmodule Pleroma.DataCase do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
+ if tags[:needs_streamer] do
+ start_supervised(Pleroma.Web.Streamer.supervisor())
+ end
+
:ok
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d0118fefa..4100108a5 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -38,9 +38,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
stream: fn _, _ -> nil end do
ActivityPub.stream_out_participations(conversation.participations)
- Enum.each(participations, fn participation ->
- assert called(Pleroma.Web.Streamer.stream("participation", participation))
- end)
+ assert called(Pleroma.Web.Streamer.stream("participation", participations))
end
end
end
diff --git a/test/web/streamer/ping_test.exs b/test/web/streamer/ping_test.exs
new file mode 100644
index 000000000..3d52c00e4
--- /dev/null
+++ b/test/web/streamer/ping_test.exs
@@ -0,0 +1,36 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PingTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ alias Pleroma.Web.Streamer
+
+ setup do
+ start_supervised({Streamer.supervisor(), [ping_interval: 30]})
+
+ :ok
+ end
+
+ describe "sockets" do
+ setup do
+ user = insert(:user)
+ {:ok, %{user: user}}
+ end
+
+ test "it sends pings", %{user: user} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 40
+ assert_receive {:text, received_event}, 40
+ assert_receive {:text, received_event}, 40
+ end)
+
+ Streamer.add_socket("public", %{transport_pid: task.pid, assigns: %{user: user}})
+
+ Task.await(task)
+ end
+ end
+end
diff --git a/test/web/streamer/state_test.exs b/test/web/streamer/state_test.exs
new file mode 100644
index 000000000..d1aeac541
--- /dev/null
+++ b/test/web/streamer/state_test.exs
@@ -0,0 +1,54 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.StateTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ alias Pleroma.Web.Streamer
+ alias Pleroma.Web.Streamer.StreamerSocket
+
+ @moduletag needs_streamer: true
+
+ describe "sockets" do
+ setup do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, %{user: user, user2: user2}}
+ end
+
+ test "it can add a socket", %{user: user} do
+ Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
+
+ assert(%{"public" => [%StreamerSocket{transport_pid: 1}]} = Streamer.get_sockets())
+ end
+
+ test "it can add multiple sockets per user", %{user: user} do
+ Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
+ Streamer.add_socket("public", %{transport_pid: 2, assigns: %{user: user}})
+
+ assert(
+ %{
+ "public" => [
+ %StreamerSocket{transport_pid: 2},
+ %StreamerSocket{transport_pid: 1}
+ ]
+ } = Streamer.get_sockets()
+ )
+ end
+
+ test "it will not add a duplicate socket", %{user: user} do
+ Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
+ Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
+
+ assert(
+ %{
+ "activity" => [
+ %StreamerSocket{transport_pid: 1}
+ ]
+ } = Streamer.get_sockets()
+ )
+ end
+ end
+end
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
new file mode 100644
index 000000000..88847e20f
--- /dev/null
+++ b/test/web/streamer/streamer_test.exs
@@ -0,0 +1,515 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.StreamerTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ alias Pleroma.List
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Streamer
+ alias Pleroma.Web.Streamer.StreamerSocket
+ alias Pleroma.Web.Streamer.Worker
+
+ @moduletag needs_streamer: true
+ clear_config_all([:instance, :skip_thread_containment])
+
+ describe "user streams" do
+ setup do
+ user = insert(:user)
+ notify = insert(:notification, user: user, activity: build(:note_activity))
+ {:ok, %{user: user, notify: notify}}
+ end
+
+ test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user", notify)
+ Task.await(task)
+ end
+
+ test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user:notification", notify)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
+ user: user
+ } do
+ blocked = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
+
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
+ user: user
+ } do
+ user2 = insert(:user)
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.add_mute(user, activity)
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
+ user: user
+ } do
+ user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+ end
+
+ test "it sends to public" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+
+ task =
+ Task.async(fn ->
+ expected_event =
+ %{
+ "event" => "delete",
+ "payload" => activity.id
+ }
+ |> Jason.encode!()
+
+ assert_receive {:text, received_event}, 4_000
+ assert received_event == expected_event
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
+
+ {:ok, activity} = CommonAPI.delete(activity.id, other_user)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ describe "thread_containment" do
+ test "it doesn't send to user if recipients invalid and thread containment is enabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
+ fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
+ topics = %{"public" => [fake_socket]}
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], true)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
+ topics = %{"public" => [fake_socket]}
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
+ topics = %{"public" => [fake_socket]}
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ 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)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
+
+ {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send unwanted DMs to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+ user_c = insert(:user)
+
+ {:ok, user_a} = User.follow(user_a, user_b)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user_a
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "@#{user_c.nickname} Test",
+ "visibility" => "direct"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Worker.handle_call({:stream, "list", activity}, self(), topics)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send unwanted private posts to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user_a
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "Test",
+ "visibility" => "private"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Worker.handle_call({:stream, "list", activity}, self(), topics)
+
+ Task.await(task)
+ end
+
+ test "it sends wanted private posts to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+
+ {:ok, user_a} = User.follow(user_a, user_b)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user_a
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "Test",
+ "visibility" => "private"
+ })
+
+ Streamer.add_socket(
+ "list:#{list.id}",
+ fake_socket
+ )
+
+ Worker.handle_call({:stream, "list", activity}, self(), %{})
+
+ Task.await(task)
+ end
+
+ test "it doesn't send muted reblogs" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+ CommonAPI.hide_reblogs(user1, user2)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user1
+ }
+
+ {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
+ {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", announce_activity)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send posts from muted threads" do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+
+ {:ok, activity} = CommonAPI.add_mute(user2, activity)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Process.sleep(4000)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user2}}
+ )
+
+ Streamer.stream("user", activity)
+ Task.await(task)
+ end
+
+ describe "direct streams" do
+ setup do
+ :ok
+ end
+
+ test "it sends conversation update to the 'direct' stream", %{} do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _received_event}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hey @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ Task.await(task)
+ end
+
+ test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ refute_receive {:text, _}, 4_000
+ end)
+
+ Process.sleep(1000)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
+
+ Task.await(task)
+ end
+
+ test "it sends conversation update to the 'direct' stream when a message is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ {:ok, create_activity2} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "in_reply_to_status_id" => create_activity.id,
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ assert_receive {:text, received_event}, 4_000
+
+ assert %{"event" => "conversation", "payload" => received_payload} =
+ Jason.decode!(received_event)
+
+ assert %{"last_status" => last_status} = Jason.decode!(received_payload)
+ assert last_status["id"] == to_string(create_activity.id)
+ end)
+
+ Process.sleep(1000)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
+
+ Task.await(task)
+ end
+ end
+end
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
deleted file mode 100644
index 96fa7645f..000000000
--- a/test/web/streamer_test.exs
+++ /dev/null
@@ -1,534 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.StreamerTest do
- use Pleroma.DataCase
-
- alias Pleroma.List
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.Streamer
- import Pleroma.Factory
-
- clear_config_all([:instance, :skip_thread_containment])
-
- describe "user streams" do
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
-
- user = insert(:user)
- notify = insert(:notification, user: user, activity: build(:note_activity))
- {:ok, %{user: user, notify: notify}}
- end
-
- test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "user",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- Streamer.stream("user", notify)
- Task.await(task)
- end
-
- test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- Streamer.stream("user:notification", notify)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
- user: user
- } do
- blocked = insert(:user)
- {:ok, user} = User.block(user, blocked)
-
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
- {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
-
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
- user: user
- } do
- user2 = insert(:user)
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
- {:ok, activity} = CommonAPI.add_mute(user, activity)
- {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
- user: user
- } do
- user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
- {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
-
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
- end
-
- test "it sends to public" do
- user = insert(:user)
- other_user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user
- }
- }
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
-
- task =
- Task.async(fn ->
- expected_event =
- %{
- "event" => "delete",
- "payload" => activity.id
- }
- |> Jason.encode!()
-
- assert_receive {:text, received_event}, 4_000
- assert received_event == expected_event
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user
- }
- }
-
- {:ok, activity} = CommonAPI.delete(activity.id, other_user)
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- describe "thread_containment" do
- test "it doesn't send to user if recipients invalid and thread containment is enabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id])
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
- fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
- topics = %{"public" => [fake_socket]}
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it sends message if recipients invalid and thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], true)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id])
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
- fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
- topics = %{"public" => [fake_socket]}
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
- fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
- topics = %{"public" => [fake_socket]}
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- 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)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user
- }
- }
-
- {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it doesn't send unwanted DMs to list" do
- user_a = insert(:user)
- user_b = insert(:user)
- user_c = insert(:user)
-
- {:ok, user_a} = User.follow(user_a, user_b)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user_a
- }
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "@#{user_c.nickname} Test",
- "visibility" => "direct"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
-
- Task.await(task)
- end
-
- test "it doesn't send unwanted private posts to list" do
- user_a = insert(:user)
- user_b = insert(:user)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user_a
- }
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
-
- Task.await(task)
- end
-
- test "it send wanted private posts to list" do
- user_a = insert(:user)
- user_b = insert(:user)
-
- {:ok, user_a} = User.follow(user_a, user_b)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user_a
- }
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
-
- Task.await(task)
- end
-
- test "it doesn't send muted reblogs" do
- user1 = insert(:user)
- user2 = insert(:user)
- user3 = insert(:user)
- CommonAPI.hide_reblogs(user1, user2)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user1
- }
- }
-
- {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
- {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", announce_activity)
-
- Task.await(task)
- end
-
- test "it doesn't send posts from muted threads" do
- user = insert(:user)
- user2 = insert(:user)
- {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
-
- {:ok, activity} = CommonAPI.add_mute(user2, activity)
-
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user",
- %{transport_pid: task.pid, assigns: %{user: user2}}
- )
-
- Streamer.stream("user", activity)
- Task.await(task)
- end
-
- describe "direct streams" do
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
-
- :ok
- end
-
- test "it sends conversation update to the 'direct' stream", %{} do
- user = insert(:user)
- another_user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _received_event}, 4_000
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hey @#{user.nickname}",
- "visibility" => "direct"
- })
-
- Task.await(task)
- end
-
- test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
- user = insert(:user)
- another_user = insert(:user)
-
- {:ok, create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
- })
-
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 4_000
- assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
-
- refute_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
-
- Task.await(task)
- end
-
- test "it sends conversation update to the 'direct' stream when a message is deleted" do
- user = insert(:user)
- another_user = insert(:user)
-
- {:ok, create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
- })
-
- {:ok, create_activity2} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "in_reply_to_status_id" => create_activity.id,
- "visibility" => "direct"
- })
-
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 4_000
- assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
-
- assert_receive {:text, received_event}, 4_000
-
- assert %{"event" => "conversation", "payload" => received_payload} =
- Jason.decode!(received_event)
-
- assert %{"last_status" => last_status} = Jason.decode!(received_payload)
- assert last_status["id"] == to_string(create_activity.id)
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
-
- Task.await(task)
- end
- end
-end
--
cgit v1.2.3
From c623b4324deaf236334a0f77a81435b5bffadf3c Mon Sep 17 00:00:00 2001
From: kaniini
Date: Mon, 16 Sep 2019 09:09:21 +0000
Subject: Revert "Merge branch 'streamer-refactoring' into 'develop'"
This reverts merge request !1653
---
test/activity/ir/topics_test.exs | 141 -------
test/integration/mastodon_websocket_test.exs | 16 +-
test/notification_test.exs | 11 +-
test/support/conn_case.ex | 4 -
test/support/data_case.ex | 4 -
test/web/activity_pub/activity_pub_test.exs | 4 +-
test/web/streamer/ping_test.exs | 36 --
test/web/streamer/state_test.exs | 54 ---
test/web/streamer/streamer_test.exs | 515 --------------------------
test/web/streamer_test.exs | 534 +++++++++++++++++++++++++++
10 files changed, 558 insertions(+), 761 deletions(-)
delete mode 100644 test/activity/ir/topics_test.exs
delete mode 100644 test/web/streamer/ping_test.exs
delete mode 100644 test/web/streamer/state_test.exs
delete mode 100644 test/web/streamer/streamer_test.exs
create mode 100644 test/web/streamer_test.exs
(limited to 'test')
diff --git a/test/activity/ir/topics_test.exs b/test/activity/ir/topics_test.exs
deleted file mode 100644
index e75f83586..000000000
--- a/test/activity/ir/topics_test.exs
+++ /dev/null
@@ -1,141 +0,0 @@
-defmodule Pleroma.Activity.Ir.TopicsTest do
- use Pleroma.DataCase
-
- alias Pleroma.Activity
- alias Pleroma.Activity.Ir.Topics
- alias Pleroma.Object
-
- require Pleroma.Constants
-
- describe "poll answer" do
- test "produce no topics" do
- activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
-
- assert [] == Topics.get_activity_topics(activity)
- end
- end
-
- describe "non poll answer" do
- test "always add user and list topics" do
- activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "user")
- assert Enum.member?(topics, "list")
- end
- end
-
- describe "public visibility" do
- setup do
- activity = %Activity{
- object: %Object{data: %{"type" => "Note"}},
- data: %{"to" => [Pleroma.Constants.as_public()]}
- }
-
- {:ok, activity: activity}
- end
-
- test "produces public topic", %{activity: activity} do
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "public")
- end
-
- test "local action produces public:local topic", %{activity: activity} do
- activity = %{activity | local: true}
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "public:local")
- end
-
- test "non-local action does not produce public:local topic", %{activity: activity} do
- activity = %{activity | local: false}
- topics = Topics.get_activity_topics(activity)
-
- refute Enum.member?(topics, "public:local")
- end
- end
-
- describe "public visibility create events" do
- setup do
- activity = %Activity{
- object: %Object{data: %{"type" => "Create", "attachment" => []}},
- data: %{"to" => [Pleroma.Constants.as_public()]}
- }
-
- {:ok, activity: activity}
- end
-
- test "with no attachments doesn't produce public:media topics", %{activity: activity} do
- topics = Topics.get_activity_topics(activity)
-
- refute Enum.member?(topics, "public:media")
- refute Enum.member?(topics, "public:local:media")
- end
-
- test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
- tagged_data = Map.put(data, "tag", ["foo", "bar"])
- activity = %{activity | object: %{object | data: tagged_data}}
-
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "hashtag:foo")
- assert Enum.member?(topics, "hashtag:bar")
- end
-
- test "only converts strinngs to hash tags", %{
- activity: %{object: %{data: data} = object} = activity
- } do
- tagged_data = Map.put(data, "tag", [2])
- activity = %{activity | object: %{object | data: tagged_data}}
-
- topics = Topics.get_activity_topics(activity)
-
- refute Enum.member?(topics, "hashtag:2")
- end
- end
-
- describe "public visibility create events with attachments" do
- setup do
- activity = %Activity{
- object: %Object{data: %{"type" => "Create", "attachment" => ["foo"]}},
- data: %{"to" => [Pleroma.Constants.as_public()]}
- }
-
- {:ok, activity: activity}
- end
-
- test "produce public:media topics", %{activity: activity} do
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "public:media")
- end
-
- test "local produces public:local:media topics", %{activity: activity} do
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "public:local:media")
- end
-
- test "non-local doesn't produce public:local:media topics", %{activity: activity} do
- activity = %{activity | local: false}
-
- topics = Topics.get_activity_topics(activity)
-
- refute Enum.member?(topics, "public:local:media")
- end
- end
-
- describe "non-public visibility" do
- test "produces direct topic" do
- activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
- topics = Topics.get_activity_topics(activity)
-
- assert Enum.member?(topics, "direct")
- refute Enum.member?(topics, "public")
- refute Enum.member?(topics, "public:local")
- refute Enum.member?(topics, "public:media")
- refute Enum.member?(topics, "public:local:media")
- end
- end
-end
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index c04262808..63bf73412 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -11,6 +11,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
alias Pleroma.Integration.WebsocketClient
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth
+ alias Pleroma.Web.Streamer
@path Pleroma.Web.Endpoint.url()
|> URI.parse()
@@ -18,6 +19,16 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|> Map.put(:path, "/api/v1/streaming")
|> URI.to_string()
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+ end
+
def start_socket(qs \\ nil, headers \\ []) do
path =
case qs do
@@ -42,14 +53,12 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end)
end
- @tag needs_streamer: true
test "allows public streams without authentication" do
assert {:ok, _} = start_socket("?stream=public")
assert {:ok, _} = start_socket("?stream=public:local")
assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
end
- @tag needs_streamer: true
test "receives well formatted events" do
user = insert(:user)
{:ok, _} = start_socket("?stream=public")
@@ -94,7 +103,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
end
- @tag needs_streamer: true
test "accepts the 'user' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@@ -103,7 +111,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end) =~ ":badarg"
end
- @tag needs_streamer: true
test "accepts the 'user:notification' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
@@ -112,7 +119,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end) =~ ":badarg"
end
- @tag needs_streamer: true
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 3d2f9a8fc..3be9db09b 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -69,7 +69,16 @@ defmodule Pleroma.NotificationTest do
end
describe "create_notification" do
- @tag needs_streamer: true
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+ end
+
test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
user = insert(:user)
task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index b39c70677..ec5892ff5 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -40,10 +40,6 @@ defmodule Pleroma.Web.ConnCase do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
- if tags[:needs_streamer] do
- start_supervised(Pleroma.Web.Streamer.supervisor())
- end
-
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
end
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 17fa15214..f3d98e7e3 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -39,10 +39,6 @@ defmodule Pleroma.DataCase do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
- if tags[:needs_streamer] do
- start_supervised(Pleroma.Web.Streamer.supervisor())
- end
-
:ok
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 4100108a5..d0118fefa 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -38,7 +38,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
stream: fn _, _ -> nil end do
ActivityPub.stream_out_participations(conversation.participations)
- assert called(Pleroma.Web.Streamer.stream("participation", participations))
+ Enum.each(participations, fn participation ->
+ assert called(Pleroma.Web.Streamer.stream("participation", participation))
+ end)
end
end
end
diff --git a/test/web/streamer/ping_test.exs b/test/web/streamer/ping_test.exs
deleted file mode 100644
index 3d52c00e4..000000000
--- a/test/web/streamer/ping_test.exs
+++ /dev/null
@@ -1,36 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PingTest do
- use Pleroma.DataCase
-
- import Pleroma.Factory
- alias Pleroma.Web.Streamer
-
- setup do
- start_supervised({Streamer.supervisor(), [ping_interval: 30]})
-
- :ok
- end
-
- describe "sockets" do
- setup do
- user = insert(:user)
- {:ok, %{user: user}}
- end
-
- test "it sends pings", %{user: user} do
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 40
- assert_receive {:text, received_event}, 40
- assert_receive {:text, received_event}, 40
- end)
-
- Streamer.add_socket("public", %{transport_pid: task.pid, assigns: %{user: user}})
-
- Task.await(task)
- end
- end
-end
diff --git a/test/web/streamer/state_test.exs b/test/web/streamer/state_test.exs
deleted file mode 100644
index d1aeac541..000000000
--- a/test/web/streamer/state_test.exs
+++ /dev/null
@@ -1,54 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.StateTest do
- use Pleroma.DataCase
-
- import Pleroma.Factory
- alias Pleroma.Web.Streamer
- alias Pleroma.Web.Streamer.StreamerSocket
-
- @moduletag needs_streamer: true
-
- describe "sockets" do
- setup do
- user = insert(:user)
- user2 = insert(:user)
- {:ok, %{user: user, user2: user2}}
- end
-
- test "it can add a socket", %{user: user} do
- Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
-
- assert(%{"public" => [%StreamerSocket{transport_pid: 1}]} = Streamer.get_sockets())
- end
-
- test "it can add multiple sockets per user", %{user: user} do
- Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
- Streamer.add_socket("public", %{transport_pid: 2, assigns: %{user: user}})
-
- assert(
- %{
- "public" => [
- %StreamerSocket{transport_pid: 2},
- %StreamerSocket{transport_pid: 1}
- ]
- } = Streamer.get_sockets()
- )
- end
-
- test "it will not add a duplicate socket", %{user: user} do
- Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
- Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
-
- assert(
- %{
- "activity" => [
- %StreamerSocket{transport_pid: 1}
- ]
- } = Streamer.get_sockets()
- )
- end
- end
-end
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
deleted file mode 100644
index 88847e20f..000000000
--- a/test/web/streamer/streamer_test.exs
+++ /dev/null
@@ -1,515 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.StreamerTest do
- use Pleroma.DataCase
-
- import Pleroma.Factory
-
- alias Pleroma.List
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.Streamer
- alias Pleroma.Web.Streamer.StreamerSocket
- alias Pleroma.Web.Streamer.Worker
-
- @moduletag needs_streamer: true
- clear_config_all([:instance, :skip_thread_containment])
-
- describe "user streams" do
- setup do
- user = insert(:user)
- notify = insert(:notification, user: user, activity: build(:note_activity))
- {:ok, %{user: user, notify: notify}}
- end
-
- test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "user",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- Streamer.stream("user", notify)
- Task.await(task)
- end
-
- test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- Streamer.stream("user:notification", notify)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
- user: user
- } do
- blocked = insert(:user)
- {:ok, user} = User.block(user, blocked)
-
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
- {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
-
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
- user: user
- } do
- user2 = insert(:user)
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
- {:ok, activity} = CommonAPI.add_mute(user, activity)
- {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
- user: user
- } do
- user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
- {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
-
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
- end
-
- test "it sends to public" do
- user = insert(:user)
- other_user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user
- }
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Worker.push_to_socket(topics, "public", activity)
-
- Task.await(task)
-
- task =
- Task.async(fn ->
- expected_event =
- %{
- "event" => "delete",
- "payload" => activity.id
- }
- |> Jason.encode!()
-
- assert_receive {:text, received_event}, 4_000
- assert received_event == expected_event
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user
- }
-
- {:ok, activity} = CommonAPI.delete(activity.id, other_user)
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Worker.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- describe "thread_containment" do
- test "it doesn't send to user if recipients invalid and thread containment is enabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id])
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
- fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
- topics = %{"public" => [fake_socket]}
- Worker.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it sends message if recipients invalid and thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], true)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id])
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
- fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
- topics = %{"public" => [fake_socket]}
- Worker.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
- fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
- topics = %{"public" => [fake_socket]}
- Worker.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- 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)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user
- }
-
- {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Worker.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it doesn't send unwanted DMs to list" do
- user_a = insert(:user)
- user_b = insert(:user)
- user_c = insert(:user)
-
- {:ok, user_a} = User.follow(user_a, user_b)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user_a
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "@#{user_c.nickname} Test",
- "visibility" => "direct"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Worker.handle_call({:stream, "list", activity}, self(), topics)
-
- Task.await(task)
- end
-
- test "it doesn't send unwanted private posts to list" do
- user_a = insert(:user)
- user_b = insert(:user)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user_a
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Worker.handle_call({:stream, "list", activity}, self(), topics)
-
- Task.await(task)
- end
-
- test "it sends wanted private posts to list" do
- user_a = insert(:user)
- user_b = insert(:user)
-
- {:ok, user_a} = User.follow(user_a, user_b)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 1_000
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user_a
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
- })
-
- Streamer.add_socket(
- "list:#{list.id}",
- fake_socket
- )
-
- Worker.handle_call({:stream, "list", activity}, self(), %{})
-
- Task.await(task)
- end
-
- test "it doesn't send muted reblogs" do
- user1 = insert(:user)
- user2 = insert(:user)
- user3 = insert(:user)
- CommonAPI.hide_reblogs(user1, user2)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user1
- }
-
- {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
- {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Worker.push_to_socket(topics, "public", announce_activity)
-
- Task.await(task)
- end
-
- test "it doesn't send posts from muted threads" do
- user = insert(:user)
- user2 = insert(:user)
- {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
-
- {:ok, activity} = CommonAPI.add_mute(user2, activity)
-
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Process.sleep(4000)
-
- Streamer.add_socket(
- "user",
- %{transport_pid: task.pid, assigns: %{user: user2}}
- )
-
- Streamer.stream("user", activity)
- Task.await(task)
- end
-
- describe "direct streams" do
- setup do
- :ok
- end
-
- test "it sends conversation update to the 'direct' stream", %{} do
- user = insert(:user)
- another_user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _received_event}, 4_000
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hey @#{user.nickname}",
- "visibility" => "direct"
- })
-
- Task.await(task)
- end
-
- test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
- user = insert(:user)
- another_user = insert(:user)
-
- {:ok, create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
- })
-
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 4_000
- assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
-
- refute_receive {:text, _}, 4_000
- end)
-
- Process.sleep(1000)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
-
- Task.await(task)
- end
-
- test "it sends conversation update to the 'direct' stream when a message is deleted" do
- user = insert(:user)
- another_user = insert(:user)
-
- {:ok, create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
- })
-
- {:ok, create_activity2} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "in_reply_to_status_id" => create_activity.id,
- "visibility" => "direct"
- })
-
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 4_000
- assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
-
- assert_receive {:text, received_event}, 4_000
-
- assert %{"event" => "conversation", "payload" => received_payload} =
- Jason.decode!(received_event)
-
- assert %{"last_status" => last_status} = Jason.decode!(received_payload)
- assert last_status["id"] == to_string(create_activity.id)
- end)
-
- Process.sleep(1000)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
-
- Task.await(task)
- end
- end
-end
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
new file mode 100644
index 000000000..96fa7645f
--- /dev/null
+++ b/test/web/streamer_test.exs
@@ -0,0 +1,534 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.StreamerTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.List
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Streamer
+ import Pleroma.Factory
+
+ clear_config_all([:instance, :skip_thread_containment])
+
+ describe "user streams" do
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+
+ user = insert(:user)
+ notify = insert(:notification, user: user, activity: build(:note_activity))
+ {:ok, %{user: user, notify: notify}}
+ end
+
+ test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user", notify)
+ Task.await(task)
+ end
+
+ test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user:notification", notify)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
+ user: user
+ } do
+ blocked = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
+
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
+ user: user
+ } do
+ user2 = insert(:user)
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.add_mute(user, activity)
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
+ user: user
+ } do
+ user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+ end
+
+ test "it sends to public" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user
+ }
+ }
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+
+ task =
+ Task.async(fn ->
+ expected_event =
+ %{
+ "event" => "delete",
+ "payload" => activity.id
+ }
+ |> Jason.encode!()
+
+ assert_receive {:text, received_event}, 4_000
+ assert received_event == expected_event
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user
+ }
+ }
+
+ {:ok, activity} = CommonAPI.delete(activity.id, other_user)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ describe "thread_containment" do
+ test "it doesn't send to user if recipients invalid and thread containment is enabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
+ fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
+ topics = %{"public" => [fake_socket]}
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], true)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
+ topics = %{"public" => [fake_socket]}
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
+ topics = %{"public" => [fake_socket]}
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ 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)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user
+ }
+ }
+
+ {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Streamer.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send unwanted DMs to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+ user_c = insert(:user)
+
+ {:ok, user_a} = User.follow(user_a, user_b)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user_a
+ }
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "@#{user_c.nickname} Test",
+ "visibility" => "direct"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send unwanted private posts to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user_a
+ }
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "Test",
+ "visibility" => "private"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
+
+ Task.await(task)
+ end
+
+ test "it send wanted private posts to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+
+ {:ok, user_a} = User.follow(user_a, user_b)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user_a
+ }
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "Test",
+ "visibility" => "private"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send muted reblogs" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+ CommonAPI.hide_reblogs(user1, user2)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %{
+ transport_pid: task.pid,
+ assigns: %{
+ user: user1
+ }
+ }
+
+ {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
+ {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Streamer.push_to_socket(topics, "public", announce_activity)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send posts from muted threads" do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+
+ {:ok, activity} = CommonAPI.add_mute(user2, activity)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user2}}
+ )
+
+ Streamer.stream("user", activity)
+ Task.await(task)
+ end
+
+ describe "direct streams" do
+ setup do
+ GenServer.start(Streamer, %{}, name: Streamer)
+
+ on_exit(fn ->
+ if pid = Process.whereis(Streamer) do
+ Process.exit(pid, :kill)
+ end
+ end)
+
+ :ok
+ end
+
+ test "it sends conversation update to the 'direct' stream", %{} do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _received_event}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hey @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ Task.await(task)
+ end
+
+ test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ refute_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
+
+ Task.await(task)
+ end
+
+ test "it sends conversation update to the 'direct' stream when a message is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ {:ok, create_activity2} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "in_reply_to_status_id" => create_activity.id,
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ assert_receive {:text, received_event}, 4_000
+
+ assert %{"event" => "conversation", "payload" => received_payload} =
+ Jason.decode!(received_event)
+
+ assert %{"last_status" => last_status} = Jason.decode!(received_payload)
+ assert last_status["id"] == to_string(create_activity.id)
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
+
+ Task.await(task)
+ end
+ end
+end
--
cgit v1.2.3
From e8120944d8c016a1aa8fcefe34b1f0cc9089ea4f Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Mon, 16 Sep 2019 13:23:06 +0300
Subject: Fix signed fetch inclusion publisher test
Oban branch changed `actor` to `actor_id` and this test was not adjusted for that
---
test/web/activity_pub/publisher_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs
index c7d1d05aa..df03b4008 100644
--- a/test/web/activity_pub/publisher_test.exs
+++ b/test/web/activity_pub/publisher_test.exs
@@ -321,7 +321,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert called(
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
inbox: "https://domain.com/users/nick1/inbox",
- actor: actor,
+ actor_id: actor.id,
id: delete.data["id"]
})
)
@@ -329,7 +329,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
assert called(
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
inbox: "https://domain2.com/users/nick1/inbox",
- actor: actor,
+ actor_id: actor.id,
id: delete.data["id"]
})
)
--
cgit v1.2.3
From 96816ceaa25c21cec7677e75dcddd7ffb42d83c3 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 16 Sep 2019 17:03:37 +0700
Subject: Revert "Merge branch 'revert-4fabf83a' into 'develop'"
This reverts commit fe7fd331263007e0fb2877ef7370a09a9704da36, reversing
changes made to 4fabf83ad01352442906d79187aeab4c777f4df8.
---
test/activity/ir/topics_test.exs | 141 +++++++
test/integration/mastodon_websocket_test.exs | 16 +-
test/notification_test.exs | 11 +-
test/support/conn_case.ex | 4 +
test/support/data_case.ex | 4 +
test/web/activity_pub/activity_pub_test.exs | 4 +-
test/web/streamer/ping_test.exs | 36 ++
test/web/streamer/state_test.exs | 54 +++
test/web/streamer/streamer_test.exs | 515 ++++++++++++++++++++++++++
test/web/streamer_test.exs | 534 ---------------------------
10 files changed, 761 insertions(+), 558 deletions(-)
create mode 100644 test/activity/ir/topics_test.exs
create mode 100644 test/web/streamer/ping_test.exs
create mode 100644 test/web/streamer/state_test.exs
create mode 100644 test/web/streamer/streamer_test.exs
delete mode 100644 test/web/streamer_test.exs
(limited to 'test')
diff --git a/test/activity/ir/topics_test.exs b/test/activity/ir/topics_test.exs
new file mode 100644
index 000000000..e75f83586
--- /dev/null
+++ b/test/activity/ir/topics_test.exs
@@ -0,0 +1,141 @@
+defmodule Pleroma.Activity.Ir.TopicsTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Activity
+ alias Pleroma.Activity.Ir.Topics
+ alias Pleroma.Object
+
+ require Pleroma.Constants
+
+ describe "poll answer" do
+ test "produce no topics" do
+ activity = %Activity{object: %Object{data: %{"type" => "Answer"}}}
+
+ assert [] == Topics.get_activity_topics(activity)
+ end
+ end
+
+ describe "non poll answer" do
+ test "always add user and list topics" do
+ activity = %Activity{object: %Object{data: %{"type" => "FooBar"}}}
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "user")
+ assert Enum.member?(topics, "list")
+ end
+ end
+
+ describe "public visibility" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Note"}},
+ data: %{"to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "produces public topic", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public")
+ end
+
+ test "local action produces public:local topic", %{activity: activity} do
+ activity = %{activity | local: true}
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:local")
+ end
+
+ test "non-local action does not produce public:local topic", %{activity: activity} do
+ activity = %{activity | local: false}
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:local")
+ end
+ end
+
+ describe "public visibility create events" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Create", "attachment" => []}},
+ data: %{"to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "with no attachments doesn't produce public:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:media")
+ refute Enum.member?(topics, "public:local:media")
+ end
+
+ test "converts tags to hash tags", %{activity: %{object: %{data: data} = object} = activity} do
+ tagged_data = Map.put(data, "tag", ["foo", "bar"])
+ activity = %{activity | object: %{object | data: tagged_data}}
+
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "hashtag:foo")
+ assert Enum.member?(topics, "hashtag:bar")
+ end
+
+ test "only converts strinngs to hash tags", %{
+ activity: %{object: %{data: data} = object} = activity
+ } do
+ tagged_data = Map.put(data, "tag", [2])
+ activity = %{activity | object: %{object | data: tagged_data}}
+
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "hashtag:2")
+ end
+ end
+
+ describe "public visibility create events with attachments" do
+ setup do
+ activity = %Activity{
+ object: %Object{data: %{"type" => "Create", "attachment" => ["foo"]}},
+ data: %{"to" => [Pleroma.Constants.as_public()]}
+ }
+
+ {:ok, activity: activity}
+ end
+
+ test "produce public:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:media")
+ end
+
+ test "local produces public:local:media topics", %{activity: activity} do
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "public:local:media")
+ end
+
+ test "non-local doesn't produce public:local:media topics", %{activity: activity} do
+ activity = %{activity | local: false}
+
+ topics = Topics.get_activity_topics(activity)
+
+ refute Enum.member?(topics, "public:local:media")
+ end
+ end
+
+ describe "non-public visibility" do
+ test "produces direct topic" do
+ activity = %Activity{object: %Object{data: %{"type" => "Note"}}, data: %{"to" => []}}
+ topics = Topics.get_activity_topics(activity)
+
+ assert Enum.member?(topics, "direct")
+ refute Enum.member?(topics, "public")
+ refute Enum.member?(topics, "public:local")
+ refute Enum.member?(topics, "public:media")
+ refute Enum.member?(topics, "public:local:media")
+ end
+ end
+end
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index 63bf73412..c04262808 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -11,7 +11,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
alias Pleroma.Integration.WebsocketClient
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth
- alias Pleroma.Web.Streamer
@path Pleroma.Web.Endpoint.url()
|> URI.parse()
@@ -19,16 +18,6 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|> Map.put(:path, "/api/v1/streaming")
|> URI.to_string()
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
- end
-
def start_socket(qs \\ nil, headers \\ []) do
path =
case qs do
@@ -53,12 +42,14 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end)
end
+ @tag needs_streamer: true
test "allows public streams without authentication" do
assert {:ok, _} = start_socket("?stream=public")
assert {:ok, _} = start_socket("?stream=public:local")
assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
end
+ @tag needs_streamer: true
test "receives well formatted events" do
user = insert(:user)
{:ok, _} = start_socket("?stream=public")
@@ -103,6 +94,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
end
+ @tag needs_streamer: true
test "accepts the 'user' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@@ -111,6 +103,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end) =~ ":badarg"
end
+ @tag needs_streamer: true
test "accepts the 'user:notification' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
@@ -119,6 +112,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
end) =~ ":badarg"
end
+ @tag needs_streamer: true
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 3be9db09b..3d2f9a8fc 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -69,16 +69,7 @@ defmodule Pleroma.NotificationTest do
end
describe "create_notification" do
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
- end
-
+ @tag needs_streamer: true
test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
user = insert(:user)
task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index ec5892ff5..b39c70677 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -40,6 +40,10 @@ defmodule Pleroma.Web.ConnCase do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
+ if tags[:needs_streamer] do
+ start_supervised(Pleroma.Web.Streamer.supervisor())
+ end
+
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
end
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index f3d98e7e3..17fa15214 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -39,6 +39,10 @@ defmodule Pleroma.DataCase do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
+ if tags[:needs_streamer] do
+ start_supervised(Pleroma.Web.Streamer.supervisor())
+ end
+
:ok
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d0118fefa..4100108a5 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -38,9 +38,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
stream: fn _, _ -> nil end do
ActivityPub.stream_out_participations(conversation.participations)
- Enum.each(participations, fn participation ->
- assert called(Pleroma.Web.Streamer.stream("participation", participation))
- end)
+ assert called(Pleroma.Web.Streamer.stream("participation", participations))
end
end
end
diff --git a/test/web/streamer/ping_test.exs b/test/web/streamer/ping_test.exs
new file mode 100644
index 000000000..3d52c00e4
--- /dev/null
+++ b/test/web/streamer/ping_test.exs
@@ -0,0 +1,36 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PingTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ alias Pleroma.Web.Streamer
+
+ setup do
+ start_supervised({Streamer.supervisor(), [ping_interval: 30]})
+
+ :ok
+ end
+
+ describe "sockets" do
+ setup do
+ user = insert(:user)
+ {:ok, %{user: user}}
+ end
+
+ test "it sends pings", %{user: user} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 40
+ assert_receive {:text, received_event}, 40
+ assert_receive {:text, received_event}, 40
+ end)
+
+ Streamer.add_socket("public", %{transport_pid: task.pid, assigns: %{user: user}})
+
+ Task.await(task)
+ end
+ end
+end
diff --git a/test/web/streamer/state_test.exs b/test/web/streamer/state_test.exs
new file mode 100644
index 000000000..d1aeac541
--- /dev/null
+++ b/test/web/streamer/state_test.exs
@@ -0,0 +1,54 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.StateTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+ alias Pleroma.Web.Streamer
+ alias Pleroma.Web.Streamer.StreamerSocket
+
+ @moduletag needs_streamer: true
+
+ describe "sockets" do
+ setup do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, %{user: user, user2: user2}}
+ end
+
+ test "it can add a socket", %{user: user} do
+ Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
+
+ assert(%{"public" => [%StreamerSocket{transport_pid: 1}]} = Streamer.get_sockets())
+ end
+
+ test "it can add multiple sockets per user", %{user: user} do
+ Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
+ Streamer.add_socket("public", %{transport_pid: 2, assigns: %{user: user}})
+
+ assert(
+ %{
+ "public" => [
+ %StreamerSocket{transport_pid: 2},
+ %StreamerSocket{transport_pid: 1}
+ ]
+ } = Streamer.get_sockets()
+ )
+ end
+
+ test "it will not add a duplicate socket", %{user: user} do
+ Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
+ Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
+
+ assert(
+ %{
+ "activity" => [
+ %StreamerSocket{transport_pid: 1}
+ ]
+ } = Streamer.get_sockets()
+ )
+ end
+ end
+end
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
new file mode 100644
index 000000000..88847e20f
--- /dev/null
+++ b/test/web/streamer/streamer_test.exs
@@ -0,0 +1,515 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.StreamerTest do
+ use Pleroma.DataCase
+
+ import Pleroma.Factory
+
+ alias Pleroma.List
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Streamer
+ alias Pleroma.Web.Streamer.StreamerSocket
+ alias Pleroma.Web.Streamer.Worker
+
+ @moduletag needs_streamer: true
+ clear_config_all([:instance, :skip_thread_containment])
+
+ describe "user streams" do
+ setup do
+ user = insert(:user)
+ notify = insert(:notification, user: user, activity: build(:note_activity))
+ {:ok, %{user: user, notify: notify}}
+ end
+
+ test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user", notify)
+ Task.await(task)
+ end
+
+ test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ Streamer.stream("user:notification", notify)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
+ user: user
+ } do
+ blocked = insert(:user)
+ {:ok, user} = User.block(user, blocked)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
+
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
+ user: user
+ } do
+ user2 = insert(:user)
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, activity} = CommonAPI.add_mute(user, activity)
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+
+ test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
+ user: user
+ } do
+ user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
+ end
+
+ test "it sends to public" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 4_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+
+ task =
+ Task.async(fn ->
+ expected_event =
+ %{
+ "event" => "delete",
+ "payload" => activity.id
+ }
+ |> Jason.encode!()
+
+ assert_receive {:text, received_event}, 4_000
+ assert received_event == expected_event
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
+
+ {:ok, activity} = CommonAPI.delete(activity.id, other_user)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ describe "thread_containment" do
+ test "it doesn't send to user if recipients invalid and thread containment is enabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
+ fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
+ topics = %{"public" => [fake_socket]}
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], true)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id])
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
+ topics = %{"public" => [fake_socket]}
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
+ Pleroma.Config.put([:instance, :skip_thread_containment], false)
+ author = insert(:user)
+ user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
+
+ activity =
+ insert(:note_activity,
+ note:
+ insert(:note,
+ user: author,
+ data: %{"to" => ["TEST-FFF"]}
+ )
+ )
+
+ task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
+ fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
+ topics = %{"public" => [fake_socket]}
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ 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)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
+
+ {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", activity)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send unwanted DMs to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+ user_c = insert(:user)
+
+ {:ok, user_a} = User.follow(user_a, user_b)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user_a
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "@#{user_c.nickname} Test",
+ "visibility" => "direct"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Worker.handle_call({:stream, "list", activity}, self(), topics)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send unwanted private posts to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user_a
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "Test",
+ "visibility" => "private"
+ })
+
+ topics = %{
+ "list:#{list.id}" => [fake_socket]
+ }
+
+ Worker.handle_call({:stream, "list", activity}, self(), topics)
+
+ Task.await(task)
+ end
+
+ test "it sends wanted private posts to list" do
+ user_a = insert(:user)
+ user_b = insert(:user)
+
+ {:ok, user_a} = User.follow(user_a, user_b)
+
+ {:ok, list} = List.create("Test", user_a)
+ {:ok, list} = List.follow(list, user_b)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user_a
+ }
+
+ {:ok, activity} =
+ CommonAPI.post(user_b, %{
+ "status" => "Test",
+ "visibility" => "private"
+ })
+
+ Streamer.add_socket(
+ "list:#{list.id}",
+ fake_socket
+ )
+
+ Worker.handle_call({:stream, "list", activity}, self(), %{})
+
+ Task.await(task)
+ end
+
+ test "it doesn't send muted reblogs" do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+ CommonAPI.hide_reblogs(user1, user2)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user1
+ }
+
+ {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
+ {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ Worker.push_to_socket(topics, "public", announce_activity)
+
+ Task.await(task)
+ end
+
+ test "it doesn't send posts from muted threads" do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+
+ {:ok, activity} = CommonAPI.add_mute(user2, activity)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Process.sleep(4000)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user2}}
+ )
+
+ Streamer.stream("user", activity)
+ Task.await(task)
+ end
+
+ describe "direct streams" do
+ setup do
+ :ok
+ end
+
+ test "it sends conversation update to the 'direct' stream", %{} do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, _received_event}, 4_000
+ end)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hey @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ Task.await(task)
+ end
+
+ test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ refute_receive {:text, _}, 4_000
+ end)
+
+ Process.sleep(1000)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
+
+ Task.await(task)
+ end
+
+ test "it sends conversation update to the 'direct' stream when a message is deleted" do
+ user = insert(:user)
+ another_user = insert(:user)
+
+ {:ok, create_activity} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "direct"
+ })
+
+ {:ok, create_activity2} =
+ CommonAPI.post(another_user, %{
+ "status" => "hi @#{user.nickname}",
+ "in_reply_to_status_id" => create_activity.id,
+ "visibility" => "direct"
+ })
+
+ task =
+ Task.async(fn ->
+ assert_receive {:text, received_event}, 4_000
+ assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
+
+ assert_receive {:text, received_event}, 4_000
+
+ assert %{"event" => "conversation", "payload" => received_payload} =
+ Jason.decode!(received_event)
+
+ assert %{"last_status" => last_status} = Jason.decode!(received_payload)
+ assert last_status["id"] == to_string(create_activity.id)
+ end)
+
+ Process.sleep(1000)
+
+ Streamer.add_socket(
+ "direct",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
+
+ Task.await(task)
+ end
+ end
+end
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
deleted file mode 100644
index 96fa7645f..000000000
--- a/test/web/streamer_test.exs
+++ /dev/null
@@ -1,534 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.StreamerTest do
- use Pleroma.DataCase
-
- alias Pleroma.List
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.Streamer
- import Pleroma.Factory
-
- clear_config_all([:instance, :skip_thread_containment])
-
- describe "user streams" do
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
-
- user = insert(:user)
- notify = insert(:notification, user: user, activity: build(:note_activity))
- {:ok, %{user: user, notify: notify}}
- end
-
- test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "user",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- Streamer.stream("user", notify)
- Task.await(task)
- end
-
- test "it sends notify to in the 'user:notification' stream", %{user: user, notify: notify} do
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- Streamer.stream("user:notification", notify)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
- user: user
- } do
- blocked = insert(:user)
- {:ok, user} = User.block(user, blocked)
-
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
- {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
-
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
- user: user
- } do
- user2 = insert(:user)
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
- {:ok, activity} = CommonAPI.add_mute(user, activity)
- {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
-
- test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
- user: user
- } do
- user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user:notification",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
- {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
-
- Streamer.stream("user:notification", notif)
- Task.await(task)
- end
- end
-
- test "it sends to public" do
- user = insert(:user)
- other_user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 4_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user
- }
- }
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
-
- task =
- Task.async(fn ->
- expected_event =
- %{
- "event" => "delete",
- "payload" => activity.id
- }
- |> Jason.encode!()
-
- assert_receive {:text, received_event}, 4_000
- assert received_event == expected_event
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user
- }
- }
-
- {:ok, activity} = CommonAPI.delete(activity.id, other_user)
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- describe "thread_containment" do
- test "it doesn't send to user if recipients invalid and thread containment is enabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id])
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
- fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
- topics = %{"public" => [fake_socket]}
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it sends message if recipients invalid and thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], true)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id])
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
- fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
- topics = %{"public" => [fake_socket]}
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
- Pleroma.Config.put([:instance, :skip_thread_containment], false)
- author = insert(:user)
- user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
-
- activity =
- insert(:note_activity,
- note:
- insert(:note,
- user: author,
- data: %{"to" => ["TEST-FFF"]}
- )
- )
-
- task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
- fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
- topics = %{"public" => [fake_socket]}
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- 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)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user
- }
- }
-
- {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", activity)
-
- Task.await(task)
- end
-
- test "it doesn't send unwanted DMs to list" do
- user_a = insert(:user)
- user_b = insert(:user)
- user_c = insert(:user)
-
- {:ok, user_a} = User.follow(user_a, user_b)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user_a
- }
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "@#{user_c.nickname} Test",
- "visibility" => "direct"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
-
- Task.await(task)
- end
-
- test "it doesn't send unwanted private posts to list" do
- user_a = insert(:user)
- user_b = insert(:user)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user_a
- }
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
-
- Task.await(task)
- end
-
- test "it send wanted private posts to list" do
- user_a = insert(:user)
- user_b = insert(:user)
-
- {:ok, user_a} = User.follow(user_a, user_b)
-
- {:ok, list} = List.create("Test", user_a)
- {:ok, list} = List.follow(list, user_b)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user_a
- }
- }
-
- {:ok, activity} =
- CommonAPI.post(user_b, %{
- "status" => "Test",
- "visibility" => "private"
- })
-
- topics = %{
- "list:#{list.id}" => [fake_socket]
- }
-
- Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
-
- Task.await(task)
- end
-
- test "it doesn't send muted reblogs" do
- user1 = insert(:user)
- user2 = insert(:user)
- user3 = insert(:user)
- CommonAPI.hide_reblogs(user1, user2)
-
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
-
- fake_socket = %{
- transport_pid: task.pid,
- assigns: %{
- user: user1
- }
- }
-
- {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
- {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2)
-
- topics = %{
- "public" => [fake_socket]
- }
-
- Streamer.push_to_socket(topics, "public", announce_activity)
-
- Task.await(task)
- end
-
- test "it doesn't send posts from muted threads" do
- user = insert(:user)
- user2 = insert(:user)
- {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
-
- {:ok, activity} = CommonAPI.add_mute(user2, activity)
-
- task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
-
- Streamer.add_socket(
- "user",
- %{transport_pid: task.pid, assigns: %{user: user2}}
- )
-
- Streamer.stream("user", activity)
- Task.await(task)
- end
-
- describe "direct streams" do
- setup do
- GenServer.start(Streamer, %{}, name: Streamer)
-
- on_exit(fn ->
- if pid = Process.whereis(Streamer) do
- Process.exit(pid, :kill)
- end
- end)
-
- :ok
- end
-
- test "it sends conversation update to the 'direct' stream", %{} do
- user = insert(:user)
- another_user = insert(:user)
-
- task =
- Task.async(fn ->
- assert_receive {:text, _received_event}, 4_000
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hey @#{user.nickname}",
- "visibility" => "direct"
- })
-
- Task.await(task)
- end
-
- test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
- user = insert(:user)
- another_user = insert(:user)
-
- {:ok, create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
- })
-
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 4_000
- assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
-
- refute_receive {:text, _}, 4_000
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _} = CommonAPI.delete(create_activity.id, another_user)
-
- Task.await(task)
- end
-
- test "it sends conversation update to the 'direct' stream when a message is deleted" do
- user = insert(:user)
- another_user = insert(:user)
-
- {:ok, create_activity} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "visibility" => "direct"
- })
-
- {:ok, create_activity2} =
- CommonAPI.post(another_user, %{
- "status" => "hi @#{user.nickname}",
- "in_reply_to_status_id" => create_activity.id,
- "visibility" => "direct"
- })
-
- task =
- Task.async(fn ->
- assert_receive {:text, received_event}, 4_000
- assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
-
- assert_receive {:text, received_event}, 4_000
-
- assert %{"event" => "conversation", "payload" => received_payload} =
- Jason.decode!(received_event)
-
- assert %{"last_status" => last_status} = Jason.decode!(received_payload)
- assert last_status["id"] == to_string(create_activity.id)
- end)
-
- Streamer.add_socket(
- "direct",
- %{transport_pid: task.pid, assigns: %{user: user}}
- )
-
- {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
-
- Task.await(task)
- end
- end
-end
--
cgit v1.2.3
From 6042e21b25885f9c3214d3296d9d2fdf35ad58ea Mon Sep 17 00:00:00 2001
From: Roman Chvanikov
Date: Mon, 16 Sep 2019 21:59:49 +0300
Subject: Move subscription notifications to a separate controller
---
.../mastodon_api/mastodon_api_controller_test.exs | 192 -----------------
.../subscription_notification_controller_test.exs | 234 +++++++++++++++++++++
2 files changed, 234 insertions(+), 192 deletions(-)
create mode 100644 test/web/pleroma_api/subscription_notification_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 1d2d9e134..fb04748bb 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -13,7 +13,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.ScheduledActivity
- alias Pleroma.SubscriptionNotification
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -1275,197 +1274,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "subscription_notifications" do
- setup do
- user = insert(:user)
- subscriber = insert(:user)
-
- User.subscribe(subscriber, user)
-
- {:ok, %{user: user, subscriber: subscriber}}
- end
-
- test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
- status_text = "Hello"
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> get("/api/v1/notifications/subscription")
-
- assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
- assert response == status_text
- end
-
- test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
- status_text = "Hello"
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
- [notification] = Repo.all(SubscriptionNotification)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> get("/api/v1/notifications/subscription/#{notification.id}")
-
- assert %{"status" => %{"content" => response}} = json_response(conn, 200)
- assert response == status_text
- end
-
- test "dismissing a single notification also deletes it", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- status_text = "Hello"
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
-
- [notification] = Repo.all(SubscriptionNotification)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> post("/api/v1/notifications/subscription/dismiss", %{"id" => notification.id})
-
- assert %{} = json_response(conn, 200)
-
- assert Repo.all(SubscriptionNotification) == []
- end
-
- test "clearing all notifications also deletes them", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- status_text1 = "Hello"
- status_text2 = "Hello again"
- {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
- {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> post("/api/v1/notifications/subscription/clear")
-
- assert %{} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, subscriber)
- |> get("/api/v1/notifications/subscription")
-
- assert json_response(conn, 200) == []
-
- assert Repo.all(SubscriptionNotification) == []
- end
-
- test "paginates notifications using min_id, since_id, max_id, and limit", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
- {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
- {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
- {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
-
- notification1_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
-
- notification2_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
-
- notification3_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
-
- notification4_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
-
- conn = assign(conn, :user, subscriber)
-
- # min_id
- conn_res =
- get(conn, "/api/v1/notifications/subscription?limit=2&min_id=#{notification1_id}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
-
- # since_id
- conn_res =
- get(conn, "/api/v1/notifications/subscription?limit=2&since_id=#{notification1_id}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
-
- # max_id
- conn_res =
- get(conn, "/api/v1/notifications/subscription?limit=2&max_id=#{notification4_id}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
- end
-
- test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
- # mutual subscription
- User.subscribe(user1, user2)
-
- {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
- {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
- {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
- {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
-
- notification1_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
-
- notification2_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
-
- notification3_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
-
- notification4_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
-
- conn = assign(conn, :user, user1)
-
- conn_res = get(conn, "/api/v1/notifications/subscription")
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification3_id, notification4_id]
- end)
-
- conn2 = assign(conn, :user, user2)
-
- conn_res = get(conn2, "/api/v1/notifications/subscription")
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification1_id, notification2_id]
- end)
-
- conn_destroy =
- delete(conn, "/api/v1/notifications/subscription/destroy_multiple", %{
- "ids" => [notification3_id, notification4_id]
- })
-
- assert json_response(conn_destroy, 200) == %{}
-
- conn_res = get(conn2, "/api/v1/notifications/subscription")
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification1_id, notification2_id]
- end)
-
- assert length(Repo.all(SubscriptionNotification)) == 2
- end
- end
-
describe "reblogging" do
test "reblogs and returns the reblogged status", %{conn: conn} do
activity = insert(:note_activity)
diff --git a/test/web/pleroma_api/subscription_notification_controller_test.exs b/test/web/pleroma_api/subscription_notification_controller_test.exs
new file mode 100644
index 000000000..ee495f112
--- /dev/null
+++ b/test/web/pleroma_api/subscription_notification_controller_test.exs
@@ -0,0 +1,234 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Repo
+ alias Pleroma.SubscriptionNotification
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ clear_config([:instance, :public])
+ clear_config([:rich_media, :enabled])
+
+ describe "subscription_notifications" do
+ setup do
+ user = insert(:user)
+ subscriber = insert(:user)
+
+ User.subscribe(subscriber, user)
+
+ {:ok, %{user: user, subscriber: subscriber}}
+ end
+
+ test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
+ status_text = "Hello"
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+ path = subscription_notification_path(conn, :list)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> get(path)
+
+ assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
+ assert response == status_text
+ end
+
+ test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
+ status_text = "Hello"
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+ [notification] = Repo.all(SubscriptionNotification)
+
+ path = subscription_notification_path(conn, :get, id: notification.id)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> get(path)
+
+ assert %{"status" => %{"content" => response}} = json_response(conn, 200)
+ assert response == status_text
+ end
+
+ test "dismissing a single notification also deletes it", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ status_text = "Hello"
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+
+ [notification] = Repo.all(SubscriptionNotification)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> post(subscription_notification_path(conn, :dismiss), %{"id" => notification.id})
+
+ assert %{} = json_response(conn, 200)
+
+ assert Repo.all(SubscriptionNotification) == []
+ end
+
+ test "clearing all notifications also deletes them", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ status_text1 = "Hello"
+ status_text2 = "Hello again"
+ {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
+ {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> post(subscription_notification_path(conn, :clear))
+
+ assert %{} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, subscriber)
+ |> get(subscription_notification_path(conn, :list))
+
+ assert json_response(conn, 200) == []
+
+ assert Repo.all(SubscriptionNotification) == []
+ end
+
+ test "paginates notifications using min_id, since_id, max_id, and limit", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
+ {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
+ {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
+ {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
+
+ notification1_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
+
+ notification2_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
+
+ notification3_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
+
+ notification4_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
+
+ conn = assign(conn, :user, subscriber)
+
+ # min_id
+ conn_res =
+ get(
+ conn,
+ subscription_notification_path(conn, :list, %{
+ "limit" => 2,
+ "min_id" => notification1_id
+ })
+ )
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+
+ # since_id
+ conn_res =
+ get(
+ conn,
+ subscription_notification_path(conn, :list, %{
+ "limit" => 2,
+ "since_id" => notification1_id
+ })
+ )
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
+
+ # max_id
+ conn_res =
+ get(
+ conn,
+ subscription_notification_path(conn, :list, %{
+ "limit" => 2,
+ "max_id" => notification4_id
+ })
+ )
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+ end
+
+ test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
+ # mutual subscription
+ User.subscribe(user1, user2)
+
+ {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
+ {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
+ {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
+ {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
+
+ notification1_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
+
+ notification2_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
+
+ notification3_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
+
+ notification4_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
+
+ conn = assign(conn, :user, user1)
+
+ conn_res = get(conn, subscription_notification_path(conn, :list))
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification3_id, notification4_id]
+ end)
+
+ conn2 = assign(conn, :user, user2)
+
+ conn_res = get(conn2, subscription_notification_path(conn, :list))
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification1_id, notification2_id]
+ end)
+
+ conn_destroy =
+ delete(conn, subscription_notification_path(conn, :destroy_multiple), %{
+ "ids" => [notification3_id, notification4_id]
+ })
+
+ assert json_response(conn_destroy, 200) == %{}
+
+ conn_res = get(conn2, subscription_notification_path(conn, :list))
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification1_id, notification2_id]
+ end)
+
+ assert length(Repo.all(SubscriptionNotification)) == 2
+ end
+ end
+end
--
cgit v1.2.3
From 450bf7a63c39c2301d5985448a867e77f1dfe3b3 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Fri, 13 Sep 2019 17:37:30 +0300
Subject: Mastodon API: Add a setting to hide follow/follower count from the
user view (`hide_follows_count` and `hide_followers_count`)
---
test/web/activity_pub/views/user_view_test.exs | 24 +++++++++++++++--
.../update_credentials_test.exs | 16 +++++++++++
test/web/mastodon_api/views/account_view_test.exs | 31 ++++++++++++++++++++--
3 files changed, 67 insertions(+), 4 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index fb7fd9e79..2b4a04afd 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -105,10 +105,20 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
- info = Map.put(user.info, :hide_followers, true)
+ info = Map.merge(user.info, %{hide_followers_count: true, hide_followers: true})
user = Map.put(user, :info, info)
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
end
+
+ test "sets correct totalItems when followers are hidden but the follower counter is not" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+ assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
+ info = Map.merge(user.info, %{hide_followers_count: false, hide_followers: true})
+ user = Map.put(user, :info, info)
+ assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
+ end
end
describe "following" do
@@ -117,9 +127,19 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
- info = Map.put(user.info, :hide_follows, true)
+ info = Map.merge(user.info, %{hide_follows_count: true, hide_follows: true})
user = Map.put(user, :info, info)
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
end
+
+ test "sets correct totalItems when follows are hidden but the follow counter is not" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
+ assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
+ info = Map.merge(user.info, %{hide_follows_count: false, hide_follows: true})
+ user = Map.put(user, :info, info)
+ assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
+ end
end
end
diff --git a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
index 87ee82050..89d4ca37e 100644
--- a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
@@ -128,6 +128,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert user["pleroma"]["hide_followers"] == true
end
+ test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ hide_followers_count: "true",
+ hide_follows_count: "true"
+ })
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_followers_count"] == true
+ assert user["pleroma"]["hide_follows_count"] == true
+ end
+
test "updates the user's skip_thread_containment option", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 1d8b28339..8ff6751d3 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -79,6 +79,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
hide_favorites: true,
hide_followers: false,
hide_follows: false,
+ hide_followers_count: false,
+ hide_follows_count: false,
relationship: %{},
skip_thread_containment: false
}
@@ -147,6 +149,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
hide_favorites: true,
hide_followers: false,
hide_follows: false,
+ hide_followers_count: false,
+ hide_follows_count: false,
relationship: %{},
skip_thread_containment: false
}
@@ -318,6 +322,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
hide_favorites: true,
hide_followers: false,
hide_follows: false,
+ hide_followers_count: false,
+ hide_follows_count: false,
relationship: %{
id: to_string(user.id),
following: false,
@@ -361,8 +367,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
end
describe "hiding follows/following" do
- test "shows when follows/following are hidden and sets follower/following count to 0" do
- user = insert(:user, info: %{hide_followers: true, hide_follows: true})
+ test "shows when follows/followers stats are hidden and sets follow/follower count to 0" do
+ info = %{
+ hide_followers: true,
+ hide_followers_count: true,
+ hide_follows: true,
+ hide_follows_count: true
+ }
+
+ user = insert(:user, info: info)
+
other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
@@ -370,6 +384,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{
followers_count: 0,
following_count: 0,
+ pleroma: %{hide_follows_count: true, hide_followers_count: true}
+ } = AccountView.render("account.json", %{user: user})
+ end
+
+ test "shows when follows/followers are hidden" do
+ user = insert(:user, info: %{hide_followers: true, hide_follows: true})
+ other_user = insert(:user)
+ {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{
+ followers_count: 1,
+ following_count: 1,
pleroma: %{hide_follows: true, hide_followers: true}
} = AccountView.render("account.json", %{user: user})
end
--
cgit v1.2.3
From 015597c2abbd9a78df76903bb2c3d229bf11e958 Mon Sep 17 00:00:00 2001
From: Roman Chvanikov
Date: Tue, 17 Sep 2019 13:43:15 +0000
Subject: Apply suggestion to
test/web/pleroma_api/subscription_notification_controller_test.exs
---
test/web/pleroma_api/subscription_notification_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/pleroma_api/subscription_notification_controller_test.exs b/test/web/pleroma_api/subscription_notification_controller_test.exs
index ee495f112..781d27ead 100644
--- a/test/web/pleroma_api/subscription_notification_controller_test.exs
+++ b/test/web/pleroma_api/subscription_notification_controller_test.exs
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
{:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
[notification] = Repo.all(SubscriptionNotification)
- path = subscription_notification_path(conn, :get, id: notification.id)
+ path = subscription_notification_path(conn, :get, notification)
conn =
conn
--
cgit v1.2.3
From 7d1773bc6b01caad8666ef07a9b2f2ac326fd0cd Mon Sep 17 00:00:00 2001
From: Roman Chvanikov
Date: Tue, 17 Sep 2019 16:48:24 +0300
Subject: Rename SubscriptionNotificationController list and get actions to
index and show
---
.../subscription_notification_controller_test.exs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'test')
diff --git a/test/web/pleroma_api/subscription_notification_controller_test.exs b/test/web/pleroma_api/subscription_notification_controller_test.exs
index 781d27ead..c6a71732d 100644
--- a/test/web/pleroma_api/subscription_notification_controller_test.exs
+++ b/test/web/pleroma_api/subscription_notification_controller_test.exs
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
status_text = "Hello"
{:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
- path = subscription_notification_path(conn, :list)
+ path = subscription_notification_path(conn, :index)
conn =
conn
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
{:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
[notification] = Repo.all(SubscriptionNotification)
- path = subscription_notification_path(conn, :get, notification)
+ path = subscription_notification_path(conn, :show, notification)
conn =
conn
@@ -101,7 +101,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
conn =
build_conn()
|> assign(:user, subscriber)
- |> get(subscription_notification_path(conn, :list))
+ |> get(subscription_notification_path(conn, :index))
assert json_response(conn, 200) == []
@@ -136,7 +136,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
conn_res =
get(
conn,
- subscription_notification_path(conn, :list, %{
+ subscription_notification_path(conn, :index, %{
"limit" => 2,
"min_id" => notification1_id
})
@@ -149,7 +149,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
conn_res =
get(
conn,
- subscription_notification_path(conn, :list, %{
+ subscription_notification_path(conn, :index, %{
"limit" => 2,
"since_id" => notification1_id
})
@@ -162,7 +162,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
conn_res =
get(
conn,
- subscription_notification_path(conn, :list, %{
+ subscription_notification_path(conn, :index, %{
"limit" => 2,
"max_id" => notification4_id
})
@@ -195,7 +195,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
conn = assign(conn, :user, user1)
- conn_res = get(conn, subscription_notification_path(conn, :list))
+ conn_res = get(conn, subscription_notification_path(conn, :index))
result = json_response(conn_res, 200)
@@ -205,7 +205,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
conn2 = assign(conn, :user, user2)
- conn_res = get(conn2, subscription_notification_path(conn, :list))
+ conn_res = get(conn2, subscription_notification_path(conn, :index))
result = json_response(conn_res, 200)
@@ -220,7 +220,7 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
assert json_response(conn_destroy, 200) == %{}
- conn_res = get(conn2, subscription_notification_path(conn, :list))
+ conn_res = get(conn2, subscription_notification_path(conn, :index))
result = json_response(conn_res, 200)
--
cgit v1.2.3
From e9f69a3eb7f17ae8c2890972851de1139983ce3d Mon Sep 17 00:00:00 2001
From: Roman Chvanikov
Date: Tue, 17 Sep 2019 16:52:23 +0300
Subject: Move pleroma_api controllers into controllers sub-folders
---
.../controllers/pleroma_api_controller_test.exs | 150 +++++++++++++
.../subscription_notification_controller_test.exs | 234 +++++++++++++++++++++
.../pleroma_api/pleroma_api_controller_test.exs | 150 -------------
.../subscription_notification_controller_test.exs | 234 ---------------------
4 files changed, 384 insertions(+), 384 deletions(-)
create mode 100644 test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
create mode 100644 test/web/pleroma_api/controllers/subscription_notification_controller_test.exs
delete mode 100644 test/web/pleroma_api/pleroma_api_controller_test.exs
delete mode 100644 test/web/pleroma_api/subscription_notification_controller_test.exs
(limited to 'test')
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
new file mode 100644
index 000000000..7eaeda4a0
--- /dev/null
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -0,0 +1,150 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Notification
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}")
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string()
+ end
+
+ test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ {:ok, activity_two} =
+ CommonAPI.post(other_user, %{
+ "status" => "Hi!",
+ "in_reply_to_status_id" => activity.id,
+ "in_reply_to_conversation_id" => participation.id
+ })
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
+ |> json_response(200)
+
+ assert length(result) == 2
+
+ id_one = activity.id
+ id_two = activity_two.id
+ assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
+ end
+
+ test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert [user] == participation.recipients
+ assert other_user not in participation.recipients
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
+ "recipients" => [user.id, other_user.id]
+ })
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string
+
+ [participation] = Participation.for_user(user)
+ participation = Repo.preload(participation, :recipients)
+
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+ end
+
+ describe "POST /api/v1/pleroma/notifications/read" do
+ test "it marks a single notification as read", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, [notification1]} = Notification.create_notifications(activity1)
+ {:ok, [notification2]} = Notification.create_notifications(activity2)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
+ |> json_response(:ok)
+
+ assert %{"pleroma" => %{"is_seen" => true}} = response
+ assert Repo.get(Notification, notification1.id).seen
+ refute Repo.get(Notification, notification2.id).seen
+ end
+
+ test "it marks multiple notifications as read", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
+
+ [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
+
+ [response1, response2] =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
+ |> json_response(:ok)
+
+ assert %{"pleroma" => %{"is_seen" => true}} = response1
+ assert %{"pleroma" => %{"is_seen" => true}} = response2
+ assert Repo.get(Notification, notification1.id).seen
+ assert Repo.get(Notification, notification2.id).seen
+ refute Repo.get(Notification, notification3.id).seen
+ end
+
+ test "it returns error when notification not found", %{conn: conn} do
+ user1 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
+ |> json_response(:bad_request)
+
+ assert response == %{"error" => "Cannot get notification"}
+ end
+ end
+end
diff --git a/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs b/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs
new file mode 100644
index 000000000..c6a71732d
--- /dev/null
+++ b/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs
@@ -0,0 +1,234 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Repo
+ alias Pleroma.SubscriptionNotification
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ clear_config([:instance, :public])
+ clear_config([:rich_media, :enabled])
+
+ describe "subscription_notifications" do
+ setup do
+ user = insert(:user)
+ subscriber = insert(:user)
+
+ User.subscribe(subscriber, user)
+
+ {:ok, %{user: user, subscriber: subscriber}}
+ end
+
+ test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
+ status_text = "Hello"
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+ path = subscription_notification_path(conn, :index)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> get(path)
+
+ assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
+ assert response == status_text
+ end
+
+ test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
+ status_text = "Hello"
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+ [notification] = Repo.all(SubscriptionNotification)
+
+ path = subscription_notification_path(conn, :show, notification)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> get(path)
+
+ assert %{"status" => %{"content" => response}} = json_response(conn, 200)
+ assert response == status_text
+ end
+
+ test "dismissing a single notification also deletes it", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ status_text = "Hello"
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
+
+ [notification] = Repo.all(SubscriptionNotification)
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> post(subscription_notification_path(conn, :dismiss), %{"id" => notification.id})
+
+ assert %{} = json_response(conn, 200)
+
+ assert Repo.all(SubscriptionNotification) == []
+ end
+
+ test "clearing all notifications also deletes them", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ status_text1 = "Hello"
+ status_text2 = "Hello again"
+ {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
+ {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
+
+ conn =
+ conn
+ |> assign(:user, subscriber)
+ |> post(subscription_notification_path(conn, :clear))
+
+ assert %{} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, subscriber)
+ |> get(subscription_notification_path(conn, :index))
+
+ assert json_response(conn, 200) == []
+
+ assert Repo.all(SubscriptionNotification) == []
+ end
+
+ test "paginates notifications using min_id, since_id, max_id, and limit", %{
+ conn: conn,
+ user: user,
+ subscriber: subscriber
+ } do
+ {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
+ {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
+ {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
+ {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
+
+ notification1_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
+
+ notification2_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
+
+ notification3_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
+
+ notification4_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
+
+ conn = assign(conn, :user, subscriber)
+
+ # min_id
+ conn_res =
+ get(
+ conn,
+ subscription_notification_path(conn, :index, %{
+ "limit" => 2,
+ "min_id" => notification1_id
+ })
+ )
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+
+ # since_id
+ conn_res =
+ get(
+ conn,
+ subscription_notification_path(conn, :index, %{
+ "limit" => 2,
+ "since_id" => notification1_id
+ })
+ )
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
+
+ # max_id
+ conn_res =
+ get(
+ conn,
+ subscription_notification_path(conn, :index, %{
+ "limit" => 2,
+ "max_id" => notification4_id
+ })
+ )
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+ end
+
+ test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
+ # mutual subscription
+ User.subscribe(user1, user2)
+
+ {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
+ {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
+ {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
+ {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
+
+ notification1_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
+
+ notification2_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
+
+ notification3_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
+
+ notification4_id =
+ Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
+
+ conn = assign(conn, :user, user1)
+
+ conn_res = get(conn, subscription_notification_path(conn, :index))
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification3_id, notification4_id]
+ end)
+
+ conn2 = assign(conn, :user, user2)
+
+ conn_res = get(conn2, subscription_notification_path(conn, :index))
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification1_id, notification2_id]
+ end)
+
+ conn_destroy =
+ delete(conn, subscription_notification_path(conn, :destroy_multiple), %{
+ "ids" => [notification3_id, notification4_id]
+ })
+
+ assert json_response(conn_destroy, 200) == %{}
+
+ conn_res = get(conn2, subscription_notification_path(conn, :index))
+
+ result = json_response(conn_res, 200)
+
+ Enum.each(result, fn %{"id" => id} ->
+ assert id in [notification1_id, notification2_id]
+ end)
+
+ assert length(Repo.all(SubscriptionNotification)) == 2
+ end
+ end
+end
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
deleted file mode 100644
index 7eaeda4a0..000000000
--- a/test/web/pleroma_api/pleroma_api_controller_test.exs
+++ /dev/null
@@ -1,150 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Conversation.Participation
- alias Pleroma.Notification
- alias Pleroma.Repo
- alias Pleroma.Web.CommonAPI
-
- import Pleroma.Factory
-
- test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
-
- [participation] = Participation.for_user(other_user)
-
- result =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/pleroma/conversations/#{participation.id}")
- |> json_response(200)
-
- assert result["id"] == participation.id |> to_string()
- end
-
- test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- third_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
-
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
-
- [participation] = Participation.for_user(other_user)
-
- {:ok, activity_two} =
- CommonAPI.post(other_user, %{
- "status" => "Hi!",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
- })
-
- result =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
- |> json_response(200)
-
- assert length(result) == 2
-
- id_one = activity.id
- id_two = activity_two.id
- assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
- end
-
- test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
-
- [participation] = Participation.for_user(user)
-
- participation = Repo.preload(participation, :recipients)
-
- assert [user] == participation.recipients
- assert other_user not in participation.recipients
-
- result =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
- "recipients" => [user.id, other_user.id]
- })
- |> json_response(200)
-
- assert result["id"] == participation.id |> to_string
-
- [participation] = Participation.for_user(user)
- participation = Repo.preload(participation, :recipients)
-
- assert user in participation.recipients
- assert other_user in participation.recipients
- end
-
- describe "POST /api/v1/pleroma/notifications/read" do
- test "it marks a single notification as read", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, [notification1]} = Notification.create_notifications(activity1)
- {:ok, [notification2]} = Notification.create_notifications(activity2)
-
- response =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
- |> json_response(:ok)
-
- assert %{"pleroma" => %{"is_seen" => true}} = response
- assert Repo.get(Notification, notification1.id).seen
- refute Repo.get(Notification, notification2.id).seen
- end
-
- test "it marks multiple notifications as read", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
-
- [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
-
- [response1, response2] =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
- |> json_response(:ok)
-
- assert %{"pleroma" => %{"is_seen" => true}} = response1
- assert %{"pleroma" => %{"is_seen" => true}} = response2
- assert Repo.get(Notification, notification1.id).seen
- assert Repo.get(Notification, notification2.id).seen
- refute Repo.get(Notification, notification3.id).seen
- end
-
- test "it returns error when notification not found", %{conn: conn} do
- user1 = insert(:user)
-
- response =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
- |> json_response(:bad_request)
-
- assert response == %{"error" => "Cannot get notification"}
- end
- end
-end
diff --git a/test/web/pleroma_api/subscription_notification_controller_test.exs b/test/web/pleroma_api/subscription_notification_controller_test.exs
deleted file mode 100644
index c6a71732d..000000000
--- a/test/web/pleroma_api/subscription_notification_controller_test.exs
+++ /dev/null
@@ -1,234 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Repo
- alias Pleroma.SubscriptionNotification
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI
- import Pleroma.Factory
- import Tesla.Mock
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- clear_config([:instance, :public])
- clear_config([:rich_media, :enabled])
-
- describe "subscription_notifications" do
- setup do
- user = insert(:user)
- subscriber = insert(:user)
-
- User.subscribe(subscriber, user)
-
- {:ok, %{user: user, subscriber: subscriber}}
- end
-
- test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
- status_text = "Hello"
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
- path = subscription_notification_path(conn, :index)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> get(path)
-
- assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
- assert response == status_text
- end
-
- test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
- status_text = "Hello"
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
- [notification] = Repo.all(SubscriptionNotification)
-
- path = subscription_notification_path(conn, :show, notification)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> get(path)
-
- assert %{"status" => %{"content" => response}} = json_response(conn, 200)
- assert response == status_text
- end
-
- test "dismissing a single notification also deletes it", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- status_text = "Hello"
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
-
- [notification] = Repo.all(SubscriptionNotification)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> post(subscription_notification_path(conn, :dismiss), %{"id" => notification.id})
-
- assert %{} = json_response(conn, 200)
-
- assert Repo.all(SubscriptionNotification) == []
- end
-
- test "clearing all notifications also deletes them", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- status_text1 = "Hello"
- status_text2 = "Hello again"
- {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
- {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> post(subscription_notification_path(conn, :clear))
-
- assert %{} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, subscriber)
- |> get(subscription_notification_path(conn, :index))
-
- assert json_response(conn, 200) == []
-
- assert Repo.all(SubscriptionNotification) == []
- end
-
- test "paginates notifications using min_id, since_id, max_id, and limit", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
- {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
- {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
- {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
-
- notification1_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
-
- notification2_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
-
- notification3_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
-
- notification4_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
-
- conn = assign(conn, :user, subscriber)
-
- # min_id
- conn_res =
- get(
- conn,
- subscription_notification_path(conn, :index, %{
- "limit" => 2,
- "min_id" => notification1_id
- })
- )
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
-
- # since_id
- conn_res =
- get(
- conn,
- subscription_notification_path(conn, :index, %{
- "limit" => 2,
- "since_id" => notification1_id
- })
- )
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
-
- # max_id
- conn_res =
- get(
- conn,
- subscription_notification_path(conn, :index, %{
- "limit" => 2,
- "max_id" => notification4_id
- })
- )
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
- end
-
- test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
- # mutual subscription
- User.subscribe(user1, user2)
-
- {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
- {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
- {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
- {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
-
- notification1_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
-
- notification2_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
-
- notification3_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
-
- notification4_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
-
- conn = assign(conn, :user, user1)
-
- conn_res = get(conn, subscription_notification_path(conn, :index))
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification3_id, notification4_id]
- end)
-
- conn2 = assign(conn, :user, user2)
-
- conn_res = get(conn2, subscription_notification_path(conn, :index))
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification1_id, notification2_id]
- end)
-
- conn_destroy =
- delete(conn, subscription_notification_path(conn, :destroy_multiple), %{
- "ids" => [notification3_id, notification4_id]
- })
-
- assert json_response(conn_destroy, 200) == %{}
-
- conn_res = get(conn2, subscription_notification_path(conn, :index))
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification1_id, notification2_id]
- end)
-
- assert length(Repo.all(SubscriptionNotification)) == 2
- end
- end
-end
--
cgit v1.2.3
From 80c5c3495bdd7939e576c8746a959f3f89f44042 Mon Sep 17 00:00:00 2001
From: Steven Fuchs
Date: Tue, 17 Sep 2019 14:44:52 +0000
Subject: remove remaining errors from tests
---
test/integration/mastodon_websocket_test.exs | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index c04262808..d02a3cc4d 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -18,6 +18,11 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|> Map.put(:path, "/api/v1/streaming")
|> URI.to_string()
+ setup_all do
+ start_supervised(Pleroma.Web.Streamer.supervisor())
+ :ok
+ end
+
def start_socket(qs \\ nil, headers \\ []) do
path =
case qs do
@@ -32,6 +37,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
capture_log(fn ->
assert {:error, {400, _}} = start_socket()
assert {:error, {404, _}} = start_socket("?stream=ncjdk")
+ Process.sleep(30)
end)
end
@@ -39,17 +45,16 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
capture_log(fn ->
assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
assert {:error, {403, _}} = start_socket("?stream=user")
+ Process.sleep(30)
end)
end
- @tag needs_streamer: true
test "allows public streams without authentication" do
assert {:ok, _} = start_socket("?stream=public")
assert {:ok, _} = start_socket("?stream=public:local")
assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
end
- @tag needs_streamer: true
test "receives well formatted events" do
user = insert(:user)
{:ok, _} = start_socket("?stream=public")
@@ -94,31 +99,32 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
end
- @tag needs_streamer: true
test "accepts the 'user' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
assert capture_log(fn ->
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user")
+ Process.sleep(30)
end) =~ ":badarg"
end
- @tag needs_streamer: true
test "accepts the 'user:notification' stream", %{token: token} = _state do
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
assert capture_log(fn ->
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
+ Process.sleep(30)
end) =~ ":badarg"
end
- @tag needs_streamer: true
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
assert capture_log(fn ->
assert {:error, {403, "Forbidden"}} =
start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
+
+ Process.sleep(30)
end) =~ ":badarg"
end
end
--
cgit v1.2.3
From 76068873dbf9da191dd2487158ca88df198b811a Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 17 Sep 2019 22:19:39 +0300
Subject: [#1234] Defined admin OAuth scopes, refined other scopes. Added
tests.
---
test/plugs/oauth_scopes_plug_test.exs | 219 ++++++++++++++++++++++------------
1 file changed, 145 insertions(+), 74 deletions(-)
(limited to 'test')
diff --git a/test/plugs/oauth_scopes_plug_test.exs b/test/plugs/oauth_scopes_plug_test.exs
index 9b0a2e702..3b895a6e4 100644
--- a/test/plugs/oauth_scopes_plug_test.exs
+++ b/test/plugs/oauth_scopes_plug_test.exs
@@ -6,23 +6,47 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
use Pleroma.Web.ConnCase, async: true
alias Pleroma.Plugs.OAuthScopesPlug
+ alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Repo
+ import Mock
import Pleroma.Factory
- test "proceeds with no op if `assigns[:token]` is nil", %{conn: conn} do
- conn =
- conn
- |> assign(:user, insert(:user))
- |> OAuthScopesPlug.call(%{scopes: ["read"]})
+ setup_with_mocks([{EnsurePublicOrAuthenticatedPlug, [], [call: fn conn, _ -> conn end]}]) do
+ :ok
+ end
- refute conn.halted
- assert conn.assigns[:user]
+ describe "when `assigns[:token]` is nil, " do
+ test "with :skip_instance_privacy_check option, proceeds with no op", %{conn: conn} do
+ conn =
+ conn
+ |> assign(:user, insert(:user))
+ |> OAuthScopesPlug.call(%{scopes: ["read"], skip_instance_privacy_check: true})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+
+ refute called(EnsurePublicOrAuthenticatedPlug.call(conn, :_))
+ end
+
+ test "without :skip_instance_privacy_check option, calls EnsurePublicOrAuthenticatedPlug", %{
+ conn: conn
+ } do
+ conn =
+ conn
+ |> assign(:user, insert(:user))
+ |> OAuthScopesPlug.call(%{scopes: ["read"]})
+
+ refute conn.halted
+ assert conn.assigns[:user]
+
+ assert called(EnsurePublicOrAuthenticatedPlug.call(conn, :_))
+ end
end
- test "proceeds with no op if `token.scopes` fulfill specified 'any of' conditions", %{
- conn: conn
- } do
+ test "if `token.scopes` fulfills specified 'any of' conditions, " <>
+ "proceeds with no op",
+ %{conn: conn} do
token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
conn =
@@ -35,9 +59,9 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
assert conn.assigns[:user]
end
- test "proceeds with no op if `token.scopes` fulfill specified 'all of' conditions", %{
- conn: conn
- } do
+ test "if `token.scopes` fulfills specified 'all of' conditions, " <>
+ "proceeds with no op",
+ %{conn: conn} do
token = insert(:oauth_token, scopes: ["scope1", "scope2", "scope3"]) |> Repo.preload(:user)
conn =
@@ -50,82 +74,112 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
assert conn.assigns[:user]
end
- test "proceeds with cleared `assigns[:user]` if `token.scopes` doesn't fulfill specified 'any of' conditions " <>
- "and `fallback: :proceed_unauthenticated` option is specified",
- %{conn: conn} do
- token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
+ describe "with `fallback: :proceed_unauthenticated` option, " do
+ test "if `token.scopes` doesn't fulfill specified 'any of' conditions, " <>
+ "clears `assigns[:user]` and calls EnsurePublicOrAuthenticatedPlug",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
- conn =
- conn
- |> assign(:user, token.user)
- |> assign(:token, token)
- |> OAuthScopesPlug.call(%{scopes: ["follow"], fallback: :proceed_unauthenticated})
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: ["follow"], fallback: :proceed_unauthenticated})
- refute conn.halted
- refute conn.assigns[:user]
- end
+ refute conn.halted
+ refute conn.assigns[:user]
- test "proceeds with cleared `assigns[:user]` if `token.scopes` doesn't fulfill specified 'all of' conditions " <>
- "and `fallback: :proceed_unauthenticated` option is specified",
- %{conn: conn} do
- token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
+ assert called(EnsurePublicOrAuthenticatedPlug.call(conn, :_))
+ end
- conn =
- conn
- |> assign(:user, token.user)
- |> assign(:token, token)
- |> OAuthScopesPlug.call(%{
- scopes: ["read", "follow"],
- op: :&,
- fallback: :proceed_unauthenticated
- })
+ test "if `token.scopes` doesn't fulfill specified 'all of' conditions, " <>
+ "clears `assigns[:user] and calls EnsurePublicOrAuthenticatedPlug",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
- refute conn.halted
- refute conn.assigns[:user]
- end
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{
+ scopes: ["read", "follow"],
+ op: :&,
+ fallback: :proceed_unauthenticated
+ })
- test "returns 403 and halts " <>
- "in case of no :fallback option and `token.scopes` not fulfilling specified 'any of' conditions",
- %{conn: conn} do
- token = insert(:oauth_token, scopes: ["read", "write"])
- any_of_scopes = ["follow"]
+ refute conn.halted
+ refute conn.assigns[:user]
- conn =
- conn
- |> assign(:token, token)
- |> OAuthScopesPlug.call(%{scopes: any_of_scopes})
+ assert called(EnsurePublicOrAuthenticatedPlug.call(conn, :_))
+ end
- assert conn.halted
- assert 403 == conn.status
+ test "with :skip_instance_privacy_check option, " <>
+ "if `token.scopes` doesn't fulfill specified conditions, " <>
+ "clears `assigns[:user]` and does not call EnsurePublicOrAuthenticatedPlug",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read:statuses", "write"]) |> Repo.preload(:user)
- expected_error = "Insufficient permissions: #{Enum.join(any_of_scopes, ", ")}."
- assert Jason.encode!(%{error: expected_error}) == conn.resp_body
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{
+ scopes: ["read"],
+ fallback: :proceed_unauthenticated,
+ skip_instance_privacy_check: true
+ })
+
+ refute conn.halted
+ refute conn.assigns[:user]
+
+ refute called(EnsurePublicOrAuthenticatedPlug.call(conn, :_))
+ end
end
- test "returns 403 and halts " <>
- "in case of no :fallback option and `token.scopes` not fulfilling specified 'all of' conditions",
- %{conn: conn} do
- token = insert(:oauth_token, scopes: ["read", "write"])
- all_of_scopes = ["write", "follow"]
+ describe "without :fallback option, " do
+ test "if `token.scopes` does not fulfill specified 'any of' conditions, " <>
+ "returns 403 and halts",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"])
+ any_of_scopes = ["follow"]
- conn =
- conn
- |> assign(:token, token)
- |> OAuthScopesPlug.call(%{scopes: all_of_scopes, op: :&})
+ conn =
+ conn
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: any_of_scopes})
+
+ assert conn.halted
+ assert 403 == conn.status
+
+ expected_error = "Insufficient permissions: #{Enum.join(any_of_scopes, ", ")}."
+ assert Jason.encode!(%{error: expected_error}) == conn.resp_body
+ end
- assert conn.halted
- assert 403 == conn.status
+ test "if `token.scopes` does not fulfill specified 'all of' conditions, " <>
+ "returns 403 and halts",
+ %{conn: conn} do
+ token = insert(:oauth_token, scopes: ["read", "write"])
+ all_of_scopes = ["write", "follow"]
- expected_error =
- "Insufficient permissions: #{Enum.join(all_of_scopes -- token.scopes, ", ")}."
+ conn =
+ conn
+ |> assign(:token, token)
+ |> OAuthScopesPlug.call(%{scopes: all_of_scopes, op: :&})
- assert Jason.encode!(%{error: expected_error}) == conn.resp_body
+ assert conn.halted
+ assert 403 == conn.status
+
+ expected_error =
+ "Insufficient permissions: #{Enum.join(all_of_scopes -- token.scopes, ", ")}."
+
+ assert Jason.encode!(%{error: expected_error}) == conn.resp_body
+ end
end
describe "with hierarchical scopes, " do
- test "proceeds with no op if `token.scopes` fulfill specified 'any of' conditions", %{
- conn: conn
- } do
+ test "if `token.scopes` fulfills specified 'any of' conditions, " <>
+ "proceeds with no op",
+ %{conn: conn} do
token = insert(:oauth_token, scopes: ["read", "write"]) |> Repo.preload(:user)
conn =
@@ -138,9 +192,9 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
assert conn.assigns[:user]
end
- test "proceeds with no op if `token.scopes` fulfill specified 'all of' conditions", %{
- conn: conn
- } do
+ test "if `token.scopes` fulfills specified 'all of' conditions, " <>
+ "proceeds with no op",
+ %{conn: conn} do
token = insert(:oauth_token, scopes: ["scope1", "scope2", "scope3"]) |> Repo.preload(:user)
conn =
@@ -153,4 +207,21 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
assert conn.assigns[:user]
end
end
+
+ describe "filter_descendants/2" do
+ test "filters scopes which directly match or are ancestors of supported scopes" do
+ f = fn scopes, supported_scopes ->
+ OAuthScopesPlug.filter_descendants(scopes, supported_scopes)
+ end
+
+ assert f.(["read", "follow"], ["write", "read"]) == ["read"]
+
+ assert f.(["read", "write:something", "follow"], ["write", "read"]) ==
+ ["read", "write:something"]
+
+ assert f.(["admin:read"], ["write", "read"]) == []
+
+ assert f.(["admin:read"], ["write", "admin"]) == ["admin:read"]
+ end
+ end
end
--
cgit v1.2.3
From b17f217bf3a16da0e98e63b59da22f40beec809d Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Tue, 17 Sep 2019 23:31:05 +0300
Subject: [#1234] Addressed code analysis issue.
---
test/plugs/oauth_scopes_plug_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/plugs/oauth_scopes_plug_test.exs b/test/plugs/oauth_scopes_plug_test.exs
index 3b895a6e4..c69e2de4f 100644
--- a/test/plugs/oauth_scopes_plug_test.exs
+++ b/test/plugs/oauth_scopes_plug_test.exs
@@ -5,8 +5,8 @@
defmodule Pleroma.Plugs.OAuthScopesPlugTest do
use Pleroma.Web.ConnCase, async: true
- alias Pleroma.Plugs.OAuthScopesPlug
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
+ alias Pleroma.Plugs.OAuthScopesPlug
alias Pleroma.Repo
import Mock
--
cgit v1.2.3
From 4faf2b1555f004664005e0efddb9815ebca4c5c7 Mon Sep 17 00:00:00 2001
From: Alex S
Date: Fri, 6 Sep 2019 17:14:31 +0300
Subject: post for creating invite tokens in admin api
---
test/web/admin_api/admin_api_controller_test.exs | 46 +++++++++---------------
1 file changed, 16 insertions(+), 30 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index c497ea098..5f36d42e4 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -574,18 +574,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
- test "/api/pleroma/admin/users/invite_token" do
- admin = insert(:user, info: %{is_admin: true})
-
- conn =
- build_conn()
- |> assign(:user, admin)
- |> put_req_header("accept", "application/json")
- |> get("/api/pleroma/admin/users/invite_token")
-
- assert conn.status == 200
- end
-
test "/api/pleroma/admin/users/:nickname/password_reset" do
admin = insert(:user, info: %{is_admin: true})
user = insert(:user)
@@ -1064,7 +1052,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"@#{admin.nickname} deactivated user @#{user.nickname}"
end
- describe "GET /api/pleroma/admin/users/invite_token" do
+ describe "POST /api/pleroma/admin/users/invite_token" do
setup do
admin = insert(:user, info: %{is_admin: true})
@@ -1076,10 +1064,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "without options", %{conn: conn} do
- conn = get(conn, "/api/pleroma/admin/users/invite_token")
+ conn = post(conn, "/api/pleroma/admin/users/invite_token")
- token = json_response(conn, 200)
- invite = UserInviteToken.find_by_token!(token)
+ invite_json = json_response(conn, 200)
+ invite = UserInviteToken.find_by_token!(invite_json["token"])
refute invite.used
refute invite.expires_at
refute invite.max_use
@@ -1088,12 +1076,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
test "with expires_at", %{conn: conn} do
conn =
- get(conn, "/api/pleroma/admin/users/invite_token", %{
- "invite" => %{"expires_at" => Date.to_string(Date.utc_today())}
+ post(conn, "/api/pleroma/admin/users/invite_token", %{
+ "expires_at" => Date.to_string(Date.utc_today())
})
- token = json_response(conn, 200)
- invite = UserInviteToken.find_by_token!(token)
+ invite_json = json_response(conn, 200)
+ invite = UserInviteToken.find_by_token!(invite_json["token"])
refute invite.used
assert invite.expires_at == Date.utc_today()
@@ -1102,13 +1090,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "with max_use", %{conn: conn} do
- conn =
- get(conn, "/api/pleroma/admin/users/invite_token", %{
- "invite" => %{"max_use" => 150}
- })
+ conn = post(conn, "/api/pleroma/admin/users/invite_token", %{"max_use" => 150})
- token = json_response(conn, 200)
- invite = UserInviteToken.find_by_token!(token)
+ invite_json = json_response(conn, 200)
+ invite = UserInviteToken.find_by_token!(invite_json["token"])
refute invite.used
refute invite.expires_at
assert invite.max_use == 150
@@ -1117,12 +1102,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
test "with max use and expires_at", %{conn: conn} do
conn =
- get(conn, "/api/pleroma/admin/users/invite_token", %{
- "invite" => %{"max_use" => 150, "expires_at" => Date.to_string(Date.utc_today())}
+ post(conn, "/api/pleroma/admin/users/invite_token", %{
+ "max_use" => 150,
+ "expires_at" => Date.to_string(Date.utc_today())
})
- token = json_response(conn, 200)
- invite = UserInviteToken.find_by_token!(token)
+ invite_json = json_response(conn, 200)
+ invite = UserInviteToken.find_by_token!(invite_json["token"])
refute invite.used
assert invite.expires_at == Date.utc_today()
assert invite.max_use == 150
--
cgit v1.2.3
From 7ef575d11e46247d1f64dd09d992e532cb8c5c37 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 18 Sep 2019 18:13:21 +0300
Subject: Initial poll refresh support
Implement refreshing the object with an interval and call the function
when getting the poll.
---
test/fixtures/tesla_mock/poll_modified.json | 1 +
test/fixtures/tesla_mock/poll_original.json | 1 +
test/fixtures/tesla_mock/rin.json | 1 +
test/object_test.exs | 86 +++++++++++++++++++++++++++++
test/support/http_request_mock.ex | 4 ++
5 files changed, 93 insertions(+)
create mode 100644 test/fixtures/tesla_mock/poll_modified.json
create mode 100644 test/fixtures/tesla_mock/poll_original.json
create mode 100644 test/fixtures/tesla_mock/rin.json
(limited to 'test')
diff --git a/test/fixtures/tesla_mock/poll_modified.json b/test/fixtures/tesla_mock/poll_modified.json
new file mode 100644
index 000000000..1d026b592
--- /dev/null
+++ b/test/fixtures/tesla_mock/poll_modified.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://patch.cx/schemas/litepub-0.1.jsonld",{"@language":"und"}],"actor":"https://patch.cx/users/rin","attachment":[],"attributedTo":"https://patch.cx/users/rin","cc":["https://patch.cx/users/rin/followers"],"closed":"2019-09-19T00:32:36.785333","content":"can you vote on this poll?","context":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","conversation":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","id":"https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d","oneOf":[{"name":"yes","replies":{"totalItems":8,"type":"Collection"},"type":"Note"},{"name":"no","replies":{"totalItems":3,"type":"Collection"},"type":"Note"}],"published":"2019-09-18T14:32:36.802152Z","sensitive":false,"summary":"","tag":[],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Question"}
\ No newline at end of file
diff --git a/test/fixtures/tesla_mock/poll_original.json b/test/fixtures/tesla_mock/poll_original.json
new file mode 100644
index 000000000..267876b3c
--- /dev/null
+++ b/test/fixtures/tesla_mock/poll_original.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://patch.cx/schemas/litepub-0.1.jsonld",{"@language":"und"}],"actor":"https://patch.cx/users/rin","attachment":[],"attributedTo":"https://patch.cx/users/rin","cc":["https://patch.cx/users/rin/followers"],"closed":"2019-09-19T00:32:36.785333","content":"can you vote on this poll?","context":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","conversation":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","id":"https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d","oneOf":[{"name":"yes","replies":{"totalItems":4,"type":"Collection"},"type":"Note"},{"name":"no","replies":{"totalItems":0,"type":"Collection"},"type":"Note"}],"published":"2019-09-18T14:32:36.802152Z","sensitive":false,"summary":"","tag":[],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Question"}
\ No newline at end of file
diff --git a/test/fixtures/tesla_mock/rin.json b/test/fixtures/tesla_mock/rin.json
new file mode 100644
index 000000000..2cf623764
--- /dev/null
+++ b/test/fixtures/tesla_mock/rin.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://patch.cx/schemas/litepub-0.1.jsonld",{"@language":"und"}],"attachment":[],"endpoints":{"oauthAuthorizationEndpoint":"https://patch.cx/oauth/authorize","oauthRegistrationEndpoint":"https://patch.cx/api/v1/apps","oauthTokenEndpoint":"https://patch.cx/oauth/token","sharedInbox":"https://patch.cx/inbox"},"followers":"https://patch.cx/users/rin/followers","following":"https://patch.cx/users/rin/following","icon":{"type":"Image","url":"https://patch.cx/media/4e914f5b84e4a259a3f6c2d2edc9ab642f2ab05f3e3d9c52c81fc2d984b3d51e.jpg"},"id":"https://patch.cx/users/rin","image":{"type":"Image","url":"https://patch.cx/media/f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg?name=f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg"},"inbox":"https://patch.cx/users/rin/inbox","manuallyApprovesFollowers":false,"name":"rinpatch","outbox":"https://patch.cx/users/rin/outbox","preferredUsername":"rin","publicKey":{"id":"https://patch.cx/users/rin#main-key","owner":"https://patch.cx/users/rin","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5DLtwGXNZElJyxFGfcVc\nXANhaMadj/iYYQwZjOJTV9QsbtiNBeIK54PJrYuU0/0YIdrvS1iqheX5IwXRhcwa\nhm3ZyLz7XeN9st7FBni4BmZMBtMpxAuYuu5p/jbWy13qAiYOhPreCx0wrWgm/lBD\n9mkgaxIxPooBE0S4ZWEJIDIV1Vft3AWcRUyWW1vIBK0uZzs6GYshbQZB952S0yo4\nFzI1hABGHncH8UvuFauh4EZ8tY7/X5I0pGRnDOcRN1dAht5w5yTA+6r5kebiFQjP\nIzN/eCO/a9Flrj9YGW7HDNtjSOH0A31PLRGlJtJO3yK57dnf5ppyCZGfL4emShQo\ncQIDAQAB\n-----END PUBLIC KEY-----\n\n"},"summary":"your friendly neighborhood pleroma developer
I like cute things and distributed systems, and really hate delete and redrafts","tag":[],"type":"Person","url":"https://patch.cx/users/rin"}
\ No newline at end of file
diff --git a/test/object_test.exs b/test/object_test.exs
index ba96aeea4..72e36316c 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -89,4 +89,90 @@ defmodule Pleroma.ObjectTest do
)
end
end
+
+ describe "get_by_id_and_maybe_refetch" do
+ test "refetches if the time since the last refetch is greater than the interval" do
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ %Object{} =
+ object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+
+ assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_modified.json")}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+ assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
+ assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3
+ end
+
+ test "returns the old object if refetch fails" do
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ %Object{} =
+ object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+
+ assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ %Tesla.Env{status: 404, body: ""}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+ assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+ end
+
+ test "does not refetch if the time since the last refetch is greater than the interval" do
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ %Object{} =
+ object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+
+ assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_modified.json")}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: 100)
+ assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+ end
+ end
end
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 231e7c498..833162a61 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1004,6 +1004,10 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
end
+ def get("https://patch.cx/users/rin", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
+ end
+
def get(url, query, body, headers) do
{:error,
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
--
cgit v1.2.3
From 84a40f6f266ea651578b3d641c000a3b762fc9f3 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 18 Sep 2019 18:31:24 +0300
Subject: Capture log in object refetch tests
---
test/object_test.exs | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
(limited to 'test')
diff --git a/test/object_test.exs b/test/object_test.exs
index 72e36316c..25e8d45d4 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -4,6 +4,7 @@
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
+ import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
alias Pleroma.Object
@@ -134,17 +135,23 @@ defmodule Pleroma.ObjectTest do
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
- mock(fn
- %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
- %Tesla.Env{status: 404, body: ""}
-
- env ->
- apply(HttpRequestMock, :request, [env])
- end)
-
- updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
- assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
- assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+ assert capture_log(fn ->
+ mock(fn
+ %{
+ method: :get,
+ url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"
+ } ->
+ %Tesla.Env{status: 404, body: ""}
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+
+ updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+ assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+ end) =~
+ "[error] Couldn't refresh https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"
end
test "does not refetch if the time since the last refetch is greater than the interval" do
--
cgit v1.2.3
From eb87a86b5b3999f3e7ee119e839da3bd6d2ed4cf Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 18 Sep 2019 19:53:51 +0300
Subject: Preserve internal fields when reinjecting
---
test/object_test.exs | 102 +++++++++++++++++++++++++++++----------------------
1 file changed, 59 insertions(+), 43 deletions(-)
(limited to 'test')
diff --git a/test/object_test.exs b/test/object_test.exs
index 25e8d45d4..3d64fdb49 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -7,8 +7,10 @@ defmodule Pleroma.ObjectTest do
import ExUnit.CaptureLog
import Pleroma.Factory
import Tesla.Mock
+ alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -92,7 +94,7 @@ defmodule Pleroma.ObjectTest do
end
describe "get_by_id_and_maybe_refetch" do
- test "refetches if the time since the last refetch is greater than the interval" do
+ setup do
mock(fn
%{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
@@ -101,34 +103,41 @@ defmodule Pleroma.ObjectTest do
apply(HttpRequestMock, :request, [env])
end)
+ mock_modified = fn resp ->
+ mock(fn
+ %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
+ resp
+
+ env ->
+ apply(HttpRequestMock, :request, [env])
+ end)
+ end
+
+ on_exit(fn -> mock(fn env -> apply(HttpRequestMock, :request, [env]) end) end)
+
+ [mock_modified: mock_modified]
+ end
+
+ test "refetches if the time since the last refetch is greater than the interval", %{
+ mock_modified: mock_modified
+ } do
%Object{} =
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
- mock(fn
- %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_modified.json")}
-
- env ->
- apply(HttpRequestMock, :request, [env])
- end)
+ mock_modified.(%Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
+ })
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3
end
- test "returns the old object if refetch fails" do
- mock(fn
- %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
-
- env ->
- apply(HttpRequestMock, :request, [env])
- end)
-
+ test "returns the old object if refetch fails", %{mock_modified: mock_modified} do
%Object{} =
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
@@ -136,16 +145,7 @@ defmodule Pleroma.ObjectTest do
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
assert capture_log(fn ->
- mock(fn
- %{
- method: :get,
- url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"
- } ->
- %Tesla.Env{status: 404, body: ""}
-
- env ->
- apply(HttpRequestMock, :request, [env])
- end)
+ mock_modified.(%Tesla.Env{status: 404, body: ""})
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
@@ -154,32 +154,48 @@ defmodule Pleroma.ObjectTest do
"[error] Couldn't refresh https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"
end
- test "does not refetch if the time since the last refetch is greater than the interval" do
- mock(fn
- %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
-
- env ->
- apply(HttpRequestMock, :request, [env])
- end)
-
+ test "does not refetch if the time since the last refetch is greater than the interval", %{
+ mock_modified: mock_modified
+ } do
%Object{} =
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
- mock(fn
- %{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_modified.json")}
-
- env ->
- apply(HttpRequestMock, :request, [env])
- end)
+ mock_modified.(%Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
+ })
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: 100)
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
end
+
+ test "preserves internal fields on refetch", %{mock_modified: mock_modified} do
+ %Object{} =
+ object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
+
+ assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
+ assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
+
+ user = insert(:user)
+ activity = Activity.get_create_by_object_ap_id(object.data["id"])
+ {:ok, _activity, object} = CommonAPI.favorite(activity.id, user)
+
+ assert object.data["like_count"] == 1
+
+ mock_modified.(%Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
+ })
+
+ updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
+ assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
+ assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3
+
+ assert updated_object.data["like_count"] == 1
+ end
end
end
--
cgit v1.2.3
From a12aeb09c42f1c120b78d517cfbad2fe29c88006 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 18 Sep 2019 23:34:13 +0300
Subject: Cleanup uploads after the tests are finished
---
test/test_helper.exs | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'test')
diff --git a/test/test_helper.exs b/test/test_helper.exs
index a927b2c3d..6a389365f 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -7,3 +7,8 @@ ExUnit.start(exclude: os_exclude)
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
Mox.defmock(Pleroma.ReverseProxy.ClientMock, for: Pleroma.ReverseProxy.Client)
{:ok, _} = Application.ensure_all_started(:ex_machina)
+
+ExUnit.after_suite(fn _results ->
+ uploads = Pleroma.Config.get([Pleroma.Uploaders.Local, :uploads], "test/uploads")
+ File.rm_rf!(uploads)
+end)
--
cgit v1.2.3
From 7e4c8b56eab0e92b98efbf27e373d68758de540f Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Mon, 12 Aug 2019 10:35:34 +0300
Subject: Add tests for emoji pack sharing
---
test/instance_static/emoji/test_pack/blank.png | Bin 0 -> 95 bytes
test/instance_static/emoji/test_pack/pack.yml | 13 +++
.../emoji/test_pack_nonshared/pack.yml | 13 +++
test/web/emoji_api_controller_test.exs | 98 +++++++++++++++++++++
4 files changed, 124 insertions(+)
create mode 100644 test/instance_static/emoji/test_pack/blank.png
create mode 100644 test/instance_static/emoji/test_pack/pack.yml
create mode 100644 test/instance_static/emoji/test_pack_nonshared/pack.yml
create mode 100644 test/web/emoji_api_controller_test.exs
(limited to 'test')
diff --git a/test/instance_static/emoji/test_pack/blank.png b/test/instance_static/emoji/test_pack/blank.png
new file mode 100644
index 000000000..8f50fa023
Binary files /dev/null and b/test/instance_static/emoji/test_pack/blank.png differ
diff --git a/test/instance_static/emoji/test_pack/pack.yml b/test/instance_static/emoji/test_pack/pack.yml
new file mode 100644
index 000000000..851b06d17
--- /dev/null
+++ b/test/instance_static/emoji/test_pack/pack.yml
@@ -0,0 +1,13 @@
+pack:
+ license: Test license
+ homepage: https://pleroma.social
+ description: Test description
+
+ fallblack-src: https://example.com
+ # SHA256 of the fallback-src
+ fallback-src-sha256: 65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75
+
+ share-files: true
+
+files:
+ blank: blank.png
diff --git a/test/instance_static/emoji/test_pack_nonshared/pack.yml b/test/instance_static/emoji/test_pack_nonshared/pack.yml
new file mode 100644
index 000000000..45c340415
--- /dev/null
+++ b/test/instance_static/emoji/test_pack_nonshared/pack.yml
@@ -0,0 +1,13 @@
+pack:
+ license: Test license
+ homepage: https://pleroma.social
+ description: Test description
+
+ fallblack-src: https://example.com
+ # SHA256 of the fallback-src
+ fallback-src-sha256: 65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75
+
+ share-files: false
+
+files:
+ blank: blank.png
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
new file mode 100644
index 000000000..c037883ee
--- /dev/null
+++ b/test/web/emoji_api_controller_test.exs
@@ -0,0 +1,98 @@
+defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Tesla.Mock
+
+ import Pleroma.Factory
+
+ test "shared & non-shared pack information in list_packs is ok" do
+ conn = build_conn()
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ assert Map.has_key?(resp, "test_pack")
+
+ pack = resp["test_pack"]
+
+ assert Map.has_key?(pack["pack"], "download-sha256")
+ assert pack["pack"]["can-download"]
+
+ assert pack["files"] == %{"blank" => "blank.png"}
+
+ # Non-shared pack
+
+ assert Map.has_key?(resp, "test_pack_nonshared")
+
+ pack = resp["test_pack_nonshared"]
+
+ refute pack["pack"]["shared"]
+ refute pack["pack"]["can-download"]
+ end
+
+ test "downloading a shared pack from download_shared" do
+ conn = build_conn()
+
+ resp =
+ conn
+ |> get(emoji_api_path(conn, :download_shared, "test_pack"))
+ |> response(200)
+
+ {:ok, arch} = :zip.unzip(resp, [:memory])
+
+ assert Enum.find(arch, fn {n, _} -> n == 'pack.yml' end)
+ assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
+ end
+
+ test "downloading a shared pack from another instance via download_from" do
+ on_exit(fn ->
+ File.rm_rf!("test/instance_static/emoji/test_pack2")
+ end)
+
+ mock(fn
+ %{
+ method: :get,
+ url: "https://example.com/api/pleroma/emoji/packs/list"
+ } ->
+ conn = build_conn()
+
+ conn
+ |> get(emoji_api_path(conn, :list_packs))
+ |> json_response(200)
+ |> json()
+
+ %{
+ method: :get,
+ url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
+ } ->
+ conn = build_conn()
+
+ conn
+ |> get(emoji_api_path(conn, :download_shared, "test_pack"))
+ |> response(200)
+ |> text()
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn()
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> assign(:user, admin)
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://example.com",
+ pack_name: "test_pack",
+ as: "test_pack2"
+ }
+ |> Jason.encode!()
+ )
+ |> text_response(200) == "ok"
+
+ assert File.exists?("test/instance_static/emoji/test_pack2/pack.yml")
+ assert File.exists?("test/instance_static/emoji/test_pack2/blank.png")
+ end
+end
--
cgit v1.2.3
From 2d4b8f3d20c4dbf60e52e95e77f2e77766974402 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Mon, 12 Aug 2019 18:03:59 +0300
Subject: Add an endpoint for deleting emoji packs
---
test/web/emoji_api_controller_test.exs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index c037883ee..13a34d38d 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -42,7 +42,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
end
- test "downloading a shared pack from another instance via download_from" do
+ test "downloading a shared pack from another instance via download_from, deleting it" do
on_exit(fn ->
File.rm_rf!("test/instance_static/emoji/test_pack2")
end)
@@ -94,5 +94,12 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert File.exists?("test/instance_static/emoji/test_pack2/pack.yml")
assert File.exists?("test/instance_static/emoji/test_pack2/blank.png")
+
+ assert conn
+ |> assign(:user, admin)
+ |> delete(emoji_api_path(conn, :delete, "test_pack2"))
+ |> response(200) == "ok"
+
+ refute File.exists?("test/instance_static/emoji/test_pack2")
end
end
--
cgit v1.2.3
From 2a94eca096f67a908410ffdd82f5bace8a3df88c Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Thu, 15 Aug 2019 11:39:39 +0300
Subject: Change YAML to JSON
---
test/instance_static/emoji/test_pack/pack.json | 16 ++++++++++++++++
test/instance_static/emoji/test_pack/pack.yml | 13 -------------
test/instance_static/emoji/test_pack_nonshared/pack.json | 16 ++++++++++++++++
test/instance_static/emoji/test_pack_nonshared/pack.yml | 13 -------------
test/web/emoji_api_controller_test.exs | 4 ++--
5 files changed, 34 insertions(+), 28 deletions(-)
create mode 100644 test/instance_static/emoji/test_pack/pack.json
delete mode 100644 test/instance_static/emoji/test_pack/pack.yml
create mode 100644 test/instance_static/emoji/test_pack_nonshared/pack.json
delete mode 100644 test/instance_static/emoji/test_pack_nonshared/pack.yml
(limited to 'test')
diff --git a/test/instance_static/emoji/test_pack/pack.json b/test/instance_static/emoji/test_pack/pack.json
new file mode 100644
index 000000000..1b260f0f7
--- /dev/null
+++ b/test/instance_static/emoji/test_pack/pack.json
@@ -0,0 +1,16 @@
+{
+ "pack": {
+ "license": "Test license",
+ "homepage": "https://pleroma.social",
+ "description": "Test description",
+
+ "fallblack-src": "https://example.com",
+ "fallback-src-sha256": "65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75",
+
+ "share-files": true
+ },
+
+ "files": {
+ "blank": "blank.png"
+ }
+}
diff --git a/test/instance_static/emoji/test_pack/pack.yml b/test/instance_static/emoji/test_pack/pack.yml
deleted file mode 100644
index 851b06d17..000000000
--- a/test/instance_static/emoji/test_pack/pack.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-pack:
- license: Test license
- homepage: https://pleroma.social
- description: Test description
-
- fallblack-src: https://example.com
- # SHA256 of the fallback-src
- fallback-src-sha256: 65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75
-
- share-files: true
-
-files:
- blank: blank.png
diff --git a/test/instance_static/emoji/test_pack_nonshared/pack.json b/test/instance_static/emoji/test_pack_nonshared/pack.json
new file mode 100644
index 000000000..b49b1efe7
--- /dev/null
+++ b/test/instance_static/emoji/test_pack_nonshared/pack.json
@@ -0,0 +1,16 @@
+{
+ "pack": {
+ "license": "Test license",
+ "homepage": "https://pleroma.social",
+ "description": "Test description",
+
+ "fallblack-src": "https://example.com",
+ "fallback-src-sha256": "65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75",
+
+ "share-files": false
+ },
+
+ "files": {
+ "blank": "blank.png"
+ }
+}
diff --git a/test/instance_static/emoji/test_pack_nonshared/pack.yml b/test/instance_static/emoji/test_pack_nonshared/pack.yml
deleted file mode 100644
index 45c340415..000000000
--- a/test/instance_static/emoji/test_pack_nonshared/pack.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-pack:
- license: Test license
- homepage: https://pleroma.social
- description: Test description
-
- fallblack-src: https://example.com
- # SHA256 of the fallback-src
- fallback-src-sha256: 65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75
-
- share-files: false
-
-files:
- blank: blank.png
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 13a34d38d..bf56c1516 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -38,7 +38,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
{:ok, arch} = :zip.unzip(resp, [:memory])
- assert Enum.find(arch, fn {n, _} -> n == 'pack.yml' end)
+ assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
end
@@ -92,7 +92,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
)
|> text_response(200) == "ok"
- assert File.exists?("test/instance_static/emoji/test_pack2/pack.yml")
+ assert File.exists?("test/instance_static/emoji/test_pack2/pack.json")
assert File.exists?("test/instance_static/emoji/test_pack2/blank.png")
assert conn
--
cgit v1.2.3
From adf31d596e77ef71e2ffe80d9dc41988f6c1cfb5 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Thu, 15 Aug 2019 12:07:51 +0300
Subject: Add tests for downloading from fallback url
---
.../emoji/test_pack_nonshared/nonshared.zip | Bin 0 -> 256 bytes
.../emoji/test_pack_nonshared/pack.json | 4 +--
test/web/emoji_api_controller_test.exs | 40 ++++++++++++++++++++-
3 files changed, 41 insertions(+), 3 deletions(-)
create mode 100644 test/instance_static/emoji/test_pack_nonshared/nonshared.zip
(limited to 'test')
diff --git a/test/instance_static/emoji/test_pack_nonshared/nonshared.zip b/test/instance_static/emoji/test_pack_nonshared/nonshared.zip
new file mode 100644
index 000000000..148446c64
Binary files /dev/null and b/test/instance_static/emoji/test_pack_nonshared/nonshared.zip differ
diff --git a/test/instance_static/emoji/test_pack_nonshared/pack.json b/test/instance_static/emoji/test_pack_nonshared/pack.json
index b49b1efe7..b96781f81 100644
--- a/test/instance_static/emoji/test_pack_nonshared/pack.json
+++ b/test/instance_static/emoji/test_pack_nonshared/pack.json
@@ -4,8 +4,8 @@
"homepage": "https://pleroma.social",
"description": "Test description",
- "fallblack-src": "https://example.com",
- "fallback-src-sha256": "65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75",
+ "fallback-src": "https://nonshared-pack",
+ "fallback-src-sha256": "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF",
"share-files": false
},
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index bf56c1516..aa30e3058 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -42,9 +42,10 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
end
- test "downloading a shared pack from another instance via download_from, deleting it" do
+ test "downloading shared & unshared packs from another instance via download_from, deleting them" do
on_exit(fn ->
File.rm_rf!("test/instance_static/emoji/test_pack2")
+ File.rm_rf!("test/instance_static/emoji/test_pack_nonshared2")
end)
mock(fn
@@ -69,6 +70,12 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
|> get(emoji_api_path(conn, :download_shared, "test_pack"))
|> response(200)
|> text()
+
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ text(File.read!("test/instance_static/emoji/test_pack_nonshared/nonshared.zip"))
end)
admin = insert(:user, info: %{is_admin: true})
@@ -101,5 +108,36 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
|> response(200) == "ok"
refute File.exists?("test/instance_static/emoji/test_pack2")
+
+ # non-shared, downloaded from the fallback URL
+
+ conn = build_conn()
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> assign(:user, admin)
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://example.com",
+ pack_name: "test_pack_nonshared",
+ as: "test_pack_nonshared2"
+ }
+ |> Jason.encode!()
+ )
+ |> text_response(200) == "ok"
+
+ assert File.exists?("test/instance_static/emoji/test_pack_nonshared2/pack.json")
+ assert File.exists?("test/instance_static/emoji/test_pack_nonshared2/blank.png")
+
+ assert conn
+ |> assign(:user, admin)
+ |> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
+ |> response(200) == "ok"
+
+ refute File.exists?("test/instance_static/emoji/test_pack_nonshared2")
end
end
--
cgit v1.2.3
From 9dc9689144a54f3e5513dd26de61ec43421d6d50 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Fri, 16 Aug 2019 13:22:14 +0300
Subject: Add tests for pack metadata updating
---
test/instance_static/emoji/test_pack/pack.json | 3 -
test/web/emoji_api_controller_test.exs | 118 +++++++++++++++++++++++--
2 files changed, 109 insertions(+), 12 deletions(-)
(limited to 'test')
diff --git a/test/instance_static/emoji/test_pack/pack.json b/test/instance_static/emoji/test_pack/pack.json
index 1b260f0f7..5a8ee75f9 100644
--- a/test/instance_static/emoji/test_pack/pack.json
+++ b/test/instance_static/emoji/test_pack/pack.json
@@ -4,9 +4,6 @@
"homepage": "https://pleroma.social",
"description": "Test description",
- "fallblack-src": "https://example.com",
- "fallback-src-sha256": "65CDCCBCA9388A68023519F997367783BE69ED42864398CAC568E56F65CE0E75",
-
"share-files": true
},
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index aa30e3058..759a4dc04 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -5,6 +5,11 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
import Pleroma.Factory
+ @emoji_dir_path Path.join(
+ Pleroma.Config.get!([:instance, :static_dir]),
+ "emoji"
+ )
+
test "shared & non-shared pack information in list_packs is ok" do
conn = build_conn()
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
@@ -44,8 +49,8 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
test "downloading shared & unshared packs from another instance via download_from, deleting them" do
on_exit(fn ->
- File.rm_rf!("test/instance_static/emoji/test_pack2")
- File.rm_rf!("test/instance_static/emoji/test_pack_nonshared2")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack2")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
end)
mock(fn
@@ -75,7 +80,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
method: :get,
url: "https://nonshared-pack"
} ->
- text(File.read!("test/instance_static/emoji/test_pack_nonshared/nonshared.zip"))
+ text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
end)
admin = insert(:user, info: %{is_admin: true})
@@ -99,15 +104,15 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
)
|> text_response(200) == "ok"
- assert File.exists?("test/instance_static/emoji/test_pack2/pack.json")
- assert File.exists?("test/instance_static/emoji/test_pack2/blank.png")
+ assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
+ assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
assert conn
|> assign(:user, admin)
|> delete(emoji_api_path(conn, :delete, "test_pack2"))
|> response(200) == "ok"
- refute File.exists?("test/instance_static/emoji/test_pack2")
+ refute File.exists?("#{@emoji_dir_path}/test_pack2")
# non-shared, downloaded from the fallback URL
@@ -130,14 +135,109 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
)
|> text_response(200) == "ok"
- assert File.exists?("test/instance_static/emoji/test_pack_nonshared2/pack.json")
- assert File.exists?("test/instance_static/emoji/test_pack_nonshared2/blank.png")
+ assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
+ assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
assert conn
|> assign(:user, admin)
|> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
|> response(200) == "ok"
- refute File.exists?("test/instance_static/emoji/test_pack_nonshared2")
+ refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
+ end
+
+ describe "updating pack metadata" do
+ setup do
+ pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
+ original_content = File.read!(pack_file)
+
+ on_exit(fn ->
+ File.write!(pack_file, original_content)
+ end)
+
+ {:ok,
+ admin: insert(:user, info: %{is_admin: true}),
+ pack_file: pack_file,
+ new_data: %{
+ "license" => "Test license changed",
+ "homepage" => "https://pleroma.social",
+ "description" => "Test description",
+ "share-files" => false
+ }}
+ end
+
+ test "for a pack without a fallback source", ctx do
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => ctx[:new_data]
+ }
+ )
+ |> json_response(200) == ctx[:new_data]
+
+ assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
+ end
+
+ test "for a pack with a fallback source", ctx do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
+ end)
+
+ new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
+
+ new_data_with_sha =
+ Map.put(
+ new_data,
+ "fallback-src-sha256",
+ "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
+ )
+
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> json_response(200) == new_data_with_sha
+
+ assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
+ end
+
+ test "when the fallback source doesn't have all the files", ctx do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ {:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
+ text(empty_arch)
+ end)
+
+ new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
+
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> text_response(:bad_request) =~ "does not have all"
+ end
end
end
--
cgit v1.2.3
From 9afe7258dd5ca1e5a6333a5a9f93d9ab43d4aaf4 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Sun, 18 Aug 2019 22:05:38 +0300
Subject: Implememt emoji pack file updating + write tests
---
test/web/emoji_api_controller_test.exs | 69 +++++++++++++++++++++++++++++++---
1 file changed, 63 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 759a4dc04..6d3603da5 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -85,11 +85,10 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
admin = insert(:user, info: %{is_admin: true})
- conn = build_conn()
+ conn = build_conn() |> assign(:user, admin)
assert conn
|> put_req_header("content-type", "application/json")
- |> assign(:user, admin)
|> post(
emoji_api_path(
conn,
@@ -108,7 +107,6 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
assert conn
- |> assign(:user, admin)
|> delete(emoji_api_path(conn, :delete, "test_pack2"))
|> response(200) == "ok"
@@ -116,11 +114,10 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
# non-shared, downloaded from the fallback URL
- conn = build_conn()
+ conn = build_conn() |> assign(:user, admin)
assert conn
|> put_req_header("content-type", "application/json")
- |> assign(:user, admin)
|> post(
emoji_api_path(
conn,
@@ -139,7 +136,6 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
assert conn
- |> assign(:user, admin)
|> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
|> response(200) == "ok"
@@ -240,4 +236,65 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
|> text_response(:bad_request) =~ "does not have all"
end
end
+
+ test "updating pack files" do
+ pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
+ original_content = File.read!(pack_file)
+
+ on_exit(fn ->
+ File.write!(pack_file, original_content)
+
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn()
+
+ same_name = %{
+ "action" => "add",
+ "shortcode" => "blank",
+ "filename" => "dir/blank.png",
+ "file" => %Plug.Upload{
+ filename: "blank.png",
+ path: "#{@emoji_dir_path}/test_pack/blank.png"
+ }
+ }
+
+ different_name = %{same_name | "shortcode" => "blank_2"}
+
+ conn = conn |> assign(:user, admin)
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
+ |> text_response(:conflict) =~ "already exists"
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
+ |> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "update",
+ "shortcode" => "blank_2",
+ "new_shortcode" => "blank_3",
+ "new_filename" => "dir_2/blank_3.png"
+ })
+ |> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
+ assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "remove",
+ "shortcode" => "blank_3"
+ })
+ |> json_response(200) == %{"blank" => "blank.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
+ end
end
--
cgit v1.2.3
From 8dbdd5c280d15fde4712989001d4ddee1cd37cff Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Tue, 20 Aug 2019 14:52:36 +0300
Subject: Allow uploading new emojis to packs from URLs
---
test/web/emoji_api_controller_test.exs | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 6d3603da5..c1aece691 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -244,6 +244,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
on_exit(fn ->
File.write!(pack_file, original_content)
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
end)
@@ -296,5 +297,38 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
|> json_response(200) == %{"blank" => "blank.png"}
refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
+
+ mock(fn
+ %{
+ method: :get,
+ url: "https://test-blank/blank_url.png"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
+ end)
+
+ # The name should be inferred from the URL ending
+ from_url = %{
+ "action" => "add",
+ "shortcode" => "blank_url",
+ "file" => "https://test-blank/blank_url.png"
+ }
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
+ |> json_response(200) == %{
+ "blank" => "blank.png",
+ "blank_url" => "blank_url.png"
+ }
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "remove",
+ "shortcode" => "blank_url"
+ })
+ |> json_response(200) == %{"blank" => "blank.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
end
end
--
cgit v1.2.3
From f5131540dc9bbf8038e6625f4524ca01b52abbbf Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 28 Aug 2019 19:29:01 +0300
Subject: Add a way to create emoji packs via an endpoint
---
test/web/emoji_api_controller_test.exs | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index c1aece691..fa194a26c 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -331,4 +331,38 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
end
+
+ test "creating and deleting a pack" do
+ on_exit(fn ->
+ File.rm_rf!("#{@emoji_dir_path}/test_created")
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :create,
+ "test_created"
+ )
+ )
+ |> text_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
+
+ assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
+ "pack" => %{},
+ "files" => %{}
+ }
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_created"))
+ |> response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
+ end
end
--
cgit v1.2.3
From 9eb2ee4df0478daec1172eec2289868105b72756 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Tue, 10 Sep 2019 21:16:30 +0300
Subject: Allow importing old (emoji.txt / plain) packs from the filesystem
---
.../emoji/test_pack_for_import/blank.png | Bin 0 -> 95 bytes
test/web/emoji_api_controller_test.exs | 41 +++++++++++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 test/instance_static/emoji/test_pack_for_import/blank.png
(limited to 'test')
diff --git a/test/instance_static/emoji/test_pack_for_import/blank.png b/test/instance_static/emoji/test_pack_for_import/blank.png
new file mode 100644
index 000000000..8f50fa023
Binary files /dev/null and b/test/instance_static/emoji/test_pack_for_import/blank.png differ
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index fa194a26c..8b2a942ce 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -365,4 +365,45 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
end
+
+ test "filesystem import" do
+ on_exit(fn ->
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+ end)
+
+ conn = build_conn()
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ refute Map.has_key?(resp, "test_pack_for_import")
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ assert conn
+ |> assign(:user, admin)
+ |> post(emoji_api_path(conn, :import_from_fs))
+ |> json_response(200) == ["test_pack_for_import"]
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+ assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
+
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+ refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+
+ emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
+
+ File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
+
+ assert conn
+ |> assign(:user, admin)
+ |> post(emoji_api_path(conn, :import_from_fs))
+ |> json_response(200) == ["test_pack_for_import"]
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ assert resp["test_pack_for_import"]["files"] == %{
+ "blank" => "blank.png",
+ "blank2" => "blank.png"
+ }
+ end
end
--
cgit v1.2.3
From 7c784128fd8016e133c59e9c5076fa2d77a9bdee Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 11 Sep 2019 19:39:47 +0300
Subject: Change emoji api responses to JSON
---
test/web/emoji_api_controller_test.exs | 36 +++++++++++++++++-----------------
1 file changed, 18 insertions(+), 18 deletions(-)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 8b2a942ce..7942a7b01 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -101,14 +101,14 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
}
|> Jason.encode!()
)
- |> text_response(200) == "ok"
+ |> json_response(200) == "ok"
assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
assert conn
|> delete(emoji_api_path(conn, :delete, "test_pack2"))
- |> response(200) == "ok"
+ |> json_response(200) == "ok"
refute File.exists?("#{@emoji_dir_path}/test_pack2")
@@ -130,14 +130,14 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
}
|> Jason.encode!()
)
- |> text_response(200) == "ok"
+ |> json_response(200) == "ok"
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
assert conn
|> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
- |> response(200) == "ok"
+ |> json_response(200) == "ok"
refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
end
@@ -225,15 +225,15 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
conn = build_conn()
- assert conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => new_data
- }
- )
- |> text_response(:bad_request) =~ "does not have all"
+ assert (conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> json_response(:bad_request))["error"] =~ "does not have all"
end
end
@@ -267,9 +267,9 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
conn = conn |> assign(:user, admin)
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
- |> text_response(:conflict) =~ "already exists"
+ assert (conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
+ |> json_response(:conflict))["error"] =~ "already exists"
assert conn
|> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
@@ -350,7 +350,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
"test_created"
)
)
- |> text_response(200) == "ok"
+ |> json_response(200) == "ok"
assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
@@ -361,7 +361,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert conn
|> delete(emoji_api_path(conn, :delete, "test_created"))
- |> response(200) == "ok"
+ |> json_response(200) == "ok"
refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
end
--
cgit v1.2.3
From 6cd651a38be898456c06d8fee7fd15f1b406848c Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 11 Sep 2019 21:50:55 +0300
Subject: Make the emoji controller api more RESTy
---
test/web/emoji_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 7942a7b01..e92e92f74 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -343,7 +343,7 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
assert conn
|> put_req_header("content-type", "application/json")
- |> post(
+ |> put(
emoji_api_path(
conn,
:create,
--
cgit v1.2.3
From 74fb6d864760ccaa18b9a20d148c590254779454 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 11 Sep 2019 22:43:00 +0300
Subject: Move EmojiAPIController from EmojiAPI to PleromaAPI
---
test/web/emoji_api_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index e92e92f74..38d11cdce 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -1,4 +1,4 @@
-defmodule Pleroma.Web.EmojiAPI.EmojiAPIControllerTest do
+defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
use Pleroma.Web.ConnCase
import Tesla.Mock
--
cgit v1.2.3
From 36f2275dc9f6c58163e4e07f8ace9d75e96033c7 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 11 Sep 2019 22:58:55 +0300
Subject: A feature for shareable emoji packs, use it in download_from & tests
---
test/web/emoji_api_controller_test.exs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 38d11cdce..1af4d3720 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -54,6 +54,12 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
end)
mock(fn
+ %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
+ json(%{features: []})
+
+ %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
+ json(%{features: ["shareable_emoji_packs"]})
+
%{
method: :get,
url: "https://example.com/api/pleroma/emoji/packs/list"
@@ -87,6 +93,22 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
conn = build_conn() |> assign(:user, admin)
+ assert (conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://old-instance",
+ pack_name: "test_pack",
+ as: "test_pack2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(500))["error"] =~ "does not support"
+
assert conn
|> put_req_header("content-type", "application/json")
|> post(
--
cgit v1.2.3
From a1325d5fd9b540017cbffbb73db85ee9fa9f12d0 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 18 Sep 2019 18:09:57 +0300
Subject: Change path from nodeinfo to metadata->features
---
test/web/emoji_api_controller_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 1af4d3720..297dc092f 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -55,10 +55,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
mock(fn
%{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
- json(%{features: []})
+ json(%{metadata: %{features: []}})
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
- json(%{features: ["shareable_emoji_packs"]})
+ json(%{metadata: %{features: ["shareable_emoji_packs"]}})
%{
method: :get,
--
cgit v1.2.3
From b585134c9092b49e7b5c24e04d6d6315d45dd0a2 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Wed, 18 Sep 2019 19:48:25 +0300
Subject: Get the nodeinfo address from the well-known
---
test/web/emoji_api_controller_test.exs | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
index 297dc092f..c5a553692 100644
--- a/test/web/emoji_api_controller_test.exs
+++ b/test/web/emoji_api_controller_test.exs
@@ -54,9 +54,15 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
end)
mock(fn
+ %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
+ json([%{href: "https://old-instance/nodeinfo/2.1.json"}])
+
%{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
json(%{metadata: %{features: []}})
+ %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
+ json([%{href: "https://example.com/nodeinfo/2.1.json"}])
+
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
--
cgit v1.2.3
From 447514dfa2759e3415399412e82bf772ff119e04 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Wed, 18 Sep 2019 23:20:54 +0200
Subject: Bump copyright years of files changed in 2019
Done via the following command:
git diff 1e6c102bfcfe0e4835a48f2483f2376f9bf86a20 --stat --name-only | cat - | xargs sed -i 's/2017-2018 Pleroma Authors/2017-2019 Pleroma Authors/'
---
test/activity_test.exs | 2 +-
test/captcha_test.exs | 2 +-
test/config_test.exs | 2 +-
test/daemons/activity_expiration_daemon_test.exs | 2 +-
test/daemons/scheduled_activity_daemon_test.exs | 2 +-
test/emails/admin_email_test.exs | 2 +-
test/emails/mailer_test.exs | 2 +-
test/emails/user_email_test.exs | 2 +-
test/formatter_test.exs | 2 +-
test/html_test.exs | 2 +-
test/integration/mastodon_websocket_test.exs | 2 +-
test/list_test.exs | 2 +-
test/notification_test.exs | 2 +-
test/object_test.exs | 2 +-
test/plugs/authentication_plug_test.exs | 2 +-
test/plugs/cache_control_test.exs | 2 +-
test/plugs/ensure_public_or_authenticated_plug_test.exs | 2 +-
test/plugs/http_security_plug_test.exs | 2 +-
test/plugs/http_signature_plug_test.exs | 2 +-
test/plugs/instance_static_test.exs | 2 +-
test/plugs/legacy_authentication_plug_test.exs | 2 +-
test/plugs/mapped_identity_to_signature_plug_test.exs | 2 +-
test/plugs/oauth_plug_test.exs | 2 +-
test/plugs/oauth_scopes_plug_test.exs | 2 +-
test/plugs/set_format_plug_test.exs | 2 +-
test/plugs/set_locale_plug_test.exs | 2 +-
test/plugs/uploaded_media_plug_test.exs | 2 +-
test/scheduled_activity_test.exs | 2 +-
test/support/captcha_mock.ex | 2 +-
test/support/conn_case.ex | 2 +-
test/support/data_case.ex | 2 +-
test/support/helpers.ex | 2 +-
test/support/http_request_mock.ex | 2 +-
test/support/mrf_module_mock.ex | 2 +-
test/support/oban_helpers.ex | 2 +-
test/support/web_push_http_client_mock.ex | 2 +-
test/tasks/ecto/migrate_test.exs | 2 +-
test/tasks/relay_test.exs | 2 +-
test/tasks/user_test.exs | 2 +-
test/test_helper.exs | 2 +-
test/upload_test.exs | 2 +-
test/user_search_test.exs | 2 +-
test/user_test.exs | 2 +-
test/web/activity_pub/activity_pub_controller_test.exs | 2 +-
test/web/activity_pub/relay_test.exs | 2 +-
test/web/activity_pub/transmogrifier/follow_handling_test.exs | 2 +-
test/web/activity_pub/transmogrifier_test.exs | 2 +-
test/web/admin_api/admin_api_controller_test.exs | 2 +-
test/web/admin_api/search_test.exs | 2 +-
test/web/common_api/common_api_utils_test.exs | 2 +-
test/web/federator_test.exs | 2 +-
test/web/instances/instance_test.exs | 2 +-
test/web/instances/instances_test.exs | 2 +-
test/web/mastodon_api/views/account_view_test.exs | 2 +-
test/web/mastodon_api/views/list_view_test.exs | 2 +-
test/web/mastodon_api/views/notification_view_test.exs | 2 +-
test/web/mastodon_api/views/push_subscription_view_test.exs | 2 +-
test/web/mastodon_api/views/scheduled_activity_view_test.exs | 2 +-
test/web/mastodon_api/views/status_view_test.exs | 2 +-
test/web/media_proxy/media_proxy_controller_test.exs | 2 +-
test/web/media_proxy/media_proxy_test.exs | 2 +-
test/web/node_info_test.exs | 2 +-
test/web/oauth/authorization_test.exs | 2 +-
test/web/oauth/oauth_controller_test.exs | 2 +-
test/web/oauth/token/utils_test.exs | 2 +-
test/web/oauth/token_test.exs | 2 +-
test/web/ostatus/activity_representer_test.exs | 2 +-
test/web/ostatus/feed_representer_test.exs | 2 +-
test/web/ostatus/ostatus_controller_test.exs | 2 +-
test/web/ostatus/ostatus_test.exs | 2 +-
test/web/plugs/federating_plug_test.exs | 2 +-
test/web/push/impl_test.exs | 2 +-
test/web/salmon/salmon_test.exs | 2 +-
test/web/streamer/streamer_test.exs | 2 +-
test/web/twitter_api/twitter_api_test.exs | 2 +-
test/web/uploader_controller_test.exs | 2 +-
test/web/views/error_view_test.exs | 2 +-
test/web/web_finger/web_finger_controller_test.exs | 2 +-
test/web/web_finger/web_finger_test.exs | 2 +-
test/web/websub/websub_controller_test.exs | 2 +-
test/web/websub/websub_test.exs | 2 +-
81 files changed, 81 insertions(+), 81 deletions(-)
(limited to 'test')
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 6512d84ac..95d9341c4 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ActivityTest do
diff --git a/test/captcha_test.exs b/test/captcha_test.exs
index 7ca9a4607..9f395d6b4 100644
--- a/test/captcha_test.exs
+++ b/test/captcha_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.CaptchaTest do
diff --git a/test/config_test.exs b/test/config_test.exs
index 73f3fcb0a..438fe62ee 100644
--- a/test/config_test.exs
+++ b/test/config_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ConfigTest do
diff --git a/test/daemons/activity_expiration_daemon_test.exs b/test/daemons/activity_expiration_daemon_test.exs
index 31f4a70a6..b51132fb0 100644
--- a/test/daemons/activity_expiration_daemon_test.exs
+++ b/test/daemons/activity_expiration_daemon_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ActivityExpirationWorkerTest do
diff --git a/test/daemons/scheduled_activity_daemon_test.exs b/test/daemons/scheduled_activity_daemon_test.exs
index 32820b2b7..c8e464491 100644
--- a/test/daemons/scheduled_activity_daemon_test.exs
+++ b/test/daemons/scheduled_activity_daemon_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ScheduledActivityDaemonTest do
diff --git a/test/emails/admin_email_test.exs b/test/emails/admin_email_test.exs
index 9e83c73c6..31eac5f12 100644
--- a/test/emails/admin_email_test.exs
+++ b/test/emails/admin_email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emails.AdminEmailTest do
diff --git a/test/emails/mailer_test.exs b/test/emails/mailer_test.exs
index ae5effb7a..2425c85dd 100644
--- a/test/emails/mailer_test.exs
+++ b/test/emails/mailer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emails.MailerTest do
diff --git a/test/emails/user_email_test.exs b/test/emails/user_email_test.exs
index 7d8df6abc..963565f7c 100644
--- a/test/emails/user_email_test.exs
+++ b/test/emails/user_email_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Emails.UserEmailTest do
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index bfa673049..c443dfe7c 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.FormatterTest do
diff --git a/test/html_test.exs b/test/html_test.exs
index b8906c46a..306ad3b3b 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTMLTest do
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index d02a3cc4d..ed7ce8fe0 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Integration.MastodonWebsocketTest do
diff --git a/test/list_test.exs b/test/list_test.exs
index 8efba75ea..ba79251da 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ListTest do
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 3d2f9a8fc..54c0f9877 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.NotificationTest do
diff --git a/test/object_test.exs b/test/object_test.exs
index ba96aeea4..570213a61 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ObjectTest do
diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs
index f7f8fd9f3..9ae4c506f 100644
--- a/test/plugs/authentication_plug_test.exs
+++ b/test/plugs/authentication_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.AuthenticationPlugTest do
diff --git a/test/plugs/cache_control_test.exs b/test/plugs/cache_control_test.exs
index 45151b289..69ce6cc7d 100644
--- a/test/plugs/cache_control_test.exs
+++ b/test/plugs/cache_control_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CacheControlTest do
diff --git a/test/plugs/ensure_public_or_authenticated_plug_test.exs b/test/plugs/ensure_public_or_authenticated_plug_test.exs
index d45662a2a..bae95e150 100644
--- a/test/plugs/ensure_public_or_authenticated_plug_test.exs
+++ b/test/plugs/ensure_public_or_authenticated_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs
index 7a2835e3d..9c1c20541 100644
--- a/test/plugs/http_security_plug_test.exs
+++ b/test/plugs/http_security_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
diff --git a/test/plugs/http_signature_plug_test.exs b/test/plugs/http_signature_plug_test.exs
index d6fd9ea81..d8ace36da 100644
--- a/test/plugs/http_signature_plug_test.exs
+++ b/test/plugs/http_signature_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
diff --git a/test/plugs/instance_static_test.exs b/test/plugs/instance_static_test.exs
index 6aabc45a4..9b27246fa 100644
--- a/test/plugs/instance_static_test.exs
+++ b/test/plugs/instance_static_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.RuntimeStaticPlugTest do
diff --git a/test/plugs/legacy_authentication_plug_test.exs b/test/plugs/legacy_authentication_plug_test.exs
index 9804e073b..568ef5abd 100644
--- a/test/plugs/legacy_authentication_plug_test.exs
+++ b/test/plugs/legacy_authentication_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
diff --git a/test/plugs/mapped_identity_to_signature_plug_test.exs b/test/plugs/mapped_identity_to_signature_plug_test.exs
index bb45d9edf..6b9d3649d 100644
--- a/test/plugs/mapped_identity_to_signature_plug_test.exs
+++ b/test/plugs/mapped_identity_to_signature_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlugTest do
diff --git a/test/plugs/oauth_plug_test.exs b/test/plugs/oauth_plug_test.exs
index 5a2ed11cc..dea11cdb0 100644
--- a/test/plugs/oauth_plug_test.exs
+++ b/test/plugs/oauth_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.OAuthPlugTest do
diff --git a/test/plugs/oauth_scopes_plug_test.exs b/test/plugs/oauth_scopes_plug_test.exs
index f328026df..6a13ea811 100644
--- a/test/plugs/oauth_scopes_plug_test.exs
+++ b/test/plugs/oauth_scopes_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.OAuthScopesPlugTest do
diff --git a/test/plugs/set_format_plug_test.exs b/test/plugs/set_format_plug_test.exs
index bb21956bb..27c026fdd 100644
--- a/test/plugs/set_format_plug_test.exs
+++ b/test/plugs/set_format_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.SetFormatPlugTest do
diff --git a/test/plugs/set_locale_plug_test.exs b/test/plugs/set_locale_plug_test.exs
index b6c4c1cea..0aaeedc1e 100644
--- a/test/plugs/set_locale_plug_test.exs
+++ b/test/plugs/set_locale_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.SetLocalePlugTest do
diff --git a/test/plugs/uploaded_media_plug_test.exs b/test/plugs/uploaded_media_plug_test.exs
index 49cf5396a..5ba963139 100644
--- a/test/plugs/uploaded_media_plug_test.exs
+++ b/test/plugs/uploaded_media_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.UploadedMediaPlugTest do
diff --git a/test/scheduled_activity_test.exs b/test/scheduled_activity_test.exs
index edc7cc3f9..dcf12fb49 100644
--- a/test/scheduled_activity_test.exs
+++ b/test/scheduled_activity_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ScheduledActivityTest do
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index ef4e68bc5..65ca6b3bd 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Captcha.Mock do
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index b39c70677..9897f72ce 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ConnCase do
diff --git a/test/support/data_case.ex b/test/support/data_case.ex
index 17fa15214..4ffcbac9e 100644
--- a/test/support/data_case.ex
+++ b/test/support/data_case.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.DataCase do
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index a601b3ec8..ce39dd9d8 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Tests.Helpers do
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 231e7c498..6f9886836 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule HttpRequestMock do
diff --git a/test/support/mrf_module_mock.ex b/test/support/mrf_module_mock.ex
index 12c7e22bc..632c7ff1d 100644
--- a/test/support/mrf_module_mock.ex
+++ b/test/support/mrf_module_mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule MRFModuleMock do
diff --git a/test/support/oban_helpers.ex b/test/support/oban_helpers.ex
index 989770926..72792c064 100644
--- a/test/support/oban_helpers.ex
+++ b/test/support/oban_helpers.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Tests.ObanHelpers do
diff --git a/test/support/web_push_http_client_mock.ex b/test/support/web_push_http_client_mock.ex
index d8accd21c..1d6ccff7e 100644
--- a/test/support/web_push_http_client_mock.ex
+++ b/test/support/web_push_http_client_mock.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebPushHttpClientMock do
diff --git a/test/tasks/ecto/migrate_test.exs b/test/tasks/ecto/migrate_test.exs
index 0538a7b40..42f6cbf47 100644
--- a/test/tasks/ecto/migrate_test.exs
+++ b/test/tasks/ecto/migrate_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-onl
defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 7bde56606..c866608ab 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.RelayTest do
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 2b9453042..cf12d9ed6 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UserTest do
diff --git a/test/test_helper.exs b/test/test_helper.exs
index a927b2c3d..fb33e0969 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []
diff --git a/test/upload_test.exs b/test/upload_test.exs
index 6721fe82e..0ca5ebced 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UploadTest do
diff --git a/test/user_search_test.exs b/test/user_search_test.exs
index 48ce973ad..f7ab31287 100644
--- a/test/user_search_test.exs
+++ b/test/user_search_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserSearchTest do
diff --git a/test/user_test.exs b/test/user_test.exs
index b09e9311d..39ba69668 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserTest do
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index f83b14452..9e8e420ec 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs
index 7315dce26..0f7556538 100644
--- a/test/web/activity_pub/relay_test.exs
+++ b/test/web/activity_pub/relay_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.RelayTest do
diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs
index fe89f7cb0..99ab573c5 100644
--- a/test/web/activity_pub/transmogrifier/follow_handling_test.exs
+++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6c296eb0d..ebed65b7c 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index c497ea098..41b4364f2 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
diff --git a/test/web/admin_api/search_test.exs b/test/web/admin_api/search_test.exs
index 501a8d007..9df4cd539 100644
--- a/test/web/admin_api/search_test.exs
+++ b/test/web/admin_api/search_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.SearchTest do
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index c281dd1f1..230146451 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.UtilsTest do
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 4096d4690..43a715706 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
index 0b53bc6cd..e54d708ad 100644
--- a/test/web/instances/instance_test.exs
+++ b/test/web/instances/instance_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Instances.InstanceTest do
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index dea8e2aea..65b03b155 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.InstancesTest do
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 1d8b28339..2ea87c5f0 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
diff --git a/test/web/mastodon_api/views/list_view_test.exs b/test/web/mastodon_api/views/list_view_test.exs
index fb00310b9..59e896a7c 100644
--- a/test/web/mastodon_api/views/list_view_test.exs
+++ b/test/web/mastodon_api/views/list_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ListViewTest do
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 977ea1e87..9231aaec8 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
diff --git a/test/web/mastodon_api/views/push_subscription_view_test.exs b/test/web/mastodon_api/views/push_subscription_view_test.exs
index dc935fc82..4e4f5b7e6 100644
--- a/test/web/mastodon_api/views/push_subscription_view_test.exs
+++ b/test/web/mastodon_api/views/push_subscription_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do
diff --git a/test/web/mastodon_api/views/scheduled_activity_view_test.exs b/test/web/mastodon_api/views/scheduled_activity_view_test.exs
index ecbb855d4..6387e4555 100644
--- a/test/web/mastodon_api/views/scheduled_activity_view_test.exs
+++ b/test/web/mastodon_api/views/scheduled_activity_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index fcdd7fbcb..51f8434fa 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
diff --git a/test/web/media_proxy/media_proxy_controller_test.exs b/test/web/media_proxy/media_proxy_controller_test.exs
index 53b8f556b..fdfdb5ec6 100644
--- a/test/web/media_proxy/media_proxy_controller_test.exs
+++ b/test/web/media_proxy/media_proxy_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index 79699cac5..96bdde219 100644
--- a/test/web/media_proxy/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MediaProxyTest do
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index f6147c286..e15a0bfff 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.NodeInfoTest do
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index d8b008437..2e82a7b79 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.AuthorizationTest do
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index b492c7794..2780e1746 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.OAuthControllerTest do
diff --git a/test/web/oauth/token/utils_test.exs b/test/web/oauth/token/utils_test.exs
index 20e338cab..dc1f9a986 100644
--- a/test/web/oauth/token/utils_test.exs
+++ b/test/web/oauth/token/utils_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.Token.UtilsTest do
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index 3c07309b7..5359940f8 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.TokenTest do
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index a3a92ce5b..a8d500890 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index 3c7b126e7..d1cadf1e4 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 095ae7041..ec96f0012 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 803a97695..f04a5cfc5 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OStatusTest do
diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs
index bb2e1687a..9dcab93da 100644
--- a/test/web/plugs/federating_plug_test.exs
+++ b/test/web/plugs/federating_plug_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatingPlugTest do
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index e2f89f40a..2f6ce4bd2 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Push.ImplTest do
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 0186f3fef..153ec41ac 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Salmon.SalmonTest do
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
index 88847e20f..b8fcd41fa 100644
--- a/test/web/streamer/streamer_test.exs
+++ b/test/web/streamer/streamer_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StreamerTest do
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 3c0528776..08f264431 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
diff --git a/test/web/uploader_controller_test.exs b/test/web/uploader_controller_test.exs
index 70028df1c..7c7f9a6ea 100644
--- a/test/web/uploader_controller_test.exs
+++ b/test/web/uploader_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.UploaderControllerTest do
diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs
index 3857d585f..4e5398c83 100644
--- a/test/web/views/error_view_test.exs
+++ b/test/web/views/error_view_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ErrorViewTest do
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index bd3ccaaf7..49cd1460b 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 8fdb9adea..696c1bd70 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebFingerTest do
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 59cacbe68..f6d002b3b 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Websub.WebsubControllerTest do
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 929acf5a2..46ca545de 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebsubTest do
--
cgit v1.2.3
From fe5e0b784604b1352e98e7915c3c67d59ac4f709 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Thu, 19 Sep 2019 08:27:55 +0300
Subject: Mastodon API: Return `pleroma.direct_conversation_id` when creating
direct messages (`POST /api/v1/statuses`)
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index fb04748bb..35a0d3fe1 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -296,7 +296,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn
|> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
- assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
+ assert %{"id" => id} = response = json_response(conn, 200)
+ assert response["visibility"] == "direct"
+ assert response["pleroma"]["direct_conversation_id"]
assert activity = Activity.get_by_id(id)
assert activity.recipients == [user2.ap_id, conn.assigns[:user].ap_id]
assert activity.data["to"] == [user2.ap_id]
--
cgit v1.2.3
From cf3041220a7a14dc3fac24177fac1f4aecc77f5f Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 17 Sep 2019 15:22:46 +0700
Subject: Add support for `rel="ugc"`
---
test/formatter_test.exs | 24 ++++++++++++----------
test/web/common_api/common_api_utils_test.exs | 6 +++---
.../update_credentials_test.exs | 2 +-
3 files changed, 17 insertions(+), 15 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index c443dfe7c..3674577d6 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -39,21 +39,21 @@ defmodule Pleroma.FormatterTest do
text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ."
expected =
- "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ."
+ ~S(Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla .)
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://mastodon.social/@lambadalambda"
expected =
- "https://mastodon.social/@lambadalambda"
+ ~S(https://mastodon.social/@lambadalambda)
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://mastodon.social:4000/@lambadalambda"
expected =
- "https://mastodon.social:4000/@lambadalambda"
+ ~S(https://mastodon.social:4000/@lambadalambda)
assert {^expected, [], []} = Formatter.linkify(text)
@@ -63,55 +63,57 @@ defmodule Pleroma.FormatterTest do
assert {^expected, [], []} = Formatter.linkify(text)
text = "http://www.cs.vu.nl/~ast/intel/"
- expected = "http://www.cs.vu.nl/~ast/intel/"
+
+ expected =
+ ~S(http://www.cs.vu.nl/~ast/intel/)
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
expected =
- "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
+ "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
expected =
- "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
+ "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://www.google.co.jp/search?q=Nasim+Aghdam"
expected =
- "https://www.google.co.jp/search?q=Nasim+Aghdam"
+ "https://www.google.co.jp/search?q=Nasim+Aghdam"
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://en.wikipedia.org/wiki/Duff's_device"
expected =
- "https://en.wikipedia.org/wiki/Duff's_device"
+ "https://en.wikipedia.org/wiki/Duff's_device"
assert {^expected, [], []} = Formatter.linkify(text)
text = "https://pleroma.com https://pleroma.com/sucks"
expected =
- "https://pleroma.com https://pleroma.com/sucks"
+ "https://pleroma.com https://pleroma.com/sucks"
assert {^expected, [], []} = Formatter.linkify(text)
text = "xmpp:contact@hacktivis.me"
- expected = "xmpp:contact@hacktivis.me"
+ expected = "xmpp:contact@hacktivis.me"
assert {^expected, [], []} = Formatter.linkify(text)
text =
"magnet:?xt=urn:btih:7ec9d298e91d6e4394d1379caf073c77ff3e3136&tr=udp%3A%2F%2Fopentor.org%3A2710&tr=udp%3A%2F%2Ftracker.blackunicorn.xyz%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com"
- expected = "#{text}"
+ expected = "#{text}"
assert {^expected, [], []} = Formatter.linkify(text)
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 230146451..78cfe3c5f 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -157,11 +157,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
expected =
- "hello world
\nanother hello world
\nanother @user__test and @user__test and @user__test google.com paragraph
\n"
+ }" class="u-url mention" href="http://foo.com/user__test">@user__test google.com paragraph
\n)
{output, _, _} = Utils.format_input(text, "text/markdown")
diff --git a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
index 89d4ca37e..1e8d0d03b 100644
--- a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
@@ -334,7 +334,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert account["fields"] == [
%{"name" => "foo", "value" => "bar"},
- %{"name" => "link", "value" => "cofe.io"}
+ %{"name" => "link", "value" => ~S(cofe.io)}
]
assert account["source"]["fields"] == [
--
cgit v1.2.3
From 95c948110ca130559fd6a5302011aa58900274ac Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 19 Sep 2019 14:39:52 +0700
Subject: Add `rel="ugc"` to hashtags and mentions
---
test/formatter_test.exs | 30 +++++++++++++---------
test/user_test.exs | 4 +--
test/web/common_api/common_api_utils_test.exs | 4 +--
.../update_credentials_test.exs | 7 +++--
.../mastodon_api/mastodon_api_controller_test.exs | 8 +++---
test/web/twitter_api/twitter_api_test.exs | 4 ++-
6 files changed, 32 insertions(+), 25 deletions(-)
(limited to 'test')
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 3674577d6..2e4280fc2 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -19,7 +19,7 @@ defmodule Pleroma.FormatterTest do
text = "I love #cofe and #2hu"
expected_text =
- "I love #cofe and #2hu"
+ ~s(I love #cofe and #2hu)
assert {^expected_text, [], _tags} = Formatter.linkify(text)
end
@@ -28,7 +28,7 @@ defmodule Pleroma.FormatterTest do
text = "#fact_3: pleroma does what mastodon't"
expected_text =
- "#fact_3: pleroma does what mastodon't"
+ ~s(#fact_3: pleroma does what mastodon't)
assert {^expected_text, [], _tags} = Formatter.linkify(text)
end
@@ -137,13 +137,13 @@ defmodule Pleroma.FormatterTest do
assert length(mentions) == 3
expected_text =
- "@gsimg According to @archa_eme_, that is @daggsy. Also hello @archaeme"
+ }" class="u-url mention" href="#{archaeme_remote.ap_id}" rel="ugc">@archaeme)
assert expected_text == text
end
@@ -158,7 +158,9 @@ defmodule Pleroma.FormatterTest do
assert length(mentions) == 1
expected_text =
- "@mike test"
+ ~s(@mike test)
assert expected_text == text
end
@@ -172,7 +174,7 @@ defmodule Pleroma.FormatterTest do
assert length(mentions) == 1
expected_text =
- "@o hi"
+ ~s(@o hi)
assert expected_text == text
end
@@ -194,13 +196,17 @@ defmodule Pleroma.FormatterTest do
assert mentions == [{"@#{user.nickname}", user}, {"@#{other_user.nickname}", other_user}]
assert expected_text ==
- "@#{user.nickname} @#{other_user.nickname} hey dudes i hate @#{third_user.nickname}"
+ }" class="u-url mention" href="#{third_user.ap_id}" rel="ugc">@#{
+ third_user.nickname
+ })
end
test "given the 'safe_mention' option, it will still work without any mention" do
diff --git a/test/user_test.exs b/test/user_test.exs
index 39ba69668..6852fcd40 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1294,9 +1294,9 @@ defmodule Pleroma.UserTest do
bio = "A.k.a. @nick@domain.com"
expected_text =
- "A.k.a. @nick@domain.com"
+ }" rel="ugc">@nick@domain.com)
assert expected_text == User.parse_bio(bio, user)
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 78cfe3c5f..2588898d0 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -159,9 +159,9 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
expected =
~s(hello world
\nanother @user__test and @user__test and @user__test google.com paragraph
\n)
+ }" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@user__test google.com paragraph\n)
{output, _, _} = Utils.format_input(text, "text/markdown")
diff --git a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
index 1e8d0d03b..560f55137 100644
--- a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
@@ -86,10 +86,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert user = json_response(conn, 200)
assert user["note"] ==
- ~s(I drink #cofe with @) <> user2.nickname <> ~s()
+ ~s(I drink #cofe with @#{user2.nickname})
end
test "updates the user's locking status", %{conn: conn} do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index fb04748bb..b85f3e758 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -996,9 +996,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications")
expected_response =
- "hi @#{user.nickname}"
+ }" rel="ugc">@#{user.nickname})
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
assert response == expected_response
@@ -1018,9 +1018,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications/#{notification.id}")
expected_response =
- "hi @#{user.nickname}"
+ }" rel="ugc">@#{user.nickname})
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
assert response == expected_response
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 08f264431..bf1e233f5 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -109,7 +109,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user2} = TwitterAPI.register_user(data2)
expected_text =
- "@john test"
+ ~s(@john test)
assert user2.bio == expected_text
end
--
cgit v1.2.3
From 9aca2cc95d0d8886d35be17e5cdd683004b425d9 Mon Sep 17 00:00:00 2001
From: D Anzorge
Date: Thu, 19 Sep 2019 16:09:24 +0200
Subject: Add test for correct AP outbox pagination
---
test/web/activity_pub/views/user_view_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 2b4a04afd..eda95e3ea 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -142,4 +142,27 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
end
end
+
+ test "outbox paginates correctly" do
+ user = insert(:user)
+
+ posts =
+ for i <- 0..25 do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "post #{i}"})
+ activity
+ end
+
+ # outbox sorts chronologically, newest first, with ten per page
+ posts = Enum.reverse(posts)
+
+ %{"first" => %{"next" => next_url}} =
+ UserView.render("outbox.json", %{user: user, max_id: nil})
+
+ next_id = Enum.at(posts, 9).id
+ assert next_url =~ next_id
+
+ %{"next" => next_url} = UserView.render("outbox.json", %{user: user, max_id: next_id})
+ next_id = Enum.at(posts, 19).id
+ assert next_url =~ next_id
+ end
end
--
cgit v1.2.3
From 7cf125245512eb49a118535eda52ddbdd0c4c6bf Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Fri, 20 Sep 2019 17:54:38 +0300
Subject: Mastodon API: Fix private and direct statuses not being filtered out
from the public timeline for an authenticated user (`GET
/api/v1/timelines/public`)
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 35a0d3fe1..51f5215c2 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -97,6 +97,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(403) == %{"error" => "This resource requires authentication."}
end
+ test "the public timeline includes only public statuses for an authenticated user" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+
+ res_conn = get(conn, "/api/v1/timelines/public")
+ assert length(json_response(res_conn, 200)) == 1
+ end
+
describe "posting statuses" do
setup do
user = insert(:user)
--
cgit v1.2.3
From 6f25668215f7f9fe20bfaf3dd72e2262a6d8915e Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sun, 22 Sep 2019 16:08:07 +0300
Subject: Admin API: Add ability to force user's password reset
---
test/user_test.exs | 17 ++++++++++++++
test/web/admin_api/admin_api_controller_test.exs | 26 ++++++++++++++++++++++
test/web/oauth/oauth_controller_test.exs | 27 +++++++++++++++++++++++
test/web/twitter_api/password_controller_test.exs | 21 ++++++++++++++++++
4 files changed, 91 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 39ba69668..164172405 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1690,4 +1690,21 @@ defmodule Pleroma.UserTest do
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
end
end
+
+ describe "set_password_reset_pending/2" do
+ setup do
+ [user: insert(:user)]
+ end
+
+ test "sets password_reset_pending to true", %{user: user} do
+ %{password_reset_pending: password_reset_pending} = user.info
+
+ refute password_reset_pending
+
+ {:ok, %{info: %{password_reset_pending: password_reset_pending}}} =
+ User.force_password_reset(user)
+
+ assert password_reset_pending
+ end
+ end
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 108143f6a..f00e02a7a 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -4,11 +4,13 @@
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase
+ use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Activity
alias Pleroma.HTML
alias Pleroma.ModerationLog
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.UserInviteToken
alias Pleroma.Web.CommonAPI
@@ -2351,6 +2353,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"@#{admin.nickname} followed relay: https://example.org/relay"
end
end
+
+ describe "PATCH /users/:nickname/force_password_reset" do
+ setup %{conn: conn} do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ %{conn: assign(conn, :user, admin), admin: admin, user: user}
+ end
+
+ test "sets password_reset_pending to true", %{admin: admin, user: user} do
+ assert user.info.password_reset_pending == false
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/force_password_reset")
+
+ assert json_response(conn, 204) == ""
+
+ ObanHelpers.perform_all()
+
+ assert User.get_by_id(user.id).info.password_reset_pending == true
+ end
+ end
end
# Needed for testing
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 2780e1746..8b88fd784 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -831,6 +831,33 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
refute Map.has_key?(resp, "access_token")
end
+ test "rejects token exchange for user with password_reset_pending set to true" do
+ password = "testpassword"
+
+ user =
+ insert(:user,
+ password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
+ info: %{password_reset_pending: true}
+ )
+
+ app = insert(:oauth_app, scopes: ["read", "write"])
+
+ conn =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "password",
+ "username" => user.nickname,
+ "password" => password,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+
+ assert resp = json_response(conn, 403)
+
+ assert resp["error"] == "Password reset is required"
+ refute Map.has_key?(resp, "access_token")
+ end
+
test "rejects an invalid authorization code" do
app = insert(:oauth_app)
diff --git a/test/web/twitter_api/password_controller_test.exs b/test/web/twitter_api/password_controller_test.exs
index 3a7246ea8..dc6d4e3e3 100644
--- a/test/web/twitter_api/password_controller_test.exs
+++ b/test/web/twitter_api/password_controller_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.PasswordResetToken
+ alias Pleroma.User
alias Pleroma.Web.OAuth.Token
import Pleroma.Factory
@@ -56,5 +57,25 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
assert length(Token.get_user_tokens(user)) == 0
end
+
+ test "it sets password_reset_pending to false", %{conn: conn} do
+ user = insert(:user, info: %{password_reset_pending: true})
+
+ {:ok, token} = PasswordResetToken.create_token(user)
+ {:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
+
+ params = %{
+ "password" => "test",
+ password_confirmation: "test",
+ token: token.token
+ }
+
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/password_reset", %{data: params})
+ |> html_response(:ok)
+
+ assert User.get_by_id(user.id).info.password_reset_pending == false
+ end
end
end
--
cgit v1.2.3
From 72a01f1350239d286978007883a087f8f3985d1b Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Sun, 22 Sep 2019 16:36:59 +0300
Subject: Use router helper to generate reset password link
---
test/web/admin_api/admin_api_controller_test.exs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index c497ea098..77c67011d 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -596,7 +596,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|> put_req_header("accept", "application/json")
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
- assert conn.status == 200
+ resp = json_response(conn, 200)
+
+ assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
end
describe "GET /api/pleroma/admin/users" do
--
cgit v1.2.3
From 2ad50583f0cc341413663a595890047823c9abeb Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 23 Sep 2019 18:54:23 +0200
Subject: Document and test /api/ap/whoami
---
test/web/activity_pub/activity_pub_controller_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 9e8e420ec..0f8638a94 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -976,4 +976,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Delivery.get(object.id, other_user.id)
end
end
+
+ describe "Additionnal ActivityPub C2S endpoints" do
+ test "/api/ap/whoami", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/ap/whoami")
+
+ user = User.get_cached_by_id(user.id)
+
+ assert UserView.render("user.json", %{user: user}) == json_response(conn, 200)
+ end
+ end
end
--
cgit v1.2.3
From 815b9045087ff4f88355b4cfa6c0a9b8080c6db6 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 23 Sep 2019 19:16:36 +0200
Subject: Add support for AP C2S uploadMedia
Closes: https://git.pleroma.social/pleroma/pleroma/issues/1171
---
.../activity_pub/activity_pub_controller_test.exs | 25 ++++++++++++++++++++++
test/web/ostatus/ostatus_controller_test.exs | 6 ++++--
2 files changed, 29 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 0f8638a94..c2bcddf85 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -990,5 +990,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert UserView.render("user.json", %{user: user}) == json_response(conn, 200)
end
+
+ clear_config([:media_proxy])
+ clear_config([Pleroma.Upload])
+
+ test "uploadMedia", %{conn: conn} do
+ user = insert(:user)
+
+ desc = "Description of the image"
+
+ image = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/ap/uploadMedia", %{"file" => image, "description" => desc})
+
+ assert object = json_response(conn, :created)
+ assert object["name"] == desc
+ assert object["type"] == "Document"
+ assert object["actor"] == user.ap_id
+ end
end
end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index ec96f0012..fc1635a2f 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -400,7 +400,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
"oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
- "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox"
+ "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
+ "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/uploadMedia"
}
assert response["@context"] == [
@@ -462,7 +463,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
"oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
- "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox"
+ "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
+ "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/uploadMedia"
}
assert response["@context"] == [
--
cgit v1.2.3
From 6b3d5ed6db6a3c73eb1f8373ebd670427aa8849d Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Mon, 23 Sep 2019 21:14:51 +0300
Subject: Emoji API Controller: Follow phoenix directory structure
---
test/web/emoji_api_controller_test.exs | 437 ---------------------
test/web/pleroma_api/emoji_api_controller_test.exs | 437 +++++++++++++++++++++
2 files changed, 437 insertions(+), 437 deletions(-)
delete mode 100644 test/web/emoji_api_controller_test.exs
create mode 100644 test/web/pleroma_api/emoji_api_controller_test.exs
(limited to 'test')
diff --git a/test/web/emoji_api_controller_test.exs b/test/web/emoji_api_controller_test.exs
deleted file mode 100644
index c5a553692..000000000
--- a/test/web/emoji_api_controller_test.exs
+++ /dev/null
@@ -1,437 +0,0 @@
-defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
- use Pleroma.Web.ConnCase
-
- import Tesla.Mock
-
- import Pleroma.Factory
-
- @emoji_dir_path Path.join(
- Pleroma.Config.get!([:instance, :static_dir]),
- "emoji"
- )
-
- test "shared & non-shared pack information in list_packs is ok" do
- conn = build_conn()
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- assert Map.has_key?(resp, "test_pack")
-
- pack = resp["test_pack"]
-
- assert Map.has_key?(pack["pack"], "download-sha256")
- assert pack["pack"]["can-download"]
-
- assert pack["files"] == %{"blank" => "blank.png"}
-
- # Non-shared pack
-
- assert Map.has_key?(resp, "test_pack_nonshared")
-
- pack = resp["test_pack_nonshared"]
-
- refute pack["pack"]["shared"]
- refute pack["pack"]["can-download"]
- end
-
- test "downloading a shared pack from download_shared" do
- conn = build_conn()
-
- resp =
- conn
- |> get(emoji_api_path(conn, :download_shared, "test_pack"))
- |> response(200)
-
- {:ok, arch} = :zip.unzip(resp, [:memory])
-
- assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
- assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
- end
-
- test "downloading shared & unshared packs from another instance via download_from, deleting them" do
- on_exit(fn ->
- File.rm_rf!("#{@emoji_dir_path}/test_pack2")
- File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
- end)
-
- mock(fn
- %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
- json([%{href: "https://old-instance/nodeinfo/2.1.json"}])
-
- %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
- json(%{metadata: %{features: []}})
-
- %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
- json([%{href: "https://example.com/nodeinfo/2.1.json"}])
-
- %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
- json(%{metadata: %{features: ["shareable_emoji_packs"]}})
-
- %{
- method: :get,
- url: "https://example.com/api/pleroma/emoji/packs/list"
- } ->
- conn = build_conn()
-
- conn
- |> get(emoji_api_path(conn, :list_packs))
- |> json_response(200)
- |> json()
-
- %{
- method: :get,
- url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
- } ->
- conn = build_conn()
-
- conn
- |> get(emoji_api_path(conn, :download_shared, "test_pack"))
- |> response(200)
- |> text()
-
- %{
- method: :get,
- url: "https://nonshared-pack"
- } ->
- text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
- end)
-
- admin = insert(:user, info: %{is_admin: true})
-
- conn = build_conn() |> assign(:user, admin)
-
- assert (conn
- |> put_req_header("content-type", "application/json")
- |> post(
- emoji_api_path(
- conn,
- :download_from
- ),
- %{
- instance_address: "https://old-instance",
- pack_name: "test_pack",
- as: "test_pack2"
- }
- |> Jason.encode!()
- )
- |> json_response(500))["error"] =~ "does not support"
-
- assert conn
- |> put_req_header("content-type", "application/json")
- |> post(
- emoji_api_path(
- conn,
- :download_from
- ),
- %{
- instance_address: "https://example.com",
- pack_name: "test_pack",
- as: "test_pack2"
- }
- |> Jason.encode!()
- )
- |> json_response(200) == "ok"
-
- assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
- assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
-
- assert conn
- |> delete(emoji_api_path(conn, :delete, "test_pack2"))
- |> json_response(200) == "ok"
-
- refute File.exists?("#{@emoji_dir_path}/test_pack2")
-
- # non-shared, downloaded from the fallback URL
-
- conn = build_conn() |> assign(:user, admin)
-
- assert conn
- |> put_req_header("content-type", "application/json")
- |> post(
- emoji_api_path(
- conn,
- :download_from
- ),
- %{
- instance_address: "https://example.com",
- pack_name: "test_pack_nonshared",
- as: "test_pack_nonshared2"
- }
- |> Jason.encode!()
- )
- |> json_response(200) == "ok"
-
- assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
- assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
-
- assert conn
- |> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
- |> json_response(200) == "ok"
-
- refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
- end
-
- describe "updating pack metadata" do
- setup do
- pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
- original_content = File.read!(pack_file)
-
- on_exit(fn ->
- File.write!(pack_file, original_content)
- end)
-
- {:ok,
- admin: insert(:user, info: %{is_admin: true}),
- pack_file: pack_file,
- new_data: %{
- "license" => "Test license changed",
- "homepage" => "https://pleroma.social",
- "description" => "Test description",
- "share-files" => false
- }}
- end
-
- test "for a pack without a fallback source", ctx do
- conn = build_conn()
-
- assert conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => ctx[:new_data]
- }
- )
- |> json_response(200) == ctx[:new_data]
-
- assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
- end
-
- test "for a pack with a fallback source", ctx do
- mock(fn
- %{
- method: :get,
- url: "https://nonshared-pack"
- } ->
- text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
- end)
-
- new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
-
- new_data_with_sha =
- Map.put(
- new_data,
- "fallback-src-sha256",
- "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
- )
-
- conn = build_conn()
-
- assert conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => new_data
- }
- )
- |> json_response(200) == new_data_with_sha
-
- assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
- end
-
- test "when the fallback source doesn't have all the files", ctx do
- mock(fn
- %{
- method: :get,
- url: "https://nonshared-pack"
- } ->
- {:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
- text(empty_arch)
- end)
-
- new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
-
- conn = build_conn()
-
- assert (conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => new_data
- }
- )
- |> json_response(:bad_request))["error"] =~ "does not have all"
- end
- end
-
- test "updating pack files" do
- pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
- original_content = File.read!(pack_file)
-
- on_exit(fn ->
- File.write!(pack_file, original_content)
-
- File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
- File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
- File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
- end)
-
- admin = insert(:user, info: %{is_admin: true})
-
- conn = build_conn()
-
- same_name = %{
- "action" => "add",
- "shortcode" => "blank",
- "filename" => "dir/blank.png",
- "file" => %Plug.Upload{
- filename: "blank.png",
- path: "#{@emoji_dir_path}/test_pack/blank.png"
- }
- }
-
- different_name = %{same_name | "shortcode" => "blank_2"}
-
- conn = conn |> assign(:user, admin)
-
- assert (conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
- |> json_response(:conflict))["error"] =~ "already exists"
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
- |> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
-
- assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
- "action" => "update",
- "shortcode" => "blank_2",
- "new_shortcode" => "blank_3",
- "new_filename" => "dir_2/blank_3.png"
- })
- |> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
-
- refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
- assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
- "action" => "remove",
- "shortcode" => "blank_3"
- })
- |> json_response(200) == %{"blank" => "blank.png"}
-
- refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
-
- mock(fn
- %{
- method: :get,
- url: "https://test-blank/blank_url.png"
- } ->
- text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
- end)
-
- # The name should be inferred from the URL ending
- from_url = %{
- "action" => "add",
- "shortcode" => "blank_url",
- "file" => "https://test-blank/blank_url.png"
- }
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
- |> json_response(200) == %{
- "blank" => "blank.png",
- "blank_url" => "blank_url.png"
- }
-
- assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
- "action" => "remove",
- "shortcode" => "blank_url"
- })
- |> json_response(200) == %{"blank" => "blank.png"}
-
- refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
- end
-
- test "creating and deleting a pack" do
- on_exit(fn ->
- File.rm_rf!("#{@emoji_dir_path}/test_created")
- end)
-
- admin = insert(:user, info: %{is_admin: true})
-
- conn = build_conn() |> assign(:user, admin)
-
- assert conn
- |> put_req_header("content-type", "application/json")
- |> put(
- emoji_api_path(
- conn,
- :create,
- "test_created"
- )
- )
- |> json_response(200) == "ok"
-
- assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
-
- assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
- "pack" => %{},
- "files" => %{}
- }
-
- assert conn
- |> delete(emoji_api_path(conn, :delete, "test_created"))
- |> json_response(200) == "ok"
-
- refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
- end
-
- test "filesystem import" do
- on_exit(fn ->
- File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
- File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
- end)
-
- conn = build_conn()
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- refute Map.has_key?(resp, "test_pack_for_import")
-
- admin = insert(:user, info: %{is_admin: true})
-
- assert conn
- |> assign(:user, admin)
- |> post(emoji_api_path(conn, :import_from_fs))
- |> json_response(200) == ["test_pack_for_import"]
-
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
- assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
-
- File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
- refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
-
- emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
-
- File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
-
- assert conn
- |> assign(:user, admin)
- |> post(emoji_api_path(conn, :import_from_fs))
- |> json_response(200) == ["test_pack_for_import"]
-
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- assert resp["test_pack_for_import"]["files"] == %{
- "blank" => "blank.png",
- "blank2" => "blank.png"
- }
- end
-end
diff --git a/test/web/pleroma_api/emoji_api_controller_test.exs b/test/web/pleroma_api/emoji_api_controller_test.exs
new file mode 100644
index 000000000..c5a553692
--- /dev/null
+++ b/test/web/pleroma_api/emoji_api_controller_test.exs
@@ -0,0 +1,437 @@
+defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Tesla.Mock
+
+ import Pleroma.Factory
+
+ @emoji_dir_path Path.join(
+ Pleroma.Config.get!([:instance, :static_dir]),
+ "emoji"
+ )
+
+ test "shared & non-shared pack information in list_packs is ok" do
+ conn = build_conn()
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ assert Map.has_key?(resp, "test_pack")
+
+ pack = resp["test_pack"]
+
+ assert Map.has_key?(pack["pack"], "download-sha256")
+ assert pack["pack"]["can-download"]
+
+ assert pack["files"] == %{"blank" => "blank.png"}
+
+ # Non-shared pack
+
+ assert Map.has_key?(resp, "test_pack_nonshared")
+
+ pack = resp["test_pack_nonshared"]
+
+ refute pack["pack"]["shared"]
+ refute pack["pack"]["can-download"]
+ end
+
+ test "downloading a shared pack from download_shared" do
+ conn = build_conn()
+
+ resp =
+ conn
+ |> get(emoji_api_path(conn, :download_shared, "test_pack"))
+ |> response(200)
+
+ {:ok, arch} = :zip.unzip(resp, [:memory])
+
+ assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
+ assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
+ end
+
+ test "downloading shared & unshared packs from another instance via download_from, deleting them" do
+ on_exit(fn ->
+ File.rm_rf!("#{@emoji_dir_path}/test_pack2")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
+ end)
+
+ mock(fn
+ %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
+ json([%{href: "https://old-instance/nodeinfo/2.1.json"}])
+
+ %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
+ json(%{metadata: %{features: []}})
+
+ %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
+ json([%{href: "https://example.com/nodeinfo/2.1.json"}])
+
+ %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
+ json(%{metadata: %{features: ["shareable_emoji_packs"]}})
+
+ %{
+ method: :get,
+ url: "https://example.com/api/pleroma/emoji/packs/list"
+ } ->
+ conn = build_conn()
+
+ conn
+ |> get(emoji_api_path(conn, :list_packs))
+ |> json_response(200)
+ |> json()
+
+ %{
+ method: :get,
+ url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
+ } ->
+ conn = build_conn()
+
+ conn
+ |> get(emoji_api_path(conn, :download_shared, "test_pack"))
+ |> response(200)
+ |> text()
+
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert (conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://old-instance",
+ pack_name: "test_pack",
+ as: "test_pack2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(500))["error"] =~ "does not support"
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://example.com",
+ pack_name: "test_pack",
+ as: "test_pack2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
+ assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_pack2"))
+ |> json_response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack2")
+
+ # non-shared, downloaded from the fallback URL
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://example.com",
+ pack_name: "test_pack_nonshared",
+ as: "test_pack_nonshared2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
+ assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
+ |> json_response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
+ end
+
+ describe "updating pack metadata" do
+ setup do
+ pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
+ original_content = File.read!(pack_file)
+
+ on_exit(fn ->
+ File.write!(pack_file, original_content)
+ end)
+
+ {:ok,
+ admin: insert(:user, info: %{is_admin: true}),
+ pack_file: pack_file,
+ new_data: %{
+ "license" => "Test license changed",
+ "homepage" => "https://pleroma.social",
+ "description" => "Test description",
+ "share-files" => false
+ }}
+ end
+
+ test "for a pack without a fallback source", ctx do
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => ctx[:new_data]
+ }
+ )
+ |> json_response(200) == ctx[:new_data]
+
+ assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
+ end
+
+ test "for a pack with a fallback source", ctx do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
+ end)
+
+ new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
+
+ new_data_with_sha =
+ Map.put(
+ new_data,
+ "fallback-src-sha256",
+ "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
+ )
+
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> json_response(200) == new_data_with_sha
+
+ assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
+ end
+
+ test "when the fallback source doesn't have all the files", ctx do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ {:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
+ text(empty_arch)
+ end)
+
+ new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
+
+ conn = build_conn()
+
+ assert (conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> json_response(:bad_request))["error"] =~ "does not have all"
+ end
+ end
+
+ test "updating pack files" do
+ pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
+ original_content = File.read!(pack_file)
+
+ on_exit(fn ->
+ File.write!(pack_file, original_content)
+
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn()
+
+ same_name = %{
+ "action" => "add",
+ "shortcode" => "blank",
+ "filename" => "dir/blank.png",
+ "file" => %Plug.Upload{
+ filename: "blank.png",
+ path: "#{@emoji_dir_path}/test_pack/blank.png"
+ }
+ }
+
+ different_name = %{same_name | "shortcode" => "blank_2"}
+
+ conn = conn |> assign(:user, admin)
+
+ assert (conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
+ |> json_response(:conflict))["error"] =~ "already exists"
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
+ |> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "update",
+ "shortcode" => "blank_2",
+ "new_shortcode" => "blank_3",
+ "new_filename" => "dir_2/blank_3.png"
+ })
+ |> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
+ assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "remove",
+ "shortcode" => "blank_3"
+ })
+ |> json_response(200) == %{"blank" => "blank.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
+
+ mock(fn
+ %{
+ method: :get,
+ url: "https://test-blank/blank_url.png"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
+ end)
+
+ # The name should be inferred from the URL ending
+ from_url = %{
+ "action" => "add",
+ "shortcode" => "blank_url",
+ "file" => "https://test-blank/blank_url.png"
+ }
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
+ |> json_response(200) == %{
+ "blank" => "blank.png",
+ "blank_url" => "blank_url.png"
+ }
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "remove",
+ "shortcode" => "blank_url"
+ })
+ |> json_response(200) == %{"blank" => "blank.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
+ end
+
+ test "creating and deleting a pack" do
+ on_exit(fn ->
+ File.rm_rf!("#{@emoji_dir_path}/test_created")
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> put(
+ emoji_api_path(
+ conn,
+ :create,
+ "test_created"
+ )
+ )
+ |> json_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
+
+ assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
+ "pack" => %{},
+ "files" => %{}
+ }
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_created"))
+ |> json_response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
+ end
+
+ test "filesystem import" do
+ on_exit(fn ->
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+ end)
+
+ conn = build_conn()
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ refute Map.has_key?(resp, "test_pack_for_import")
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ assert conn
+ |> assign(:user, admin)
+ |> post(emoji_api_path(conn, :import_from_fs))
+ |> json_response(200) == ["test_pack_for_import"]
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+ assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
+
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+ refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+
+ emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
+
+ File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
+
+ assert conn
+ |> assign(:user, admin)
+ |> post(emoji_api_path(conn, :import_from_fs))
+ |> json_response(200) == ["test_pack_for_import"]
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ assert resp["test_pack_for_import"]["files"] == %{
+ "blank" => "blank.png",
+ "blank2" => "blank.png"
+ }
+ end
+end
--
cgit v1.2.3
From 494bb6bac64361860db194aed57618450a76177d Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Mon, 23 Sep 2019 22:37:30 +0300
Subject: updated tests
---
.../mastodon_api/mastodon_api_controller_test.exs | 39 ++++++++++++++--------
1 file changed, 26 insertions(+), 13 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 46e74fc75..14cd71aa8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2798,6 +2798,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
%{user: user}
end
+ test "returns empty result when rich_media disabled", %{conn: conn, user: user} do
+ Config.put([:rich_media, :enabled], false)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response == nil
+ end
+
test "returns rich-media card", %{conn: conn, user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
@@ -2869,22 +2881,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
end
- test "returns empty object when id invalid", %{conn: conn} do
- response =
- conn
- |> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card")
- |> json_response(200)
-
- assert response == %{}
+ test "returns 404 response when id invalid", %{conn: conn} do
+ assert %{"error" => "Record not found"} =
+ conn
+ |> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card")
+ |> json_response(404)
end
- test "returns empty object when id isn't FlakeID", %{conn: conn} do
- response =
- conn
- |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
- |> json_response(200)
+ test "returns 404 response when id isn't FlakeID", %{conn: conn} do
+ assert %{"error" => "Record not found"} =
+ conn
+ |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
+ |> json_response(404)
- assert response == %{}
+ assert %{"error" => "Record not found"} =
+ conn
+ |> get("/api/v1/statuses/8118/card")
+ |> json_response(404)
end
end
--
cgit v1.2.3
From e1d2d69c8799cb6d3efbdc28d9e98867da76b4c2 Mon Sep 17 00:00:00 2001
From: Steven Fuchs
Date: Mon, 23 Sep 2019 22:33:59 +0000
Subject: Clean up views
---
test/web/admin_api/views/report_view_test.exs | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
(limited to 'test')
diff --git a/test/web/admin_api/views/report_view_test.exs b/test/web/admin_api/views/report_view_test.exs
index a00c9c579..40df01101 100644
--- a/test/web/admin_api/views/report_view_test.exs
+++ b/test/web/admin_api/views/report_view_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
use Pleroma.DataCase
import Pleroma.Factory
+ alias Pleroma.Web.AdminAPI.Report
alias Pleroma.Web.AdminAPI.ReportView
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.AccountView
@@ -34,7 +35,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
}
result =
- ReportView.render("show.json", %{report: activity})
+ ReportView.render("show.json", Report.extract_report_info(activity))
|> Map.delete(:created_at)
assert result == expected
@@ -66,7 +67,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
}
result =
- ReportView.render("show.json", %{report: report_activity})
+ ReportView.render("show.json", Report.extract_report_info(report_activity))
|> Map.delete(:created_at)
assert result == expected
@@ -78,7 +79,9 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
- assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
+
+ assert %{state: "closed"} =
+ ReportView.render("show.json", Report.extract_report_info(activity))
end
test "renders report description" do
@@ -92,7 +95,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
})
assert %{content: "posts are too good for this instance"} =
- ReportView.render("show.json", %{report: activity})
+ ReportView.render("show.json", Report.extract_report_info(activity))
end
test "sanitizes report description" do
@@ -109,7 +112,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
activity = Map.put(activity, :data, data)
refute "" ==
- ReportView.render("show.json", %{report: activity})[:content]
+ ReportView.render("show.json", Report.extract_report_info(activity))[:content]
end
test "doesn't error out when the user doesn't exists" do
@@ -125,6 +128,6 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
Pleroma.User.delete(other_user)
Pleroma.User.invalidate_cache(other_user)
- assert %{} = ReportView.render("show.json", %{report: activity})
+ assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))
end
end
--
cgit v1.2.3
From 79b25be4e1e9e97277a831c98ccea86a038914de Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 24 Sep 2019 14:16:52 +0700
Subject: Do not return tuple when unneeded
---
test/user_test.exs | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index aebe7aa06..21ea1d28e 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -74,8 +74,8 @@ defmodule Pleroma.UserTest do
CommonAPI.follow(follower, unlocked)
CommonAPI.follow(follower, locked)
- assert {:ok, []} = User.get_follow_requests(unlocked)
- assert {:ok, [activity]} = User.get_follow_requests(locked)
+ assert [] = User.get_follow_requests(unlocked)
+ assert [activity] = User.get_follow_requests(locked)
assert activity
end
@@ -90,7 +90,7 @@ defmodule Pleroma.UserTest do
CommonAPI.follow(accepted_follower, locked)
User.follow(accepted_follower, locked)
- assert {:ok, [activity]} = User.get_follow_requests(locked)
+ assert [activity] = User.get_follow_requests(locked)
assert activity
end
@@ -99,10 +99,10 @@ defmodule Pleroma.UserTest do
follower = insert(:user)
CommonAPI.follow(follower, followed)
- assert {:ok, [_activity]} = User.get_follow_requests(followed)
+ assert [_activity] = User.get_follow_requests(followed)
{:ok, _follower} = User.block(followed, follower)
- assert {:ok, []} = User.get_follow_requests(followed)
+ assert [] = User.get_follow_requests(followed)
end
test "follow_all follows mutliple users" do
@@ -560,7 +560,7 @@ defmodule Pleroma.UserTest do
test "it enforces the fqn format for nicknames" do
cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
- assert cs.changes.local == false
+ assert Ecto.Changeset.get_field(cs, :local) == false
assert cs.changes.avatar
refute cs.valid?
end
@@ -584,7 +584,7 @@ defmodule Pleroma.UserTest do
{:ok, follower_one} = User.follow(follower_one, user)
{:ok, follower_two} = User.follow(follower_two, user)
- {:ok, res} = User.get_followers(user)
+ res = User.get_followers(user)
assert Enum.member?(res, follower_one)
assert Enum.member?(res, follower_two)
@@ -600,7 +600,7 @@ defmodule Pleroma.UserTest do
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
- {:ok, res} = User.get_friends(user)
+ res = User.get_friends(user)
followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
@@ -975,7 +975,7 @@ defmodule Pleroma.UserTest do
info = User.get_cached_user_info(user2)
assert info.follower_count == 0
- assert {:ok, []} = User.get_followers(user2)
+ assert [] = User.get_followers(user2)
end
test "hide a user from friends" do
@@ -991,7 +991,7 @@ defmodule Pleroma.UserTest do
assert info.following_count == 0
assert User.following_count(user2) == 0
- assert {:ok, []} = User.get_friends(user2)
+ assert [] = User.get_friends(user2)
end
test "hide a user's statuses from timelines and notifications" do
@@ -1034,7 +1034,7 @@ defmodule Pleroma.UserTest do
test ".delete_user_activities deletes all create activities", %{user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
- {:ok, _} = User.delete_user_activities(user)
+ User.delete_user_activities(user)
# TODO: Remove favorites, repeats, delete activities.
refute Activity.get_by_id(activity.id)
--
cgit v1.2.3
From a66a7a328ffe908bda4e8453111559aa7cd579a6 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 24 Sep 2019 15:16:44 +0700
Subject: Extract notification actions from `MastodonAPIController` into
`NotificationController`
---
.../controllers/notification_controller_test.exs | 299 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 293 --------------------
2 files changed, 299 insertions(+), 293 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/notification_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs
new file mode 100644
index 000000000..e4137e92c
--- /dev/null
+++ b/test/web/mastodon_api/controllers/notification_controller_test.exs
@@ -0,0 +1,299 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Notification
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "list of notifications", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+
+ {:ok, [_notification]} = Notification.create_notifications(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications")
+
+ expected_response =
+ "hi @#{user.nickname}"
+
+ assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
+ assert response == expected_response
+ end
+
+ test "getting a single notification", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+
+ {:ok, [notification]} = Notification.create_notifications(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications/#{notification.id}")
+
+ expected_response =
+ "hi @#{user.nickname}"
+
+ assert %{"status" => %{"content" => response}} = json_response(conn, 200)
+ assert response == expected_response
+ end
+
+ test "dismissing a single notification", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+
+ {:ok, [notification]} = Notification.create_notifications(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
+
+ assert %{} = json_response(conn, 200)
+ end
+
+ test "clearing all notifications", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+
+ {:ok, [_notification]} = Notification.create_notifications(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/notifications/clear")
+
+ assert %{} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/notifications")
+
+ assert all = json_response(conn, 200)
+ assert all == []
+ end
+
+ test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+
+ notification1_id = get_notification_id_by_activity(activity1)
+ notification2_id = get_notification_id_by_activity(activity2)
+ notification3_id = get_notification_id_by_activity(activity3)
+ notification4_id = get_notification_id_by_activity(activity4)
+
+ conn = assign(conn, :user, user)
+
+ # min_id
+ result =
+ conn
+ |> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
+ |> json_response(:ok)
+
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+
+ # since_id
+ result =
+ conn
+ |> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
+ |> json_response(:ok)
+
+ assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
+
+ # max_id
+ result =
+ conn
+ |> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
+ |> json_response(:ok)
+
+ assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
+ end
+
+ test "filters notifications using exclude_types", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
+ {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
+ {:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
+ {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
+
+ mention_notification_id = get_notification_id_by_activity(mention_activity)
+ favorite_notification_id = get_notification_id_by_activity(favorite_activity)
+ reblog_notification_id = get_notification_id_by_activity(reblog_activity)
+ follow_notification_id = get_notification_id_by_activity(follow_activity)
+
+ conn = assign(conn, :user, user)
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]})
+
+ assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
+
+ assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
+
+ assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
+
+ conn_res =
+ get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
+
+ assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
+ end
+
+ test "destroy multiple", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
+ {:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
+
+ notification1_id = get_notification_id_by_activity(activity1)
+ notification2_id = get_notification_id_by_activity(activity2)
+ notification3_id = get_notification_id_by_activity(activity3)
+ notification4_id = get_notification_id_by_activity(activity4)
+
+ conn = assign(conn, :user, user)
+
+ result =
+ conn
+ |> get("/api/v1/notifications")
+ |> json_response(:ok)
+
+ assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
+
+ conn2 =
+ conn
+ |> assign(:user, other_user)
+
+ result =
+ conn2
+ |> get("/api/v1/notifications")
+ |> json_response(:ok)
+
+ assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
+
+ conn_destroy =
+ conn
+ |> delete("/api/v1/notifications/destroy_multiple", %{
+ "ids" => [notification1_id, notification2_id]
+ })
+
+ assert json_response(conn_destroy, 200) == %{}
+
+ result =
+ conn2
+ |> get("/api/v1/notifications")
+ |> json_response(:ok)
+
+ assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
+ end
+
+ test "doesn't see notifications after muting user with notifications", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+ {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+
+ conn = assign(conn, :user, user)
+
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+
+ {:ok, user} = User.mute(user, user2)
+
+ conn = assign(build_conn(), :user, user)
+ conn = get(conn, "/api/v1/notifications")
+
+ assert json_response(conn, 200) == []
+ end
+
+ test "see notifications after muting user without notifications", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+ {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+
+ conn = assign(conn, :user, user)
+
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+
+ {:ok, user} = User.mute(user, user2, false)
+
+ conn = assign(build_conn(), :user, user)
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+ end
+
+ test "see notifications after muting user with notifications and with_muted parameter", %{
+ conn: conn
+ } do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+ {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
+
+ conn = assign(conn, :user, user)
+
+ conn = get(conn, "/api/v1/notifications")
+
+ assert length(json_response(conn, 200)) == 1
+
+ {:ok, user} = User.mute(user, user2)
+
+ conn = assign(build_conn(), :user, user)
+ conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
+
+ assert length(json_response(conn, 200)) == 1
+ end
+
+ defp get_notification_id_by_activity(%{id: id}) do
+ Notification
+ |> Repo.get_by(activity_id: id)
+ |> Map.get(:id)
+ |> to_string()
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 73a3bf135..0eb78fe5b 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -999,299 +999,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "notifications" do
- test "list of notifications", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
-
- {:ok, [_notification]} = Notification.create_notifications(activity)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/notifications")
-
- expected_response =
- ~s(hi @#{user.nickname})
-
- assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
- assert response == expected_response
- end
-
- test "getting a single notification", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
-
- {:ok, [notification]} = Notification.create_notifications(activity)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/notifications/#{notification.id}")
-
- expected_response =
- ~s(hi @#{user.nickname})
-
- assert %{"status" => %{"content" => response}} = json_response(conn, 200)
- assert response == expected_response
- end
-
- test "dismissing a single notification", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
-
- {:ok, [notification]} = Notification.create_notifications(activity)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
-
- assert %{} = json_response(conn, 200)
- end
-
- test "clearing all notifications", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
-
- {:ok, [_notification]} = Notification.create_notifications(activity)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/notifications/clear")
-
- assert %{} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> get("/api/v1/notifications")
-
- assert all = json_response(conn, 200)
- assert all == []
- end
-
- test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
-
- notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string()
- notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string()
- notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string()
- notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string()
-
- conn =
- conn
- |> assign(:user, user)
-
- # min_id
- conn_res =
- conn
- |> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
-
- # since_id
- conn_res =
- conn
- |> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
-
- # max_id
- conn_res =
- conn
- |> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
- end
-
- test "filters notifications using exclude_types", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
- {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
- {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
- {:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
- {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
-
- mention_notification_id =
- Repo.get_by(Notification, activity_id: mention_activity.id).id |> to_string()
-
- favorite_notification_id =
- Repo.get_by(Notification, activity_id: favorite_activity.id).id |> to_string()
-
- reblog_notification_id =
- Repo.get_by(Notification, activity_id: reblog_activity.id).id |> to_string()
-
- follow_notification_id =
- Repo.get_by(Notification, activity_id: follow_activity.id).id |> to_string()
-
- conn =
- conn
- |> assign(:user, user)
-
- conn_res =
- get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]})
-
- assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
-
- conn_res =
- get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
-
- assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
-
- conn_res =
- get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
-
- assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
-
- conn_res =
- get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
-
- assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
- end
-
- test "destroy multiple", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
- {:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
- {:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
-
- notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string()
- notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string()
- notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string()
- notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string()
-
- conn =
- conn
- |> assign(:user, user)
-
- conn_res =
- conn
- |> get("/api/v1/notifications")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
-
- conn2 =
- conn
- |> assign(:user, other_user)
-
- conn_res =
- conn2
- |> get("/api/v1/notifications")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
-
- conn_destroy =
- conn
- |> delete("/api/v1/notifications/destroy_multiple", %{
- "ids" => [notification1_id, notification2_id]
- })
-
- assert json_response(conn_destroy, 200) == %{}
-
- conn_res =
- conn2
- |> get("/api/v1/notifications")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
- end
-
- test "doesn't see notifications after muting user with notifications", %{conn: conn} do
- user = insert(:user)
- user2 = insert(:user)
-
- {:ok, _, _, _} = CommonAPI.follow(user, user2)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
-
- conn = assign(conn, :user, user)
-
- conn = get(conn, "/api/v1/notifications")
-
- assert length(json_response(conn, 200)) == 1
-
- {:ok, user} = User.mute(user, user2)
-
- conn = assign(build_conn(), :user, user)
- conn = get(conn, "/api/v1/notifications")
-
- assert json_response(conn, 200) == []
- end
-
- test "see notifications after muting user without notifications", %{conn: conn} do
- user = insert(:user)
- user2 = insert(:user)
-
- {:ok, _, _, _} = CommonAPI.follow(user, user2)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
-
- conn = assign(conn, :user, user)
-
- conn = get(conn, "/api/v1/notifications")
-
- assert length(json_response(conn, 200)) == 1
-
- {:ok, user} = User.mute(user, user2, false)
-
- conn = assign(build_conn(), :user, user)
- conn = get(conn, "/api/v1/notifications")
-
- assert length(json_response(conn, 200)) == 1
- end
-
- test "see notifications after muting user with notifications and with_muted parameter", %{
- conn: conn
- } do
- user = insert(:user)
- user2 = insert(:user)
-
- {:ok, _, _, _} = CommonAPI.follow(user, user2)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
-
- conn = assign(conn, :user, user)
-
- conn = get(conn, "/api/v1/notifications")
-
- assert length(json_response(conn, 200)) == 1
-
- {:ok, user} = User.mute(user, user2)
-
- conn = assign(build_conn(), :user, user)
- conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
-
- assert length(json_response(conn, 200)) == 1
- end
- end
-
describe "reblogging" do
test "reblogs and returns the reblogged status", %{conn: conn} do
activity = insert(:note_activity)
--
cgit v1.2.3
From 209395c7e60afe7115f22afd6936d9c6bdd7bb72 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 24 Sep 2019 19:50:07 +0700
Subject: Add User.change_info/2 and User.update_info/2
---
test/tasks/database_test.exs | 4 +---
test/user_test.exs | 18 ++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 17 +++++------------
test/web/oauth/oauth_controller_test.exs | 9 +++------
test/web/ostatus/ostatus_controller_test.exs | 22 +++++++++-------------
5 files changed, 36 insertions(+), 34 deletions(-)
(limited to 'test')
diff --git a/test/tasks/database_test.exs b/test/tasks/database_test.exs
index a9925c361..b63dcac00 100644
--- a/test/tasks/database_test.exs
+++ b/test/tasks/database_test.exs
@@ -77,12 +77,10 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
assert length(following) == 2
assert info.follower_count == 0
- info_cng = Ecto.Changeset.change(info, %{follower_count: 3})
-
{:ok, user} =
user
|> Ecto.Changeset.change(%{following: following ++ following})
- |> Ecto.Changeset.put_embed(:info, info_cng)
+ |> User.change_info(&Ecto.Changeset.change(&1, %{follower_count: 3}))
|> Repo.update()
assert length(user.following) == 4
diff --git a/test/user_test.exs b/test/user_test.exs
index 21ea1d28e..126bd69e8 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1707,4 +1707,22 @@ defmodule Pleroma.UserTest do
assert password_reset_pending
end
end
+
+ test "change_info/2" do
+ user = insert(:user)
+ assert user.info.hide_follows == false
+
+ changeset = User.change_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
+ assert changeset.changes.info.changes.hide_follows == true
+ end
+
+ test "update_info/2" do
+ user = insert(:user)
+ assert user.info.hide_follows == false
+
+ assert {:ok, _} = User.update_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
+
+ 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
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 73a3bf135..e32468f85 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2613,14 +2613,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
# Stats should count users with missing or nil `info.deactivated` value
- user = User.get_cached_by_id(user.id)
- info_change = Changeset.change(user.info, %{deactivated: nil})
{:ok, _user} =
- user
- |> Changeset.change()
- |> Changeset.put_embed(:info, info_change)
- |> User.update_and_set_cache()
+ user.id
+ |> User.get_cached_by_id()
+ |> User.update_info(&Changeset.change(&1, %{deactivated: nil}))
Pleroma.Stats.force_update()
@@ -3953,13 +3950,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
setup do
- user = insert(:user)
- info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
-
{:ok, user} =
- user
- |> Changeset.change()
- |> Changeset.put_embed(:info, info_change)
+ insert(:user)
+ |> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|> Repo.update()
assert user.info.confirmation_pending
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 8b88fd784..0cf755806 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
import Pleroma.Factory
alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.OAuthController
alias Pleroma.Web.OAuth.Token
@@ -775,15 +776,11 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
Pleroma.Config.put([:instance, :account_activation_required], true)
-
password = "testpassword"
- user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
- info_change = Pleroma.User.Info.confirmation_changeset(user.info, need_confirmation: true)
{:ok, user} =
- user
- |> Ecto.Changeset.change()
- |> Ecto.Changeset.put_embed(:info, info_change)
+ insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
+ |> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|> Repo.update()
refute Pleroma.User.auth_active?(user)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index ec96f0012..2b40fb47e 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -50,20 +50,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
end) =~ "[error]"
- # Set a wrong magic-key for a user so it has to refetch
- salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
-
# Wrong key
- info_cng =
- User.Info.remote_user_creation(salmon_user.info, %{
- magic_key:
- "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
- })
-
- salmon_user
- |> Ecto.Changeset.change()
- |> Ecto.Changeset.put_embed(:info, info_cng)
- |> User.update_and_set_cache()
+ info = %{
+ magic_key:
+ "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
+ }
+
+ # Set a wrong magic-key for a user so it has to refetch
+ "http://gs.example.org:4040/index.php/user/1"
+ |> User.get_cached_by_ap_id()
+ |> User.update_info(&User.Info.remote_user_creation(&1, info))
assert capture_log(fn ->
conn =
--
cgit v1.2.3
From 0dc8f3d6d2fa18261e9a6fa8da540c434f1fa67b Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 24 Sep 2019 19:03:06 +0200
Subject: =?UTF-8?q?/api/ap/uploadMedia=20=E2=86=92=20/api/ap/upload=5Fmedi?=
=?UTF-8?q?a?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
test/web/activity_pub/activity_pub_controller_test.exs | 2 +-
test/web/ostatus/ostatus_controller_test.exs | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index c2bcddf85..8868d8a0d 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -1008,7 +1008,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn =
conn
|> assign(:user, user)
- |> post("/api/ap/uploadMedia", %{"file" => image, "description" => desc})
+ |> post("/api/ap/upload_media", %{"file" => image, "description" => desc})
assert object = json_response(conn, :created)
assert object["name"] == desc
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index fc1635a2f..3a867b8c0 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -401,7 +401,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
"sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
- "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/uploadMedia"
+ "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
}
assert response["@context"] == [
@@ -464,7 +464,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
"sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
- "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/uploadMedia"
+ "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
}
assert response["@context"] == [
--
cgit v1.2.3
From 60cbea5bb2e70d6a843d6f595a3c1cfe9cc78d1e Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Wed, 25 Sep 2019 01:25:42 +0300
Subject: Allow activities pagination via limit/offset
---
test/web/activity_pub/activity_pub_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 4100108a5..f28fd6871 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -647,6 +647,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert last == last_expected
end
+ test "paginates via offset/limit" do
+ _first_activities = ActivityBuilder.insert_list(10)
+ activities = ActivityBuilder.insert_list(10)
+ _later_activities = ActivityBuilder.insert_list(10)
+ first_expected = List.first(activities)
+
+ activities =
+ ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset)
+
+ first = List.first(activities)
+
+ assert length(activities) == 20
+ assert first == first_expected
+ end
+
test "doesn't return reblogs for users for whom reblogs have been muted" do
activity = insert(:note_activity)
user = insert(:user)
--
cgit v1.2.3
From b5dfe83433e092a007f85ed9c0ffe5a47dbfcccd Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 18 Sep 2019 21:54:31 +0700
Subject: Replace `Pleroma.FlakeId` with `flake_id` hex package
---
test/flake_id_test.exs | 47 -----------------------------------------------
1 file changed, 47 deletions(-)
delete mode 100644 test/flake_id_test.exs
(limited to 'test')
diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs
deleted file mode 100644
index 85ed5bbdf..000000000
--- a/test/flake_id_test.exs
+++ /dev/null
@@ -1,47 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.FlakeIdTest do
- use Pleroma.DataCase
- import Kernel, except: [to_string: 1]
- import Pleroma.FlakeId
-
- describe "fake flakes (compatibility with older serial integers)" do
- test "from_string/1" do
- fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
- assert from_string("42") == fake_flake
- assert from_string(42) == fake_flake
- end
-
- test "zero or -1 is a null flake" do
- fake_flake = <<0::integer-size(128)>>
- assert from_string("0") == fake_flake
- assert from_string("-1") == fake_flake
- end
-
- test "to_string/1" do
- fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
- assert to_string(fake_flake) == "42"
- end
- end
-
- test "ecto type behaviour" do
- flake = <<0, 0, 1, 104, 80, 229, 2, 235, 140, 22, 69, 201, 53, 210, 0, 0>>
- flake_s = "9eoozpwTul5mjSEDRI"
-
- assert cast(flake) == {:ok, flake_s}
- assert cast(flake_s) == {:ok, flake_s}
-
- assert load(flake) == {:ok, flake_s}
- assert load(flake_s) == {:ok, flake_s}
-
- assert dump(flake_s) == {:ok, flake}
- assert dump(flake) == {:ok, flake}
- end
-
- test "is_flake_id?/1" do
- assert is_flake_id?("9eoozpwTul5mjSEDRI")
- refute is_flake_id?("http://example.com/activities/3ebbadd1-eb14-4e20-8118-b6f79c0c7b0b")
- end
-end
--
cgit v1.2.3
From 1b2e4a0ae0648c4e2542edecca131b06aa02016c Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 25 Sep 2019 13:13:35 +0300
Subject: clears `robot.txt` after tests
---
test/tasks/instance_test.exs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/tasks/instance_test.exs b/test/tasks/instance_test.exs
index 70986374e..a3b0dcb50 100644
--- a/test/tasks/instance_test.exs
+++ b/test/tasks/instance_test.exs
@@ -7,7 +7,16 @@ defmodule Pleroma.InstanceTest do
setup do
File.mkdir_p!(tmp_path())
- on_exit(fn -> File.rm_rf(tmp_path()) end)
+
+ on_exit(fn ->
+ File.rm_rf(tmp_path())
+ static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
+
+ if File.exists?(static_dir) do
+ File.rm_rf(Path.join(static_dir, "robots.txt"))
+ end
+ end)
+
:ok
end
--
cgit v1.2.3
From ba9d35a9049e0d46900d2dd95afd27c09f327a2c Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Tue, 24 Sep 2019 19:18:07 +0300
Subject: Add an API endpoint for listing remote packs
---
test/web/pleroma_api/emoji_api_controller_test.exs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
(limited to 'test')
diff --git a/test/web/pleroma_api/emoji_api_controller_test.exs b/test/web/pleroma_api/emoji_api_controller_test.exs
index c5a553692..166a0201d 100644
--- a/test/web/pleroma_api/emoji_api_controller_test.exs
+++ b/test/web/pleroma_api/emoji_api_controller_test.exs
@@ -33,6 +33,28 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
refute pack["pack"]["can-download"]
end
+ test "listing remote packs" do
+ admin = insert(:user, info: %{is_admin: true})
+ conn = build_conn() |> assign(:user, admin)
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ mock(fn
+ %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
+ json([%{href: "https://example.com/nodeinfo/2.1.json"}])
+
+ %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
+ json(%{metadata: %{features: ["shareable_emoji_packs"]}})
+
+ %{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
+ json(resp)
+ end)
+
+ assert conn
+ |> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"})
+ |> json_response(200) == resp
+ end
+
test "downloading a shared pack from download_shared" do
conn = build_conn()
--
cgit v1.2.3
From 118d6dcdf4b2c81b4cbe51fd43977722b3eee164 Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis
Date: Tue, 24 Sep 2019 19:38:05 +0300
Subject: Fix nodeinfo handling
---
test/web/pleroma_api/emoji_api_controller_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/pleroma_api/emoji_api_controller_test.exs b/test/web/pleroma_api/emoji_api_controller_test.exs
index 166a0201d..93a507a01 100644
--- a/test/web/pleroma_api/emoji_api_controller_test.exs
+++ b/test/web/pleroma_api/emoji_api_controller_test.exs
@@ -41,7 +41,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
mock(fn
%{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
- json([%{href: "https://example.com/nodeinfo/2.1.json"}])
+ json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
@@ -77,13 +77,13 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
mock(fn
%{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
- json([%{href: "https://old-instance/nodeinfo/2.1.json"}])
+ json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})
%{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
json(%{metadata: %{features: []}})
%{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
- json([%{href: "https://example.com/nodeinfo/2.1.json"}])
+ json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
--
cgit v1.2.3
From d87be2ec96912b147ad8fb6b17c1ee00d7d30a7f Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 25 Sep 2019 15:59:04 +0300
Subject: Don't embed the first page in inboxes/outboxes and refactor the views
to follow View/Controller pattern
Note that I mentioned the change in 1.1 section because I intend to
backport this, if this is not needed I will move it back to Unreleased.
---
test/web/activity_pub/activity_pub_controller_test.exs | 6 +++---
test/web/activity_pub/views/user_view_test.exs | 16 ++++++++++++----
2 files changed, 15 insertions(+), 7 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 9e8e420ec..ab52044ae 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -479,7 +479,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn
|> assign(:user, user)
|> put_req_header("accept", "application/activity+json")
- |> get("/users/#{user.nickname}/inbox")
+ |> get("/users/#{user.nickname}/inbox?page=true")
assert response(conn, 200) =~ note_object.data["content"]
end
@@ -567,7 +567,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn =
conn
|> put_req_header("accept", "application/activity+json")
- |> get("/users/#{user.nickname}/outbox")
+ |> get("/users/#{user.nickname}/outbox?page=true")
assert response(conn, 200) =~ note_object.data["content"]
end
@@ -579,7 +579,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn =
conn
|> put_req_header("accept", "application/activity+json")
- |> get("/users/#{user.nickname}/outbox")
+ |> get("/users/#{user.nickname}/outbox?page=true")
assert response(conn, 200) =~ announce_activity.data["object"]
end
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 78b0408ee..3155749aa 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -159,7 +159,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
end
end
- test "outbox paginates correctly" do
+ test "activity collection page aginates correctly" do
user = insert(:user)
posts =
@@ -171,13 +171,21 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
# outbox sorts chronologically, newest first, with ten per page
posts = Enum.reverse(posts)
- %{"first" => %{"next" => next_url}} =
- UserView.render("outbox.json", %{user: user, max_id: nil})
+ %{"next" => next_url} =
+ UserView.render("activity_collection_page.json", %{
+ iri: "#{user.ap_id}/outbox",
+ activities: Enum.take(posts, 10)
+ })
next_id = Enum.at(posts, 9).id
assert next_url =~ next_id
- %{"next" => next_url} = UserView.render("outbox.json", %{user: user, max_id: next_id})
+ %{"next" => next_url} =
+ UserView.render("activity_collection_page.json", %{
+ iri: "#{user.ap_id}/outbox",
+ activities: Enum.take(Enum.drop(posts, 10), 10)
+ })
+
next_id = Enum.at(posts, 19).id
assert next_url =~ next_id
end
--
cgit v1.2.3
From dd4263da5a93a022ba7c46fb1cb4687f8cb1c790 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Wed, 25 Sep 2019 17:47:22 +0000
Subject: Apply suggestion to test/tasks/instance_test.exs
---
test/tasks/instance_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/tasks/instance_test.exs b/test/tasks/instance_test.exs
index a3b0dcb50..6d7eed4c1 100644
--- a/test/tasks/instance_test.exs
+++ b/test/tasks/instance_test.exs
@@ -10,7 +10,7 @@ defmodule Pleroma.InstanceTest do
on_exit(fn ->
File.rm_rf(tmp_path())
- static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
+ static_dir = Pleroma.Config.get([:instance, :static_dir], "test/instance_static/")
if File.exists?(static_dir) do
File.rm_rf(Path.join(static_dir, "robots.txt"))
--
cgit v1.2.3
From 5fb72170a72e61f0b8035fba63b7bbdff7acde05 Mon Sep 17 00:00:00 2001
From: Hakaba Hitoyo
Date: Thu, 26 Sep 2019 02:57:41 +0000
Subject: Revert "add _discoverable_ keyword into ActivityPub @context"
This reverts commit 3aef4bdf8f37efd1055a84c5fca12ec4559a17f5.
---
test/web/mastodon_api/views/account_view_test.exs | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 6206107f7..f2f334992 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -67,7 +67,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: "valid html",
sensitive: false,
- pleroma: %{},
+ pleroma: %{
+ discoverable: false
+ },
fields: []
},
pleroma: %{
@@ -137,7 +139,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: user.bio,
sensitive: false,
- pleroma: %{},
+ pleroma: %{
+ discoverable: false
+ },
fields: []
},
pleroma: %{
@@ -310,7 +314,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: user.bio,
sensitive: false,
- pleroma: %{},
+ pleroma: %{
+ discoverable: false
+ },
fields: []
},
pleroma: %{
--
cgit v1.2.3
From 3572cf29b7374947ebfbb42a20d370a75f5f0a40 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 26 Sep 2019 10:53:42 +0700
Subject: Extract timeline actions from `MastodonAPIController` into
`TimelineController`
---
.../controllers/timeline_controller_test.exs | 291 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 283 +-------------------
2 files changed, 294 insertions(+), 280 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/timeline_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs
new file mode 100644
index 000000000..d3652d964
--- /dev/null
+++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs
@@ -0,0 +1,291 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ alias Pleroma.Config
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.OStatus
+
+ clear_config([:instance, :public])
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ test "the home timeline", %{conn: conn} do
+ user = insert(:user)
+ following = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/timelines/home")
+
+ assert Enum.empty?(json_response(conn, :ok))
+
+ {:ok, user} = User.follow(user, following)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/timelines/home")
+
+ assert [%{"content" => "test"}] = json_response(conn, :ok)
+ end
+
+ describe "public" do
+ @tag capture_log: true
+ test "the public timeline", %{conn: conn} do
+ following = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
+
+ {:ok, [_activity]} =
+ OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
+
+ conn = get(conn, "/api/v1/timelines/public", %{"local" => "False"})
+
+ assert length(json_response(conn, :ok)) == 2
+
+ conn = get(build_conn(), "/api/v1/timelines/public", %{"local" => "True"})
+
+ assert [%{"content" => "test"}] = json_response(conn, :ok)
+
+ conn = get(build_conn(), "/api/v1/timelines/public", %{"local" => "1"})
+
+ assert [%{"content" => "test"}] = json_response(conn, :ok)
+ end
+
+ test "the public timeline when public is set to false", %{conn: conn} do
+ Config.put([:instance, :public], false)
+
+ assert %{"error" => "This resource requires authentication."} ==
+ conn
+ |> get("/api/v1/timelines/public", %{"local" => "False"})
+ |> json_response(:forbidden)
+ end
+
+ test "the public timeline includes only public statuses for an authenticated user" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+
+ res_conn = get(conn, "/api/v1/timelines/public")
+ assert length(json_response(res_conn, 200)) == 1
+ end
+ end
+
+ describe "direct" do
+ test "direct timeline", %{conn: conn} do
+ user_one = insert(:user)
+ user_two = insert(:user)
+
+ {:ok, user_two} = User.follow(user_two, user_one)
+
+ {:ok, direct} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, _follower_only} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "private"
+ })
+
+ # Only direct should be visible here
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/direct")
+
+ [status] = json_response(res_conn, :ok)
+
+ assert %{"visibility" => "direct"} = status
+ assert status["url"] != direct.data["id"]
+
+ # User should be able to see their own direct message
+ res_conn =
+ build_conn()
+ |> assign(:user, user_one)
+ |> get("api/v1/timelines/direct")
+
+ [status] = json_response(res_conn, :ok)
+
+ assert %{"visibility" => "direct"} = status
+
+ # Both should be visible here
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/home")
+
+ [_s1, _s2] = json_response(res_conn, :ok)
+
+ # Test pagination
+ Enum.each(1..20, fn _ ->
+ {:ok, _} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "direct"
+ })
+ end)
+
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/direct")
+
+ statuses = json_response(res_conn, :ok)
+ assert length(statuses) == 20
+
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]})
+
+ [status] = json_response(res_conn, :ok)
+
+ assert status["url"] != direct.data["id"]
+ end
+
+ test "doesn't include DMs from blocked users", %{conn: conn} do
+ blocker = insert(:user)
+ blocked = insert(:user)
+ user = insert(:user)
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ {:ok, _blocked_direct} =
+ CommonAPI.post(blocked, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, direct} =
+ CommonAPI.post(user, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("api/v1/timelines/direct")
+
+ [status] = json_response(res_conn, :ok)
+ assert status["id"] == direct.id
+ end
+ end
+
+ describe "list" do
+ test "list timeline", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
+ {:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
+ {:ok, list} = Pleroma.List.create("name", user)
+ {:ok, list} = Pleroma.List.follow(list, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/timelines/list/#{list.id}")
+
+ assert [%{"id" => id}] = json_response(conn, :ok)
+
+ assert id == to_string(activity_two.id)
+ end
+
+ test "list timeline does not leak non-public statuses for unfollowed users", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
+
+ {:ok, _activity_two} =
+ CommonAPI.post(other_user, %{
+ "status" => "Marisa is cute.",
+ "visibility" => "private"
+ })
+
+ {:ok, list} = Pleroma.List.create("name", user)
+ {:ok, list} = Pleroma.List.follow(list, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/timelines/list/#{list.id}")
+
+ assert [%{"id" => id}] = json_response(conn, :ok)
+
+ assert id == to_string(activity_one.id)
+ end
+ end
+
+ describe "hashtag" do
+ @tag capture_log: true
+ test "hashtag timeline", %{conn: conn} do
+ following = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
+
+ {:ok, [_activity]} =
+ OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
+
+ nconn = get(conn, "/api/v1/timelines/tag/2hu")
+
+ assert [%{"id" => id}] = json_response(nconn, :ok)
+
+ assert id == to_string(activity.id)
+
+ # works for different capitalization too
+ nconn = get(conn, "/api/v1/timelines/tag/2HU")
+
+ assert [%{"id" => id}] = json_response(nconn, :ok)
+
+ assert id == to_string(activity.id)
+ end
+
+ test "multi-hashtag timeline", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
+ {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
+ {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
+
+ any_test = get(conn, "/api/v1/timelines/tag/test", %{"any" => ["test1"]})
+
+ [status_none, status_test1, status_test] = json_response(any_test, :ok)
+
+ assert to_string(activity_test.id) == status_test["id"]
+ assert to_string(activity_test1.id) == status_test1["id"]
+ assert to_string(activity_none.id) == status_none["id"]
+
+ restricted_test =
+ get(conn, "/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
+
+ assert [status_test1] == json_response(restricted_test, :ok)
+
+ all_test = get(conn, "/api/v1/timelines/tag/test", %{"all" => ["none"]})
+
+ assert [status_none] == json_response(all_test, :ok)
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index cd672132b..7f7a89516 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -20,12 +20,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.MastodonAPI.FilterView
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Token
- alias Pleroma.Web.OStatus
alias Pleroma.Web.Push
- import Pleroma.Factory
+
import ExUnit.CaptureLog
- import Tesla.Mock
+ import Pleroma.Factory
import Swoosh.TestAssertions
+ import Tesla.Mock
@image "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
@@ -37,82 +37,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
clear_config([:instance, :public])
clear_config([:rich_media, :enabled])
- test "the home timeline", %{conn: conn} do
- user = insert(:user)
- following = insert(:user)
-
- {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/timelines/home")
-
- assert Enum.empty?(json_response(conn, 200))
-
- {:ok, user} = User.follow(user, following)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> get("/api/v1/timelines/home")
-
- assert [%{"content" => "test"}] = json_response(conn, 200)
- end
-
- test "the public timeline", %{conn: conn} do
- following = insert(:user)
-
- capture_log(fn ->
- {:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
-
- {:ok, [_activity]} =
- OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
-
- conn =
- conn
- |> get("/api/v1/timelines/public", %{"local" => "False"})
-
- assert length(json_response(conn, 200)) == 2
-
- conn =
- build_conn()
- |> get("/api/v1/timelines/public", %{"local" => "True"})
-
- assert [%{"content" => "test"}] = json_response(conn, 200)
-
- conn =
- build_conn()
- |> get("/api/v1/timelines/public", %{"local" => "1"})
-
- assert [%{"content" => "test"}] = json_response(conn, 200)
- end)
- end
-
- test "the public timeline when public is set to false", %{conn: conn} do
- Config.put([:instance, :public], false)
-
- assert conn
- |> get("/api/v1/timelines/public", %{"local" => "False"})
- |> json_response(403) == %{"error" => "This resource requires authentication."}
- end
-
- test "the public timeline includes only public statuses for an authenticated user" do
- user = insert(:user)
-
- conn =
- build_conn()
- |> assign(:user, user)
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
-
- res_conn = get(conn, "/api/v1/timelines/public")
- assert length(json_response(res_conn, 200)) == 1
- end
-
describe "posting statuses" do
setup do
user = insert(:user)
@@ -419,80 +343,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- test "direct timeline", %{conn: conn} do
- user_one = insert(:user)
- user_two = insert(:user)
-
- {:ok, user_two} = User.follow(user_two, user_one)
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
- })
-
- {:ok, _follower_only} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "private"
- })
-
- # Only direct should be visible here
- res_conn =
- conn
- |> assign(:user, user_two)
- |> get("api/v1/timelines/direct")
-
- [status] = json_response(res_conn, 200)
-
- assert %{"visibility" => "direct"} = status
- assert status["url"] != direct.data["id"]
-
- # User should be able to see their own direct message
- res_conn =
- build_conn()
- |> assign(:user, user_one)
- |> get("api/v1/timelines/direct")
-
- [status] = json_response(res_conn, 200)
-
- assert %{"visibility" => "direct"} = status
-
- # Both should be visible here
- res_conn =
- conn
- |> assign(:user, user_two)
- |> get("api/v1/timelines/home")
-
- [_s1, _s2] = json_response(res_conn, 200)
-
- # Test pagination
- Enum.each(1..20, fn _ ->
- {:ok, _} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "direct"
- })
- end)
-
- res_conn =
- conn
- |> assign(:user, user_two)
- |> get("api/v1/timelines/direct")
-
- statuses = json_response(res_conn, 200)
- assert length(statuses) == 20
-
- res_conn =
- conn
- |> assign(:user, user_two)
- |> get("api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]})
-
- [status] = json_response(res_conn, 200)
-
- assert status["url"] != direct.data["id"]
- end
-
test "Conversations", %{conn: conn} do
user_one = insert(:user)
user_two = insert(:user)
@@ -556,33 +406,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
end
- test "doesn't include DMs from blocked users", %{conn: conn} do
- blocker = insert(:user)
- blocked = insert(:user)
- user = insert(:user)
- {:ok, blocker} = User.block(blocker, blocked)
-
- {:ok, _blocked_direct} =
- CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}!",
- "visibility" => "direct"
- })
-
- {:ok, direct} =
- CommonAPI.post(user, %{
- "status" => "Hi @#{blocker.nickname}!",
- "visibility" => "direct"
- })
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("api/v1/timelines/direct")
-
- [status] = json_response(res_conn, 200)
- assert status["id"] == direct.id
- end
-
test "verify_credentials", %{conn: conn} do
user = insert(:user)
@@ -955,50 +778,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "list timelines" do
- test "list timeline", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
- {:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
- {:ok, list} = Pleroma.List.create("name", user)
- {:ok, list} = Pleroma.List.follow(list, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/timelines/list/#{list.id}")
-
- assert [%{"id" => id}] = json_response(conn, 200)
-
- assert id == to_string(activity_two.id)
- end
-
- test "list timeline does not leak non-public statuses for unfollowed users", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
-
- {:ok, _activity_two} =
- CommonAPI.post(other_user, %{
- "status" => "Marisa is cute.",
- "visibility" => "private"
- })
-
- {:ok, list} = Pleroma.List.create("name", user)
- {:ok, list} = Pleroma.List.follow(list, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/timelines/list/#{list.id}")
-
- assert [%{"id" => id}] = json_response(conn, 200)
-
- assert id == to_string(activity_one.id)
- end
- end
-
describe "reblogging" do
test "reblogs and returns the reblogged status", %{conn: conn} do
activity = insert(:note_activity)
@@ -1554,62 +1333,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert url =~ "an_image"
end
- test "hashtag timeline", %{conn: conn} do
- following = insert(:user)
-
- capture_log(fn ->
- {:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
-
- {:ok, [_activity]} =
- OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
-
- nconn =
- conn
- |> get("/api/v1/timelines/tag/2hu")
-
- assert [%{"id" => id}] = json_response(nconn, 200)
-
- assert id == to_string(activity.id)
-
- # works for different capitalization too
- nconn =
- conn
- |> get("/api/v1/timelines/tag/2HU")
-
- assert [%{"id" => id}] = json_response(nconn, 200)
-
- assert id == to_string(activity.id)
- end)
- end
-
- test "multi-hashtag timeline", %{conn: conn} do
- user = insert(:user)
-
- {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
- {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
- {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
-
- any_test =
- conn
- |> get("/api/v1/timelines/tag/test", %{"any" => ["test1"]})
-
- [status_none, status_test1, status_test] = json_response(any_test, 200)
-
- assert to_string(activity_test.id) == status_test["id"]
- assert to_string(activity_test1.id) == status_test1["id"]
- assert to_string(activity_none.id) == status_none["id"]
-
- restricted_test =
- conn
- |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
-
- assert [status_test1] == json_response(restricted_test, 200)
-
- all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]})
-
- assert [status_none] == json_response(all_test, 200)
- end
-
test "getting followers", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 75290cbfbd0f93cf3ecec5f44c4624b8c8601c51 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 26 Sep 2019 18:49:57 +0700
Subject: Add Pleroma.JobQueueMonitor
---
test/healthcheck_test.exs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/healthcheck_test.exs b/test/healthcheck_test.exs
index 6bb8d5b7f..66d5026ff 100644
--- a/test/healthcheck_test.exs
+++ b/test/healthcheck_test.exs
@@ -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
--
cgit v1.2.3
From 98d1347a4ea1c296d2f07b9467addc56ef2dc676 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 9 Sep 2019 21:49:02 +0700
Subject: Extract status actions from `MastodonAPIController` into
`StatusController`
---
test/integration/mastodon_websocket_test.exs | 2 +-
test/web/admin_api/views/report_view_test.exs | 2 +-
.../mastodon_api/views/notification_view_test.exs | 6 +--
test/web/mastodon_api/views/status_view_test.exs | 44 +++++++++++-----------
4 files changed, 27 insertions(+), 27 deletions(-)
(limited to 'test')
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index ed7ce8fe0..63fce07bb 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -68,7 +68,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok, json} = Jason.decode(json["payload"])
view_json =
- Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: activity, for: nil)
+ Pleroma.Web.MastodonAPI.StatusView.render("show.json", activity: activity, for: nil)
|> Jason.encode!()
|> Jason.decode!()
diff --git a/test/web/admin_api/views/report_view_test.exs b/test/web/admin_api/views/report_view_test.exs
index 40df01101..35b6947a0 100644
--- a/test/web/admin_api/views/report_view_test.exs
+++ b/test/web/admin_api/views/report_view_test.exs
@@ -61,7 +61,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
AccountView.render("account.json", %{user: other_user}),
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
),
- statuses: [StatusView.render("status.json", %{activity: activity})],
+ statuses: [StatusView.render("show.json", %{activity: activity})],
state: "open",
id: report_activity.id
}
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 9231aaec8..86268fcfa 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -28,7 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
pleroma: %{is_seen: false},
type: "mention",
account: AccountView.render("account.json", %{user: user, for: mentioned_user}),
- status: StatusView.render("status.json", %{activity: activity, for: mentioned_user}),
+ status: StatusView.render("show.json", %{activity: activity, for: mentioned_user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -51,7 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
pleroma: %{is_seen: false},
type: "favourite",
account: AccountView.render("account.json", %{user: another_user, for: user}),
- status: StatusView.render("status.json", %{activity: create_activity, for: user}),
+ status: StatusView.render("show.json", %{activity: create_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -73,7 +73,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
pleroma: %{is_seen: false},
type: "reblog",
account: AccountView.render("account.json", %{user: another_user, for: user}),
- status: StatusView.render("status.json", %{activity: reblog_activity, for: user}),
+ status: StatusView.render("show.json", %{activity: reblog_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 51f8434fa..c17d0ef95 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -29,7 +29,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
status =
- StatusView.render("status.json",
+ StatusView.render("show.json",
activity: activity,
with_direct_conversation_id: true,
for: user
@@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
Repo.delete(user)
Cachex.clear(:user_cache)
- %{account: ms_user} = StatusView.render("status.json", activity: activity)
+ %{account: ms_user} = StatusView.render("show.json", activity: activity)
assert ms_user.acct == "erroruser@example.com"
end
@@ -63,7 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
Cachex.clear(:user_cache)
- result = StatusView.render("status.json", activity: activity)
+ result = StatusView.render("show.json", activity: activity)
assert result[:account][:id] == to_string(user.id)
end
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
User.get_cached_by_ap_id(note.data["actor"])
- status = StatusView.render("status.json", %{activity: note})
+ status = StatusView.render("show.json", %{activity: note})
assert status.content == ""
end
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
convo_id = Utils.context_to_conversation_id(object_data["context"])
- status = StatusView.render("status.json", %{activity: note})
+ status = StatusView.render("show.json", %{activity: note})
created_at =
(object_data["published"] || "")
@@ -165,11 +165,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, user} = User.mute(user, other_user)
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
- status = StatusView.render("status.json", %{activity: activity})
+ status = StatusView.render("show.json", %{activity: activity})
assert status.muted == false
- status = StatusView.render("status.json", %{activity: activity, for: user})
+ status = StatusView.render("show.json", %{activity: activity, for: user})
assert status.muted == true
end
@@ -181,13 +181,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, user} = User.mute(user, other_user)
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
- status = StatusView.render("status.json", %{activity: activity, for: user})
+ status = StatusView.render("show.json", %{activity: activity, for: user})
assert status.pleroma.thread_muted == false
{:ok, activity} = CommonAPI.add_mute(user, activity)
- status = StatusView.render("status.json", %{activity: activity, for: user})
+ status = StatusView.render("show.json", %{activity: activity, for: user})
assert status.pleroma.thread_muted == true
end
@@ -196,11 +196,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "Cute girls doing cute things"})
- status = StatusView.render("status.json", %{activity: activity})
+ status = StatusView.render("show.json", %{activity: activity})
assert status.bookmarked == false
- status = StatusView.render("status.json", %{activity: activity, for: user})
+ status = StatusView.render("show.json", %{activity: activity, for: user})
assert status.bookmarked == false
@@ -208,7 +208,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
activity = Activity.get_by_id_with_object(activity.id)
- status = StatusView.render("status.json", %{activity: activity, for: user})
+ status = StatusView.render("show.json", %{activity: activity, for: user})
assert status.bookmarked == true
end
@@ -220,7 +220,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, activity} =
CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
- status = StatusView.render("status.json", %{activity: activity})
+ status = StatusView.render("show.json", %{activity: activity})
assert status.in_reply_to_id == to_string(note.id)
@@ -237,7 +237,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- status = StatusView.render("status.json", %{activity: activity})
+ status = StatusView.render("show.json", %{activity: activity})
assert status.mentions ==
Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
@@ -263,7 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert length(activity.recipients) == 3
- %{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
+ %{mentions: [mention] = mentions} = StatusView.render("show.json", %{activity: activity})
assert length(mentions) == 1
assert mention.url == recipient_ap_id
@@ -300,7 +300,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert length(activity.recipients) == 3
- %{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
+ %{mentions: [mention] = mentions} = StatusView.render("show.json", %{activity: activity})
assert length(mentions) == 1
assert mention.url == recipient.ap_id
@@ -340,7 +340,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810"
[activity] = Activity.search(nil, id)
- status = StatusView.render("status.json", %{activity: activity})
+ status = StatusView.render("show.json", %{activity: activity})
assert status.uri == id
assert status.url == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
@@ -352,7 +352,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
- represented = StatusView.render("status.json", %{for: user, activity: reblog})
+ represented = StatusView.render("show.json", %{for: user, activity: reblog})
assert represented[:id] == to_string(reblog.id)
assert represented[:reblog][:id] == to_string(activity.id)
@@ -369,7 +369,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
%Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
- represented = StatusView.render("status.json", %{for: user, activity: activity})
+ represented = StatusView.render("show.json", %{for: user, activity: activity})
assert represented[:id] == to_string(activity.id)
assert length(represented[:media_attachments]) == 1
@@ -570,7 +570,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
"status" => "drink more water"
})
- result = StatusView.render("status.json", %{activity: activity, for: other_user})
+ result = StatusView.render("show.json", %{activity: activity, for: other_user})
assert result[:account][:pleroma][:relationship] ==
AccountView.render("relationship.json", %{user: other_user, target: user})
@@ -587,7 +587,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user)
- result = StatusView.render("status.json", %{activity: activity, for: user})
+ result = StatusView.render("show.json", %{activity: activity, for: user})
assert result[:account][:pleroma][:relationship] ==
AccountView.render("relationship.json", %{user: user, target: other_user})
@@ -604,7 +604,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
{:ok, activity} =
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
- status = StatusView.render("status.json", activity: activity)
+ status = StatusView.render("show.json", activity: activity)
assert status.visibility == "list"
end
--
cgit v1.2.3
From 76b7e5cd5b34e68055bab7353cb845f3429d897f Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 26 Sep 2019 13:38:45 +0700
Subject: Move StatusController tests from MastodonAPIControllerTest to
StatusControllerTest
---
.../controllers/status_controller_test.exs | 1056 ++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 1123 +-------------------
2 files changed, 1104 insertions(+), 1075 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/status_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
new file mode 100644
index 000000000..f80ce7704
--- /dev/null
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -0,0 +1,1056 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Activity
+ alias Pleroma.ActivityExpiration
+ alias Pleroma.Config
+ alias Pleroma.Object
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ describe "posting statuses" do
+ setup do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ [conn: conn]
+ end
+
+ test "posting a status", %{conn: conn} do
+ idempotency_key = "Pikachu rocks!"
+
+ conn_one =
+ conn
+ |> put_req_header("idempotency-key", idempotency_key)
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
+
+ {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
+ # Six hours
+ assert ttl > :timer.seconds(6 * 60 * 60 - 1)
+
+ assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
+ json_response(conn_one, 200)
+
+ assert Activity.get_by_id(id)
+
+ conn_two =
+ conn
+ |> put_req_header("idempotency-key", idempotency_key)
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
+
+ assert %{"id" => second_id} = json_response(conn_two, 200)
+ assert id == second_id
+
+ conn_three =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
+
+ assert %{"id" => third_id} = json_response(conn_three, 200)
+ refute id == third_id
+
+ # An activity that will expire:
+ # 2 hours
+ expires_in = 120 * 60
+
+ conn_four =
+ conn
+ |> post("api/v1/statuses", %{
+ "status" => "oolong",
+ "expires_in" => expires_in
+ })
+
+ assert fourth_response = %{"id" => fourth_id} = json_response(conn_four, 200)
+ assert activity = Activity.get_by_id(fourth_id)
+ assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
+
+ estimated_expires_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(expires_in)
+ |> NaiveDateTime.truncate(:second)
+
+ # This assert will fail if the test takes longer than a minute. I sure hope it never does:
+ assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60
+
+ assert fourth_response["pleroma"]["expires_at"] ==
+ NaiveDateTime.to_iso8601(expiration.scheduled_at)
+ end
+
+ test "replying to a status", %{conn: conn} do
+ user = insert(:user)
+ {:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"})
+
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
+
+ assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+
+ activity = Activity.get_by_id(id)
+
+ assert activity.data["context"] == replied_to.data["context"]
+ assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
+ end
+
+ test "replying to a direct message with visibility other than direct", %{conn: conn} do
+ user = insert(:user)
+ {:ok, replied_to} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
+
+ Enum.each(["public", "private", "unlisted"], fn visibility ->
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" => "@#{user.nickname} hey",
+ "in_reply_to_id" => replied_to.id,
+ "visibility" => visibility
+ })
+
+ assert json_response(conn, 422) == %{"error" => "The message visibility must be direct"}
+ end)
+ end
+
+ test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
+
+ assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+ assert Activity.get_by_id(id)
+ end
+
+ test "posting a sensitive status", %{conn: conn} do
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
+
+ assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
+ assert Activity.get_by_id(id)
+ end
+
+ test "posting a fake status", %{conn: conn} do
+ real_conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" =>
+ "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"
+ })
+
+ real_status = json_response(real_conn, 200)
+
+ assert real_status
+ assert Object.get_by_ap_id(real_status["uri"])
+
+ real_status =
+ real_status
+ |> Map.put("id", nil)
+ |> Map.put("url", nil)
+ |> Map.put("uri", nil)
+ |> Map.put("created_at", nil)
+ |> Kernel.put_in(["pleroma", "conversation_id"], nil)
+
+ fake_conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" =>
+ "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",
+ "preview" => true
+ })
+
+ fake_status = json_response(fake_conn, 200)
+
+ assert fake_status
+ refute Object.get_by_ap_id(fake_status["uri"])
+
+ fake_status =
+ fake_status
+ |> Map.put("id", nil)
+ |> Map.put("url", nil)
+ |> Map.put("uri", nil)
+ |> Map.put("created_at", nil)
+ |> Kernel.put_in(["pleroma", "conversation_id"], nil)
+
+ assert real_status == fake_status
+ end
+
+ test "posting a status with OGP link preview", %{conn: conn} do
+ Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ Config.put([:rich_media, :enabled], true)
+
+ conn =
+ conn
+ |> post("/api/v1/statuses", %{
+ "status" => "https://example.com/ogp"
+ })
+
+ assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
+ assert Activity.get_by_id(id)
+ end
+
+ test "posting a direct status", %{conn: conn} do
+ user2 = insert(:user)
+ content = "direct cofe @#{user2.nickname}"
+
+ conn =
+ conn
+ |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
+
+ assert %{"id" => id} = response = json_response(conn, 200)
+ assert response["visibility"] == "direct"
+ assert response["pleroma"]["direct_conversation_id"]
+ assert activity = Activity.get_by_id(id)
+ assert activity.recipients == [user2.ap_id, conn.assigns[:user].ap_id]
+ assert activity.data["to"] == [user2.ap_id]
+ assert activity.data["cc"] == []
+ end
+ end
+
+ describe "posting polls" do
+ test "posting a poll", %{conn: conn} do
+ user = insert(:user)
+ time = NaiveDateTime.utc_now()
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "Who is the #bestgrill?",
+ "poll" => %{"options" => ["Rei", "Asuka", "Misato"], "expires_in" => 420}
+ })
+
+ response = json_response(conn, 200)
+
+ assert Enum.all?(response["poll"]["options"], fn %{"title" => title} ->
+ title in ["Rei", "Asuka", "Misato"]
+ end)
+
+ assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
+ refute response["poll"]["expred"]
+ end
+
+ test "option limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Config.get([:instance, :poll_limits, :max_options])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "desu~",
+ "poll" => %{"options" => Enum.map(0..limit, fn _ -> "desu" end), "expires_in" => 1}
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Poll can't contain more than #{limit} options"
+ end
+
+ test "option character limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Config.get([:instance, :poll_limits, :max_option_chars])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "...",
+ "poll" => %{
+ "options" => [Enum.reduce(0..limit, "", fn _, acc -> acc <> "." end)],
+ "expires_in" => 1
+ }
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Poll options cannot be longer than #{limit} characters each"
+ end
+
+ test "minimal date limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Config.get([:instance, :poll_limits, :min_expiration])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "imagine arbitrary limits",
+ "poll" => %{
+ "options" => ["this post was made by pleroma gang"],
+ "expires_in" => limit - 1
+ }
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Expiration date is too soon"
+ end
+
+ test "maximum date limit is enforced", %{conn: conn} do
+ user = insert(:user)
+ limit = Config.get([:instance, :poll_limits, :max_expiration])
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "imagine arbitrary limits",
+ "poll" => %{
+ "options" => ["this post was made by pleroma gang"],
+ "expires_in" => limit + 1
+ }
+ })
+
+ %{"error" => error} = json_response(conn, 422)
+ assert error == "Expiration date is too far in the future"
+ end
+ end
+
+ test "get a status", %{conn: conn} do
+ activity = insert(:note_activity)
+
+ conn =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
+
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == to_string(activity.id)
+ end
+
+ test "get statuses by IDs", %{conn: conn} do
+ %{id: id1} = insert(:note_activity)
+ %{id: id2} = insert(:note_activity)
+
+ query_string = "ids[]=#{id1}&ids[]=#{id2}"
+ conn = get(conn, "/api/v1/statuses/?#{query_string}")
+
+ assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"])
+ end
+
+ describe "deleting a status" do
+ test "when you created it", %{conn: conn} do
+ activity = insert(:note_activity)
+ author = User.get_cached_by_ap_id(activity.data["actor"])
+
+ conn =
+ conn
+ |> assign(:user, author)
+ |> delete("/api/v1/statuses/#{activity.id}")
+
+ assert %{} = json_response(conn, 200)
+
+ refute Activity.get_by_id(activity.id)
+ end
+
+ test "when you didn't create it", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/api/v1/statuses/#{activity.id}")
+
+ assert %{"error" => _} = json_response(conn, 403)
+
+ assert Activity.get_by_id(activity.id) == activity
+ end
+
+ test "when you're an admin or moderator", %{conn: conn} do
+ activity1 = insert(:note_activity)
+ activity2 = insert(:note_activity)
+ admin = insert(:user, info: %{is_admin: true})
+ moderator = insert(:user, info: %{is_moderator: true})
+
+ res_conn =
+ conn
+ |> assign(:user, admin)
+ |> delete("/api/v1/statuses/#{activity1.id}")
+
+ assert %{} = json_response(res_conn, 200)
+
+ res_conn =
+ conn
+ |> assign(:user, moderator)
+ |> delete("/api/v1/statuses/#{activity2.id}")
+
+ assert %{} = json_response(res_conn, 200)
+
+ refute Activity.get_by_id(activity1.id)
+ refute Activity.get_by_id(activity2.id)
+ end
+ end
+
+ describe "reblogging" do
+ test "reblogs and returns the reblogged status", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/reblog")
+
+ assert %{
+ "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
+ "reblogged" => true
+ } = json_response(conn, 200)
+
+ assert to_string(activity.id) == id
+ end
+
+ test "reblogged status for another user", %{conn: conn} do
+ activity = insert(:note_activity)
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+ CommonAPI.favorite(activity.id, user2)
+ {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
+ {:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
+ {:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
+
+ conn_res =
+ conn
+ |> assign(:user, user3)
+ |> get("/api/v1/statuses/#{reblog_activity1.id}")
+
+ assert %{
+ "reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
+ "reblogged" => false,
+ "favourited" => false,
+ "bookmarked" => false
+ } = json_response(conn_res, 200)
+
+ conn_res =
+ conn
+ |> assign(:user, user2)
+ |> get("/api/v1/statuses/#{reblog_activity1.id}")
+
+ assert %{
+ "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
+ "reblogged" => true,
+ "favourited" => true,
+ "bookmarked" => true
+ } = json_response(conn_res, 200)
+
+ assert to_string(activity.id) == id
+ end
+
+ test "returns 400 error when activity is not exist", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/foo/reblog")
+
+ assert json_response(conn, 400) == %{"error" => "Could not repeat"}
+ end
+ end
+
+ describe "unreblogging" do
+ test "unreblogs and returns the unreblogged status", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user)
+
+ {:ok, _, _} = CommonAPI.repeat(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/unreblog")
+
+ assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200)
+
+ assert to_string(activity.id) == id
+ end
+
+ test "returns 400 error when activity is not exist", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/foo/unreblog")
+
+ assert json_response(conn, 400) == %{"error" => "Could not unrepeat"}
+ end
+ end
+
+ describe "favoriting" do
+ test "favs a status and returns it", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/favourite")
+
+ assert %{"id" => id, "favourites_count" => 1, "favourited" => true} =
+ json_response(conn, 200)
+
+ assert to_string(activity.id) == id
+ end
+
+ test "returns 400 error for a wrong id", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/1/favourite")
+
+ assert json_response(conn, 400) == %{"error" => "Could not favorite"}
+ end
+ end
+
+ describe "unfavoriting" do
+ test "unfavorites a status and returns it", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user)
+
+ {:ok, _, _} = CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/unfavourite")
+
+ assert %{"id" => id, "favourites_count" => 0, "favourited" => false} =
+ json_response(conn, 200)
+
+ assert to_string(activity.id) == id
+ end
+
+ test "returns 400 error for a wrong id", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/1/unfavourite")
+
+ assert json_response(conn, 400) == %{"error" => "Could not unfavorite"}
+ end
+ end
+
+ describe "pinned statuses" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ [user: user, activity: activity]
+ end
+
+ clear_config([:instance, :max_pinned_statuses]) do
+ Config.put([:instance, :max_pinned_statuses], 1)
+ end
+
+ test "pin status", %{conn: conn, user: user, activity: activity} do
+ id_str = to_string(activity.id)
+
+ assert %{"id" => ^id_str, "pinned" => true} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/pin")
+ |> json_response(200)
+
+ assert [%{"id" => ^id_str, "pinned" => true}] =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> json_response(200)
+ end
+
+ test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
+ {:ok, dm} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{dm.id}/pin")
+
+ assert json_response(conn, 400) == %{"error" => "Could not pin"}
+ end
+
+ test "unpin status", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.pin(activity.id, user)
+
+ id_str = to_string(activity.id)
+ user = refresh_record(user)
+
+ assert %{"id" => ^id_str, "pinned" => false} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/unpin")
+ |> json_response(200)
+
+ assert [] =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> json_response(200)
+ end
+
+ test "/unpin: returns 400 error when activity is not exist", %{conn: conn, user: user} do
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/1/unpin")
+
+ assert json_response(conn, 400) == %{"error" => "Could not unpin"}
+ end
+
+ test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
+ {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ id_str_one = to_string(activity_one.id)
+
+ assert %{"id" => ^id_str_one, "pinned" => true} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{id_str_one}/pin")
+ |> json_response(200)
+
+ user = refresh_record(user)
+
+ assert %{"error" => "You have already pinned the maximum number of statuses"} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity_two.id}/pin")
+ |> json_response(400)
+ end
+ end
+
+ describe "cards" do
+ setup do
+ Config.put([:rich_media, :enabled], true)
+
+ user = insert(:user)
+ %{user: user}
+ end
+
+ test "returns rich-media card", %{conn: conn, user: user} do
+ Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
+
+ card_data = %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "provider_name" => "example.com",
+ "provider_url" => "https://example.com",
+ "title" => "The Rock",
+ "type" => "link",
+ "url" => "https://example.com/ogp",
+ "description" =>
+ "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
+ "pleroma" => %{
+ "opengraph" => %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "title" => "The Rock",
+ "type" => "video.movie",
+ "url" => "https://example.com/ogp",
+ "description" =>
+ "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
+ }
+ }
+ }
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response == card_data
+
+ # works with private posts
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "https://example.com/ogp", "visibility" => "direct"})
+
+ response_two =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response_two == card_data
+ end
+
+ test "replaces missing description with an empty string", %{conn: conn, user: user} do
+ Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "https://example.com/ogp-missing-data"})
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(:ok)
+
+ assert response == %{
+ "type" => "link",
+ "title" => "Pleroma",
+ "description" => "",
+ "image" => nil,
+ "provider_name" => "example.com",
+ "provider_url" => "https://example.com",
+ "url" => "https://example.com/ogp-missing-data",
+ "pleroma" => %{
+ "opengraph" => %{
+ "title" => "Pleroma",
+ "type" => "website",
+ "url" => "https://example.com/ogp-missing-data"
+ }
+ }
+ }
+ end
+ end
+
+ test "bookmarks" do
+ user = insert(:user)
+ for_user = insert(:user)
+
+ {:ok, activity1} =
+ CommonAPI.post(user, %{
+ "status" => "heweoo?"
+ })
+
+ {:ok, activity2} =
+ CommonAPI.post(user, %{
+ "status" => "heweoo!"
+ })
+
+ response1 =
+ build_conn()
+ |> assign(:user, for_user)
+ |> post("/api/v1/statuses/#{activity1.id}/bookmark")
+
+ assert json_response(response1, 200)["bookmarked"] == true
+
+ response2 =
+ build_conn()
+ |> assign(:user, for_user)
+ |> post("/api/v1/statuses/#{activity2.id}/bookmark")
+
+ assert json_response(response2, 200)["bookmarked"] == true
+
+ bookmarks =
+ build_conn()
+ |> assign(:user, for_user)
+ |> get("/api/v1/bookmarks")
+
+ assert [json_response(response2, 200), json_response(response1, 200)] ==
+ json_response(bookmarks, 200)
+
+ response1 =
+ build_conn()
+ |> assign(:user, for_user)
+ |> post("/api/v1/statuses/#{activity1.id}/unbookmark")
+
+ assert json_response(response1, 200)["bookmarked"] == false
+
+ bookmarks =
+ build_conn()
+ |> assign(:user, for_user)
+ |> get("/api/v1/bookmarks")
+
+ assert [json_response(response2, 200)] == json_response(bookmarks, 200)
+ end
+
+ describe "conversation muting" do
+ setup do
+ post_user = insert(:user)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(post_user, %{"status" => "HIE"})
+
+ [user: user, activity: activity]
+ end
+
+ test "mute conversation", %{conn: conn, user: user, activity: activity} do
+ id_str = to_string(activity.id)
+
+ assert %{"id" => ^id_str, "muted" => true} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/mute")
+ |> json_response(200)
+ end
+
+ test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.add_mute(user, activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/mute")
+
+ assert json_response(conn, 400) == %{"error" => "conversation is already muted"}
+ end
+
+ test "unmute conversation", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.add_mute(user, activity)
+
+ id_str = to_string(activity.id)
+ user = refresh_record(user)
+
+ assert %{"id" => ^id_str, "muted" => false} =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/unmute")
+ |> json_response(200)
+ end
+ end
+
+ test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+
+ {:ok, replied_to} = CommonAPI.post(user1, %{"status" => "cofe"})
+
+ # Reply to status from another user
+ conn1 =
+ conn
+ |> assign(:user, user2)
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
+
+ assert %{"content" => "xD", "id" => id} = json_response(conn1, 200)
+
+ activity = Activity.get_by_id_with_object(id)
+
+ assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"]
+ assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
+
+ # Reblog from the third user
+ conn2 =
+ conn
+ |> assign(:user, user3)
+ |> post("/api/v1/statuses/#{activity.id}/reblog")
+
+ assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
+ json_response(conn2, 200)
+
+ assert to_string(activity.id) == id
+
+ # Getting third user status
+ conn3 =
+ conn
+ |> assign(:user, user3)
+ |> get("api/v1/timelines/home")
+
+ [reblogged_activity] = json_response(conn3, 200)
+
+ assert reblogged_activity["reblog"]["in_reply_to_id"] == replied_to.id
+
+ replied_to_user = User.get_by_ap_id(replied_to.data["actor"])
+ assert reblogged_activity["reblog"]["in_reply_to_account_id"] == replied_to_user.id
+ end
+
+ describe "GET /api/v1/statuses/:id/favourited_by" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ [conn: conn, activity: activity, user: user]
+ end
+
+ test "returns users who have favorited the status", %{conn: conn, activity: activity} do
+ other_user = insert(:user)
+ {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(:ok)
+
+ [%{"id" => id}] = response
+
+ assert id == other_user.id
+ end
+
+ test "returns empty array when status has not been favorited yet", %{
+ conn: conn,
+ activity: activity
+ } do
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "does not return users who have favorited the status but are blocked", %{
+ conn: %{assigns: %{user: user}} = conn,
+ activity: activity
+ } do
+ other_user = insert(:user)
+ {:ok, user} = User.block(user, other_user)
+
+ {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
+ other_user = insert(:user)
+ {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
+
+ response =
+ conn
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(:ok)
+
+ [%{"id" => id}] = response
+ assert id == other_user.id
+ end
+
+ test "requires authentification for private posts", %{conn: conn, user: user} do
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} wanna get some #cofe together?",
+ "visibility" => "direct"
+ })
+
+ {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
+
+ conn
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(404)
+
+ response =
+ build_conn()
+ |> assign(:user, other_user)
+ |> get("/api/v1/statuses/#{activity.id}/favourited_by")
+ |> json_response(200)
+
+ [%{"id" => id}] = response
+ assert id == other_user.id
+ end
+ end
+
+ describe "GET /api/v1/statuses/:id/reblogged_by" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ [conn: conn, activity: activity, user: user]
+ end
+
+ test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
+ other_user = insert(:user)
+ {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ [%{"id" => id}] = response
+
+ assert id == other_user.id
+ end
+
+ test "returns empty array when status has not been reblogged yet", %{
+ conn: conn,
+ activity: activity
+ } do
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "does not return users who have reblogged the status but are blocked", %{
+ conn: %{assigns: %{user: user}} = conn,
+ activity: activity
+ } do
+ other_user = insert(:user)
+ {:ok, user} = User.block(user, other_user)
+
+ {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
+ other_user = insert(:user)
+ {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
+
+ response =
+ conn
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ [%{"id" => id}] = response
+ assert id == other_user.id
+ end
+
+ test "requires authentification for private posts", %{conn: conn, user: user} do
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} wanna get some #cofe together?",
+ "visibility" => "direct"
+ })
+
+ conn
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(404)
+
+ response =
+ build_conn()
+ |> assign(:user, other_user)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(200)
+
+ assert [] == response
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 7f7a89516..6435ad7a9 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Ecto.Changeset
alias Pleroma.Activity
- alias Pleroma.ActivityExpiration
alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Object
@@ -37,312 +36,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
clear_config([:instance, :public])
clear_config([:rich_media, :enabled])
- describe "posting statuses" do
- setup do
- user = insert(:user)
-
- conn =
- build_conn()
- |> assign(:user, user)
-
- [conn: conn]
- end
-
- test "posting a status", %{conn: conn} do
- idempotency_key = "Pikachu rocks!"
-
- conn_one =
- conn
- |> put_req_header("idempotency-key", idempotency_key)
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "spoiler_text" => "2hu",
- "sensitive" => "false"
- })
-
- {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
- # Six hours
- assert ttl > :timer.seconds(6 * 60 * 60 - 1)
-
- assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
- json_response(conn_one, 200)
-
- assert Activity.get_by_id(id)
-
- conn_two =
- conn
- |> put_req_header("idempotency-key", idempotency_key)
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "spoiler_text" => "2hu",
- "sensitive" => "false"
- })
-
- assert %{"id" => second_id} = json_response(conn_two, 200)
- assert id == second_id
-
- conn_three =
- conn
- |> post("/api/v1/statuses", %{
- "status" => "cofe",
- "spoiler_text" => "2hu",
- "sensitive" => "false"
- })
-
- assert %{"id" => third_id} = json_response(conn_three, 200)
- refute id == third_id
-
- # An activity that will expire:
- # 2 hours
- expires_in = 120 * 60
-
- conn_four =
- conn
- |> post("api/v1/statuses", %{
- "status" => "oolong",
- "expires_in" => expires_in
- })
-
- assert fourth_response = %{"id" => fourth_id} = json_response(conn_four, 200)
- assert activity = Activity.get_by_id(fourth_id)
- assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
-
- estimated_expires_at =
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(expires_in)
- |> NaiveDateTime.truncate(:second)
-
- # This assert will fail if the test takes longer than a minute. I sure hope it never does:
- assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60
-
- assert fourth_response["pleroma"]["expires_at"] ==
- NaiveDateTime.to_iso8601(expiration.scheduled_at)
- end
-
- test "replying to a status", %{conn: conn} do
- user = insert(:user)
- {:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"})
-
- conn =
- conn
- |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
-
- assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
-
- activity = Activity.get_by_id(id)
-
- assert activity.data["context"] == replied_to.data["context"]
- assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
- end
-
- test "replying to a direct message with visibility other than direct", %{conn: conn} do
- user = insert(:user)
- {:ok, replied_to} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
-
- Enum.each(["public", "private", "unlisted"], fn visibility ->
- conn =
- conn
- |> post("/api/v1/statuses", %{
- "status" => "@#{user.nickname} hey",
- "in_reply_to_id" => replied_to.id,
- "visibility" => visibility
- })
-
- assert json_response(conn, 422) == %{"error" => "The message visibility must be direct"}
- end)
- end
-
- test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
- conn =
- conn
- |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
-
- assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
- assert Activity.get_by_id(id)
- end
-
- test "posting a sensitive status", %{conn: conn} do
- conn =
- conn
- |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
-
- assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
- assert Activity.get_by_id(id)
- end
-
- test "posting a fake status", %{conn: conn} do
- real_conn =
- conn
- |> post("/api/v1/statuses", %{
- "status" =>
- "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"
- })
-
- real_status = json_response(real_conn, 200)
-
- assert real_status
- assert Object.get_by_ap_id(real_status["uri"])
-
- real_status =
- real_status
- |> Map.put("id", nil)
- |> Map.put("url", nil)
- |> Map.put("uri", nil)
- |> Map.put("created_at", nil)
- |> Kernel.put_in(["pleroma", "conversation_id"], nil)
-
- fake_conn =
- conn
- |> post("/api/v1/statuses", %{
- "status" =>
- "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",
- "preview" => true
- })
-
- fake_status = json_response(fake_conn, 200)
-
- assert fake_status
- refute Object.get_by_ap_id(fake_status["uri"])
-
- fake_status =
- fake_status
- |> Map.put("id", nil)
- |> Map.put("url", nil)
- |> Map.put("uri", nil)
- |> Map.put("created_at", nil)
- |> Kernel.put_in(["pleroma", "conversation_id"], nil)
-
- assert real_status == fake_status
- end
-
- test "posting a status with OGP link preview", %{conn: conn} do
- Config.put([:rich_media, :enabled], true)
-
- conn =
- conn
- |> post("/api/v1/statuses", %{
- "status" => "https://example.com/ogp"
- })
-
- assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
- assert Activity.get_by_id(id)
- end
-
- test "posting a direct status", %{conn: conn} do
- user2 = insert(:user)
- content = "direct cofe @#{user2.nickname}"
-
- conn =
- conn
- |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
-
- assert %{"id" => id} = response = json_response(conn, 200)
- assert response["visibility"] == "direct"
- assert response["pleroma"]["direct_conversation_id"]
- assert activity = Activity.get_by_id(id)
- assert activity.recipients == [user2.ap_id, conn.assigns[:user].ap_id]
- assert activity.data["to"] == [user2.ap_id]
- assert activity.data["cc"] == []
- end
- end
-
- describe "posting polls" do
- test "posting a poll", %{conn: conn} do
- user = insert(:user)
- time = NaiveDateTime.utc_now()
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "Who is the #bestgrill?",
- "poll" => %{"options" => ["Rei", "Asuka", "Misato"], "expires_in" => 420}
- })
-
- response = json_response(conn, 200)
-
- assert Enum.all?(response["poll"]["options"], fn %{"title" => title} ->
- title in ["Rei", "Asuka", "Misato"]
- end)
-
- assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
- refute response["poll"]["expred"]
- end
-
- test "option limit is enforced", %{conn: conn} do
- user = insert(:user)
- limit = Config.get([:instance, :poll_limits, :max_options])
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "desu~",
- "poll" => %{"options" => Enum.map(0..limit, fn _ -> "desu" end), "expires_in" => 1}
- })
-
- %{"error" => error} = json_response(conn, 422)
- assert error == "Poll can't contain more than #{limit} options"
- end
-
- test "option character limit is enforced", %{conn: conn} do
- user = insert(:user)
- limit = Config.get([:instance, :poll_limits, :max_option_chars])
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "...",
- "poll" => %{
- "options" => [Enum.reduce(0..limit, "", fn _, acc -> acc <> "." end)],
- "expires_in" => 1
- }
- })
-
- %{"error" => error} = json_response(conn, 422)
- assert error == "Poll options cannot be longer than #{limit} characters each"
- end
-
- test "minimal date limit is enforced", %{conn: conn} do
- user = insert(:user)
- limit = Config.get([:instance, :poll_limits, :min_expiration])
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "imagine arbitrary limits",
- "poll" => %{
- "options" => ["this post was made by pleroma gang"],
- "expires_in" => limit - 1
- }
- })
-
- %{"error" => error} = json_response(conn, 422)
- assert error == "Expiration date is too soon"
- end
-
- test "maximum date limit is enforced", %{conn: conn} do
- user = insert(:user)
- limit = Config.get([:instance, :poll_limits, :max_expiration])
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "imagine arbitrary limits",
- "poll" => %{
- "options" => ["this post was made by pleroma gang"],
- "expires_in" => limit + 1
- }
- })
-
- %{"error" => error} = json_response(conn, 422)
- assert error == "Expiration date is too far in the future"
- end
- end
-
test "Conversations", %{conn: conn} do
user_one = insert(:user)
user_two = insert(:user)
@@ -575,81 +268,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert expected == json_response(conn, 200)
end
- test "get a status", %{conn: conn} do
- activity = insert(:note_activity)
-
- conn =
- conn
- |> get("/api/v1/statuses/#{activity.id}")
-
- assert %{"id" => id} = json_response(conn, 200)
- assert id == to_string(activity.id)
- end
-
- test "get statuses by IDs", %{conn: conn} do
- %{id: id1} = insert(:note_activity)
- %{id: id2} = insert(:note_activity)
-
- query_string = "ids[]=#{id1}&ids[]=#{id2}"
- conn = get(conn, "/api/v1/statuses/?#{query_string}")
-
- assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"])
- end
-
- describe "deleting a status" do
- test "when you created it", %{conn: conn} do
- activity = insert(:note_activity)
- author = User.get_cached_by_ap_id(activity.data["actor"])
-
- conn =
- conn
- |> assign(:user, author)
- |> delete("/api/v1/statuses/#{activity.id}")
-
- assert %{} = json_response(conn, 200)
-
- refute Activity.get_by_id(activity.id)
- end
-
- test "when you didn't create it", %{conn: conn} do
- activity = insert(:note_activity)
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> delete("/api/v1/statuses/#{activity.id}")
-
- assert %{"error" => _} = json_response(conn, 403)
-
- assert Activity.get_by_id(activity.id) == activity
- end
-
- test "when you're an admin or moderator", %{conn: conn} do
- activity1 = insert(:note_activity)
- activity2 = insert(:note_activity)
- admin = insert(:user, info: %{is_admin: true})
- moderator = insert(:user, info: %{is_moderator: true})
-
- res_conn =
- conn
- |> assign(:user, admin)
- |> delete("/api/v1/statuses/#{activity1.id}")
-
- assert %{} = json_response(res_conn, 200)
-
- res_conn =
- conn
- |> assign(:user, moderator)
- |> delete("/api/v1/statuses/#{activity2.id}")
-
- assert %{} = json_response(res_conn, 200)
-
- refute Activity.get_by_id(activity1.id)
- refute Activity.get_by_id(activity2.id)
- end
- end
-
describe "filters" do
test "creating a filter", %{conn: conn} do
user = insert(:user)
@@ -778,160 +396,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "reblogging" do
- test "reblogs and returns the reblogged status", %{conn: conn} do
- activity = insert(:note_activity)
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/reblog")
-
- assert %{
- "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
- "reblogged" => true
- } = json_response(conn, 200)
-
- assert to_string(activity.id) == id
- end
-
- test "reblogged status for another user", %{conn: conn} do
- activity = insert(:note_activity)
- user1 = insert(:user)
- user2 = insert(:user)
- user3 = insert(:user)
- CommonAPI.favorite(activity.id, user2)
- {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
- {:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
- {:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
-
- conn_res =
- conn
- |> assign(:user, user3)
- |> get("/api/v1/statuses/#{reblog_activity1.id}")
-
- assert %{
- "reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
- "reblogged" => false,
- "favourited" => false,
- "bookmarked" => false
- } = json_response(conn_res, 200)
-
- conn_res =
- conn
- |> assign(:user, user2)
- |> get("/api/v1/statuses/#{reblog_activity1.id}")
-
- assert %{
- "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
- "reblogged" => true,
- "favourited" => true,
- "bookmarked" => true
- } = json_response(conn_res, 200)
-
- assert to_string(activity.id) == id
- end
-
- test "returns 400 error when activity is not exist", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/foo/reblog")
-
- assert json_response(conn, 400) == %{"error" => "Could not repeat"}
- end
- end
-
- describe "unreblogging" do
- test "unreblogs and returns the unreblogged status", %{conn: conn} do
- activity = insert(:note_activity)
- user = insert(:user)
-
- {:ok, _, _} = CommonAPI.repeat(activity.id, user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/unreblog")
-
- assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200)
-
- assert to_string(activity.id) == id
- end
-
- test "returns 400 error when activity is not exist", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/foo/unreblog")
-
- assert json_response(conn, 400) == %{"error" => "Could not unrepeat"}
- end
- end
-
- describe "favoriting" do
- test "favs a status and returns it", %{conn: conn} do
- activity = insert(:note_activity)
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/favourite")
-
- assert %{"id" => id, "favourites_count" => 1, "favourited" => true} =
- json_response(conn, 200)
-
- assert to_string(activity.id) == id
- end
-
- test "returns 400 error for a wrong id", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/1/favourite")
-
- assert json_response(conn, 400) == %{"error" => "Could not favorite"}
- end
- end
-
- describe "unfavoriting" do
- test "unfavorites a status and returns it", %{conn: conn} do
- activity = insert(:note_activity)
- user = insert(:user)
-
- {:ok, _, _} = CommonAPI.favorite(activity.id, user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/unfavourite")
-
- assert %{"id" => id, "favourites_count" => 0, "favourited" => false} =
- json_response(conn, 200)
-
- assert to_string(activity.id) == id
- end
-
- test "returns 400 error for a wrong id", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/1/unfavourite")
-
- assert json_response(conn, 400) == %{"error" => "Could not unfavorite"}
- end
- end
-
describe "user timelines" do
test "gets a users statuses", %{conn: conn} do
user_one = insert(:user)
@@ -2025,346 +1489,91 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
"thumbnail" => _,
"languages" => _,
"registrations" => _,
- "poll_limits" => _
- } = result
-
- assert email == from_config_email
- end
-
- test "get instance stats", %{conn: conn} do
- user = insert(:user, %{local: true})
-
- user2 = insert(:user, %{local: true})
- {:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
-
- insert(:user, %{local: false, nickname: "u@peer1.com"})
- insert(:user, %{local: false, nickname: "u@peer2.com"})
-
- {:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
-
- # Stats should count users with missing or nil `info.deactivated` value
-
- {:ok, _user} =
- user.id
- |> User.get_cached_by_id()
- |> User.update_info(&Changeset.change(&1, %{deactivated: nil}))
-
- Pleroma.Stats.force_update()
-
- conn = get(conn, "/api/v1/instance")
-
- assert result = json_response(conn, 200)
-
- stats = result["stats"]
-
- assert stats
- assert stats["user_count"] == 1
- assert stats["status_count"] == 1
- assert stats["domain_count"] == 2
- end
-
- test "get peers", %{conn: conn} do
- insert(:user, %{local: false, nickname: "u@peer1.com"})
- insert(:user, %{local: false, nickname: "u@peer2.com"})
-
- Pleroma.Stats.force_update()
-
- conn = get(conn, "/api/v1/instance/peers")
-
- assert result = json_response(conn, 200)
-
- assert ["peer1.com", "peer2.com"] == Enum.sort(result)
- 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 "pinned statuses" do
- setup do
- user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
-
- [user: user, activity: activity]
- end
-
- clear_config([:instance, :max_pinned_statuses]) do
- Config.put([:instance, :max_pinned_statuses], 1)
- end
-
- test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
- {:ok, _} = CommonAPI.pin(activity.id, user)
-
- result =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> json_response(200)
-
- id_str = to_string(activity.id)
-
- assert [%{"id" => ^id_str, "pinned" => true}] = result
- end
-
- test "pin status", %{conn: conn, user: user, activity: activity} do
- id_str = to_string(activity.id)
-
- assert %{"id" => ^id_str, "pinned" => true} =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/pin")
- |> json_response(200)
-
- assert [%{"id" => ^id_str, "pinned" => true}] =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> json_response(200)
- end
-
- test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
- {:ok, dm} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{dm.id}/pin")
-
- assert json_response(conn, 400) == %{"error" => "Could not pin"}
- end
-
- test "unpin status", %{conn: conn, user: user, activity: activity} do
- {:ok, _} = CommonAPI.pin(activity.id, user)
-
- id_str = to_string(activity.id)
- user = refresh_record(user)
-
- assert %{"id" => ^id_str, "pinned" => false} =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/unpin")
- |> json_response(200)
-
- assert [] =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> json_response(200)
- end
+ "poll_limits" => _
+ } = result
- test "/unpin: returns 400 error when activity is not exist", %{conn: conn, user: user} do
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/1/unpin")
+ assert email == from_config_email
+ end
- assert json_response(conn, 400) == %{"error" => "Could not unpin"}
- end
+ test "get instance stats", %{conn: conn} do
+ user = insert(:user, %{local: true})
- test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ user2 = insert(:user, %{local: true})
+ {:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
- id_str_one = to_string(activity_one.id)
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
- assert %{"id" => ^id_str_one, "pinned" => true} =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{id_str_one}/pin")
- |> json_response(200)
+ {:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
- user = refresh_record(user)
+ # Stats should count users with missing or nil `info.deactivated` value
- assert %{"error" => "You have already pinned the maximum number of statuses"} =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity_two.id}/pin")
- |> json_response(400)
- end
- end
+ {:ok, _user} =
+ user.id
+ |> User.get_cached_by_id()
+ |> User.update_info(&Changeset.change(&1, %{deactivated: nil}))
- describe "cards" do
- setup do
- Config.put([:rich_media, :enabled], true)
+ Pleroma.Stats.force_update()
- user = insert(:user)
- %{user: user}
- end
-
- test "returns rich-media card", %{conn: conn, user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
-
- card_data = %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "provider_name" => "example.com",
- "provider_url" => "https://example.com",
- "title" => "The Rock",
- "type" => "link",
- "url" => "https://example.com/ogp",
- "description" =>
- "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
- "pleroma" => %{
- "opengraph" => %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "title" => "The Rock",
- "type" => "video.movie",
- "url" => "https://example.com/ogp",
- "description" =>
- "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
- }
- }
- }
+ conn = get(conn, "/api/v1/instance")
- response =
- conn
- |> get("/api/v1/statuses/#{activity.id}/card")
- |> json_response(200)
+ assert result = json_response(conn, 200)
- assert response == card_data
+ stats = result["stats"]
- # works with private posts
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "https://example.com/ogp", "visibility" => "direct"})
+ assert stats
+ assert stats["user_count"] == 1
+ assert stats["status_count"] == 1
+ assert stats["domain_count"] == 2
+ end
- response_two =
- conn
- |> assign(:user, user)
- |> get("/api/v1/statuses/#{activity.id}/card")
- |> json_response(200)
+ test "get peers", %{conn: conn} do
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
- assert response_two == card_data
- end
+ Pleroma.Stats.force_update()
- test "replaces missing description with an empty string", %{conn: conn, user: user} do
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "https://example.com/ogp-missing-data"})
+ conn = get(conn, "/api/v1/instance/peers")
- response =
- conn
- |> get("/api/v1/statuses/#{activity.id}/card")
- |> json_response(:ok)
+ assert result = json_response(conn, 200)
- assert response == %{
- "type" => "link",
- "title" => "Pleroma",
- "description" => "",
- "image" => nil,
- "provider_name" => "example.com",
- "provider_url" => "https://example.com",
- "url" => "https://example.com/ogp-missing-data",
- "pleroma" => %{
- "opengraph" => %{
- "title" => "Pleroma",
- "type" => "website",
- "url" => "https://example.com/ogp-missing-data"
- }
- }
- }
- end
+ assert ["peer1.com", "peer2.com"] == Enum.sort(result)
end
- test "bookmarks" do
+ test "put settings", %{conn: conn} do
user = insert(:user)
- for_user = insert(:user)
-
- {:ok, activity1} =
- CommonAPI.post(user, %{
- "status" => "heweoo?"
- })
- {:ok, activity2} =
- CommonAPI.post(user, %{
- "status" => "heweoo!"
- })
-
- response1 =
- build_conn()
- |> assign(:user, for_user)
- |> post("/api/v1/statuses/#{activity1.id}/bookmark")
-
- assert json_response(response1, 200)["bookmarked"] == true
-
- response2 =
- build_conn()
- |> assign(:user, for_user)
- |> post("/api/v1/statuses/#{activity2.id}/bookmark")
-
- assert json_response(response2, 200)["bookmarked"] == true
-
- bookmarks =
- build_conn()
- |> assign(:user, for_user)
- |> get("/api/v1/bookmarks")
-
- assert [json_response(response2, 200), json_response(response1, 200)] ==
- json_response(bookmarks, 200)
-
- response1 =
- build_conn()
- |> assign(:user, for_user)
- |> post("/api/v1/statuses/#{activity1.id}/unbookmark")
-
- assert json_response(response1, 200)["bookmarked"] == false
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
- bookmarks =
- build_conn()
- |> assign(:user, for_user)
- |> get("/api/v1/bookmarks")
+ assert _result = json_response(conn, 200)
- assert [json_response(response2, 200)] == json_response(bookmarks, 200)
+ user = User.get_cached_by_ap_id(user.ap_id)
+ assert user.info.settings == %{"programming" => "socks"}
end
- describe "conversation muting" do
+ describe "pinned statuses" do
setup do
- post_user = insert(:user)
user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(post_user, %{"status" => "HIE"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
[user: user, activity: activity]
end
- test "mute conversation", %{conn: conn, user: user, activity: activity} do
- id_str = to_string(activity.id)
-
- assert %{"id" => ^id_str, "muted" => true} =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/mute")
- |> json_response(200)
- end
-
- test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
- {:ok, _} = CommonAPI.add_mute(user, activity)
+ test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.pin(activity.id, user)
- conn =
+ result =
conn
|> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/mute")
-
- assert json_response(conn, 400) == %{"error" => "conversation is already muted"}
- end
-
- test "unmute conversation", %{conn: conn, user: user, activity: activity} do
- {:ok, _} = CommonAPI.add_mute(user, activity)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> json_response(200)
id_str = to_string(activity.id)
- user = refresh_record(user)
- assert %{"id" => ^id_str, "muted" => false} =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/unmute")
- |> json_response(200)
+ assert [%{"id" => ^id_str, "pinned" => true}] = result
end
end
@@ -2811,51 +2020,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- user3 = insert(:user)
-
- {:ok, replied_to} = CommonAPI.post(user1, %{"status" => "cofe"})
-
- # Reply to status from another user
- conn1 =
- conn
- |> assign(:user, user2)
- |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
-
- assert %{"content" => "xD", "id" => id} = json_response(conn1, 200)
-
- activity = Activity.get_by_id_with_object(id)
-
- assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"]
- assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
-
- # Reblog from the third user
- conn2 =
- conn
- |> assign(:user, user3)
- |> post("/api/v1/statuses/#{activity.id}/reblog")
-
- assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
- json_response(conn2, 200)
-
- assert to_string(activity.id) == id
-
- # Getting third user status
- conn3 =
- conn
- |> assign(:user, user3)
- |> get("api/v1/timelines/home")
-
- [reblogged_activity] = json_response(conn3, 200)
-
- assert reblogged_activity["reblog"]["in_reply_to_id"] == replied_to.id
-
- replied_to_user = User.get_by_ap_id(replied_to.data["actor"])
- assert reblogged_activity["reblog"]["in_reply_to_account_id"] == replied_to_user.id
- end
-
describe "create account by app" do
test "Account registration via Application", %{conn: conn} do
conn =
@@ -3135,197 +2299,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "GET /api/v1/statuses/:id/favourited_by" do
- setup do
- user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
-
- conn =
- build_conn()
- |> assign(:user, user)
-
- [conn: conn, activity: activity, user: user]
- end
-
- test "returns users who have favorited the status", %{conn: conn, activity: activity} do
- other_user = insert(:user)
- {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
-
- response =
- conn
- |> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
-
- [%{"id" => id}] = response
-
- assert id == other_user.id
- end
-
- test "returns empty array when status has not been favorited yet", %{
- conn: conn,
- activity: activity
- } do
- response =
- conn
- |> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "does not return users who have favorited the status but are blocked", %{
- conn: %{assigns: %{user: user}} = conn,
- activity: activity
- } do
- other_user = insert(:user)
- {:ok, user} = User.block(user, other_user)
-
- {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
-
- response =
- conn
- |> assign(:user, user)
- |> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
- other_user = insert(:user)
- {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
-
- response =
- conn
- |> assign(:user, nil)
- |> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(:ok)
-
- [%{"id" => id}] = response
- assert id == other_user.id
- end
-
- test "requires authentification for private posts", %{conn: conn, user: user} do
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "@#{other_user.nickname} wanna get some #cofe together?",
- "visibility" => "direct"
- })
-
- {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
-
- conn
- |> assign(:user, nil)
- |> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(404)
-
- response =
- build_conn()
- |> assign(:user, other_user)
- |> get("/api/v1/statuses/#{activity.id}/favourited_by")
- |> json_response(200)
-
- [%{"id" => id}] = response
- assert id == other_user.id
- end
- end
-
- describe "GET /api/v1/statuses/:id/reblogged_by" do
- setup do
- user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
-
- conn =
- build_conn()
- |> assign(:user, user)
-
- [conn: conn, activity: activity, user: user]
- end
-
- test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
- other_user = insert(:user)
- {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
-
- response =
- conn
- |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
-
- [%{"id" => id}] = response
-
- assert id == other_user.id
- end
-
- test "returns empty array when status has not been reblogged yet", %{
- conn: conn,
- activity: activity
- } do
- response =
- conn
- |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "does not return users who have reblogged the status but are blocked", %{
- conn: %{assigns: %{user: user}} = conn,
- activity: activity
- } do
- other_user = insert(:user)
- {:ok, user} = User.block(user, other_user)
-
- {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
-
- response =
- conn
- |> assign(:user, user)
- |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
- other_user = insert(:user)
- {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
-
- response =
- conn
- |> assign(:user, nil)
- |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(:ok)
-
- [%{"id" => id}] = response
- assert id == other_user.id
- end
-
- test "requires authentification for private posts", %{conn: conn, user: user} do
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "@#{other_user.nickname} wanna get some #cofe together?",
- "visibility" => "direct"
- })
-
- conn
- |> assign(:user, nil)
- |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(404)
-
- response =
- build_conn()
- |> assign(:user, other_user)
- |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
- |> json_response(200)
-
- assert [] == response
- end
- end
-
describe "POST /auth/password, with valid parameters" do
setup %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 5ea5c58a85b7be56370b151ce8977982d47fde8c Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 26 Sep 2019 14:28:35 +0700
Subject: Move view logic from StatusController.context to StatusView and add a
test
---
.../controllers/status_controller_test.exs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index f80ce7704..14c7bd6d9 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -1053,4 +1053,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert [] == response
end
end
+
+ test "context" do
+ user = insert(:user)
+
+ {:ok, %{id: id1}} = CommonAPI.post(user, %{"status" => "1"})
+ {:ok, %{id: id2}} = CommonAPI.post(user, %{"status" => "2", "in_reply_to_status_id" => id1})
+ {:ok, %{id: id3}} = CommonAPI.post(user, %{"status" => "3", "in_reply_to_status_id" => id2})
+ {:ok, %{id: id4}} = CommonAPI.post(user, %{"status" => "4", "in_reply_to_status_id" => id3})
+ {:ok, %{id: id5}} = CommonAPI.post(user, %{"status" => "5", "in_reply_to_status_id" => id4})
+
+ response =
+ build_conn()
+ |> assign(:user, nil)
+ |> get("/api/v1/statuses/#{id3}/context")
+ |> json_response(:ok)
+
+ assert %{
+ "ancestors" => [%{"id" => ^id1}, %{"id" => ^id2}],
+ "descendants" => [%{"id" => ^id4}, %{"id" => ^id5}]
+ } = response
+ end
end
--
cgit v1.2.3
From 14294243a294d764b449e1eae19c4cd87b9d4d82 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Fri, 27 Sep 2019 04:22:40 +0000
Subject: mastodon api: implement follow_requests_count
---
test/web/mastodon_api/views/account_view_test.exs | 75 +++++++++++++++++++++++
1 file changed, 75 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index f2f334992..d965f76bf 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -419,4 +419,79 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
} = AccountView.render("account.json", %{user: user, for: user})
end
end
+
+ describe "follow requests counter" do
+ test "shows zero when no follow requests are pending" do
+ user = insert(:user)
+
+ assert %{follow_requests_count: 0} =
+ AccountView.render("account.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{follow_requests_count: 0} =
+ AccountView.render("account.json", %{user: user, for: user})
+ end
+
+ test "shows non-zero when follow requests are pending" do
+ user = insert(:user, %{info: %{locked: true}})
+
+ assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 1} =
+ AccountView.render("account.json", %{user: user, for: user})
+ end
+
+ test "decreases when accepting a follow request" do
+ user = insert(:user, %{info: %{locked: true}})
+
+ assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 1} =
+ AccountView.render("account.json", %{user: user, for: user})
+
+ {:ok, _other_user} = CommonAPI.accept_follow_request(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 0} =
+ AccountView.render("account.json", %{user: user, for: user})
+ end
+
+ test "decreases when rejecting a follow request" do
+ user = insert(:user, %{info: %{locked: true}})
+
+ assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 1} =
+ AccountView.render("account.json", %{user: user, for: user})
+
+ {:ok, _other_user} = CommonAPI.reject_follow_request(other_user, user)
+
+ assert %{locked: true, follow_requests_count: 0} =
+ AccountView.render("account.json", %{user: user, for: user})
+ end
+
+ test "shows non-zero when historical unapproved requests are present" do
+ user = insert(:user, %{info: %{locked: true}})
+
+ assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+
+ other_user = insert(:user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ {:ok, user} = User.update_info(user, &User.Info.user_upgrade(&1, %{locked: false}))
+
+ assert %{locked: false, follow_requests_count: 1} =
+ AccountView.render("account.json", %{user: user, for: user})
+ end
+ end
end
--
cgit v1.2.3
From 621377f378c7cfde88f87356e9fd65ed6d9f6d50 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 27 Sep 2019 13:06:25 +0700
Subject: Extract filter actions from `MastodonAPIController` to
`FilterController`
---
.../controllers/filter_controller_test.exs | 137 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 129 -------------------
2 files changed, 137 insertions(+), 129 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/filter_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/filter_controller_test.exs b/test/web/mastodon_api/controllers/filter_controller_test.exs
new file mode 100644
index 000000000..5d5b56c8e
--- /dev/null
+++ b/test/web/mastodon_api/controllers/filter_controller_test.exs
@@ -0,0 +1,137 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Web.MastodonAPI.FilterView
+
+ import Pleroma.Factory
+
+ test "creating a filter", %{conn: conn} do
+ user = insert(:user)
+
+ filter = %Pleroma.Filter{
+ phrase: "knights",
+ context: ["home"]
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/filters", %{"phrase" => filter.phrase, context: filter.context})
+
+ assert response = json_response(conn, 200)
+ assert response["phrase"] == filter.phrase
+ assert response["context"] == filter.context
+ assert response["irreversible"] == false
+ assert response["id"] != nil
+ assert response["id"] != ""
+ end
+
+ test "fetching a list of filters", %{conn: conn} do
+ user = insert(:user)
+
+ query_one = %Pleroma.Filter{
+ user_id: user.id,
+ filter_id: 1,
+ phrase: "knights",
+ context: ["home"]
+ }
+
+ query_two = %Pleroma.Filter{
+ user_id: user.id,
+ filter_id: 2,
+ phrase: "who",
+ context: ["home"]
+ }
+
+ {:ok, filter_one} = Pleroma.Filter.create(query_one)
+ {:ok, filter_two} = Pleroma.Filter.create(query_two)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/filters")
+ |> json_response(200)
+
+ assert response ==
+ render_json(
+ FilterView,
+ "filters.json",
+ filters: [filter_two, filter_one]
+ )
+ end
+
+ test "get a filter", %{conn: conn} do
+ user = insert(:user)
+
+ query = %Pleroma.Filter{
+ user_id: user.id,
+ filter_id: 2,
+ phrase: "knight",
+ context: ["home"]
+ }
+
+ {:ok, filter} = Pleroma.Filter.create(query)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/filters/#{filter.filter_id}")
+
+ assert _response = json_response(conn, 200)
+ end
+
+ test "update a filter", %{conn: conn} do
+ user = insert(:user)
+
+ query = %Pleroma.Filter{
+ user_id: user.id,
+ filter_id: 2,
+ phrase: "knight",
+ context: ["home"]
+ }
+
+ {:ok, _filter} = Pleroma.Filter.create(query)
+
+ new = %Pleroma.Filter{
+ phrase: "nii",
+ context: ["home"]
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/v1/filters/#{query.filter_id}", %{
+ phrase: new.phrase,
+ context: new.context
+ })
+
+ assert response = json_response(conn, 200)
+ assert response["phrase"] == new.phrase
+ assert response["context"] == new.context
+ end
+
+ test "delete a filter", %{conn: conn} do
+ user = insert(:user)
+
+ query = %Pleroma.Filter{
+ user_id: user.id,
+ filter_id: 2,
+ phrase: "knight",
+ context: ["home"]
+ }
+
+ {:ok, filter} = Pleroma.Filter.create(query)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/api/v1/filters/#{filter.filter_id}")
+
+ assert response = json_response(conn, 200)
+ assert response == %{}
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6435ad7a9..9c6cdbd7a 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -16,7 +16,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.MastodonAPI.FilterView
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.Push
@@ -268,134 +267,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert expected == json_response(conn, 200)
end
- describe "filters" do
- test "creating a filter", %{conn: conn} do
- user = insert(:user)
-
- filter = %Pleroma.Filter{
- phrase: "knights",
- context: ["home"]
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/filters", %{"phrase" => filter.phrase, context: filter.context})
-
- assert response = json_response(conn, 200)
- assert response["phrase"] == filter.phrase
- assert response["context"] == filter.context
- assert response["irreversible"] == false
- assert response["id"] != nil
- assert response["id"] != ""
- end
-
- test "fetching a list of filters", %{conn: conn} do
- user = insert(:user)
-
- query_one = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 1,
- phrase: "knights",
- context: ["home"]
- }
-
- query_two = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "who",
- context: ["home"]
- }
-
- {:ok, filter_one} = Pleroma.Filter.create(query_one)
- {:ok, filter_two} = Pleroma.Filter.create(query_two)
-
- response =
- conn
- |> assign(:user, user)
- |> get("/api/v1/filters")
- |> json_response(200)
-
- assert response ==
- render_json(
- FilterView,
- "filters.json",
- filters: [filter_two, filter_one]
- )
- end
-
- test "get a filter", %{conn: conn} do
- user = insert(:user)
-
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "knight",
- context: ["home"]
- }
-
- {:ok, filter} = Pleroma.Filter.create(query)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/filters/#{filter.filter_id}")
-
- assert _response = json_response(conn, 200)
- end
-
- test "update a filter", %{conn: conn} do
- user = insert(:user)
-
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "knight",
- context: ["home"]
- }
-
- {:ok, _filter} = Pleroma.Filter.create(query)
-
- new = %Pleroma.Filter{
- phrase: "nii",
- context: ["home"]
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/filters/#{query.filter_id}", %{
- phrase: new.phrase,
- context: new.context
- })
-
- assert response = json_response(conn, 200)
- assert response["phrase"] == new.phrase
- assert response["context"] == new.context
- end
-
- test "delete a filter", %{conn: conn} do
- user = insert(:user)
-
- query = %Pleroma.Filter{
- user_id: user.id,
- filter_id: 2,
- phrase: "knight",
- context: ["home"]
- }
-
- {:ok, filter} = Pleroma.Filter.create(query)
-
- conn =
- conn
- |> assign(:user, user)
- |> delete("/api/v1/filters/#{filter.filter_id}")
-
- assert response = json_response(conn, 200)
- assert response == %{}
- end
- end
-
describe "user timelines" do
test "gets a users statuses", %{conn: conn} do
user_one = insert(:user)
--
cgit v1.2.3
From 0a5b106ddd333f2dec2b62badeca98e6091ba805 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 27 Sep 2019 13:35:45 +0700
Subject: Extract scheduled statuses actions from `MastodonAPIController` to
`ScheduledActivityController`
---
.../scheduled_activity_controller_test.exs | 113 +++++++++++
.../controllers/status_controller_test.exs | 112 +++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 212 ---------------------
3 files changed, 225 insertions(+), 212 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs b/test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
new file mode 100644
index 000000000..9ad6a4fa7
--- /dev/null
+++ b/test/web/mastodon_api/controllers/scheduled_activity_controller_test.exs
@@ -0,0 +1,113 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Repo
+ alias Pleroma.ScheduledActivity
+
+ import Pleroma.Factory
+
+ test "shows scheduled activities", %{conn: conn} do
+ user = insert(:user)
+ scheduled_activity_id1 = insert(:scheduled_activity, user: user).id |> to_string()
+ scheduled_activity_id2 = insert(:scheduled_activity, user: user).id |> to_string()
+ scheduled_activity_id3 = insert(:scheduled_activity, user: user).id |> to_string()
+ scheduled_activity_id4 = insert(:scheduled_activity, user: user).id |> to_string()
+
+ conn =
+ conn
+ |> assign(:user, user)
+
+ # min_id
+ conn_res =
+ conn
+ |> get("/api/v1/scheduled_statuses?limit=2&min_id=#{scheduled_activity_id1}")
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
+
+ # since_id
+ conn_res =
+ conn
+ |> get("/api/v1/scheduled_statuses?limit=2&since_id=#{scheduled_activity_id1}")
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^scheduled_activity_id4}, %{"id" => ^scheduled_activity_id3}] = result
+
+ # max_id
+ conn_res =
+ conn
+ |> get("/api/v1/scheduled_statuses?limit=2&max_id=#{scheduled_activity_id4}")
+
+ result = json_response(conn_res, 200)
+ assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
+ end
+
+ test "shows a scheduled activity", %{conn: conn} do
+ user = insert(:user)
+ scheduled_activity = insert(:scheduled_activity, user: user)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
+
+ assert %{"id" => scheduled_activity_id} = json_response(res_conn, 200)
+ assert scheduled_activity_id == scheduled_activity.id |> to_string()
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/scheduled_statuses/404")
+
+ assert %{"error" => "Record not found"} = json_response(res_conn, 404)
+ end
+
+ test "updates a scheduled activity", %{conn: conn} do
+ user = insert(:user)
+ scheduled_activity = insert(:scheduled_activity, user: user)
+
+ new_scheduled_at =
+ NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
+ scheduled_at: new_scheduled_at
+ })
+
+ assert %{"scheduled_at" => expected_scheduled_at} = json_response(res_conn, 200)
+ assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(new_scheduled_at)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
+
+ assert %{"error" => "Record not found"} = json_response(res_conn, 404)
+ end
+
+ test "deletes a scheduled activity", %{conn: conn} do
+ user = insert(:user)
+ scheduled_activity = insert(:scheduled_activity, user: user)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
+
+ assert %{} = json_response(res_conn, 200)
+ assert nil == Repo.get(ScheduledActivity, scheduled_activity.id)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
+
+ assert %{"error" => "Record not found"} = json_response(res_conn, 404)
+ end
+end
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index 14c7bd6d9..cbd4bafe8 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -9,7 +9,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
alias Pleroma.ActivityExpiration
alias Pleroma.Config
alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.ScheduledActivity
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -224,6 +227,115 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
end
end
+ describe "posting scheduled statuses" do
+ test "creates a scheduled activity", %{conn: conn} do
+ user = insert(:user)
+ scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "scheduled",
+ "scheduled_at" => scheduled_at
+ })
+
+ assert %{"scheduled_at" => expected_scheduled_at} = json_response(conn, 200)
+ assert expected_scheduled_at == CommonAPI.Utils.to_masto_date(scheduled_at)
+ assert [] == Repo.all(Activity)
+ end
+
+ test "creates a scheduled activity with a media attachment", %{conn: conn} do
+ user = insert(:user)
+ scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "media_ids" => [to_string(upload.id)],
+ "status" => "scheduled",
+ "scheduled_at" => scheduled_at
+ })
+
+ assert %{"media_attachments" => [media_attachment]} = json_response(conn, 200)
+ assert %{"type" => "image"} = media_attachment
+ end
+
+ test "skips the scheduling and creates the activity if scheduled_at is earlier than 5 minutes from now",
+ %{conn: conn} do
+ user = insert(:user)
+
+ scheduled_at =
+ NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(5) - 1, :millisecond)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "not scheduled",
+ "scheduled_at" => scheduled_at
+ })
+
+ assert %{"content" => "not scheduled"} = json_response(conn, 200)
+ assert [] == Repo.all(ScheduledActivity)
+ end
+
+ test "returns error when daily user limit is exceeded", %{conn: conn} do
+ user = insert(:user)
+
+ today =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+
+ attrs = %{params: %{}, scheduled_at: today}
+ {:ok, _} = ScheduledActivity.create(user, attrs)
+ {:ok, _} = ScheduledActivity.create(user, attrs)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today})
+
+ assert %{"error" => "daily limit exceeded"} == json_response(conn, 422)
+ end
+
+ test "returns error when total user limit is exceeded", %{conn: conn} do
+ user = insert(:user)
+
+ today =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+
+ tomorrow =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.hours(36), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+
+ attrs = %{params: %{}, scheduled_at: today}
+ {:ok, _} = ScheduledActivity.create(user, attrs)
+ {:ok, _} = ScheduledActivity.create(user, attrs)
+ {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow})
+
+ assert %{"error" => "total limit exceeded"} == json_response(conn, 422)
+ end
+ end
+
describe "posting polls" do
test "posting a poll", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6435ad7a9..e77610ba3 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -6,12 +6,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
alias Ecto.Changeset
- alias Pleroma.Activity
alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
- alias Pleroma.ScheduledActivity
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -1810,216 +1808,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "scheduled activities" do
- test "creates a scheduled activity", %{conn: conn} do
- user = insert(:user)
- scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "scheduled",
- "scheduled_at" => scheduled_at
- })
-
- assert %{"scheduled_at" => expected_scheduled_at} = json_response(conn, 200)
- assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(scheduled_at)
- assert [] == Repo.all(Activity)
- end
-
- test "creates a scheduled activity with a media attachment", %{conn: conn} do
- user = insert(:user)
- scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "media_ids" => [to_string(upload.id)],
- "status" => "scheduled",
- "scheduled_at" => scheduled_at
- })
-
- assert %{"media_attachments" => [media_attachment]} = json_response(conn, 200)
- assert %{"type" => "image"} = media_attachment
- end
-
- test "skips the scheduling and creates the activity if scheduled_at is earlier than 5 minutes from now",
- %{conn: conn} do
- user = insert(:user)
-
- scheduled_at =
- NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(5) - 1, :millisecond)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{
- "status" => "not scheduled",
- "scheduled_at" => scheduled_at
- })
-
- assert %{"content" => "not scheduled"} = json_response(conn, 200)
- assert [] == Repo.all(ScheduledActivity)
- end
-
- test "returns error when daily user limit is exceeded", %{conn: conn} do
- user = insert(:user)
-
- today =
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
- |> NaiveDateTime.to_iso8601()
-
- attrs = %{params: %{}, scheduled_at: today}
- {:ok, _} = ScheduledActivity.create(user, attrs)
- {:ok, _} = ScheduledActivity.create(user, attrs)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today})
-
- assert %{"error" => "daily limit exceeded"} == json_response(conn, 422)
- end
-
- test "returns error when total user limit is exceeded", %{conn: conn} do
- user = insert(:user)
-
- today =
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
- |> NaiveDateTime.to_iso8601()
-
- tomorrow =
- NaiveDateTime.utc_now()
- |> NaiveDateTime.add(:timer.hours(36), :millisecond)
- |> NaiveDateTime.to_iso8601()
-
- attrs = %{params: %{}, scheduled_at: today}
- {:ok, _} = ScheduledActivity.create(user, attrs)
- {:ok, _} = ScheduledActivity.create(user, attrs)
- {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow})
-
- assert %{"error" => "total limit exceeded"} == json_response(conn, 422)
- end
-
- test "shows scheduled activities", %{conn: conn} do
- user = insert(:user)
- scheduled_activity_id1 = insert(:scheduled_activity, user: user).id |> to_string()
- scheduled_activity_id2 = insert(:scheduled_activity, user: user).id |> to_string()
- scheduled_activity_id3 = insert(:scheduled_activity, user: user).id |> to_string()
- scheduled_activity_id4 = insert(:scheduled_activity, user: user).id |> to_string()
-
- conn =
- conn
- |> assign(:user, user)
-
- # min_id
- conn_res =
- conn
- |> get("/api/v1/scheduled_statuses?limit=2&min_id=#{scheduled_activity_id1}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
-
- # since_id
- conn_res =
- conn
- |> get("/api/v1/scheduled_statuses?limit=2&since_id=#{scheduled_activity_id1}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^scheduled_activity_id4}, %{"id" => ^scheduled_activity_id3}] = result
-
- # max_id
- conn_res =
- conn
- |> get("/api/v1/scheduled_statuses?limit=2&max_id=#{scheduled_activity_id4}")
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
- end
-
- test "shows a scheduled activity", %{conn: conn} do
- user = insert(:user)
- scheduled_activity = insert(:scheduled_activity, user: user)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
-
- assert %{"id" => scheduled_activity_id} = json_response(res_conn, 200)
- assert scheduled_activity_id == scheduled_activity.id |> to_string()
-
- res_conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/scheduled_statuses/404")
-
- assert %{"error" => "Record not found"} = json_response(res_conn, 404)
- end
-
- test "updates a scheduled activity", %{conn: conn} do
- user = insert(:user)
- scheduled_activity = insert(:scheduled_activity, user: user)
-
- new_scheduled_at =
- NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
- scheduled_at: new_scheduled_at
- })
-
- assert %{"scheduled_at" => expected_scheduled_at} = json_response(res_conn, 200)
- assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(new_scheduled_at)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
-
- assert %{"error" => "Record not found"} = json_response(res_conn, 404)
- end
-
- test "deletes a scheduled activity", %{conn: conn} do
- user = insert(:user)
- scheduled_activity = insert(:scheduled_activity, user: user)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
-
- assert %{} = json_response(res_conn, 200)
- assert nil == Repo.get(ScheduledActivity, scheduled_activity.id)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
-
- assert %{"error" => "Record not found"} = json_response(res_conn, 404)
- end
- end
-
describe "create account by app" do
test "Account registration via Application", %{conn: conn} do
conn =
--
cgit v1.2.3
From 99c5a35890f470c30661e900380bcd7c4b75d6d0 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 27 Sep 2019 14:25:17 +0700
Subject: Extract follow requests actions from `MastodonAPIController` to
`FollowRequestController`
---
.../controllers/follow_request_controller_test.exs | 81 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 67 ------------------
2 files changed, 81 insertions(+), 67 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/follow_request_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/follow_request_controller_test.exs b/test/web/mastodon_api/controllers/follow_request_controller_test.exs
new file mode 100644
index 000000000..4bf292df5
--- /dev/null
+++ b/test/web/mastodon_api/controllers/follow_request_controller_test.exs
@@ -0,0 +1,81 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
+
+ import Pleroma.Factory
+
+ describe "locked accounts" do
+ test "/api/v1/follow_requests works" do
+ user = insert(:user, %{info: %User.Info{locked: true}})
+ other_user = insert(:user)
+
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
+
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/follow_requests")
+
+ assert [relationship] = json_response(conn, 200)
+ assert to_string(other_user.id) == relationship["id"]
+ end
+
+ test "/api/v1/follow_requests/:id/authorize works" do
+ user = insert(:user, %{info: %User.Info{locked: true}})
+ other_user = insert(:user)
+
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
+
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/follow_requests/#{other_user.id}/authorize")
+
+ assert relationship = json_response(conn, 200)
+ assert to_string(other_user.id) == relationship["id"]
+
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
+
+ assert User.following?(other_user, user) == true
+ end
+
+ test "/api/v1/follow_requests/:id/reject works" do
+ user = insert(:user, %{info: %User.Info{locked: true}})
+ other_user = insert(:user)
+
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
+
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/follow_requests/#{other_user.id}/reject")
+
+ assert relationship = json_response(conn, 200)
+ assert to_string(other_user.id) == relationship["id"]
+
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
+
+ assert User.following?(other_user, user) == false
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6435ad7a9..60ade00d2 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -570,51 +570,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
describe "locked accounts" do
- test "/api/v1/follow_requests works" do
- user = insert(:user, %{info: %User.Info{locked: true}})
- other_user = insert(:user)
-
- {:ok, _activity} = ActivityPub.follow(other_user, user)
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == false
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> get("/api/v1/follow_requests")
-
- assert [relationship] = json_response(conn, 200)
- assert to_string(other_user.id) == relationship["id"]
- end
-
- test "/api/v1/follow_requests/:id/authorize works" do
- user = insert(:user, %{info: %User.Info{locked: true}})
- other_user = insert(:user)
-
- {:ok, _activity} = ActivityPub.follow(other_user, user)
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == false
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/follow_requests/#{other_user.id}/authorize")
-
- assert relationship = json_response(conn, 200)
- assert to_string(other_user.id) == relationship["id"]
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == true
- end
-
test "verify_credentials", %{conn: conn} do
user = insert(:user, %{info: %User.Info{default_scope: "private"}})
@@ -626,28 +581,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "source" => %{"privacy" => "private"}} = json_response(conn, 200)
assert id == to_string(user.id)
end
-
- test "/api/v1/follow_requests/:id/reject works" do
- user = insert(:user, %{info: %User.Info{locked: true}})
- other_user = insert(:user)
-
- {:ok, _activity} = ActivityPub.follow(other_user, user)
-
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/follow_requests/#{other_user.id}/reject")
-
- assert relationship = json_response(conn, 200)
- assert to_string(other_user.id) == relationship["id"]
-
- user = User.get_cached_by_id(user.id)
- other_user = User.get_cached_by_id(other_user.id)
-
- assert User.following?(other_user, user) == false
- end
end
describe "account fetching" do
--
cgit v1.2.3
From 408750b94e1374c815c80a1060892231f40b54fb Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 27 Sep 2019 14:28:05 +0700
Subject: Extract domain blocks actions from `MastodonAPIController` to
`DomainBlockController`
---
.../controllers/domain_block_controller_test.exs | 51 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 40 -----------------
2 files changed, 51 insertions(+), 40 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/domain_block_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/domain_block_controller_test.exs b/test/web/mastodon_api/controllers/domain_block_controller_test.exs
new file mode 100644
index 000000000..3c3558385
--- /dev/null
+++ b/test/web/mastodon_api/controllers/domain_block_controller_test.exs
@@ -0,0 +1,51 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.User
+
+ import Pleroma.Factory
+
+ test "blocking / unblocking a domain", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
+
+ assert %{} = json_response(conn, 200)
+ user = User.get_cached_by_ap_id(user.ap_id)
+ assert User.blocks?(user, other_user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
+
+ assert %{} = json_response(conn, 200)
+ user = User.get_cached_by_ap_id(user.ap_id)
+ refute User.blocks?(user, other_user)
+ end
+
+ test "getting a list of domain blocks", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, user} = User.block_domain(user, "bad.site")
+ {:ok, user} = User.block_domain(user, "even.worse.site")
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/domain_blocks")
+
+ domain_blocks = json_response(conn, 200)
+
+ assert "bad.site" in domain_blocks
+ assert "even.worse.site" in domain_blocks
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6435ad7a9..5bd76d431 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1176,46 +1176,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
end
- test "blocking / unblocking a domain", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
-
- assert %{} = json_response(conn, 200)
- user = User.get_cached_by_ap_id(user.ap_id)
- assert User.blocks?(user, other_user)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
-
- assert %{} = json_response(conn, 200)
- user = User.get_cached_by_ap_id(user.ap_id)
- refute User.blocks?(user, other_user)
- end
-
- test "getting a list of domain blocks", %{conn: conn} do
- user = insert(:user)
-
- {:ok, user} = User.block_domain(user, "bad.site")
- {:ok, user} = User.block_domain(user, "even.worse.site")
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/domain_blocks")
-
- domain_blocks = json_response(conn, 200)
-
- assert "bad.site" in domain_blocks
- assert "even.worse.site" in domain_blocks
- end
-
test "unimplemented follow_requests, blocks, domain blocks" do
user = insert(:user)
--
cgit v1.2.3
From f9380289eb251c818e87e8f0ad0a41fc8bdd90aa Mon Sep 17 00:00:00 2001
From: minibikini
Date: Fri, 27 Sep 2019 21:59:23 +0000
Subject: Add `remote_ip` plug
---
test/plugs/remote_ip_test.exs | 72 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100644 test/plugs/remote_ip_test.exs
(limited to 'test')
diff --git a/test/plugs/remote_ip_test.exs b/test/plugs/remote_ip_test.exs
new file mode 100644
index 000000000..d120c588b
--- /dev/null
+++ b/test/plugs/remote_ip_test.exs
@@ -0,0 +1,72 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Plugs.RemoteIpTest do
+ use ExUnit.Case, async: true
+ use Plug.Test
+
+ alias Pleroma.Plugs.RemoteIp
+
+ test "disabled" do
+ Pleroma.Config.put(RemoteIp, enabled: false)
+
+ %{remote_ip: remote_ip} = conn(:get, "/")
+
+ conn =
+ conn(:get, "/")
+ |> put_req_header("x-forwarded-for", "1.1.1.1")
+ |> RemoteIp.call(nil)
+
+ assert conn.remote_ip == remote_ip
+ end
+
+ test "enabled" do
+ Pleroma.Config.put(RemoteIp, enabled: true)
+
+ conn =
+ conn(:get, "/")
+ |> put_req_header("x-forwarded-for", "1.1.1.1")
+ |> RemoteIp.call(nil)
+
+ assert conn.remote_ip == {1, 1, 1, 1}
+ end
+
+ test "custom headers" do
+ Pleroma.Config.put(RemoteIp, enabled: true, headers: ["cf-connecting-ip"])
+
+ conn =
+ conn(:get, "/")
+ |> put_req_header("x-forwarded-for", "1.1.1.1")
+ |> RemoteIp.call(nil)
+
+ refute conn.remote_ip == {1, 1, 1, 1}
+
+ conn =
+ conn(:get, "/")
+ |> put_req_header("cf-connecting-ip", "1.1.1.1")
+ |> RemoteIp.call(nil)
+
+ assert conn.remote_ip == {1, 1, 1, 1}
+ end
+
+ test "custom proxies" do
+ Pleroma.Config.put(RemoteIp, enabled: true)
+
+ conn =
+ conn(:get, "/")
+ |> put_req_header("x-forwarded-for", "173.245.48.1, 1.1.1.1, 173.245.48.2")
+ |> RemoteIp.call(nil)
+
+ refute conn.remote_ip == {1, 1, 1, 1}
+
+ Pleroma.Config.put([RemoteIp, :proxies], ["173.245.48.0/20"])
+
+ conn =
+ conn(:get, "/")
+ |> put_req_header("x-forwarded-for", "173.245.48.1, 1.1.1.1, 173.245.48.2")
+ |> RemoteIp.call(nil)
+
+ assert conn.remote_ip == {1, 1, 1, 1}
+ end
+end
--
cgit v1.2.3
From 374f83d29b5793d75a3a6be7c18cf52cfed42b64 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 28 Sep 2019 01:56:20 +0300
Subject: Fix not being able to post empty statuses with attachments
Attachment field was filled in after the empty status check
---
.../controllers/status_controller_test.exs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index cbd4bafe8..c0121ac63 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -99,6 +99,28 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
NaiveDateTime.to_iso8601(expiration.scheduled_at)
end
+ test "posting an empty status with an attachment", %{conn: conn} do
+ user = insert(:user)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "media_ids" => [to_string(upload.id)],
+ "status" => ""
+ })
+
+ assert json_response(conn, 200)
+ end
+
test "replying to a status", %{conn: conn} do
user = insert(:user)
{:ok, replied_to} = CommonAPI.post(user, %{"status" => "cofe"})
--
cgit v1.2.3
From 9202904da9b48eb2a3884b8e89ea879e01d44b9a Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sat, 28 Sep 2019 01:21:28 +0200
Subject: status_controller.ex: Posting media status without content defined
---
test/web/mastodon_api/controllers/status_controller_test.exs | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index c0121ac63..b194feae6 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -99,7 +99,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
NaiveDateTime.to_iso8601(expiration.scheduled_at)
end
- test "posting an empty status with an attachment", %{conn: conn} do
+ test "posting an undefined status with an attachment", %{conn: conn} do
user = insert(:user)
file = %Plug.Upload{
@@ -114,8 +114,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
conn
|> assign(:user, user)
|> post("/api/v1/statuses", %{
- "media_ids" => [to_string(upload.id)],
- "status" => ""
+ "media_ids" => [to_string(upload.id)]
})
assert json_response(conn, 200)
--
cgit v1.2.3
From e9d1aa75d5dc0859b692e891f6e65949208a5f0f Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sun, 29 Sep 2019 18:43:27 +0300
Subject: Revert subscription refactoring.
As discussed in pleroma-meta#2
This reverts commit eb9aa7aa1095de150d036839c78c402019efb4b1, reversing
changes made to c4fbb56984d8f86df948cfd9b0f7c081d688c365.
---
test/notification_test.exs | 12 +-
test/web/mastodon_api/mastodon_api_test.exs | 4 +-
.../controllers/pleroma_api_controller_test.exs | 150 -------------
.../subscription_notification_controller_test.exs | 234 ---------------------
.../pleroma_api/pleroma_api_controller_test.exs | 150 +++++++++++++
5 files changed, 157 insertions(+), 393 deletions(-)
delete mode 100644 test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
delete mode 100644 test/web/pleroma_api/controllers/subscription_notification_controller_test.exs
create mode 100644 test/web/pleroma_api/pleroma_api_controller_test.exs
(limited to 'test')
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 1dbad34c1..54c0f9877 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -33,16 +33,16 @@ defmodule Pleroma.NotificationTest do
assert other_notification.activity_id == activity.id
end
- test "it does not create a notification for subscribed users" do
+ test "it creates a notification for subscribed users" do
user = insert(:user)
subscriber = insert(:user)
User.subscribe(subscriber, user)
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
- {:ok, notifications} = Notification.create_notifications(status)
+ {:ok, [notification]} = Notification.create_notifications(status)
- assert notifications == []
+ assert notification.user_id == subscriber.id
end
test "does not create a notification for subscribed users if status is a reply" do
@@ -182,16 +182,14 @@ defmodule Pleroma.NotificationTest do
refute Notification.create_notification(activity_dupe, followed_user)
end
- test "it doesn't create notifications for follow+subscribed users" do
+ test "it doesn't create duplicate notifications for follow+subscribed users" do
user = insert(:user)
subscriber = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(subscriber, user)
User.subscribe(subscriber, user)
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
- {:ok, notifications} = Notification.create_notifications(status)
-
- assert notifications == []
+ {:ok, [_notif]} = Notification.create_notifications(status)
end
test "it doesn't create subscription notifications if the recipient cannot see the status" do
diff --git a/test/web/mastodon_api/mastodon_api_test.exs b/test/web/mastodon_api/mastodon_api_test.exs
index 848fce7ad..7fcb2bd55 100644
--- a/test/web/mastodon_api/mastodon_api_test.exs
+++ b/test/web/mastodon_api/mastodon_api_test.exs
@@ -75,9 +75,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
User.subscribe(subscriber, user)
- {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin @#{subscriber.nickname}"})
+ {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
- {:ok, status1} = CommonAPI.post(user, %{"status" => "Magi @#{subscriber.nickname}"})
+ {:ok, status1} = CommonAPI.post(user, %{"status" => "Magi"})
{:ok, [notification]} = Notification.create_notifications(status)
{:ok, [notification1]} = Notification.create_notifications(status1)
res = MastodonAPI.get_notifications(subscriber)
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
deleted file mode 100644
index 7eaeda4a0..000000000
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ /dev/null
@@ -1,150 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Conversation.Participation
- alias Pleroma.Notification
- alias Pleroma.Repo
- alias Pleroma.Web.CommonAPI
-
- import Pleroma.Factory
-
- test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
-
- [participation] = Participation.for_user(other_user)
-
- result =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/pleroma/conversations/#{participation.id}")
- |> json_response(200)
-
- assert result["id"] == participation.id |> to_string()
- end
-
- test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- third_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
-
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
-
- [participation] = Participation.for_user(other_user)
-
- {:ok, activity_two} =
- CommonAPI.post(other_user, %{
- "status" => "Hi!",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
- })
-
- result =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
- |> json_response(200)
-
- assert length(result) == 2
-
- id_one = activity.id
- id_two = activity_two.id
- assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
- end
-
- test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
-
- [participation] = Participation.for_user(user)
-
- participation = Repo.preload(participation, :recipients)
-
- assert [user] == participation.recipients
- assert other_user not in participation.recipients
-
- result =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
- "recipients" => [user.id, other_user.id]
- })
- |> json_response(200)
-
- assert result["id"] == participation.id |> to_string
-
- [participation] = Participation.for_user(user)
- participation = Repo.preload(participation, :recipients)
-
- assert user in participation.recipients
- assert other_user in participation.recipients
- end
-
- describe "POST /api/v1/pleroma/notifications/read" do
- test "it marks a single notification as read", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, [notification1]} = Notification.create_notifications(activity1)
- {:ok, [notification2]} = Notification.create_notifications(activity2)
-
- response =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
- |> json_response(:ok)
-
- assert %{"pleroma" => %{"is_seen" => true}} = response
- assert Repo.get(Notification, notification1.id).seen
- refute Repo.get(Notification, notification2.id).seen
- end
-
- test "it marks multiple notifications as read", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
-
- [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
-
- [response1, response2] =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
- |> json_response(:ok)
-
- assert %{"pleroma" => %{"is_seen" => true}} = response1
- assert %{"pleroma" => %{"is_seen" => true}} = response2
- assert Repo.get(Notification, notification1.id).seen
- assert Repo.get(Notification, notification2.id).seen
- refute Repo.get(Notification, notification3.id).seen
- end
-
- test "it returns error when notification not found", %{conn: conn} do
- user1 = insert(:user)
-
- response =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
- |> json_response(:bad_request)
-
- assert response == %{"error" => "Cannot get notification"}
- end
- end
-end
diff --git a/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs b/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs
deleted file mode 100644
index c6a71732d..000000000
--- a/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs
+++ /dev/null
@@ -1,234 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Repo
- alias Pleroma.SubscriptionNotification
- alias Pleroma.User
- alias Pleroma.Web.CommonAPI
- import Pleroma.Factory
- import Tesla.Mock
-
- setup do
- mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- :ok
- end
-
- clear_config([:instance, :public])
- clear_config([:rich_media, :enabled])
-
- describe "subscription_notifications" do
- setup do
- user = insert(:user)
- subscriber = insert(:user)
-
- User.subscribe(subscriber, user)
-
- {:ok, %{user: user, subscriber: subscriber}}
- end
-
- test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
- status_text = "Hello"
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
- path = subscription_notification_path(conn, :index)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> get(path)
-
- assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
- assert response == status_text
- end
-
- test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
- status_text = "Hello"
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
- [notification] = Repo.all(SubscriptionNotification)
-
- path = subscription_notification_path(conn, :show, notification)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> get(path)
-
- assert %{"status" => %{"content" => response}} = json_response(conn, 200)
- assert response == status_text
- end
-
- test "dismissing a single notification also deletes it", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- status_text = "Hello"
- {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
-
- [notification] = Repo.all(SubscriptionNotification)
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> post(subscription_notification_path(conn, :dismiss), %{"id" => notification.id})
-
- assert %{} = json_response(conn, 200)
-
- assert Repo.all(SubscriptionNotification) == []
- end
-
- test "clearing all notifications also deletes them", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- status_text1 = "Hello"
- status_text2 = "Hello again"
- {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
- {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
-
- conn =
- conn
- |> assign(:user, subscriber)
- |> post(subscription_notification_path(conn, :clear))
-
- assert %{} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, subscriber)
- |> get(subscription_notification_path(conn, :index))
-
- assert json_response(conn, 200) == []
-
- assert Repo.all(SubscriptionNotification) == []
- end
-
- test "paginates notifications using min_id, since_id, max_id, and limit", %{
- conn: conn,
- user: user,
- subscriber: subscriber
- } do
- {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
- {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
- {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
- {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
-
- notification1_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
-
- notification2_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
-
- notification3_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
-
- notification4_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
-
- conn = assign(conn, :user, subscriber)
-
- # min_id
- conn_res =
- get(
- conn,
- subscription_notification_path(conn, :index, %{
- "limit" => 2,
- "min_id" => notification1_id
- })
- )
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
-
- # since_id
- conn_res =
- get(
- conn,
- subscription_notification_path(conn, :index, %{
- "limit" => 2,
- "since_id" => notification1_id
- })
- )
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
-
- # max_id
- conn_res =
- get(
- conn,
- subscription_notification_path(conn, :index, %{
- "limit" => 2,
- "max_id" => notification4_id
- })
- )
-
- result = json_response(conn_res, 200)
- assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
- end
-
- test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
- # mutual subscription
- User.subscribe(user1, user2)
-
- {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
- {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
- {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
- {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
-
- notification1_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
-
- notification2_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
-
- notification3_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
-
- notification4_id =
- Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
-
- conn = assign(conn, :user, user1)
-
- conn_res = get(conn, subscription_notification_path(conn, :index))
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification3_id, notification4_id]
- end)
-
- conn2 = assign(conn, :user, user2)
-
- conn_res = get(conn2, subscription_notification_path(conn, :index))
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification1_id, notification2_id]
- end)
-
- conn_destroy =
- delete(conn, subscription_notification_path(conn, :destroy_multiple), %{
- "ids" => [notification3_id, notification4_id]
- })
-
- assert json_response(conn_destroy, 200) == %{}
-
- conn_res = get(conn2, subscription_notification_path(conn, :index))
-
- result = json_response(conn_res, 200)
-
- Enum.each(result, fn %{"id" => id} ->
- assert id in [notification1_id, notification2_id]
- end)
-
- assert length(Repo.all(SubscriptionNotification)) == 2
- end
- end
-end
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
new file mode 100644
index 000000000..7eaeda4a0
--- /dev/null
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -0,0 +1,150 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Notification
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}")
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string()
+ end
+
+ test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ {:ok, activity_two} =
+ CommonAPI.post(other_user, %{
+ "status" => "Hi!",
+ "in_reply_to_status_id" => activity.id,
+ "in_reply_to_conversation_id" => participation.id
+ })
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
+ |> json_response(200)
+
+ assert length(result) == 2
+
+ id_one = activity.id
+ id_two = activity_two.id
+ assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
+ end
+
+ test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert [user] == participation.recipients
+ assert other_user not in participation.recipients
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
+ "recipients" => [user.id, other_user.id]
+ })
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string
+
+ [participation] = Participation.for_user(user)
+ participation = Repo.preload(participation, :recipients)
+
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+ end
+
+ describe "POST /api/v1/pleroma/notifications/read" do
+ test "it marks a single notification as read", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, [notification1]} = Notification.create_notifications(activity1)
+ {:ok, [notification2]} = Notification.create_notifications(activity2)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
+ |> json_response(:ok)
+
+ assert %{"pleroma" => %{"is_seen" => true}} = response
+ assert Repo.get(Notification, notification1.id).seen
+ refute Repo.get(Notification, notification2.id).seen
+ end
+
+ test "it marks multiple notifications as read", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
+
+ [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
+
+ [response1, response2] =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
+ |> json_response(:ok)
+
+ assert %{"pleroma" => %{"is_seen" => true}} = response1
+ assert %{"pleroma" => %{"is_seen" => true}} = response2
+ assert Repo.get(Notification, notification1.id).seen
+ assert Repo.get(Notification, notification2.id).seen
+ refute Repo.get(Notification, notification3.id).seen
+ end
+
+ test "it returns error when notification not found", %{conn: conn} do
+ user1 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
+ |> json_response(:bad_request)
+
+ assert response == %{"error" => "Cannot get notification"}
+ end
+ end
+end
--
cgit v1.2.3
From d4d88b3361ea57d763c5093470b7ebaee6bcf11c Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 16:52:07 +0700
Subject: Extract conversation actions from `MastodonAPIController` to
ConversationController
---
.../controllers/conversation_controller_test.exs | 75 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 63 ------------------
2 files changed, 75 insertions(+), 63 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/conversation_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/conversation_controller_test.exs b/test/web/mastodon_api/controllers/conversation_controller_test.exs
new file mode 100644
index 000000000..7117fc76a
--- /dev/null
+++ b/test/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -0,0 +1,75 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "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)
+
+ {:ok, direct} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, _follower_only} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "private"
+ })
+
+ res_conn =
+ conn
+ |> assign(:user, user_one)
+ |> get("/api/v1/conversations")
+
+ assert response = json_response(res_conn, 200)
+
+ assert [
+ %{
+ "id" => res_id,
+ "accounts" => res_accounts,
+ "last_status" => res_last_status,
+ "unread" => unread
+ }
+ ] = response
+
+ account_ids = Enum.map(res_accounts, & &1["id"])
+ assert length(res_accounts) == 2
+ assert user_two.id in account_ids
+ assert user_three.id in account_ids
+ assert is_binary(res_id)
+ assert unread == true
+ assert res_last_status["id"] == direct.id
+
+ # 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")
+
+ assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b3acb7a22..8080d3941 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -33,69 +33,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
clear_config([:instance, :public])
clear_config([:rich_media, :enabled])
- test "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)
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
- "visibility" => "direct"
- })
-
- {:ok, _follower_only} =
- CommonAPI.post(user_one, %{
- "status" => "Hi @#{user_two.nickname}!",
- "visibility" => "private"
- })
-
- res_conn =
- conn
- |> assign(:user, user_one)
- |> get("/api/v1/conversations")
-
- assert response = json_response(res_conn, 200)
-
- assert [
- %{
- "id" => res_id,
- "accounts" => res_accounts,
- "last_status" => res_last_status,
- "unread" => unread
- }
- ] = response
-
- account_ids = Enum.map(res_accounts, & &1["id"])
- assert length(res_accounts) == 2
- assert user_two.id in account_ids
- assert user_three.id in account_ids
- assert is_binary(res_id)
- assert unread == true
- assert res_last_status["id"] == direct.id
-
- # 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")
-
- assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
- end
-
test "verify_credentials", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From c3d09921e4dd13f02ab141bba9ba8372f70bab76 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Fri, 27 Sep 2019 11:15:20 +0000
Subject: test: factory: implement support for generating mock audio and listen
objects
---
test/support/factory.ex | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
(limited to 'test')
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 719115003..4f3244025 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -71,6 +71,47 @@ defmodule Pleroma.Factory do
}
end
+ def audio_factory(attrs \\ %{}) do
+ text = sequence(:text, &"lain radio episode #{&1}")
+
+ user = attrs[:user] || insert(:user)
+
+ data = %{
+ "type" => "Audio",
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
+ "artist" => "lain",
+ "title" => text,
+ "album" => "lain radio",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "actor" => user.ap_id,
+ "length" => 180_000
+ }
+
+ %Pleroma.Object{
+ data: merge_attributes(data, Map.get(attrs, :data, %{}))
+ }
+ end
+
+ def listen_factory do
+ audio = insert(:audio)
+
+ data = %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+ "type" => "Listen",
+ "actor" => audio.data["actor"],
+ "to" => audio.data["to"],
+ "object" => audio.data,
+ "published" => audio.data["published"]
+ }
+
+ %Pleroma.Activity{
+ data: data,
+ actor: data["actor"],
+ recipients: data["to"]
+ }
+ end
+
def direct_note_factory do
user2 = insert(:user)
--
cgit v1.2.3
From b7877e9b1c61e42d60bb65deef0cec7f1103dd89 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Fri, 27 Sep 2019 11:40:40 +0000
Subject: mastodon api: implement rendering of listen activities
---
test/web/mastodon_api/views/status_view_test.exs | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index c17d0ef95..683132f8d 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -608,4 +608,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert status.visibility == "list"
end
+
+ test "successfully renders a Listen activity (pleroma extension)" do
+ listen_activity = insert(:listen)
+
+ status = StatusView.render("listen.json", activity: listen_activity)
+
+ assert status.length == listen_activity.data["object"]["length"]
+ assert status.title == listen_activity.data["object"]["title"]
+ end
end
--
cgit v1.2.3
From 1f9de2a8cdc1913b26afab1f914aea526db608d8 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Fri, 27 Sep 2019 12:22:35 +0000
Subject: activitypub: implement IR-level considerations for Listen activities
---
test/web/activity_pub/activity_pub_test.exs | 36 +++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f28fd6871..a203d1d30 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -257,6 +257,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ describe "listen activities" do
+ test "does not increase user note count" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ ActivityPub.listen(%{
+ to: ["https://www.w3.org/ns/activitystreams#Public"],
+ actor: user,
+ context: "",
+ object: %{
+ "actor" => user.ap_id,
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "artist" => "lain",
+ "title" => "lain radio episode 1",
+ "length" => 180_000,
+ "type" => "Audio"
+ }
+ })
+
+ assert activity.actor == user.ap_id
+
+ user = User.get_cached_by_id(user.id)
+ assert user.info.note_count == 0
+ end
+
+ test "can be fetched into a timeline" do
+ _listen_activity_1 = insert(:listen)
+ _listen_activity_2 = insert(:listen)
+ _listen_activity_3 = insert(:listen)
+
+ timeline = ActivityPub.fetch_activities([], %{"type" => ["Listen"]})
+
+ assert length(timeline) == 3
+ end
+ end
+
describe "create activities" do
test "removes doubled 'to' recipients" do
user = insert(:user)
--
cgit v1.2.3
From 172c74a77baf5b8910987e19c620158d0497d16a Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Fri, 27 Sep 2019 12:40:31 +0000
Subject: activitypub: transmogrifier: implement support for Listen activities
---
test/web/activity_pub/transmogrifier_test.exs | 29 +++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index a35db71dc..9040c87ca 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -177,6 +177,35 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end)
end
+ test "it works for incoming listens" do
+ data = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Listen",
+ "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
+ "actor" => "http://mastodon.example.org/users/admin",
+ "object" => %{
+ "type" => "Audio",
+ "id" => "http://mastodon.example.org/users/admin/listens/1234",
+ "attributedTo" => "http://mastodon.example.org/users/admin",
+ "title" => "lain radio episode 1",
+ "artist" => "lain",
+ "album" => "lain radio",
+ "length" => 180_000
+ }
+ }
+
+ {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+ object = Object.normalize(activity)
+
+ assert object.data["title"] == "lain radio episode 1"
+ assert object.data["artist"] == "lain"
+ assert object.data["album"] == "lain radio"
+ assert object.data["length"] == 180_000
+ end
+
test "it rewrites Note votes to Answers and increments vote counters on question activities" do
user = insert(:user)
--
cgit v1.2.3
From 2c82d8603bb4c3f7281023752dc78aa31a814ab6 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sat, 28 Sep 2019 00:24:32 +0000
Subject: common api: implement scrobbling
---
test/web/common_api/common_api_test.exs | 39 +++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index f28a66090..0f4a5eb25 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -510,4 +510,43 @@ defmodule Pleroma.Web.CommonAPITest do
assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
end
end
+
+ describe "listen/2" do
+ test "returns a valid activity" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.listen(user, %{
+ "title" => "lain radio episode 1",
+ "album" => "lain radio",
+ "artist" => "lain",
+ "length" => 180_000
+ })
+
+ object = Object.normalize(activity)
+
+ assert object.data["title"] == "lain radio episode 1"
+
+ assert Visibility.get_visibility(activity) == "public"
+ end
+
+ test "respects visibility=private" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.listen(user, %{
+ "title" => "lain radio episode 1",
+ "album" => "lain radio",
+ "artist" => "lain",
+ "length" => 180_000,
+ "visibility" => "private"
+ })
+
+ object = Object.normalize(activity)
+
+ assert object.data["title"] == "lain radio episode 1"
+
+ assert Visibility.get_visibility(activity) == "private"
+ end
+ end
end
--
cgit v1.2.3
From 7cad6ea67a47df2776a15dd69b9e408c517800e6 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sat, 28 Sep 2019 02:12:12 +0000
Subject: pleroma api: hook up scrobbler controller
---
.../controllers/scrobble_controller_test.exs | 63 ++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 test/web/pleroma_api/controllers/scrobble_controller_test.exs
(limited to 'test')
diff --git a/test/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/web/pleroma_api/controllers/scrobble_controller_test.exs
new file mode 100644
index 000000000..8cbb5889e
--- /dev/null
+++ b/test/web/pleroma_api/controllers/scrobble_controller_test.exs
@@ -0,0 +1,63 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Web.CommonAPI
+ import Pleroma.Factory
+
+ describe "POST /api/v1/pleroma/now-playing" do
+ test "works correctly", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/now-playing", %{
+ "title" => "lain radio episode 1",
+ "artist" => "lain",
+ "album" => "lain radio",
+ "length" => "180000"
+ })
+
+ assert %{"title" => "lain radio episode 1"} = json_response(conn, 200)
+ end
+ end
+
+ describe "GET /api/v1/pleroma/accounts/:id/now-playing" do
+ test "works correctly", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.listen(user, %{
+ "title" => "lain radio episode 1",
+ "artist" => "lain",
+ "album" => "lain radio"
+ })
+
+ {:ok, _activity} =
+ CommonAPI.listen(user, %{
+ "title" => "lain radio episode 2",
+ "artist" => "lain",
+ "album" => "lain radio"
+ })
+
+ {:ok, _activity} =
+ CommonAPI.listen(user, %{
+ "title" => "lain radio episode 3",
+ "artist" => "lain",
+ "album" => "lain radio"
+ })
+
+ conn =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/now-playing")
+
+ result = json_response(conn, 200)
+
+ assert length(result) == 3
+ end
+ end
+end
--
cgit v1.2.3
From e7309d3b606f4ede3282cf559b30ba23f62cbea5 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sat, 28 Sep 2019 11:57:24 +0000
Subject: test: transmogrifier: add test proving that transmogrifier can handle
outgoing listens
---
test/web/activity_pub/transmogrifier_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 9040c87ca..f77311b3c 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1219,6 +1219,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["bcc"])
end
+
+ test "it can handle Listen activities" do
+ listen_activity = insert(:listen)
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
+
+ assert modified["type"] == "Listen"
+ end
end
describe "user upgrade" do
--
cgit v1.2.3
From 71eff09e564ae3eeaf02acecbb8d89b7d4e2e511 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sat, 28 Sep 2019 12:12:35 +0000
Subject: common api: make sure the generated IR is actually federatable
---
test/web/activity_pub/transmogrifier_test.exs | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index f77311b3c..2c6357fe6 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1226,6 +1226,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
assert modified["type"] == "Listen"
+
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
end
end
--
cgit v1.2.3
From 211008ae2f1ea97490a0ac70b8c801e58af6834c Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sun, 29 Sep 2019 00:35:40 +0000
Subject: test: fix scrobble controller tests
---
test/web/pleroma_api/controllers/scrobble_controller_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/web/pleroma_api/controllers/scrobble_controller_test.exs
index 8cbb5889e..b86bd2250 100644
--- a/test/web/pleroma_api/controllers/scrobble_controller_test.exs
+++ b/test/web/pleroma_api/controllers/scrobble_controller_test.exs
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
end
end
- describe "GET /api/v1/pleroma/accounts/:id/now-playing" do
+ describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
test "works correctly", %{conn: conn} do
user = insert(:user)
@@ -53,7 +53,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
conn =
conn
- |> get("/api/v1/pleroma/accounts/#{user.id}/now-playing")
+ |> get("/api/v1/pleroma/accounts/#{user.id}/scrobbles")
result = json_response(conn, 200)
--
cgit v1.2.3
From 1d7cbdaf7b2f3ff6576959ed26885d7545f31a14 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sun, 29 Sep 2019 02:18:34 +0000
Subject: change new scrobble endpoint
---
test/web/pleroma_api/controllers/scrobble_controller_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/web/pleroma_api/controllers/scrobble_controller_test.exs
index b86bd2250..881f8012c 100644
--- a/test/web/pleroma_api/controllers/scrobble_controller_test.exs
+++ b/test/web/pleroma_api/controllers/scrobble_controller_test.exs
@@ -8,14 +8,14 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
- describe "POST /api/v1/pleroma/now-playing" do
+ describe "POST /api/v1/pleroma/scrobble" do
test "works correctly", %{conn: conn} do
user = insert(:user)
conn =
conn
|> assign(:user, user)
- |> post("/api/v1/pleroma/now-playing", %{
+ |> post("/api/v1/pleroma/scrobble", %{
"title" => "lain radio episode 1",
"artist" => "lain",
"album" => "lain radio",
--
cgit v1.2.3
From b7f27a4f584e54b13d0b7c1b288ad3e7bffcf95a Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 17:04:03 +0700
Subject: Extract report actions from `MastodonAPIController` to
`ReportController`
Update MastodonAPI.ReportView
---
.../controllers/report_controller_test.exs | 88 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 79 -------------------
2 files changed, 88 insertions(+), 79 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/report_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/report_controller_test.exs b/test/web/mastodon_api/controllers/report_controller_test.exs
new file mode 100644
index 000000000..fcece40fb
--- /dev/null
+++ b/test/web/mastodon_api/controllers/report_controller_test.exs
@@ -0,0 +1,88 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ setup do
+ reporter = insert(:user)
+ target_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+
+ [reporter: reporter, target_user: target_user, activity: activity]
+ end
+
+ test "submit a basic report", %{conn: conn, reporter: reporter, target_user: target_user} do
+ assert %{"action_taken" => false, "id" => _} =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"account_id" => target_user.id})
+ |> json_response(200)
+ end
+
+ test "submit a report with statuses and comment", %{
+ conn: conn,
+ reporter: reporter,
+ target_user: target_user,
+ activity: activity
+ } do
+ assert %{"action_taken" => false, "id" => _} =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{
+ "account_id" => target_user.id,
+ "status_ids" => [activity.id],
+ "comment" => "bad status!",
+ "forward" => "false"
+ })
+ |> json_response(200)
+ end
+
+ test "account_id is required", %{
+ conn: conn,
+ reporter: reporter,
+ activity: activity
+ } do
+ assert %{"error" => "Valid `account_id` required"} =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
+ |> json_response(400)
+ end
+
+ test "comment must be up to the size specified in the config", %{
+ conn: conn,
+ reporter: reporter,
+ target_user: target_user
+ } do
+ max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
+ comment = String.pad_trailing("a", max_size + 1, "a")
+
+ error = %{"error" => "Comment must be up to #{max_size} characters"}
+
+ assert ^error =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
+ |> json_response(400)
+ end
+
+ test "returns error when account is not exist", %{
+ conn: conn,
+ reporter: reporter,
+ activity: activity
+ } do
+ conn =
+ conn
+ |> assign(:user, reporter)
+ |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
+
+ assert json_response(conn, 400) == %{"error" => "Account not found"}
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b3acb7a22..d316a61c1 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1380,85 +1380,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "reports" do
- setup do
- reporter = insert(:user)
- target_user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
-
- [reporter: reporter, target_user: target_user, activity: activity]
- end
-
- test "submit a basic report", %{conn: conn, reporter: reporter, target_user: target_user} do
- assert %{"action_taken" => false, "id" => _} =
- conn
- |> assign(:user, reporter)
- |> post("/api/v1/reports", %{"account_id" => target_user.id})
- |> json_response(200)
- end
-
- test "submit a report with statuses and comment", %{
- conn: conn,
- reporter: reporter,
- target_user: target_user,
- activity: activity
- } do
- assert %{"action_taken" => false, "id" => _} =
- conn
- |> assign(:user, reporter)
- |> post("/api/v1/reports", %{
- "account_id" => target_user.id,
- "status_ids" => [activity.id],
- "comment" => "bad status!",
- "forward" => "false"
- })
- |> json_response(200)
- end
-
- test "account_id is required", %{
- conn: conn,
- reporter: reporter,
- activity: activity
- } do
- assert %{"error" => "Valid `account_id` required"} =
- conn
- |> assign(:user, reporter)
- |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
- |> json_response(400)
- end
-
- test "comment must be up to the size specified in the config", %{
- conn: conn,
- reporter: reporter,
- target_user: target_user
- } do
- max_size = Config.get([:instance, :max_report_comment_size], 1000)
- comment = String.pad_trailing("a", max_size + 1, "a")
-
- error = %{"error" => "Comment must be up to #{max_size} characters"}
-
- assert ^error =
- conn
- |> assign(:user, reporter)
- |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
- |> json_response(400)
- end
-
- test "returns error when account is not exist", %{
- conn: conn,
- reporter: reporter,
- activity: activity
- } do
- conn =
- conn
- |> assign(:user, reporter)
- |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
-
- assert json_response(conn, 400) == %{"error" => "Account not found"}
- end
- end
-
describe "link headers" do
test "preserves parameters in link headers", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 1207e8819507aac55e5725f383987b0078bb1cbe Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 18:30:10 +0700
Subject: Fix ReportControllerTest
---
test/web/mastodon_api/controllers/report_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/report_controller_test.exs b/test/web/mastodon_api/controllers/report_controller_test.exs
index fcece40fb..979ca48f3 100644
--- a/test/web/mastodon_api/controllers/report_controller_test.exs
+++ b/test/web/mastodon_api/controllers/report_controller_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
+defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.CommonAPI
--
cgit v1.2.3
From e7aef27c0011d3fd0b569ebdb9196a1e011eae5d Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 19:10:54 +0700
Subject: Fix merge
---
test/list_test.exs | 4 +-
test/web/admin_api/views/report_view_test.exs | 8 +-
.../controllers/account_controller_test.exs | 810 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 773 --------------------
test/web/mastodon_api/views/account_view_test.exs | 48 +-
.../mastodon_api/views/notification_view_test.exs | 8 +-
test/web/mastodon_api/views/status_view_test.exs | 2 +-
test/web/twitter_api/twitter_api_test.exs | 28 +-
8 files changed, 859 insertions(+), 822 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/account_controller_test.exs
(limited to 'test')
diff --git a/test/list_test.exs b/test/list_test.exs
index ba79251da..e7b23915b 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -113,10 +113,10 @@ defmodule Pleroma.ListTest do
{:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_1)
{:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_2)
- lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id)
+ lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1)
assert owned_list in lists_1
refute not_owned_list in lists_1
- lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id)
+ lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2)
assert owned_list in lists_2
refute not_owned_list in lists_2
end
diff --git a/test/web/admin_api/views/report_view_test.exs b/test/web/admin_api/views/report_view_test.exs
index 35b6947a0..475705857 100644
--- a/test/web/admin_api/views/report_view_test.exs
+++ b/test/web/admin_api/views/report_view_test.exs
@@ -21,12 +21,12 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
content: nil,
actor:
Map.merge(
- AccountView.render("account.json", %{user: user}),
+ AccountView.render("show.json", %{user: user}),
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
),
account:
Map.merge(
- AccountView.render("account.json", %{user: other_user}),
+ AccountView.render("show.json", %{user: other_user}),
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
),
statuses: [],
@@ -53,12 +53,12 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
content: nil,
actor:
Map.merge(
- AccountView.render("account.json", %{user: user}),
+ AccountView.render("show.json", %{user: user}),
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
),
account:
Map.merge(
- AccountView.render("account.json", %{user: other_user}),
+ AccountView.render("show.json", %{user: other_user}),
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
),
statuses: [StatusView.render("show.json", %{activity: activity})],
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs
new file mode 100644
index 000000000..6cf929011
--- /dev/null
+++ b/test/web/mastodon_api/controllers/account_controller_test.exs
@@ -0,0 +1,810 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ describe "account fetching" do
+ test "works by id" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/#{user.id}")
+
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == to_string(user.id)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/-1")
+
+ assert %{"error" => "Can't find user"} = json_response(conn, 404)
+ end
+
+ test "works by nickname" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/#{user.nickname}")
+
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == user.id
+ end
+
+ test "works by nickname for remote users" do
+ limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ user = insert(:user, nickname: "user@example.com", local: false)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/#{user.nickname}")
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == user.id
+ end
+
+ test "respects limit_to_local_content == :all for remote user nicknames" do
+ limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
+ Pleroma.Config.put([:instance, :limit_to_local_content], :all)
+
+ user = insert(:user, nickname: "user@example.com", local: false)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/#{user.nickname}")
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
+ assert json_response(conn, 404)
+ end
+
+ test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
+ limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+
+ user = insert(:user, nickname: "user@example.com", local: false)
+ reading_user = insert(:user)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/#{user.nickname}")
+
+ assert json_response(conn, 404)
+
+ conn =
+ build_conn()
+ |> assign(:user, reading_user)
+ |> get("/api/v1/accounts/#{user.nickname}")
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == user.id
+ end
+
+ test "accounts fetches correct account for nicknames beginning with numbers", %{conn: conn} do
+ # Need to set an old-style integer ID to reproduce the problem
+ # (these are no longer assigned to new accounts but were preserved
+ # for existing accounts during the migration to flakeIDs)
+ user_one = insert(:user, %{id: 1212})
+ user_two = insert(:user, %{nickname: "#{user_one.id}garbage"})
+
+ resp_one =
+ conn
+ |> get("/api/v1/accounts/#{user_one.id}")
+
+ resp_two =
+ conn
+ |> get("/api/v1/accounts/#{user_two.nickname}")
+
+ resp_three =
+ conn
+ |> get("/api/v1/accounts/#{user_two.id}")
+
+ acc_one = json_response(resp_one, 200)
+ acc_two = json_response(resp_two, 200)
+ acc_three = json_response(resp_three, 200)
+ refute acc_one == acc_two
+ assert acc_two == acc_three
+ end
+ end
+
+ describe "user timelines" do
+ test "gets a users statuses", %{conn: conn} do
+ user_one = insert(:user)
+ user_two = insert(:user)
+ user_three = insert(:user)
+
+ {:ok, user_three} = User.follow(user_three, user_one)
+
+ {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
+
+ {:ok, direct_activity} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi, @#{user_two.nickname}.",
+ "visibility" => "direct"
+ })
+
+ {:ok, private_activity} =
+ CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"})
+
+ resp =
+ conn
+ |> get("/api/v1/accounts/#{user_one.id}/statuses")
+
+ assert [%{"id" => id}] = json_response(resp, 200)
+ assert id == to_string(activity.id)
+
+ resp =
+ conn
+ |> assign(:user, user_two)
+ |> get("/api/v1/accounts/#{user_one.id}/statuses")
+
+ assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
+ assert id_one == to_string(direct_activity.id)
+ assert id_two == to_string(activity.id)
+
+ resp =
+ conn
+ |> assign(:user, user_three)
+ |> get("/api/v1/accounts/#{user_one.id}/statuses")
+
+ assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
+ assert id_one == to_string(private_activity.id)
+ assert id_two == to_string(activity.id)
+ end
+
+ test "unimplemented pinned statuses feature", %{conn: conn} do
+ note = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note.data["actor"])
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+
+ assert json_response(conn, 200) == []
+ end
+
+ test "gets an users media", %{conn: conn} do
+ note = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note.data["actor"])
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
+
+ {:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(image_post.id)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(image_post.id)
+ end
+
+ test "gets a user's statuses without reblogs", %{conn: conn} do
+ user = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, _, _} = CommonAPI.repeat(post.id, user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(post.id)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(post.id)
+ end
+
+ test "filters user's statuses by a hashtag", %{conn: conn} do
+ user = insert(:user)
+ {:ok, post} = CommonAPI.post(user, %{"status" => "#hashtag"})
+ {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses", %{"tagged" => "hashtag"})
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(post.id)
+ end
+ end
+
+ describe "followers" do
+ test "getting followers", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{other_user.id}/followers")
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(user.id)
+ end
+
+ test "getting followers, hide_followers", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user, %{info: %{hide_followers: true}})
+ {:ok, _user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{other_user.id}/followers")
+
+ assert [] == json_response(conn, 200)
+ end
+
+ test "getting followers, hide_followers, same user requesting", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user, %{info: %{hide_followers: true}})
+ {:ok, _user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/accounts/#{other_user.id}/followers")
+
+ refute [] == json_response(conn, 200)
+ end
+
+ test "getting followers, pagination", %{conn: conn} do
+ user = insert(:user)
+ follower1 = insert(:user)
+ follower2 = insert(:user)
+ follower3 = insert(:user)
+ {:ok, _} = User.follow(follower1, user)
+ {:ok, _} = User.follow(follower2, user)
+ {:ok, _} = User.follow(follower3, user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1.id}")
+
+ assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
+ assert id3 == follower3.id
+ assert id2 == follower2.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3.id}")
+
+ assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
+ assert id2 == follower2.id
+ assert id1 == follower1.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3.id}")
+
+ assert [%{"id" => id2}] = json_response(res_conn, 200)
+ assert id2 == follower2.id
+
+ assert [link_header] = get_resp_header(res_conn, "link")
+ assert link_header =~ ~r/min_id=#{follower2.id}/
+ assert link_header =~ ~r/max_id=#{follower2.id}/
+ end
+ end
+
+ describe "following" do
+ test "getting following", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following")
+
+ assert [%{"id" => id}] = json_response(conn, 200)
+ assert id == to_string(other_user.id)
+ end
+
+ test "getting following, hide_follows", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following")
+
+ assert [] == json_response(conn, 200)
+ end
+
+ test "getting following, hide_follows, same user requesting", %{conn: conn} do
+ user = insert(:user, %{info: %{hide_follows: true}})
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/following")
+
+ refute [] == json_response(conn, 200)
+ end
+
+ test "getting following, pagination", %{conn: conn} do
+ user = insert(:user)
+ following1 = insert(:user)
+ following2 = insert(:user)
+ following3 = insert(:user)
+ {:ok, _} = User.follow(user, following1)
+ {:ok, _} = User.follow(user, following2)
+ {:ok, _} = User.follow(user, following3)
+
+ conn =
+ conn
+ |> assign(:user, user)
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
+
+ assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
+ assert id3 == following3.id
+ assert id2 == following2.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
+
+ assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
+ assert id2 == following2.id
+ assert id1 == following1.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
+
+ assert [%{"id" => id2}] = json_response(res_conn, 200)
+ assert id2 == following2.id
+
+ assert [link_header] = get_resp_header(res_conn, "link")
+ assert link_header =~ ~r/min_id=#{following2.id}/
+ assert link_header =~ ~r/max_id=#{following2.id}/
+ end
+ end
+
+ describe "follow/unfollow" do
+ test "following / unfollowing a user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/follow")
+
+ assert %{"id" => _id, "following" => true} = json_response(conn, 200)
+
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unfollow")
+
+ assert %{"id" => _id, "following" => false} = json_response(conn, 200)
+
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/follows", %{"uri" => other_user.nickname})
+
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == to_string(other_user.id)
+ end
+
+ test "following without reblogs" do
+ follower = insert(:user)
+ followed = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, follower)
+ |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=false")
+
+ assert %{"showing_reblogs" => false} = json_response(conn, 200)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+ {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
+
+ conn =
+ build_conn()
+ |> assign(:user, User.get_cached_by_id(follower.id))
+ |> get("/api/v1/timelines/home")
+
+ assert [] == json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, follower)
+ |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
+
+ assert %{"showing_reblogs" => true} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, User.get_cached_by_id(follower.id))
+ |> get("/api/v1/timelines/home")
+
+ expected_activity_id = reblog.id
+ assert [%{"id" => ^expected_activity_id}] = json_response(conn, 200)
+ end
+
+ test "following / unfollowing errors" do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ # self follow
+ conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
+ assert %{"error" => "Record not found"} = json_response(conn_res, 404)
+
+ # self unfollow
+ user = User.get_cached_by_id(user.id)
+ conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
+ assert %{"error" => "Record not found"} = json_response(conn_res, 404)
+
+ # self follow via uri
+ user = User.get_cached_by_id(user.id)
+ conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
+ assert %{"error" => "Record not found"} = json_response(conn_res, 404)
+
+ # follow non existing user
+ conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
+ assert %{"error" => "Record not found"} = json_response(conn_res, 404)
+
+ # follow non existing user via uri
+ conn_res = post(conn, "/api/v1/follows", %{"uri" => "doesntexist"})
+ assert %{"error" => "Record not found"} = json_response(conn_res, 404)
+
+ # unfollow non existing user
+ conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
+ assert %{"error" => "Record not found"} = json_response(conn_res, 404)
+ end
+ end
+
+ describe "mute/unmute" do
+ test "with notifications", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/mute")
+
+ response = json_response(conn, 200)
+
+ assert %{"id" => _id, "muting" => true, "muting_notifications" => true} = response
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unmute")
+
+ response = json_response(conn, 200)
+ assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
+ end
+
+ test "without notifications", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
+
+ response = json_response(conn, 200)
+
+ assert %{"id" => _id, "muting" => true, "muting_notifications" => false} = response
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unmute")
+
+ response = json_response(conn, 200)
+ assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
+ end
+ end
+
+ describe "getting favorites timeline of specified user" do
+ setup do
+ [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
+ [current_user: current_user, user: user]
+ end
+
+ test "returns list of statuses favorited by specified user", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ [activity | _] = insert_pair(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ [like] = response
+
+ assert length(response) == 1
+ assert like["id"] == activity.id
+ end
+
+ test "returns favorites for specified user_id when user is not logged in", %{
+ conn: conn,
+ user: user
+ } do
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+ end
+
+ test "returns favorited DM only when user is logged in and he is one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ {:ok, direct} =
+ CommonAPI.post(current_user, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+
+ anonymous_response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(anonymous_response)
+ end
+
+ test "does not return others' favorited DM when user is not one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ user_two = insert(:user)
+
+ {:ok, direct} =
+ CommonAPI.post(user_two, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "paginates favorites using since_id and max_id", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ activities = insert_list(10, :note_activity)
+
+ Enum.each(activities, fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ third_activity = Enum.at(activities, 2)
+ seventh_activity = Enum.at(activities, 6)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
+ since_id: third_activity.id,
+ max_id: seventh_activity.id
+ })
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ refute third_activity in response
+ refute seventh_activity in response
+ end
+
+ test "limits favorites using limit parameter", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ 7
+ |> insert_list(:note_activity)
+ |> Enum.each(fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ end
+
+ test "returns empty response when user does not have any favorited statuses", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "returns 404 error when specified user is not exist", %{conn: conn} do
+ conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+
+ test "returns 403 error when user has hidden own favorites", %{
+ conn: conn,
+ current_user: current_user
+ } do
+ user = insert(:user, %{info: %{hide_favorites: true}})
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+
+ test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
+ user = insert(:user)
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert user.info.hide_favorites
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+ end
+
+ describe "pinned statuses" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ [user: user, activity: activity]
+ end
+
+ test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
+ {:ok, _} = CommonAPI.pin(activity.id, user)
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
+ |> json_response(200)
+
+ id_str = to_string(activity.id)
+
+ assert [%{"id" => ^id_str, "pinned" => true}] = result
+ end
+ end
+
+ test "subscribing / unsubscribing to a user", %{conn: conn} do
+ user = insert(:user)
+ subscription_target = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
+
+ assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
+
+ assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
+ end
+
+ test "blocking / unblocking a user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/block")
+
+ assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
+
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unblock")
+
+ assert %{"id" => _id, "blocking" => false} = json_response(conn, 200)
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 46b035770..7cdefdcdd 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -202,125 +202,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert expected == json_response(conn, 200)
end
- describe "user timelines" do
- test "gets a users statuses", %{conn: conn} do
- user_one = insert(:user)
- user_two = insert(:user)
- user_three = insert(:user)
-
- {:ok, user_three} = User.follow(user_three, user_one)
-
- {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
-
- {:ok, direct_activity} =
- CommonAPI.post(user_one, %{
- "status" => "Hi, @#{user_two.nickname}.",
- "visibility" => "direct"
- })
-
- {:ok, private_activity} =
- CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"})
-
- resp =
- conn
- |> get("/api/v1/accounts/#{user_one.id}/statuses")
-
- assert [%{"id" => id}] = json_response(resp, 200)
- assert id == to_string(activity.id)
-
- resp =
- conn
- |> assign(:user, user_two)
- |> get("/api/v1/accounts/#{user_one.id}/statuses")
-
- assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
- assert id_one == to_string(direct_activity.id)
- assert id_two == to_string(activity.id)
-
- resp =
- conn
- |> assign(:user, user_three)
- |> get("/api/v1/accounts/#{user_one.id}/statuses")
-
- assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200)
- assert id_one == to_string(private_activity.id)
- assert id_two == to_string(activity.id)
- end
-
- test "unimplemented pinned statuses feature", %{conn: conn} do
- note = insert(:note_activity)
- user = User.get_cached_by_ap_id(note.data["actor"])
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
-
- assert json_response(conn, 200) == []
- end
-
- test "gets an users media", %{conn: conn} do
- note = insert(:note_activity)
- user = User.get_cached_by_ap_id(note.data["actor"])
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
-
- {:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(image_post.id)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "1"})
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(image_post.id)
- end
-
- test "gets a user's statuses without reblogs", %{conn: conn} do
- user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"})
- {:ok, _, _} = CommonAPI.repeat(post.id, user)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"})
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(post.id)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"})
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(post.id)
- end
-
- test "filters user's statuses by a hashtag", %{conn: conn} do
- user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "#hashtag"})
- {:ok, _post} = CommonAPI.post(user, %{"status" => "hashtag"})
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/statuses", %{"tagged" => "hashtag"})
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(post.id)
- end
- end
-
describe "user relationships" do
test "returns the relationships for the current user", %{conn: conn} do
user = insert(:user)
@@ -400,87 +281,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "account fetching" do
- test "works by id" do
- user = insert(:user)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/#{user.id}")
-
- assert %{"id" => id} = json_response(conn, 200)
- assert id == to_string(user.id)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/-1")
-
- assert %{"error" => "Can't find user"} = json_response(conn, 404)
- end
-
- test "works by nickname" do
- user = insert(:user)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/#{user.nickname}")
-
- assert %{"id" => id} = json_response(conn, 200)
- assert id == user.id
- end
-
- test "works by nickname for remote users" do
- limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
- Pleroma.Config.put([:instance, :limit_to_local_content], false)
- user = insert(:user, nickname: "user@example.com", local: false)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/#{user.nickname}")
-
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
- assert %{"id" => id} = json_response(conn, 200)
- assert id == user.id
- end
-
- test "respects limit_to_local_content == :all for remote user nicknames" do
- limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
- Pleroma.Config.put([:instance, :limit_to_local_content], :all)
-
- user = insert(:user, nickname: "user@example.com", local: false)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/#{user.nickname}")
-
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
- assert json_response(conn, 404)
- end
-
- test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
- limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
- Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
-
- user = insert(:user, nickname: "user@example.com", local: false)
- reading_user = insert(:user)
-
- conn =
- build_conn()
- |> get("/api/v1/accounts/#{user.nickname}")
-
- assert json_response(conn, 404)
-
- conn =
- build_conn()
- |> assign(:user, reading_user)
- |> get("/api/v1/accounts/#{user.nickname}")
-
- Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
- assert %{"id" => id} = json_response(conn, 200)
- assert id == user.id
- end
- end
-
describe "/api/v1/pleroma/mascot" do
test "mascot upload", %{conn: conn} do
user = insert(:user)
@@ -548,316 +348,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert url =~ "an_image"
end
end
-
- test "getting followers", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{other_user.id}/followers")
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(user.id)
- end
-
- test "getting followers, hide_followers", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user, %{info: %{hide_followers: true}})
- {:ok, _user} = User.follow(user, other_user)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{other_user.id}/followers")
-
- assert [] == json_response(conn, 200)
- end
-
- test "getting followers, hide_followers, same user requesting", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user, %{info: %{hide_followers: true}})
- {:ok, _user} = User.follow(user, other_user)
-
- conn =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/accounts/#{other_user.id}/followers")
-
- refute [] == json_response(conn, 200)
- end
-
- test "getting followers, pagination", %{conn: conn} do
- user = insert(:user)
- follower1 = insert(:user)
- follower2 = insert(:user)
- follower3 = insert(:user)
- {:ok, _} = User.follow(follower1, user)
- {:ok, _} = User.follow(follower2, user)
- {:ok, _} = User.follow(follower3, user)
-
- conn =
- conn
- |> assign(:user, user)
-
- res_conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1.id}")
-
- assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
- assert id3 == follower3.id
- assert id2 == follower2.id
-
- res_conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3.id}")
-
- assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
- assert id2 == follower2.id
- assert id1 == follower1.id
-
- res_conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3.id}")
-
- assert [%{"id" => id2}] = json_response(res_conn, 200)
- assert id2 == follower2.id
-
- assert [link_header] = get_resp_header(res_conn, "link")
- assert link_header =~ ~r/min_id=#{follower2.id}/
- assert link_header =~ ~r/max_id=#{follower2.id}/
- end
-
- test "getting following", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/following")
-
- assert [%{"id" => id}] = json_response(conn, 200)
- assert id == to_string(other_user.id)
- end
-
- test "getting following, hide_follows", %{conn: conn} do
- user = insert(:user, %{info: %{hide_follows: true}})
- other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/following")
-
- assert [] == json_response(conn, 200)
- end
-
- test "getting following, hide_follows, same user requesting", %{conn: conn} do
- user = insert(:user, %{info: %{hide_follows: true}})
- other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/#{user.id}/following")
-
- refute [] == json_response(conn, 200)
- end
-
- test "getting following, pagination", %{conn: conn} do
- user = insert(:user)
- following1 = insert(:user)
- following2 = insert(:user)
- following3 = insert(:user)
- {:ok, _} = User.follow(user, following1)
- {:ok, _} = User.follow(user, following2)
- {:ok, _} = User.follow(user, following3)
-
- conn =
- conn
- |> assign(:user, user)
-
- res_conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
-
- assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
- assert id3 == following3.id
- assert id2 == following2.id
-
- res_conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
-
- assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
- assert id2 == following2.id
- assert id1 == following1.id
-
- res_conn =
- conn
- |> get("/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
-
- assert [%{"id" => id2}] = json_response(res_conn, 200)
- assert id2 == following2.id
-
- assert [link_header] = get_resp_header(res_conn, "link")
- assert link_header =~ ~r/min_id=#{following2.id}/
- assert link_header =~ ~r/max_id=#{following2.id}/
- end
-
- test "following / unfollowing a user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/follow")
-
- assert %{"id" => _id, "following" => true} = json_response(conn, 200)
-
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unfollow")
-
- assert %{"id" => _id, "following" => false} = json_response(conn, 200)
-
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/follows", %{"uri" => other_user.nickname})
-
- assert %{"id" => id} = json_response(conn, 200)
- assert id == to_string(other_user.id)
- end
-
- test "following without reblogs" do
- follower = insert(:user)
- followed = insert(:user)
- other_user = insert(:user)
-
- conn =
- build_conn()
- |> assign(:user, follower)
- |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=false")
-
- assert %{"showing_reblogs" => false} = json_response(conn, 200)
-
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
- {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
-
- conn =
- build_conn()
- |> assign(:user, User.get_cached_by_id(follower.id))
- |> get("/api/v1/timelines/home")
-
- assert [] == json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, follower)
- |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
-
- assert %{"showing_reblogs" => true} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, User.get_cached_by_id(follower.id))
- |> get("/api/v1/timelines/home")
-
- expected_activity_id = reblog.id
- assert [%{"id" => ^expected_activity_id}] = json_response(conn, 200)
- end
-
- test "following / unfollowing errors" do
- user = insert(:user)
-
- conn =
- build_conn()
- |> assign(:user, user)
-
- # self follow
- conn_res = post(conn, "/api/v1/accounts/#{user.id}/follow")
- assert %{"error" => "Record not found"} = json_response(conn_res, 404)
-
- # self unfollow
- user = User.get_cached_by_id(user.id)
- conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
- assert %{"error" => "Record not found"} = json_response(conn_res, 404)
-
- # self follow via uri
- user = User.get_cached_by_id(user.id)
- conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
- assert %{"error" => "Record not found"} = json_response(conn_res, 404)
-
- # follow non existing user
- conn_res = post(conn, "/api/v1/accounts/doesntexist/follow")
- assert %{"error" => "Record not found"} = json_response(conn_res, 404)
-
- # follow non existing user via uri
- conn_res = post(conn, "/api/v1/follows", %{"uri" => "doesntexist"})
- assert %{"error" => "Record not found"} = json_response(conn_res, 404)
-
- # unfollow non existing user
- conn_res = post(conn, "/api/v1/accounts/doesntexist/unfollow")
- assert %{"error" => "Record not found"} = json_response(conn_res, 404)
- end
-
- describe "mute/unmute" do
- test "with notifications", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/mute")
-
- response = json_response(conn, 200)
-
- assert %{"id" => _id, "muting" => true, "muting_notifications" => true} = response
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unmute")
-
- response = json_response(conn, 200)
- assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
- end
-
- test "without notifications", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/mute", %{"notifications" => "false"})
-
- response = json_response(conn, 200)
-
- assert %{"id" => _id, "muting" => true, "muting_notifications" => false} = response
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unmute")
-
- response = json_response(conn, 200)
- assert %{"id" => _id, "muting" => false, "muting_notifications" => false} = response
- end
- end
-
describe "subscribing / unsubscribing" do
test "subscribing / unsubscribing to a user", %{conn: conn} do
user = insert(:user)
@@ -920,27 +410,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
end
- test "blocking / unblocking a user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/block")
-
- assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
-
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unblock")
-
- assert %{"id" => _id, "blocking" => false} = json_response(conn, 200)
- end
-
test "getting a list of blocks", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1017,199 +486,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] = json_response(third_conn, 200)
end
- describe "getting favorites timeline of specified user" do
- setup do
- [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
- [current_user: current_user, user: user]
- end
-
- test "returns list of statuses favorited by specified user", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- [activity | _] = insert_pair(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- [like] = response
-
- assert length(response) == 1
- assert like["id"] == activity.id
- end
-
- test "returns favorites for specified user_id when user is not logged in", %{
- conn: conn,
- user: user
- } do
- activity = insert(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- response =
- conn
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert length(response) == 1
- end
-
- test "returns favorited DM only when user is logged in and he is one of recipients", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- {:ok, direct} =
- CommonAPI.post(current_user, %{
- "status" => "Hi @#{user.nickname}!",
- "visibility" => "direct"
- })
-
- CommonAPI.favorite(direct.id, user)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert length(response) == 1
-
- anonymous_response =
- conn
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert Enum.empty?(anonymous_response)
- end
-
- test "does not return others' favorited DM when user is not one of recipients", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- user_two = insert(:user)
-
- {:ok, direct} =
- CommonAPI.post(user_two, %{
- "status" => "Hi @#{user.nickname}!",
- "visibility" => "direct"
- })
-
- CommonAPI.favorite(direct.id, user)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "paginates favorites using since_id and max_id", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- activities = insert_list(10, :note_activity)
-
- Enum.each(activities, fn activity ->
- CommonAPI.favorite(activity.id, user)
- end)
-
- third_activity = Enum.at(activities, 2)
- seventh_activity = Enum.at(activities, 6)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
- since_id: third_activity.id,
- max_id: seventh_activity.id
- })
- |> json_response(:ok)
-
- assert length(response) == 3
- refute third_activity in response
- refute seventh_activity in response
- end
-
- test "limits favorites using limit parameter", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- 7
- |> insert_list(:note_activity)
- |> Enum.each(fn activity ->
- CommonAPI.favorite(activity.id, user)
- end)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
- |> json_response(:ok)
-
- assert length(response) == 3
- end
-
- test "returns empty response when user does not have any favorited statuses", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "returns 404 error when specified user is not exist", %{conn: conn} do
- conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
-
- assert json_response(conn, 404) == %{"error" => "Record not found"}
- end
-
- test "returns 403 error when user has hidden own favorites", %{
- conn: conn,
- current_user: current_user
- } do
- user = insert(:user, %{info: %{hide_favorites: true}})
- activity = insert(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- conn =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
-
- assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
- end
-
- test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
- user = insert(:user)
- activity = insert(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- conn =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
-
- assert user.info.hide_favorites
- assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
- end
- end
-
test "get instance information", %{conn: conn} do
conn = get(conn, "/api/v1/instance")
assert result = json_response(conn, 200)
@@ -1294,29 +570,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user.info.settings == %{"programming" => "socks"}
end
- describe "pinned statuses" do
- setup do
- user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
-
- [user: user, activity: activity]
- end
-
- test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
- {:ok, _} = CommonAPI.pin(activity.id, user)
-
- result =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
- |> json_response(200)
-
- id_str = to_string(activity.id)
-
- assert [%{"id" => ^id_str, "pinned" => true}] = result
- end
- end
-
describe "link headers" do
test "preserves parameters in link headers", %{conn: conn} do
user = insert(:user)
@@ -1349,32 +602,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- test "accounts fetches correct account for nicknames beginning with numbers", %{conn: conn} do
- # Need to set an old-style integer ID to reproduce the problem
- # (these are no longer assigned to new accounts but were preserved
- # for existing accounts during the migration to flakeIDs)
- user_one = insert(:user, %{id: 1212})
- user_two = insert(:user, %{nickname: "#{user_one.id}garbage"})
-
- resp_one =
- conn
- |> get("/api/v1/accounts/#{user_one.id}")
-
- resp_two =
- conn
- |> get("/api/v1/accounts/#{user_two.nickname}")
-
- resp_three =
- conn
- |> get("/api/v1/accounts/#{user_two.id}")
-
- acc_one = json_response(resp_one, 200)
- acc_two = json_response(resp_two, 200)
- acc_three = json_response(resp_three, 200)
- refute acc_one == acc_two
- assert acc_two == acc_three
- end
-
describe "custom emoji" do
test "with tags", %{conn: conn} do
[emoji | _body] =
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index d965f76bf..62b2ab7e3 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -88,7 +88,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
}
}
- assert expected == AccountView.render("account.json", %{user: user})
+ assert expected == AccountView.render("show.json", %{user: user})
end
test "Represent the user account for the account owner" do
@@ -106,7 +106,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{
pleroma: %{notification_settings: ^notification_settings},
source: %{privacy: ^privacy}
- } = AccountView.render("account.json", %{user: user, for: user})
+ } = AccountView.render("show.json", %{user: user, for: user})
end
test "Represent a Service(bot) account" do
@@ -160,13 +160,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
}
}
- assert expected == AccountView.render("account.json", %{user: user})
+ assert expected == AccountView.render("show.json", %{user: user})
end
test "Represent a deactivated user for an admin" do
admin = insert(:user, %{info: %{is_admin: true}})
deactivated_user = insert(:user, %{info: %{deactivated: true}})
- represented = AccountView.render("account.json", %{user: deactivated_user, for: admin})
+ represented = AccountView.render("show.json", %{user: deactivated_user, for: admin})
assert represented[:pleroma][:deactivated] == true
end
@@ -348,27 +348,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
}
}
- assert expected == AccountView.render("account.json", %{user: user, for: other_user})
+ assert expected == AccountView.render("show.json", %{user: user, for: other_user})
end
test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
result =
- AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
+ AccountView.render("show.json", %{user: user, for: user, with_pleroma_settings: true})
assert result.pleroma.settings_store == %{:fe => "test"}
- result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
+ result = AccountView.render("show.json", %{user: user, with_pleroma_settings: true})
assert result.pleroma[:settings_store] == nil
- result = AccountView.render("account.json", %{user: user, for: user})
+ result = AccountView.render("show.json", %{user: user, for: user})
assert result.pleroma[:settings_store] == nil
end
test "sanitizes display names" do
user = insert(:user, name: "")
- result = AccountView.render("account.json", %{user: user})
+ result = AccountView.render("show.json", %{user: user})
refute result.display_name == ""
end
@@ -391,7 +391,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
followers_count: 0,
following_count: 0,
pleroma: %{hide_follows_count: true, hide_followers_count: true}
- } = AccountView.render("account.json", %{user: user})
+ } = AccountView.render("show.json", %{user: user})
end
test "shows when follows/followers are hidden" do
@@ -404,7 +404,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
followers_count: 1,
following_count: 1,
pleroma: %{hide_follows: true, hide_followers: true}
- } = AccountView.render("account.json", %{user: user})
+ } = AccountView.render("show.json", %{user: user})
end
test "shows actual follower/following count to the account owner" do
@@ -416,7 +416,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{
followers_count: 1,
following_count: 1
- } = AccountView.render("account.json", %{user: user, for: user})
+ } = AccountView.render("show.json", %{user: user, for: user})
end
end
@@ -425,65 +425,65 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user = insert(:user)
assert %{follow_requests_count: 0} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{follow_requests_count: 0} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
end
test "shows non-zero when follow requests are pending" do
user = insert(:user, %{info: %{locked: true}})
- assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{locked: true, follow_requests_count: 1} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
end
test "decreases when accepting a follow request" do
user = insert(:user, %{info: %{locked: true}})
- assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{locked: true, follow_requests_count: 1} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
{:ok, _other_user} = CommonAPI.accept_follow_request(other_user, user)
assert %{locked: true, follow_requests_count: 0} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
end
test "decreases when rejecting a follow request" do
user = insert(:user, %{info: %{locked: true}})
- assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{locked: true, follow_requests_count: 1} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
{:ok, _other_user} = CommonAPI.reject_follow_request(other_user, user)
assert %{locked: true, follow_requests_count: 0} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
end
test "shows non-zero when historical unapproved requests are present" do
user = insert(:user, %{info: %{locked: true}})
- assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
+ assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
@@ -491,7 +491,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
{:ok, user} = User.update_info(user, &User.Info.user_upgrade(&1, %{locked: false}))
assert %{locked: false, follow_requests_count: 1} =
- AccountView.render("account.json", %{user: user, for: user})
+ AccountView.render("show.json", %{user: user, for: user})
end
end
end
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 86268fcfa..81ab82e2b 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -27,7 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "mention",
- account: AccountView.render("account.json", %{user: user, for: mentioned_user}),
+ account: AccountView.render("show.json", %{user: user, for: mentioned_user}),
status: StatusView.render("show.json", %{activity: activity, for: mentioned_user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "favourite",
- account: AccountView.render("account.json", %{user: another_user, for: user}),
+ account: AccountView.render("show.json", %{user: another_user, for: user}),
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -72,7 +72,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "reblog",
- account: AccountView.render("account.json", %{user: another_user, for: user}),
+ account: AccountView.render("show.json", %{user: another_user, for: user}),
status: StatusView.render("show.json", %{activity: reblog_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -92,7 +92,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "follow",
- account: AccountView.render("account.json", %{user: follower, for: followed}),
+ account: AccountView.render("show.json", %{user: follower, for: followed}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 683132f8d..8df23d0a8 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -103,7 +103,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
id: to_string(note.id),
uri: object_data["id"],
url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
- account: AccountView.render("account.json", %{user: user}),
+ account: AccountView.render("show.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
card: nil,
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index bf1e233f5..d1d61d11a 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -29,8 +29,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
fetched_user = User.get_cached_by_nickname("lain")
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
end
test "it registers a new user with empty string in bio and returns the user." do
@@ -47,8 +47,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
fetched_user = User.get_cached_by_nickname("lain")
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
end
test "it sends confirmation email if :account_activation_required is specified in instance config" do
@@ -148,8 +148,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert invite.used == true
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
end
test "returns error on invalid token" do
@@ -213,8 +213,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
fetched_user = User.get_cached_by_nickname("vinny")
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
end
{:ok, data: data, check_fn: check_fn}
@@ -288,8 +288,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert invite.used == true
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
data = %{
"nickname" => "GrimReaper",
@@ -339,8 +339,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
refute invite.used
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
end
test "error after max uses" do
@@ -363,8 +363,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
- assert AccountView.render("account.json", %{user: user}) ==
- AccountView.render("account.json", %{user: fetched_user})
+ assert AccountView.render("show.json", %{user: user}) ==
+ AccountView.render("show.json", %{user: fetched_user})
data = %{
"nickname" => "GrimReaper",
--
cgit v1.2.3
From 3c5ecb70b45ae3db193e58b9a3b4a6100b411e4d Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 14:28:12 +0700
Subject: Add PleromaAPI.AccountController
---
.../controllers/account_controller_test.exs | 212 ----------
.../mastodon_api/mastodon_api_controller_test.exs | 179 --------
.../controllers/account_controller_test.exs | 395 ++++++++++++++++++
.../controllers/emoji_api_controller_test.exs | 463 +++++++++++++++++++++
.../controllers/pleroma_api_controller_test.exs | 150 +++++++
test/web/pleroma_api/emoji_api_controller_test.exs | 459 --------------------
.../pleroma_api/pleroma_api_controller_test.exs | 150 -------
7 files changed, 1008 insertions(+), 1000 deletions(-)
create mode 100644 test/web/pleroma_api/controllers/account_controller_test.exs
create mode 100644 test/web/pleroma_api/controllers/emoji_api_controller_test.exs
create mode 100644 test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
delete mode 100644 test/web/pleroma_api/emoji_api_controller_test.exs
delete mode 100644 test/web/pleroma_api/pleroma_api_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs
index 6cf929011..32ccc5351 100644
--- a/test/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/web/mastodon_api/controllers/account_controller_test.exs
@@ -552,199 +552,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
end
- describe "getting favorites timeline of specified user" do
- setup do
- [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
- [current_user: current_user, user: user]
- end
-
- test "returns list of statuses favorited by specified user", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- [activity | _] = insert_pair(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- [like] = response
-
- assert length(response) == 1
- assert like["id"] == activity.id
- end
-
- test "returns favorites for specified user_id when user is not logged in", %{
- conn: conn,
- user: user
- } do
- activity = insert(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- response =
- conn
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert length(response) == 1
- end
-
- test "returns favorited DM only when user is logged in and he is one of recipients", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- {:ok, direct} =
- CommonAPI.post(current_user, %{
- "status" => "Hi @#{user.nickname}!",
- "visibility" => "direct"
- })
-
- CommonAPI.favorite(direct.id, user)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert length(response) == 1
-
- anonymous_response =
- conn
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert Enum.empty?(anonymous_response)
- end
-
- test "does not return others' favorited DM when user is not one of recipients", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- user_two = insert(:user)
-
- {:ok, direct} =
- CommonAPI.post(user_two, %{
- "status" => "Hi @#{user.nickname}!",
- "visibility" => "direct"
- })
-
- CommonAPI.favorite(direct.id, user)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "paginates favorites using since_id and max_id", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- activities = insert_list(10, :note_activity)
-
- Enum.each(activities, fn activity ->
- CommonAPI.favorite(activity.id, user)
- end)
-
- third_activity = Enum.at(activities, 2)
- seventh_activity = Enum.at(activities, 6)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
- since_id: third_activity.id,
- max_id: seventh_activity.id
- })
- |> json_response(:ok)
-
- assert length(response) == 3
- refute third_activity in response
- refute seventh_activity in response
- end
-
- test "limits favorites using limit parameter", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- 7
- |> insert_list(:note_activity)
- |> Enum.each(fn activity ->
- CommonAPI.favorite(activity.id, user)
- end)
-
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
- |> json_response(:ok)
-
- assert length(response) == 3
- end
-
- test "returns empty response when user does not have any favorited statuses", %{
- conn: conn,
- current_user: current_user,
- user: user
- } do
- response =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
- |> json_response(:ok)
-
- assert Enum.empty?(response)
- end
-
- test "returns 404 error when specified user is not exist", %{conn: conn} do
- conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
-
- assert json_response(conn, 404) == %{"error" => "Record not found"}
- end
-
- test "returns 403 error when user has hidden own favorites", %{
- conn: conn,
- current_user: current_user
- } do
- user = insert(:user, %{info: %{hide_favorites: true}})
- activity = insert(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- conn =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
-
- assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
- end
-
- test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
- user = insert(:user)
- activity = insert(:note_activity)
- CommonAPI.favorite(activity.id, user)
-
- conn =
- conn
- |> assign(:user, current_user)
- |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
-
- assert user.info.hide_favorites
- assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
- end
- end
-
describe "pinned statuses" do
setup do
user = insert(:user)
@@ -768,25 +575,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
end
end
- test "subscribing / unsubscribing to a user", %{conn: conn} do
- user = insert(:user)
- subscription_target = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
-
- assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
-
- assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
- end
-
test "blocking / unblocking a user", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 7cdefdcdd..671f9f254 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -23,8 +23,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
import Swoosh.TestAssertions
import Tesla.Mock
- @image "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
-
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
:ok
@@ -80,101 +78,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert expected == json_response(conn, 200)
end
- test "user avatar can be set", %{conn: conn} do
- user = insert(:user)
- avatar_image = File.read!("test/fixtures/avatar_data_uri")
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/accounts/update_avatar", %{img: avatar_image})
-
- user = refresh_record(user)
-
- assert %{
- "name" => _,
- "type" => _,
- "url" => [
- %{
- "href" => _,
- "mediaType" => _,
- "type" => _
- }
- ]
- } = user.avatar
-
- assert %{"url" => _} = json_response(conn, 200)
- end
-
- test "user avatar can be reset", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/accounts/update_avatar", %{img: ""})
-
- user = User.get_cached_by_id(user.id)
-
- assert user.avatar == nil
-
- assert %{"url" => nil} = json_response(conn, 200)
- end
-
- test "can set profile banner", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
-
- user = refresh_record(user)
- assert user.info.banner["type"] == "Image"
-
- assert %{"url" => _} = json_response(conn, 200)
- end
-
- test "can reset profile banner", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
-
- user = refresh_record(user)
- assert user.info.banner == %{}
-
- assert %{"url" => nil} = json_response(conn, 200)
- end
-
- test "background image can be set", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/accounts/update_background", %{"img" => @image})
-
- user = refresh_record(user)
- assert user.info.background["type"] == "Image"
- assert %{"url" => _} = json_response(conn, 200)
- end
-
- test "background image can be reset", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/accounts/update_background", %{"img" => ""})
-
- user = refresh_record(user)
- assert user.info.background == %{}
- assert %{"url" => nil} = json_response(conn, 200)
- end
-
test "creates an oauth app", %{conn: conn} do
user = insert(:user)
app_attrs = build(:oauth_app)
@@ -348,52 +251,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert url =~ "an_image"
end
end
- describe "subscribing / unsubscribing" do
- test "subscribing / unsubscribing to a user", %{conn: conn} do
- user = insert(:user)
- subscription_target = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
-
- assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
-
- assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
- end
- end
-
- describe "subscribing" do
- test "returns 404 when subscription_target not found", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/target_id/subscribe")
-
- assert %{"error" => "Record not found"} = json_response(conn, 404)
- end
- end
-
- describe "unsubscribing" do
- test "returns 404 when subscription_target not found", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/target_id/unsubscribe")
-
- assert %{"error" => "Record not found"} = json_response(conn, 404)
- end
- end
test "getting a list of mutes", %{conn: conn} do
user = insert(:user)
@@ -1088,42 +945,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
- setup do
- {:ok, user} =
- insert(:user)
- |> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
- |> Repo.update()
-
- assert user.info.confirmation_pending
-
- [user: user]
- end
-
- clear_config([:instance, :account_activation_required]) do
- Config.put([:instance, :account_activation_required], true)
- end
-
- test "resend account confirmation email", %{conn: conn, user: user} do
- conn
- |> assign(:user, user)
- |> post("/api/v1/pleroma/accounts/confirmation_resend?email=#{user.email}")
- |> json_response(:no_content)
-
- ObanHelpers.perform_all()
-
- email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
- notify_email = Config.get([:instance, :notify_email])
- instance_name = Config.get([:instance, :name])
-
- assert_email_sent(
- from: {instance_name, notify_email},
- to: {user.name, user.email},
- html_body: email.html_body
- )
- end
- end
-
describe "GET /api/v1/suggestions" do
setup do
user = insert(:user)
diff --git a/test/web/pleroma_api/controllers/account_controller_test.exs b/test/web/pleroma_api/controllers/account_controller_test.exs
new file mode 100644
index 000000000..3b4665afd
--- /dev/null
+++ b/test/web/pleroma_api/controllers/account_controller_test.exs
@@ -0,0 +1,395 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Config
+ alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+ import Swoosh.TestAssertions
+
+ @image "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
+
+ describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
+ setup do
+ {:ok, user} =
+ insert(:user)
+ |> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
+ |> Repo.update()
+
+ assert user.info.confirmation_pending
+
+ [user: user]
+ end
+
+ clear_config([:instance, :account_activation_required]) do
+ Config.put([:instance, :account_activation_required], true)
+ end
+
+ test "resend account confirmation email", %{conn: conn, user: user} do
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/confirmation_resend?email=#{user.email}")
+ |> json_response(:no_content)
+
+ ObanHelpers.perform_all()
+
+ email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
+ notify_email = Config.get([:instance, :notify_email])
+ instance_name = Config.get([:instance, :name])
+
+ assert_email_sent(
+ from: {instance_name, notify_email},
+ to: {user.name, user.email},
+ html_body: email.html_body
+ )
+ end
+ end
+
+ describe "PATCH /api/v1/pleroma/accounts/update_avatar" do
+ test "user avatar can be set", %{conn: conn} do
+ user = insert(:user)
+ avatar_image = File.read!("test/fixtures/avatar_data_uri")
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_avatar", %{img: avatar_image})
+
+ user = refresh_record(user)
+
+ assert %{
+ "name" => _,
+ "type" => _,
+ "url" => [
+ %{
+ "href" => _,
+ "mediaType" => _,
+ "type" => _
+ }
+ ]
+ } = user.avatar
+
+ assert %{"url" => _} = json_response(conn, 200)
+ end
+
+ test "user avatar can be reset", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_avatar", %{img: ""})
+
+ user = User.get_cached_by_id(user.id)
+
+ assert user.avatar == nil
+
+ assert %{"url" => nil} = json_response(conn, 200)
+ end
+ end
+
+ describe "PATCH /api/v1/pleroma/accounts/update_banner" do
+ test "can set profile banner", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
+
+ user = refresh_record(user)
+ assert user.info.banner["type"] == "Image"
+
+ assert %{"url" => _} = json_response(conn, 200)
+ end
+
+ test "can reset profile banner", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
+
+ user = refresh_record(user)
+ assert user.info.banner == %{}
+
+ assert %{"url" => nil} = json_response(conn, 200)
+ end
+ end
+
+ describe "PATCH /api/v1/pleroma/accounts/update_background" do
+ test "background image can be set", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_background", %{"img" => @image})
+
+ user = refresh_record(user)
+ assert user.info.background["type"] == "Image"
+ assert %{"url" => _} = json_response(conn, 200)
+ end
+
+ test "background image can be reset", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/accounts/update_background", %{"img" => ""})
+
+ user = refresh_record(user)
+ assert user.info.background == %{}
+ assert %{"url" => nil} = json_response(conn, 200)
+ end
+ end
+
+ describe "getting favorites timeline of specified user" do
+ setup do
+ [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
+ [current_user: current_user, user: user]
+ end
+
+ test "returns list of statuses favorited by specified user", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ [activity | _] = insert_pair(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ [like] = response
+
+ assert length(response) == 1
+ assert like["id"] == activity.id
+ end
+
+ test "returns favorites for specified user_id when user is not logged in", %{
+ conn: conn,
+ user: user
+ } do
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+ end
+
+ test "returns favorited DM only when user is logged in and he is one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ {:ok, direct} =
+ CommonAPI.post(current_user, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+
+ anonymous_response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(anonymous_response)
+ end
+
+ test "does not return others' favorited DM when user is not one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ user_two = insert(:user)
+
+ {:ok, direct} =
+ CommonAPI.post(user_two, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "paginates favorites using since_id and max_id", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ activities = insert_list(10, :note_activity)
+
+ Enum.each(activities, fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ third_activity = Enum.at(activities, 2)
+ seventh_activity = Enum.at(activities, 6)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
+ since_id: third_activity.id,
+ max_id: seventh_activity.id
+ })
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ refute third_activity in response
+ refute seventh_activity in response
+ end
+
+ test "limits favorites using limit parameter", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ 7
+ |> insert_list(:note_activity)
+ |> Enum.each(fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ end
+
+ test "returns empty response when user does not have any favorited statuses", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "returns 404 error when specified user is not exist", %{conn: conn} do
+ conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+
+ test "returns 403 error when user has hidden own favorites", %{
+ conn: conn,
+ current_user: current_user
+ } do
+ user = insert(:user, %{info: %{hide_favorites: true}})
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+
+ test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
+ user = insert(:user)
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert user.info.hide_favorites
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+ end
+
+ describe "subscribing / unsubscribing" do
+ test "subscribing / unsubscribing to a user", %{conn: conn} do
+ user = insert(:user)
+ subscription_target = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
+
+ assert %{"id" => _id, "subscribing" => true} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
+
+ assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
+ end
+ end
+
+ describe "subscribing" do
+ test "returns 404 when subscription_target not found", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/target_id/subscribe")
+
+ assert %{"error" => "Record not found"} = json_response(conn, 404)
+ end
+ end
+
+ describe "unsubscribing" do
+ test "returns 404 when subscription_target not found", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/target_id/unsubscribe")
+
+ assert %{"error" => "Record not found"} = json_response(conn, 404)
+ end
+ end
+end
diff --git a/test/web/pleroma_api/controllers/emoji_api_controller_test.exs b/test/web/pleroma_api/controllers/emoji_api_controller_test.exs
new file mode 100644
index 000000000..5f74460e8
--- /dev/null
+++ b/test/web/pleroma_api/controllers/emoji_api_controller_test.exs
@@ -0,0 +1,463 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Tesla.Mock
+
+ import Pleroma.Factory
+
+ @emoji_dir_path Path.join(
+ Pleroma.Config.get!([:instance, :static_dir]),
+ "emoji"
+ )
+
+ test "shared & non-shared pack information in list_packs is ok" do
+ conn = build_conn()
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ assert Map.has_key?(resp, "test_pack")
+
+ pack = resp["test_pack"]
+
+ assert Map.has_key?(pack["pack"], "download-sha256")
+ assert pack["pack"]["can-download"]
+
+ assert pack["files"] == %{"blank" => "blank.png"}
+
+ # Non-shared pack
+
+ assert Map.has_key?(resp, "test_pack_nonshared")
+
+ pack = resp["test_pack_nonshared"]
+
+ refute pack["pack"]["shared"]
+ refute pack["pack"]["can-download"]
+ end
+
+ test "listing remote packs" do
+ admin = insert(:user, info: %{is_admin: true})
+ conn = build_conn() |> assign(:user, admin)
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ mock(fn
+ %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
+ json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
+
+ %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
+ json(%{metadata: %{features: ["shareable_emoji_packs"]}})
+
+ %{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
+ json(resp)
+ end)
+
+ assert conn
+ |> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"})
+ |> json_response(200) == resp
+ end
+
+ test "downloading a shared pack from download_shared" do
+ conn = build_conn()
+
+ resp =
+ conn
+ |> get(emoji_api_path(conn, :download_shared, "test_pack"))
+ |> response(200)
+
+ {:ok, arch} = :zip.unzip(resp, [:memory])
+
+ assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
+ assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
+ end
+
+ test "downloading shared & unshared packs from another instance via download_from, deleting them" do
+ on_exit(fn ->
+ File.rm_rf!("#{@emoji_dir_path}/test_pack2")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
+ end)
+
+ mock(fn
+ %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
+ json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})
+
+ %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
+ json(%{metadata: %{features: []}})
+
+ %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
+ json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
+
+ %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
+ json(%{metadata: %{features: ["shareable_emoji_packs"]}})
+
+ %{
+ method: :get,
+ url: "https://example.com/api/pleroma/emoji/packs/list"
+ } ->
+ conn = build_conn()
+
+ conn
+ |> get(emoji_api_path(conn, :list_packs))
+ |> json_response(200)
+ |> json()
+
+ %{
+ method: :get,
+ url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
+ } ->
+ conn = build_conn()
+
+ conn
+ |> get(emoji_api_path(conn, :download_shared, "test_pack"))
+ |> response(200)
+ |> text()
+
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert (conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://old-instance",
+ pack_name: "test_pack",
+ as: "test_pack2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(500))["error"] =~ "does not support"
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://example.com",
+ pack_name: "test_pack",
+ as: "test_pack2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
+ assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_pack2"))
+ |> json_response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack2")
+
+ # non-shared, downloaded from the fallback URL
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ emoji_api_path(
+ conn,
+ :download_from
+ ),
+ %{
+ instance_address: "https://example.com",
+ pack_name: "test_pack_nonshared",
+ as: "test_pack_nonshared2"
+ }
+ |> Jason.encode!()
+ )
+ |> json_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
+ assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
+ |> json_response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
+ end
+
+ describe "updating pack metadata" do
+ setup do
+ pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
+ original_content = File.read!(pack_file)
+
+ on_exit(fn ->
+ File.write!(pack_file, original_content)
+ end)
+
+ {:ok,
+ admin: insert(:user, info: %{is_admin: true}),
+ pack_file: pack_file,
+ new_data: %{
+ "license" => "Test license changed",
+ "homepage" => "https://pleroma.social",
+ "description" => "Test description",
+ "share-files" => false
+ }}
+ end
+
+ test "for a pack without a fallback source", ctx do
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => ctx[:new_data]
+ }
+ )
+ |> json_response(200) == ctx[:new_data]
+
+ assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
+ end
+
+ test "for a pack with a fallback source", ctx do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
+ end)
+
+ new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
+
+ new_data_with_sha =
+ Map.put(
+ new_data,
+ "fallback-src-sha256",
+ "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
+ )
+
+ conn = build_conn()
+
+ assert conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> json_response(200) == new_data_with_sha
+
+ assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
+ end
+
+ test "when the fallback source doesn't have all the files", ctx do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://nonshared-pack"
+ } ->
+ {:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
+ text(empty_arch)
+ end)
+
+ new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
+
+ conn = build_conn()
+
+ assert (conn
+ |> assign(:user, ctx[:admin])
+ |> post(
+ emoji_api_path(conn, :update_metadata, "test_pack"),
+ %{
+ "new_data" => new_data
+ }
+ )
+ |> json_response(:bad_request))["error"] =~ "does not have all"
+ end
+ end
+
+ test "updating pack files" do
+ pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
+ original_content = File.read!(pack_file)
+
+ on_exit(fn ->
+ File.write!(pack_file, original_content)
+
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
+ File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn()
+
+ same_name = %{
+ "action" => "add",
+ "shortcode" => "blank",
+ "filename" => "dir/blank.png",
+ "file" => %Plug.Upload{
+ filename: "blank.png",
+ path: "#{@emoji_dir_path}/test_pack/blank.png"
+ }
+ }
+
+ different_name = %{same_name | "shortcode" => "blank_2"}
+
+ conn = conn |> assign(:user, admin)
+
+ assert (conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
+ |> json_response(:conflict))["error"] =~ "already exists"
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
+ |> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "update",
+ "shortcode" => "blank_2",
+ "new_shortcode" => "blank_3",
+ "new_filename" => "dir_2/blank_3.png"
+ })
+ |> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
+ assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "remove",
+ "shortcode" => "blank_3"
+ })
+ |> json_response(200) == %{"blank" => "blank.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
+
+ mock(fn
+ %{
+ method: :get,
+ url: "https://test-blank/blank_url.png"
+ } ->
+ text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
+ end)
+
+ # The name should be inferred from the URL ending
+ from_url = %{
+ "action" => "add",
+ "shortcode" => "blank_url",
+ "file" => "https://test-blank/blank_url.png"
+ }
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
+ |> json_response(200) == %{
+ "blank" => "blank.png",
+ "blank_url" => "blank_url.png"
+ }
+
+ assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
+
+ assert conn
+ |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
+ "action" => "remove",
+ "shortcode" => "blank_url"
+ })
+ |> json_response(200) == %{"blank" => "blank.png"}
+
+ refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
+ end
+
+ test "creating and deleting a pack" do
+ on_exit(fn ->
+ File.rm_rf!("#{@emoji_dir_path}/test_created")
+ end)
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ conn = build_conn() |> assign(:user, admin)
+
+ assert conn
+ |> put_req_header("content-type", "application/json")
+ |> put(
+ emoji_api_path(
+ conn,
+ :create,
+ "test_created"
+ )
+ )
+ |> json_response(200) == "ok"
+
+ assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
+
+ assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
+ "pack" => %{},
+ "files" => %{}
+ }
+
+ assert conn
+ |> delete(emoji_api_path(conn, :delete, "test_created"))
+ |> json_response(200) == "ok"
+
+ refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
+ end
+
+ test "filesystem import" do
+ on_exit(fn ->
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+ end)
+
+ conn = build_conn()
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ refute Map.has_key?(resp, "test_pack_for_import")
+
+ admin = insert(:user, info: %{is_admin: true})
+
+ assert conn
+ |> assign(:user, admin)
+ |> post(emoji_api_path(conn, :import_from_fs))
+ |> json_response(200) == ["test_pack_for_import"]
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+ assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
+
+ File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+ refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
+
+ emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
+
+ File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
+
+ assert conn
+ |> assign(:user, admin)
+ |> post(emoji_api_path(conn, :import_from_fs))
+ |> json_response(200) == ["test_pack_for_import"]
+
+ resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
+
+ assert resp["test_pack_for_import"]["files"] == %{
+ "blank" => "blank.png",
+ "blank2" => "blank.png"
+ }
+ end
+end
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
new file mode 100644
index 000000000..7eaeda4a0
--- /dev/null
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -0,0 +1,150 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Notification
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}")
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string()
+ end
+
+ test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ {:ok, activity_two} =
+ CommonAPI.post(other_user, %{
+ "status" => "Hi!",
+ "in_reply_to_status_id" => activity.id,
+ "in_reply_to_conversation_id" => participation.id
+ })
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
+ |> json_response(200)
+
+ assert length(result) == 2
+
+ id_one = activity.id
+ id_two = activity_two.id
+ assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
+ end
+
+ test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert [user] == participation.recipients
+ assert other_user not in participation.recipients
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
+ "recipients" => [user.id, other_user.id]
+ })
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string
+
+ [participation] = Participation.for_user(user)
+ participation = Repo.preload(participation, :recipients)
+
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+ end
+
+ describe "POST /api/v1/pleroma/notifications/read" do
+ test "it marks a single notification as read", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, [notification1]} = Notification.create_notifications(activity1)
+ {:ok, [notification2]} = Notification.create_notifications(activity2)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
+ |> json_response(:ok)
+
+ assert %{"pleroma" => %{"is_seen" => true}} = response
+ assert Repo.get(Notification, notification1.id).seen
+ refute Repo.get(Notification, notification2.id).seen
+ end
+
+ test "it marks multiple notifications as read", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
+ {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
+
+ [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
+
+ [response1, response2] =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
+ |> json_response(:ok)
+
+ assert %{"pleroma" => %{"is_seen" => true}} = response1
+ assert %{"pleroma" => %{"is_seen" => true}} = response2
+ assert Repo.get(Notification, notification1.id).seen
+ assert Repo.get(Notification, notification2.id).seen
+ refute Repo.get(Notification, notification3.id).seen
+ end
+
+ test "it returns error when notification not found", %{conn: conn} do
+ user1 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
+ |> json_response(:bad_request)
+
+ assert response == %{"error" => "Cannot get notification"}
+ end
+ end
+end
diff --git a/test/web/pleroma_api/emoji_api_controller_test.exs b/test/web/pleroma_api/emoji_api_controller_test.exs
deleted file mode 100644
index 93a507a01..000000000
--- a/test/web/pleroma_api/emoji_api_controller_test.exs
+++ /dev/null
@@ -1,459 +0,0 @@
-defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
- use Pleroma.Web.ConnCase
-
- import Tesla.Mock
-
- import Pleroma.Factory
-
- @emoji_dir_path Path.join(
- Pleroma.Config.get!([:instance, :static_dir]),
- "emoji"
- )
-
- test "shared & non-shared pack information in list_packs is ok" do
- conn = build_conn()
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- assert Map.has_key?(resp, "test_pack")
-
- pack = resp["test_pack"]
-
- assert Map.has_key?(pack["pack"], "download-sha256")
- assert pack["pack"]["can-download"]
-
- assert pack["files"] == %{"blank" => "blank.png"}
-
- # Non-shared pack
-
- assert Map.has_key?(resp, "test_pack_nonshared")
-
- pack = resp["test_pack_nonshared"]
-
- refute pack["pack"]["shared"]
- refute pack["pack"]["can-download"]
- end
-
- test "listing remote packs" do
- admin = insert(:user, info: %{is_admin: true})
- conn = build_conn() |> assign(:user, admin)
-
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- mock(fn
- %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
- json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
-
- %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
- json(%{metadata: %{features: ["shareable_emoji_packs"]}})
-
- %{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
- json(resp)
- end)
-
- assert conn
- |> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"})
- |> json_response(200) == resp
- end
-
- test "downloading a shared pack from download_shared" do
- conn = build_conn()
-
- resp =
- conn
- |> get(emoji_api_path(conn, :download_shared, "test_pack"))
- |> response(200)
-
- {:ok, arch} = :zip.unzip(resp, [:memory])
-
- assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
- assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
- end
-
- test "downloading shared & unshared packs from another instance via download_from, deleting them" do
- on_exit(fn ->
- File.rm_rf!("#{@emoji_dir_path}/test_pack2")
- File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
- end)
-
- mock(fn
- %{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
- json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})
-
- %{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
- json(%{metadata: %{features: []}})
-
- %{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
- json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
-
- %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
- json(%{metadata: %{features: ["shareable_emoji_packs"]}})
-
- %{
- method: :get,
- url: "https://example.com/api/pleroma/emoji/packs/list"
- } ->
- conn = build_conn()
-
- conn
- |> get(emoji_api_path(conn, :list_packs))
- |> json_response(200)
- |> json()
-
- %{
- method: :get,
- url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
- } ->
- conn = build_conn()
-
- conn
- |> get(emoji_api_path(conn, :download_shared, "test_pack"))
- |> response(200)
- |> text()
-
- %{
- method: :get,
- url: "https://nonshared-pack"
- } ->
- text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
- end)
-
- admin = insert(:user, info: %{is_admin: true})
-
- conn = build_conn() |> assign(:user, admin)
-
- assert (conn
- |> put_req_header("content-type", "application/json")
- |> post(
- emoji_api_path(
- conn,
- :download_from
- ),
- %{
- instance_address: "https://old-instance",
- pack_name: "test_pack",
- as: "test_pack2"
- }
- |> Jason.encode!()
- )
- |> json_response(500))["error"] =~ "does not support"
-
- assert conn
- |> put_req_header("content-type", "application/json")
- |> post(
- emoji_api_path(
- conn,
- :download_from
- ),
- %{
- instance_address: "https://example.com",
- pack_name: "test_pack",
- as: "test_pack2"
- }
- |> Jason.encode!()
- )
- |> json_response(200) == "ok"
-
- assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
- assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
-
- assert conn
- |> delete(emoji_api_path(conn, :delete, "test_pack2"))
- |> json_response(200) == "ok"
-
- refute File.exists?("#{@emoji_dir_path}/test_pack2")
-
- # non-shared, downloaded from the fallback URL
-
- conn = build_conn() |> assign(:user, admin)
-
- assert conn
- |> put_req_header("content-type", "application/json")
- |> post(
- emoji_api_path(
- conn,
- :download_from
- ),
- %{
- instance_address: "https://example.com",
- pack_name: "test_pack_nonshared",
- as: "test_pack_nonshared2"
- }
- |> Jason.encode!()
- )
- |> json_response(200) == "ok"
-
- assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
- assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
-
- assert conn
- |> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
- |> json_response(200) == "ok"
-
- refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
- end
-
- describe "updating pack metadata" do
- setup do
- pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
- original_content = File.read!(pack_file)
-
- on_exit(fn ->
- File.write!(pack_file, original_content)
- end)
-
- {:ok,
- admin: insert(:user, info: %{is_admin: true}),
- pack_file: pack_file,
- new_data: %{
- "license" => "Test license changed",
- "homepage" => "https://pleroma.social",
- "description" => "Test description",
- "share-files" => false
- }}
- end
-
- test "for a pack without a fallback source", ctx do
- conn = build_conn()
-
- assert conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => ctx[:new_data]
- }
- )
- |> json_response(200) == ctx[:new_data]
-
- assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
- end
-
- test "for a pack with a fallback source", ctx do
- mock(fn
- %{
- method: :get,
- url: "https://nonshared-pack"
- } ->
- text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
- end)
-
- new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
-
- new_data_with_sha =
- Map.put(
- new_data,
- "fallback-src-sha256",
- "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
- )
-
- conn = build_conn()
-
- assert conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => new_data
- }
- )
- |> json_response(200) == new_data_with_sha
-
- assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
- end
-
- test "when the fallback source doesn't have all the files", ctx do
- mock(fn
- %{
- method: :get,
- url: "https://nonshared-pack"
- } ->
- {:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
- text(empty_arch)
- end)
-
- new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
-
- conn = build_conn()
-
- assert (conn
- |> assign(:user, ctx[:admin])
- |> post(
- emoji_api_path(conn, :update_metadata, "test_pack"),
- %{
- "new_data" => new_data
- }
- )
- |> json_response(:bad_request))["error"] =~ "does not have all"
- end
- end
-
- test "updating pack files" do
- pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
- original_content = File.read!(pack_file)
-
- on_exit(fn ->
- File.write!(pack_file, original_content)
-
- File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
- File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
- File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
- end)
-
- admin = insert(:user, info: %{is_admin: true})
-
- conn = build_conn()
-
- same_name = %{
- "action" => "add",
- "shortcode" => "blank",
- "filename" => "dir/blank.png",
- "file" => %Plug.Upload{
- filename: "blank.png",
- path: "#{@emoji_dir_path}/test_pack/blank.png"
- }
- }
-
- different_name = %{same_name | "shortcode" => "blank_2"}
-
- conn = conn |> assign(:user, admin)
-
- assert (conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
- |> json_response(:conflict))["error"] =~ "already exists"
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
- |> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
-
- assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
- "action" => "update",
- "shortcode" => "blank_2",
- "new_shortcode" => "blank_3",
- "new_filename" => "dir_2/blank_3.png"
- })
- |> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
-
- refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
- assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
- "action" => "remove",
- "shortcode" => "blank_3"
- })
- |> json_response(200) == %{"blank" => "blank.png"}
-
- refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
-
- mock(fn
- %{
- method: :get,
- url: "https://test-blank/blank_url.png"
- } ->
- text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
- end)
-
- # The name should be inferred from the URL ending
- from_url = %{
- "action" => "add",
- "shortcode" => "blank_url",
- "file" => "https://test-blank/blank_url.png"
- }
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
- |> json_response(200) == %{
- "blank" => "blank.png",
- "blank_url" => "blank_url.png"
- }
-
- assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
-
- assert conn
- |> post(emoji_api_path(conn, :update_file, "test_pack"), %{
- "action" => "remove",
- "shortcode" => "blank_url"
- })
- |> json_response(200) == %{"blank" => "blank.png"}
-
- refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
- end
-
- test "creating and deleting a pack" do
- on_exit(fn ->
- File.rm_rf!("#{@emoji_dir_path}/test_created")
- end)
-
- admin = insert(:user, info: %{is_admin: true})
-
- conn = build_conn() |> assign(:user, admin)
-
- assert conn
- |> put_req_header("content-type", "application/json")
- |> put(
- emoji_api_path(
- conn,
- :create,
- "test_created"
- )
- )
- |> json_response(200) == "ok"
-
- assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
-
- assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
- "pack" => %{},
- "files" => %{}
- }
-
- assert conn
- |> delete(emoji_api_path(conn, :delete, "test_created"))
- |> json_response(200) == "ok"
-
- refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
- end
-
- test "filesystem import" do
- on_exit(fn ->
- File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
- File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
- end)
-
- conn = build_conn()
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- refute Map.has_key?(resp, "test_pack_for_import")
-
- admin = insert(:user, info: %{is_admin: true})
-
- assert conn
- |> assign(:user, admin)
- |> post(emoji_api_path(conn, :import_from_fs))
- |> json_response(200) == ["test_pack_for_import"]
-
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
- assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
-
- File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
- refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
-
- emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
-
- File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
-
- assert conn
- |> assign(:user, admin)
- |> post(emoji_api_path(conn, :import_from_fs))
- |> json_response(200) == ["test_pack_for_import"]
-
- resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
-
- assert resp["test_pack_for_import"]["files"] == %{
- "blank" => "blank.png",
- "blank2" => "blank.png"
- }
- end
-end
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
deleted file mode 100644
index 7eaeda4a0..000000000
--- a/test/web/pleroma_api/pleroma_api_controller_test.exs
+++ /dev/null
@@ -1,150 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
- use Pleroma.Web.ConnCase
-
- alias Pleroma.Conversation.Participation
- alias Pleroma.Notification
- alias Pleroma.Repo
- alias Pleroma.Web.CommonAPI
-
- import Pleroma.Factory
-
- test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
-
- [participation] = Participation.for_user(other_user)
-
- result =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/pleroma/conversations/#{participation.id}")
- |> json_response(200)
-
- assert result["id"] == participation.id |> to_string()
- end
-
- test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- third_user = insert(:user)
-
- {:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
-
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
-
- [participation] = Participation.for_user(other_user)
-
- {:ok, activity_two} =
- CommonAPI.post(other_user, %{
- "status" => "Hi!",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
- })
-
- result =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
- |> json_response(200)
-
- assert length(result) == 2
-
- id_one = activity.id
- id_two = activity_two.id
- assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
- end
-
- test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
-
- [participation] = Participation.for_user(user)
-
- participation = Repo.preload(participation, :recipients)
-
- assert [user] == participation.recipients
- assert other_user not in participation.recipients
-
- result =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
- "recipients" => [user.id, other_user.id]
- })
- |> json_response(200)
-
- assert result["id"] == participation.id |> to_string
-
- [participation] = Participation.for_user(user)
- participation = Repo.preload(participation, :recipients)
-
- assert user in participation.recipients
- assert other_user in participation.recipients
- end
-
- describe "POST /api/v1/pleroma/notifications/read" do
- test "it marks a single notification as read", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, [notification1]} = Notification.create_notifications(activity1)
- {:ok, [notification2]} = Notification.create_notifications(activity2)
-
- response =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
- |> json_response(:ok)
-
- assert %{"pleroma" => %{"is_seen" => true}} = response
- assert Repo.get(Notification, notification1.id).seen
- refute Repo.get(Notification, notification2.id).seen
- end
-
- test "it marks multiple notifications as read", %{conn: conn} do
- user1 = insert(:user)
- user2 = insert(:user)
- {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
- {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
-
- [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
-
- [response1, response2] =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
- |> json_response(:ok)
-
- assert %{"pleroma" => %{"is_seen" => true}} = response1
- assert %{"pleroma" => %{"is_seen" => true}} = response2
- assert Repo.get(Notification, notification1.id).seen
- assert Repo.get(Notification, notification2.id).seen
- refute Repo.get(Notification, notification3.id).seen
- end
-
- test "it returns error when notification not found", %{conn: conn} do
- user1 = insert(:user)
-
- response =
- conn
- |> assign(:user, user1)
- |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
- |> json_response(:bad_request)
-
- assert response == %{"error" => "Cannot get notification"}
- end
- end
-end
--
cgit v1.2.3
From 38db4878a451b5e78a8a74bd916390dea5c21643 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 14:28:37 +0700
Subject: Disable async in DomainBlockControllerTest
---
test/web/mastodon_api/controllers/domain_block_controller_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/domain_block_controller_test.exs b/test/web/mastodon_api/controllers/domain_block_controller_test.exs
index 3c3558385..25a279cdc 100644
--- a/test/web/mastodon_api/controllers/domain_block_controller_test.exs
+++ b/test/web/mastodon_api/controllers/domain_block_controller_test.exs
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
- use Pleroma.Web.ConnCase, async: true
+ use Pleroma.Web.ConnCase
alias Pleroma.User
--
cgit v1.2.3
From 122cc050abb84b94fa57a15576c2a38b2912d559 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 14:43:54 +0700
Subject: Move account_lists test to MastodonAPI.AccountControllerTest
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 17 -----------------
1 file changed, 17 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 671f9f254..0acc5d067 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1082,23 +1082,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "GET /api/v1/accounts/:id/lists - account_lists" do
- test "returns lists to which the account belongs", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- assert {:ok, %Pleroma.List{} = list} = Pleroma.List.create("Test List", user)
- {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
-
- res =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/#{other_user.id}/lists")
- |> json_response(200)
-
- assert res == [%{"id" => to_string(list.id), "title" => "Test List"}]
- end
- end
-
describe "empty_array, stubs for mastodon api" do
test "GET /api/v1/accounts/:id/identity_proofs", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From c0ce2d5faf872da219e724f4fc2e4deecb89e978 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 16:08:29 +0700
Subject: Move account_register, relationships and verify_credentials to
MastodonAPI.AccountController
---
.../controllers/account_controller_test.exs | 254 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 236 -------------------
2 files changed, 254 insertions(+), 236 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs
index 32ccc5351..8c8017838 100644
--- a/test/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/web/mastodon_api/controllers/account_controller_test.exs
@@ -5,9 +5,11 @@
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
use Pleroma.Web.ConnCase
+ alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.OAuth.Token
import Pleroma.Factory
@@ -595,4 +597,256 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert %{"id" => _id, "blocking" => false} = json_response(conn, 200)
end
+
+ describe "create account by app" do
+ setup do
+ valid_params = %{
+ username: "lain",
+ email: "lain@example.org",
+ password: "PlzDontHackLain",
+ agreement: true
+ }
+
+ [valid_params: valid_params]
+ end
+
+ test "Account registration via Application", %{conn: conn} do
+ conn =
+ conn
+ |> post("/api/v1/apps", %{
+ client_name: "client_name",
+ redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
+ scopes: "read, write, follow"
+ })
+
+ %{
+ "client_id" => client_id,
+ "client_secret" => client_secret,
+ "id" => _,
+ "name" => "client_name",
+ "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
+ "vapid_key" => _,
+ "website" => nil
+ } = json_response(conn, 200)
+
+ conn =
+ conn
+ |> post("/oauth/token", %{
+ grant_type: "client_credentials",
+ client_id: client_id,
+ client_secret: client_secret
+ })
+
+ assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
+ json_response(conn, 200)
+
+ assert token
+ token_from_db = Repo.get_by(Token, token: token)
+ assert token_from_db
+ assert refresh
+ assert scope == "read write follow"
+
+ conn =
+ build_conn()
+ |> put_req_header("authorization", "Bearer " <> token)
+ |> post("/api/v1/accounts", %{
+ username: "lain",
+ email: "lain@example.org",
+ password: "PlzDontHackLain",
+ bio: "Test Bio",
+ agreement: true
+ })
+
+ %{
+ "access_token" => token,
+ "created_at" => _created_at,
+ "scope" => _scope,
+ "token_type" => "Bearer"
+ } = json_response(conn, 200)
+
+ token_from_db = Repo.get_by(Token, token: token)
+ assert token_from_db
+ token_from_db = Repo.preload(token_from_db, :user)
+ assert token_from_db.user
+
+ assert token_from_db.user.info.confirmation_pending
+ end
+
+ test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
+ _user = insert(:user, email: "lain@example.org")
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+
+ res = post(conn, "/api/v1/accounts", valid_params)
+ assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}
+ end
+
+ test "rate limit", %{conn: conn} do
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ put_req_header(conn, "authorization", "Bearer " <> app_token.token)
+ |> Map.put(:remote_ip, {15, 15, 15, 15})
+
+ for i <- 1..5 do
+ conn =
+ conn
+ |> post("/api/v1/accounts", %{
+ username: "#{i}lain",
+ email: "#{i}lain@example.org",
+ password: "PlzDontHackLain",
+ agreement: true
+ })
+
+ %{
+ "access_token" => token,
+ "created_at" => _created_at,
+ "scope" => _scope,
+ "token_type" => "Bearer"
+ } = json_response(conn, 200)
+
+ token_from_db = Repo.get_by(Token, token: token)
+ assert token_from_db
+ token_from_db = Repo.preload(token_from_db, :user)
+ assert token_from_db.user
+
+ assert token_from_db.user.info.confirmation_pending
+ end
+
+ conn =
+ conn
+ |> post("/api/v1/accounts", %{
+ username: "6lain",
+ email: "6lain@example.org",
+ password: "PlzDontHackLain",
+ agreement: true
+ })
+
+ assert json_response(conn, :too_many_requests) == %{"error" => "Throttled"}
+ end
+
+ test "returns bad_request if missing required params", %{
+ conn: conn,
+ valid_params: valid_params
+ } do
+ app_token = insert(:oauth_token, user: nil)
+
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> app_token.token)
+
+ res = post(conn, "/api/v1/accounts", valid_params)
+ assert json_response(res, 200)
+
+ [{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
+ |> Stream.zip(valid_params)
+ |> Enum.each(fn {ip, {attr, _}} ->
+ res =
+ conn
+ |> Map.put(:remote_ip, ip)
+ |> post("/api/v1/accounts", Map.delete(valid_params, attr))
+ |> json_response(400)
+
+ assert res == %{"error" => "Missing parameters"}
+ end)
+ end
+
+ test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer " <> "invalid-token")
+
+ res = post(conn, "/api/v1/accounts", valid_params)
+ assert json_response(res, 403) == %{"error" => "Invalid credentials"}
+ end
+ end
+
+ describe "GET /api/v1/accounts/:id/lists - account_lists" do
+ test "returns lists to which the account belongs", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ assert {:ok, %Pleroma.List{} = list} = Pleroma.List.create("Test List", user)
+ {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/#{other_user.id}/lists")
+ |> json_response(200)
+
+ assert res == [%{"id" => to_string(list.id), "title" => "Test List"}]
+ end
+ end
+
+ describe "verify_credentials" do
+ test "verify_credentials", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/verify_credentials")
+
+ response = json_response(conn, 200)
+
+ assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
+ assert response["pleroma"]["chat_token"]
+ assert id == to_string(user.id)
+ end
+
+ test "verify_credentials default scope unlisted", %{conn: conn} do
+ user = insert(:user, %{info: %User.Info{default_scope: "unlisted"}})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/verify_credentials")
+
+ assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} = json_response(conn, 200)
+ assert id == to_string(user.id)
+ end
+
+ test "locked accounts", %{conn: conn} do
+ user = insert(:user, %{info: %User.Info{default_scope: "private"}})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/verify_credentials")
+
+ assert %{"id" => id, "source" => %{"privacy" => "private"}} = json_response(conn, 200)
+ assert id == to_string(user.id)
+ end
+ end
+
+ describe "user relationships" do
+ test "returns the relationships for the current user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, user} = User.follow(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/relationships", %{"id" => [other_user.id]})
+
+ assert [relationship] = json_response(conn, 200)
+
+ assert to_string(other_user.id) == relationship["id"]
+ end
+
+ test "returns an empty list on a bad request", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/relationships", %{})
+
+ assert [] = json_response(conn, 200)
+ end
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 0acc5d067..f2f8c0578 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -15,7 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.App
- alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.Push
import ExUnit.CaptureLog
@@ -31,33 +30,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
clear_config([:instance, :public])
clear_config([:rich_media, :enabled])
- test "verify_credentials", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/verify_credentials")
-
- response = json_response(conn, 200)
-
- assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
- assert response["pleroma"]["chat_token"]
- assert id == to_string(user.id)
- end
-
- test "verify_credentials default scope unlisted", %{conn: conn} do
- user = insert(:user, %{info: %User.Info{default_scope: "unlisted"}})
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/verify_credentials")
-
- assert %{"id" => id, "source" => %{"privacy" => "unlisted"}} = json_response(conn, 200)
- assert id == to_string(user.id)
- end
-
test "apps/verify_credentials", %{conn: conn} do
token = insert(:oauth_token)
@@ -105,34 +77,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert expected == json_response(conn, 200)
end
- describe "user relationships" do
- test "returns the relationships for the current user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/relationships", %{"id" => [other_user.id]})
-
- assert [relationship] = json_response(conn, 200)
-
- assert to_string(other_user.id) == relationship["id"]
- end
-
- test "returns an empty list on a bad request", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/relationships", %{})
-
- assert [] = json_response(conn, 200)
- end
- end
-
describe "media upload" do
setup do
user = insert(:user)
@@ -170,20 +114,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "locked accounts" do
- test "verify_credentials", %{conn: conn} do
- user = insert(:user, %{info: %User.Info{default_scope: "private"}})
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/verify_credentials")
-
- assert %{"id" => id, "source" => %{"privacy" => "private"}} = json_response(conn, 200)
- assert id == to_string(user.id)
- end
- end
-
describe "/api/v1/pleroma/mascot" do
test "mascot upload", %{conn: conn} do
user = insert(:user)
@@ -555,172 +485,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "create account by app" do
- setup do
- valid_params = %{
- username: "lain",
- email: "lain@example.org",
- password: "PlzDontHackLain",
- agreement: true
- }
-
- [valid_params: valid_params]
- end
-
- test "Account registration via Application", %{conn: conn} do
- conn =
- conn
- |> post("/api/v1/apps", %{
- client_name: "client_name",
- redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
- scopes: "read, write, follow"
- })
-
- %{
- "client_id" => client_id,
- "client_secret" => client_secret,
- "id" => _,
- "name" => "client_name",
- "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
- "vapid_key" => _,
- "website" => nil
- } = json_response(conn, 200)
-
- conn =
- conn
- |> post("/oauth/token", %{
- grant_type: "client_credentials",
- client_id: client_id,
- client_secret: client_secret
- })
-
- assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
- json_response(conn, 200)
-
- assert token
- token_from_db = Repo.get_by(Token, token: token)
- assert token_from_db
- assert refresh
- assert scope == "read write follow"
-
- conn =
- build_conn()
- |> put_req_header("authorization", "Bearer " <> token)
- |> post("/api/v1/accounts", %{
- username: "lain",
- email: "lain@example.org",
- password: "PlzDontHackLain",
- bio: "Test Bio",
- agreement: true
- })
-
- %{
- "access_token" => token,
- "created_at" => _created_at,
- "scope" => _scope,
- "token_type" => "Bearer"
- } = json_response(conn, 200)
-
- token_from_db = Repo.get_by(Token, token: token)
- assert token_from_db
- token_from_db = Repo.preload(token_from_db, :user)
- assert token_from_db.user
-
- assert token_from_db.user.info.confirmation_pending
- end
-
- test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
- _user = insert(:user, email: "lain@example.org")
- app_token = insert(:oauth_token, user: nil)
-
- conn =
- conn
- |> put_req_header("authorization", "Bearer " <> app_token.token)
-
- res = post(conn, "/api/v1/accounts", valid_params)
- assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}
- end
-
- test "rate limit", %{conn: conn} do
- app_token = insert(:oauth_token, user: nil)
-
- conn =
- put_req_header(conn, "authorization", "Bearer " <> app_token.token)
- |> Map.put(:remote_ip, {15, 15, 15, 15})
-
- for i <- 1..5 do
- conn =
- conn
- |> post("/api/v1/accounts", %{
- username: "#{i}lain",
- email: "#{i}lain@example.org",
- password: "PlzDontHackLain",
- agreement: true
- })
-
- %{
- "access_token" => token,
- "created_at" => _created_at,
- "scope" => _scope,
- "token_type" => "Bearer"
- } = json_response(conn, 200)
-
- token_from_db = Repo.get_by(Token, token: token)
- assert token_from_db
- token_from_db = Repo.preload(token_from_db, :user)
- assert token_from_db.user
-
- assert token_from_db.user.info.confirmation_pending
- end
-
- conn =
- conn
- |> post("/api/v1/accounts", %{
- username: "6lain",
- email: "6lain@example.org",
- password: "PlzDontHackLain",
- agreement: true
- })
-
- assert json_response(conn, :too_many_requests) == %{"error" => "Throttled"}
- end
-
- test "returns bad_request if missing required params", %{
- conn: conn,
- valid_params: valid_params
- } do
- app_token = insert(:oauth_token, user: nil)
-
- conn =
- conn
- |> put_req_header("authorization", "Bearer " <> app_token.token)
-
- res = post(conn, "/api/v1/accounts", valid_params)
- assert json_response(res, 200)
-
- [{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
- |> Stream.zip(valid_params)
- |> Enum.each(fn {ip, {attr, _}} ->
- res =
- conn
- |> Map.put(:remote_ip, ip)
- |> post("/api/v1/accounts", Map.delete(valid_params, attr))
- |> json_response(400)
-
- assert res == %{"error" => "Missing parameters"}
- end)
- end
-
- test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
- conn =
- conn
- |> put_req_header("authorization", "Bearer " <> "invalid-token")
-
- res = post(conn, "/api/v1/accounts", valid_params)
- assert json_response(res, 403) == %{"error" => "Invalid credentials"}
- end
- end
-
describe "GET /api/v1/polls/:id" do
test "returns poll entity for object id", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 987e0b8be8a7e0c40eacc96aaec53a6534563cab Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 15:47:01 +0700
Subject: Move update_credentials to MastodonAPI.AccountController
---
.../account_controller/update_credentials_test.exs | 384 +++++++++++++++++++++
.../update_credentials_test.exs | 384 ---------------------
2 files changed, 384 insertions(+), 384 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
delete mode 100644 test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
new file mode 100644
index 000000000..560f55137
--- /dev/null
+++ b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
@@ -0,0 +1,384 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
+ alias Pleroma.Repo
+ alias Pleroma.User
+
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+ clear_config([:instance, :max_account_fields])
+
+ describe "updating credentials" do
+ test "sets user settings in a generic way", %{conn: conn} do
+ user = insert(:user)
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ pleroma_fe: %{
+ theme: "bla"
+ }
+ }
+ })
+
+ assert user = json_response(res_conn, 200)
+ assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
+
+ user = Repo.get(User, user["id"])
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ masto_fe: %{
+ theme: "bla"
+ }
+ }
+ })
+
+ assert user = json_response(res_conn, 200)
+
+ assert user["pleroma"]["settings_store"] ==
+ %{
+ "pleroma_fe" => %{"theme" => "bla"},
+ "masto_fe" => %{"theme" => "bla"}
+ }
+
+ user = Repo.get(User, user["id"])
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ masto_fe: %{
+ theme: "blub"
+ }
+ }
+ })
+
+ assert user = json_response(res_conn, 200)
+
+ assert user["pleroma"]["settings_store"] ==
+ %{
+ "pleroma_fe" => %{"theme" => "bla"},
+ "masto_fe" => %{"theme" => "blub"}
+ }
+ end
+
+ test "updates the user's bio", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "note" => "I drink #cofe with @#{user2.nickname}"
+ })
+
+ assert user = json_response(conn, 200)
+
+ assert user["note"] ==
+ ~s(I drink #cofe with @#{user2.nickname})
+ end
+
+ test "updates the user's locking status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{locked: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["locked"] == true
+ end
+
+ test "updates the user's default scope", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["privacy"] == "cofe"
+ end
+
+ test "updates the user's hide_followers status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_followers"] == true
+ end
+
+ test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ hide_followers_count: "true",
+ hide_follows_count: "true"
+ })
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_followers_count"] == true
+ assert user["pleroma"]["hide_follows_count"] == true
+ end
+
+ test "updates the user's skip_thread_containment option", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
+ |> json_response(200)
+
+ assert response["pleroma"]["skip_thread_containment"] == true
+ assert refresh_record(user).info.skip_thread_containment
+ end
+
+ test "updates the user's hide_follows status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_follows"] == true
+ end
+
+ test "updates the user's hide_favorites status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_favorites"] == true
+ end
+
+ test "updates the user's show_role status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["pleroma"]["show_role"] == false
+ end
+
+ test "updates the user's no_rich_text status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["pleroma"]["no_rich_text"] == true
+ end
+
+ test "updates the user's name", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
+
+ assert user = json_response(conn, 200)
+ assert user["display_name"] == "markorepairs"
+ end
+
+ test "updates the user's avatar", %{conn: conn} do
+ user = insert(:user)
+
+ new_avatar = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
+
+ assert user_response = json_response(conn, 200)
+ assert user_response["avatar"] != User.avatar_url(user)
+ end
+
+ test "updates the user's banner", %{conn: conn} do
+ user = insert(:user)
+
+ new_header = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
+
+ assert user_response = json_response(conn, 200)
+ assert user_response["header"] != User.banner_url(user)
+ end
+
+ test "updates the user's background", %{conn: conn} do
+ user = insert(:user)
+
+ new_header = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_background_image" => new_header
+ })
+
+ assert user_response = json_response(conn, 200)
+ assert user_response["pleroma"]["background_image"]
+ end
+
+ test "requires 'write' permission", %{conn: conn} do
+ token1 = insert(:oauth_token, scopes: ["read"])
+ token2 = insert(:oauth_token, scopes: ["write", "follow"])
+
+ for token <- [token1, token2] do
+ conn =
+ conn
+ |> put_req_header("authorization", "Bearer #{token.token}")
+ |> patch("/api/v1/accounts/update_credentials", %{})
+
+ if token == token1 do
+ assert %{"error" => "Insufficient permissions: write."} == json_response(conn, 403)
+ else
+ assert json_response(conn, 200)
+ end
+ end
+ end
+
+ test "updates profile emojos", %{conn: conn} do
+ user = insert(:user)
+
+ note = "*sips :blank:*"
+ name = "I am :firefox:"
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "note" => note,
+ "display_name" => name
+ })
+
+ assert json_response(conn, 200)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}")
+
+ assert user = json_response(conn, 200)
+
+ assert user["note"] == note
+ assert user["display_name"] == name
+ assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
+ end
+
+ test "update fields", %{conn: conn} do
+ user = insert(:user)
+
+ fields = [
+ %{"name" => "foo", "value" => ""},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ account =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(200)
+
+ assert account["fields"] == [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "link", "value" => ~S(cofe.io)}
+ ]
+
+ assert account["source"]["fields"] == [
+ %{
+ "name" => "foo",
+ "value" => ""
+ },
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
+ value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
+
+ long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
+
+ fields = [%{"name" => "foo", "value" => long_value}]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+
+ long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
+
+ fields = [%{"name" => long_name, "value" => "bar"}]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+
+ Pleroma.Config.put([:instance, :max_account_fields], 1)
+
+ fields = [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+ end
+ end
+end
diff --git a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
deleted file mode 100644
index 560f55137..000000000
--- a/test/web/mastodon_api/controllers/mastodon_api_controller/update_credentials_test.exs
+++ /dev/null
@@ -1,384 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
- alias Pleroma.Repo
- alias Pleroma.User
-
- use Pleroma.Web.ConnCase
-
- import Pleroma.Factory
- clear_config([:instance, :max_account_fields])
-
- describe "updating credentials" do
- test "sets user settings in a generic way", %{conn: conn} do
- user = insert(:user)
-
- res_conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "pleroma_settings_store" => %{
- pleroma_fe: %{
- theme: "bla"
- }
- }
- })
-
- assert user = json_response(res_conn, 200)
- assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
-
- user = Repo.get(User, user["id"])
-
- res_conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "pleroma_settings_store" => %{
- masto_fe: %{
- theme: "bla"
- }
- }
- })
-
- assert user = json_response(res_conn, 200)
-
- assert user["pleroma"]["settings_store"] ==
- %{
- "pleroma_fe" => %{"theme" => "bla"},
- "masto_fe" => %{"theme" => "bla"}
- }
-
- user = Repo.get(User, user["id"])
-
- res_conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "pleroma_settings_store" => %{
- masto_fe: %{
- theme: "blub"
- }
- }
- })
-
- assert user = json_response(res_conn, 200)
-
- assert user["pleroma"]["settings_store"] ==
- %{
- "pleroma_fe" => %{"theme" => "bla"},
- "masto_fe" => %{"theme" => "blub"}
- }
- end
-
- test "updates the user's bio", %{conn: conn} do
- user = insert(:user)
- user2 = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "note" => "I drink #cofe with @#{user2.nickname}"
- })
-
- assert user = json_response(conn, 200)
-
- assert user["note"] ==
- ~s(I drink #cofe with @#{user2.nickname})
- end
-
- test "updates the user's locking status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{locked: "true"})
-
- assert user = json_response(conn, 200)
- assert user["locked"] == true
- end
-
- test "updates the user's default scope", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["privacy"] == "cofe"
- end
-
- test "updates the user's hide_followers status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_followers"] == true
- end
-
- test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- hide_followers_count: "true",
- hide_follows_count: "true"
- })
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_followers_count"] == true
- assert user["pleroma"]["hide_follows_count"] == true
- end
-
- test "updates the user's skip_thread_containment option", %{conn: conn} do
- user = insert(:user)
-
- response =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
- |> json_response(200)
-
- assert response["pleroma"]["skip_thread_containment"] == true
- assert refresh_record(user).info.skip_thread_containment
- end
-
- test "updates the user's hide_follows status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_follows"] == true
- end
-
- test "updates the user's hide_favorites status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_favorites"] == true
- end
-
- test "updates the user's show_role status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["pleroma"]["show_role"] == false
- end
-
- test "updates the user's no_rich_text status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["pleroma"]["no_rich_text"] == true
- end
-
- test "updates the user's name", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
-
- assert user = json_response(conn, 200)
- assert user["display_name"] == "markorepairs"
- end
-
- test "updates the user's avatar", %{conn: conn} do
- user = insert(:user)
-
- new_avatar = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
-
- assert user_response = json_response(conn, 200)
- assert user_response["avatar"] != User.avatar_url(user)
- end
-
- test "updates the user's banner", %{conn: conn} do
- user = insert(:user)
-
- new_header = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
-
- assert user_response = json_response(conn, 200)
- assert user_response["header"] != User.banner_url(user)
- end
-
- test "updates the user's background", %{conn: conn} do
- user = insert(:user)
-
- new_header = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "pleroma_background_image" => new_header
- })
-
- assert user_response = json_response(conn, 200)
- assert user_response["pleroma"]["background_image"]
- end
-
- test "requires 'write' permission", %{conn: conn} do
- token1 = insert(:oauth_token, scopes: ["read"])
- token2 = insert(:oauth_token, scopes: ["write", "follow"])
-
- for token <- [token1, token2] do
- conn =
- conn
- |> put_req_header("authorization", "Bearer #{token.token}")
- |> patch("/api/v1/accounts/update_credentials", %{})
-
- if token == token1 do
- assert %{"error" => "Insufficient permissions: write."} == json_response(conn, 403)
- else
- assert json_response(conn, 200)
- end
- end
- end
-
- test "updates profile emojos", %{conn: conn} do
- user = insert(:user)
-
- note = "*sips :blank:*"
- name = "I am :firefox:"
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "note" => note,
- "display_name" => name
- })
-
- assert json_response(conn, 200)
-
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}")
-
- assert user = json_response(conn, 200)
-
- assert user["note"] == note
- assert user["display_name"] == name
- assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
- end
-
- test "update fields", %{conn: conn} do
- user = insert(:user)
-
- fields = [
- %{"name" => "foo", "value" => ""},
- %{"name" => "link", "value" => "cofe.io"}
- ]
-
- account =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
- |> json_response(200)
-
- assert account["fields"] == [
- %{"name" => "foo", "value" => "bar"},
- %{"name" => "link", "value" => ~S(cofe.io)}
- ]
-
- assert account["source"]["fields"] == [
- %{
- "name" => "foo",
- "value" => ""
- },
- %{"name" => "link", "value" => "cofe.io"}
- ]
-
- name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
- value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
-
- long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
-
- fields = [%{"name" => "foo", "value" => long_value}]
-
- assert %{"error" => "Invalid request"} ==
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
- |> json_response(403)
-
- long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
-
- fields = [%{"name" => long_name, "value" => "bar"}]
-
- assert %{"error" => "Invalid request"} ==
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
- |> json_response(403)
-
- Pleroma.Config.put([:instance, :max_account_fields], 1)
-
- fields = [
- %{"name" => "foo", "value" => "bar"},
- %{"name" => "link", "value" => "cofe.io"}
- ]
-
- assert %{"error" => "Invalid request"} ==
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
- |> json_response(403)
- end
- end
-end
--
cgit v1.2.3
From c55facf78b6714947d8c5b02b76846f5f2ae7744 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 19:06:17 +0700
Subject: Fix warning in TransmogrifierTest
---
test/web/activity_pub/transmogrifier_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 2c6357fe6..193d6d301 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1231,7 +1231,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+ {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
end
end
--
cgit v1.2.3
From 0c6009dd2e475d3487123390885c46bf3fc5dea8 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 30 Sep 2019 19:32:43 +0700
Subject: Extract mascot actions from `MastodonAPIController` to
MascotController
---
.../mastodon_api/mastodon_api_controller_test.exs | 68 -------------------
.../controllers/mascot_controller_test.exs | 77 ++++++++++++++++++++++
2 files changed, 77 insertions(+), 68 deletions(-)
create mode 100644 test/web/pleroma_api/controllers/mascot_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f2f8c0578..feeaf079b 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -114,74 +114,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "/api/v1/pleroma/mascot" do
- test "mascot upload", %{conn: conn} do
- user = insert(:user)
-
- non_image_file = %Plug.Upload{
- content_type: "audio/mpeg",
- path: Path.absname("test/fixtures/sound.mp3"),
- filename: "sound.mp3"
- }
-
- conn =
- conn
- |> assign(:user, user)
- |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
-
- assert json_response(conn, 415)
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> put("/api/v1/pleroma/mascot", %{"file" => file})
-
- assert %{"id" => _, "type" => image} = json_response(conn, 200)
- end
-
- test "mascot retrieving", %{conn: conn} do
- user = insert(:user)
- # When user hasn't set a mascot, we should just get pleroma tan back
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/pleroma/mascot")
-
- assert %{"url" => url} = json_response(conn, 200)
- assert url =~ "pleroma-fox-tan-smol"
-
- # When a user sets their mascot, we should get that back
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> put("/api/v1/pleroma/mascot", %{"file" => file})
-
- assert json_response(conn, 200)
-
- user = User.get_cached_by_id(user.id)
-
- conn =
- build_conn()
- |> assign(:user, user)
- |> get("/api/v1/pleroma/mascot")
-
- assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
- assert url =~ "an_image"
- end
- end
-
test "getting a list of mutes", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
diff --git a/test/web/pleroma_api/controllers/mascot_controller_test.exs b/test/web/pleroma_api/controllers/mascot_controller_test.exs
new file mode 100644
index 000000000..ae9539b04
--- /dev/null
+++ b/test/web/pleroma_api/controllers/mascot_controller_test.exs
@@ -0,0 +1,77 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+
+ import Pleroma.Factory
+
+ test "mascot upload", %{conn: conn} do
+ user = insert(:user)
+
+ non_image_file = %Plug.Upload{
+ content_type: "audio/mpeg",
+ path: Path.absname("test/fixtures/sound.mp3"),
+ filename: "sound.mp3"
+ }
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
+
+ assert json_response(conn, 415)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> put("/api/v1/pleroma/mascot", %{"file" => file})
+
+ assert %{"id" => _, "type" => image} = json_response(conn, 200)
+ end
+
+ test "mascot retrieving", %{conn: conn} do
+ user = insert(:user)
+ # When user hasn't set a mascot, we should just get pleroma tan back
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/pleroma/mascot")
+
+ assert %{"url" => url} = json_response(conn, 200)
+ assert url =~ "pleroma-fox-tan-smol"
+
+ # When a user sets their mascot, we should get that back
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> put("/api/v1/pleroma/mascot", %{"file" => file})
+
+ assert json_response(conn, 200)
+
+ user = User.get_cached_by_id(user.id)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/pleroma/mascot")
+
+ assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
+ assert url =~ "an_image"
+ end
+end
--
cgit v1.2.3
From dae744478e7a5b789f2fb541b47eea558a0f2d53 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 30 Sep 2019 18:13:05 +0200
Subject: Transmogrifier: Handle compact objects in undos.
---
.../mastodon-undo-like-compact-object.json | 29 ++++++++++++++++++++++
test/web/activity_pub/transmogrifier_test.exs | 25 +++++++++++++++++++
2 files changed, 54 insertions(+)
create mode 100644 test/fixtures/mastodon-undo-like-compact-object.json
(limited to 'test')
diff --git a/test/fixtures/mastodon-undo-like-compact-object.json b/test/fixtures/mastodon-undo-like-compact-object.json
new file mode 100644
index 000000000..ae66a0d19
--- /dev/null
+++ b/test/fixtures/mastodon-undo-like-compact-object.json
@@ -0,0 +1,29 @@
+{
+ "type": "Undo",
+ "signature": {
+ "type": "RsaSignature2017",
+ "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "created": "2018-05-19T16:36:58Z"
+ },
+ "object": "http://mastodon.example.org/users/admin#likes/2",
+ "nickname": "lain",
+ "id": "http://mastodon.example.org/users/admin#likes/2/undo",
+ "actor": "http://mastodon.example.org/users/admin",
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "toot": "http://joinmastodon.org/ns#",
+ "sensitive": "as:sensitive",
+ "ostatus": "http://ostatus.org#",
+ "movedTo": "as:movedTo",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "atomUri": "ostatus:atomUri",
+ "Hashtag": "as:Hashtag",
+ "Emoji": "toot:Emoji"
+ }
+ ]
+}
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 193d6d301..6c64be10b 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -378,6 +378,31 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
end
+ test "it works for incoming unlikes with an existing like activity and a compact object" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
+
+ like_data =
+ File.read!("test/fixtures/mastodon-like.json")
+ |> Poison.decode!()
+ |> Map.put("object", activity.data["object"])
+
+ {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
+
+ data =
+ File.read!("test/fixtures/mastodon-undo-like.json")
+ |> Poison.decode!()
+ |> Map.put("object", like_data["id"])
+ |> Map.put("actor", like_data["actor"])
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Undo"
+ assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo"
+ assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2"
+ end
+
test "it works for incoming announces" do
data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
--
cgit v1.2.3
From f364438032b387624ced6b53ec0666738aa199ca Mon Sep 17 00:00:00 2001
From: kPherox
Date: Tue, 1 Oct 2019 02:24:06 +0900
Subject: Add `rel="ugc"`
---
.../controllers/account_controller/update_credentials_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
index cdbacf46b..599cd61c8 100644
--- a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
@@ -362,7 +362,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert account["fields"] == [
%{"name" => "foo", "value" => "bar"},
- %{"name" => "link", "value" => "cofe.io"}
+ %{"name" => "link", "value" => ~S(cofe.io)}
]
assert account["source"]["fields"] == [
--
cgit v1.2.3
From 36a34c36fe518dae23fb19d02ccb43de8c2621dd Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 1 Oct 2019 11:44:34 +0700
Subject: Extract poll actions from `MastodonAPIController` to `PollController`
---
.../controllers/poll_controller_test.exs | 184 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 172 -------------------
test/web/mastodon_api/views/poll_view_test.exs | 126 ++++++++++++++
test/web/mastodon_api/views/status_view_test.exs | 110 ------------
4 files changed, 310 insertions(+), 282 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/poll_controller_test.exs
create mode 100644 test/web/mastodon_api/views/poll_view_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/poll_controller_test.exs b/test/web/mastodon_api/controllers/poll_controller_test.exs
new file mode 100644
index 000000000..40cf3e879
--- /dev/null
+++ b/test/web/mastodon_api/controllers/poll_controller_test.exs
@@ -0,0 +1,184 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.PollControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Object
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ describe "GET /api/v1/polls/:id" do
+ test "returns poll entity for object id", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Pleroma does",
+ "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/polls/#{object.id}")
+
+ response = json_response(conn, 200)
+ id = to_string(object.id)
+ assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
+ end
+
+ test "does not expose polls for private statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Pleroma does",
+ "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20},
+ "visibility" => "private"
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/polls/#{object.id}")
+
+ assert json_response(conn, 404)
+ end
+ end
+
+ describe "POST /api/v1/polls/:id/votes" do
+ test "votes are added to the poll", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "A very delicious sandwich",
+ "poll" => %{
+ "options" => ["Lettuce", "Grilled Bacon", "Tomato"],
+ "expires_in" => 20,
+ "multiple" => true
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
+
+ assert json_response(conn, 200)
+ object = Object.get_by_id(object.id)
+
+ assert Enum.all?(object.data["anyOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
+ total_items == 1
+ end)
+ end
+
+ test "author can't vote", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ assert conn
+ |> assign(:user, user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [1]})
+ |> json_response(422) == %{"error" => "Poll's author can't vote"}
+
+ object = Object.get_by_id(object.id)
+
+ refute Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 1
+ end
+
+ test "does not allow multiple choices on a single-choice question", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "The glass is",
+ "poll" => %{"options" => ["half empty", "half full"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ assert conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1]})
+ |> json_response(422) == %{"error" => "Too many choices"}
+
+ object = Object.get_by_id(object.id)
+
+ refute Enum.any?(object.data["oneOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
+ total_items == 1
+ end)
+ end
+
+ test "does not allow choice index to be greater than options count", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [2]})
+
+ assert json_response(conn, 422) == %{"error" => "Invalid indices"}
+ end
+
+ test "returns 404 error when object is not exist", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/polls/1/votes", %{"choices" => [0]})
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+
+ test "returns 404 when poll is private and not available for user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Am I cute?",
+ "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20},
+ "visibility" => "private"
+ })
+
+ object = Object.normalize(activity)
+
+ conn =
+ conn
+ |> assign(:user, other_user)
+ |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0]})
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index feeaf079b..2ec46bc90 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -417,178 +417,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "GET /api/v1/polls/:id" do
- test "returns poll entity for object id", %{conn: conn} do
- user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Pleroma does",
- "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20}
- })
-
- object = Object.normalize(activity)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/polls/#{object.id}")
-
- response = json_response(conn, 200)
- id = to_string(object.id)
- assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
- end
-
- test "does not expose polls for private statuses", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Pleroma does",
- "poll" => %{"options" => ["what Mastodon't", "n't what Mastodoes"], "expires_in" => 20},
- "visibility" => "private"
- })
-
- object = Object.normalize(activity)
-
- conn =
- conn
- |> assign(:user, other_user)
- |> get("/api/v1/polls/#{object.id}")
-
- assert json_response(conn, 404)
- end
- end
-
- describe "POST /api/v1/polls/:id/votes" do
- test "votes are added to the poll", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "A very delicious sandwich",
- "poll" => %{
- "options" => ["Lettuce", "Grilled Bacon", "Tomato"],
- "expires_in" => 20,
- "multiple" => true
- }
- })
-
- object = Object.normalize(activity)
-
- conn =
- conn
- |> assign(:user, other_user)
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1, 2]})
-
- assert json_response(conn, 200)
- object = Object.get_by_id(object.id)
-
- assert Enum.all?(object.data["anyOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
- total_items == 1
- end)
- end
-
- test "author can't vote", %{conn: conn} do
- user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
- })
-
- object = Object.normalize(activity)
-
- assert conn
- |> assign(:user, user)
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [1]})
- |> json_response(422) == %{"error" => "Poll's author can't vote"}
-
- object = Object.get_by_id(object.id)
-
- refute Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 1
- end
-
- test "does not allow multiple choices on a single-choice question", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "The glass is",
- "poll" => %{"options" => ["half empty", "half full"], "expires_in" => 20}
- })
-
- object = Object.normalize(activity)
-
- assert conn
- |> assign(:user, other_user)
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0, 1]})
- |> json_response(422) == %{"error" => "Too many choices"}
-
- object = Object.get_by_id(object.id)
-
- refute Enum.any?(object.data["oneOf"], fn %{"replies" => %{"totalItems" => total_items}} ->
- total_items == 1
- end)
- end
-
- test "does not allow choice index to be greater than options count", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
- })
-
- object = Object.normalize(activity)
-
- conn =
- conn
- |> assign(:user, other_user)
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [2]})
-
- assert json_response(conn, 422) == %{"error" => "Invalid indices"}
- end
-
- test "returns 404 error when object is not exist", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/polls/1/votes", %{"choices" => [0]})
-
- assert json_response(conn, 404) == %{"error" => "Record not found"}
- end
-
- test "returns 404 when poll is private and not available for user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20},
- "visibility" => "private"
- })
-
- object = Object.normalize(activity)
-
- conn =
- conn
- |> assign(:user, other_user)
- |> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0]})
-
- assert json_response(conn, 404) == %{"error" => "Record not found"}
- end
- end
-
describe "POST /auth/password, with valid parameters" do
setup %{conn: conn} do
user = insert(:user)
diff --git a/test/web/mastodon_api/views/poll_view_test.exs b/test/web/mastodon_api/views/poll_view_test.exs
new file mode 100644
index 000000000..8cd7636a5
--- /dev/null
+++ b/test/web/mastodon_api/views/poll_view_test.exs
@@ -0,0 +1,126 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.PollViewTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Object
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MastodonAPI.PollView
+
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ test "renders a poll" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Is Tenshi eating a corndog cute?",
+ "poll" => %{
+ "options" => ["absolutely!", "sure", "yes", "why are you even asking?"],
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ expected = %{
+ emojis: [],
+ expired: false,
+ id: to_string(object.id),
+ multiple: false,
+ options: [
+ %{title: "absolutely!", votes_count: 0},
+ %{title: "sure", votes_count: 0},
+ %{title: "yes", votes_count: 0},
+ %{title: "why are you even asking?", votes_count: 0}
+ ],
+ voted: false,
+ votes_count: 0
+ }
+
+ result = PollView.render("show.json", %{object: object})
+ expires_at = result.expires_at
+ result = Map.delete(result, :expires_at)
+
+ assert result == expected
+
+ expires_at = NaiveDateTime.from_iso8601!(expires_at)
+ assert NaiveDateTime.diff(expires_at, NaiveDateTime.utc_now()) in 15..20
+ end
+
+ test "detects if it is multiple choice" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Which Mastodon developer is your favourite?",
+ "poll" => %{
+ "options" => ["Gargron", "Eugen"],
+ "expires_in" => 20,
+ "multiple" => true
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ assert %{multiple: true} = PollView.render("show.json", %{object: object})
+ end
+
+ test "detects emoji" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "What's with the smug face?",
+ "poll" => %{
+ "options" => [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"],
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ assert %{emojis: [%{shortcode: "blank"}]} = PollView.render("show.json", %{object: object})
+ end
+
+ test "detects vote status" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Which input devices do you use?",
+ "poll" => %{
+ "options" => ["mouse", "trackball", "trackpoint"],
+ "multiple" => true,
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+
+ {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2])
+
+ result = PollView.render("show.json", %{object: object, for: other_user})
+
+ assert result[:voted] == true
+ assert Enum.at(result[:options], 1)[:votes_count] == 1
+ assert Enum.at(result[:options], 2)[:votes_count] == 1
+ end
+
+ test "does not crash on polls with no end date" do
+ object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i")
+ result = PollView.render("show.json", %{object: object})
+
+ assert result[:expires_at] == nil
+ assert result[:expired] == false
+ end
+end
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 8df23d0a8..1d5a6e956 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -451,116 +451,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
end
end
- describe "poll view" do
- test "renders a poll" do
- user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Is Tenshi eating a corndog cute?",
- "poll" => %{
- "options" => ["absolutely!", "sure", "yes", "why are you even asking?"],
- "expires_in" => 20
- }
- })
-
- object = Object.normalize(activity)
-
- expected = %{
- emojis: [],
- expired: false,
- id: to_string(object.id),
- multiple: false,
- options: [
- %{title: "absolutely!", votes_count: 0},
- %{title: "sure", votes_count: 0},
- %{title: "yes", votes_count: 0},
- %{title: "why are you even asking?", votes_count: 0}
- ],
- voted: false,
- votes_count: 0
- }
-
- result = StatusView.render("poll.json", %{object: object})
- expires_at = result.expires_at
- result = Map.delete(result, :expires_at)
-
- assert result == expected
-
- expires_at = NaiveDateTime.from_iso8601!(expires_at)
- assert NaiveDateTime.diff(expires_at, NaiveDateTime.utc_now()) in 15..20
- end
-
- test "detects if it is multiple choice" do
- user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Which Mastodon developer is your favourite?",
- "poll" => %{
- "options" => ["Gargron", "Eugen"],
- "expires_in" => 20,
- "multiple" => true
- }
- })
-
- object = Object.normalize(activity)
-
- assert %{multiple: true} = StatusView.render("poll.json", %{object: object})
- end
-
- test "detects emoji" do
- user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "What's with the smug face?",
- "poll" => %{
- "options" => [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"],
- "expires_in" => 20
- }
- })
-
- object = Object.normalize(activity)
-
- assert %{emojis: [%{shortcode: "blank"}]} =
- StatusView.render("poll.json", %{object: object})
- end
-
- test "detects vote status" do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, activity} =
- CommonAPI.post(user, %{
- "status" => "Which input devices do you use?",
- "poll" => %{
- "options" => ["mouse", "trackball", "trackpoint"],
- "multiple" => true,
- "expires_in" => 20
- }
- })
-
- object = Object.normalize(activity)
-
- {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2])
-
- result = StatusView.render("poll.json", %{object: object, for: other_user})
-
- assert result[:voted] == true
- assert Enum.at(result[:options], 1)[:votes_count] == 1
- assert Enum.at(result[:options], 2)[:votes_count] == 1
- end
-
- test "does not crash on polls with no end date" do
- object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i")
- result = StatusView.render("poll.json", %{object: object})
-
- assert result[:expires_at] == nil
- assert result[:expired] == false
- end
- end
-
test "embeds a relationship in the account" do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 585bc57edbe10dcd19d2294824e0a0600f4bfe4c Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 1 Oct 2019 14:36:35 +0700
Subject: Extract media actions from `MastodonAPIController` to
`MediaController`
---
.../controllers/media_controller_test.exs | 92 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 80 -------------------
2 files changed, 92 insertions(+), 80 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/media_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/media_controller_test.exs b/test/web/mastodon_api/controllers/media_controller_test.exs
new file mode 100644
index 000000000..06c6a1cb3
--- /dev/null
+++ b/test/web/mastodon_api/controllers/media_controller_test.exs
@@ -0,0 +1,92 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Object
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
+
+ import Pleroma.Factory
+
+ describe "media upload" do
+ setup do
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+
+ image = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ [conn: conn, image: image]
+ end
+
+ clear_config([:media_proxy])
+ clear_config([Pleroma.Upload])
+
+ test "returns uploaded image", %{conn: conn, image: image} do
+ desc = "Description of the image"
+
+ media =
+ conn
+ |> post("/api/v1/media", %{"file" => image, "description" => desc})
+ |> json_response(:ok)
+
+ assert media["type"] == "image"
+ assert media["description"] == desc
+ assert media["id"]
+
+ object = Object.get_by_id(media["id"])
+ assert object.data["actor"] == User.ap_id(conn.assigns[:user])
+ end
+ end
+
+ describe "PUT /api/v1/media/:id" do
+ setup do
+ actor = insert(:user)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, %Object{} = object} =
+ ActivityPub.upload(
+ file,
+ actor: User.ap_id(actor),
+ description: "test-m"
+ )
+
+ [actor: actor, object: object]
+ end
+
+ test "updates name of media", %{conn: conn, actor: actor, object: object} do
+ media =
+ conn
+ |> assign(:user, actor)
+ |> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
+ |> json_response(:ok)
+
+ assert media["description"] == "test-media"
+ assert refresh_record(object).data["name"] == "test-media"
+ end
+
+ test "returns error wheb request is bad", %{conn: conn, actor: actor, object: object} do
+ media =
+ conn
+ |> assign(:user, actor)
+ |> put("/api/v1/media/#{object.id}", %{})
+ |> json_response(400)
+
+ assert media == %{"error" => "bad_request"}
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 2ec46bc90..da5606165 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -12,7 +12,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.Push
@@ -77,43 +76,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert expected == json_response(conn, 200)
end
- describe "media upload" do
- setup do
- user = insert(:user)
-
- conn =
- build_conn()
- |> assign(:user, user)
-
- image = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- [conn: conn, image: image]
- end
-
- clear_config([:media_proxy])
- clear_config([Pleroma.Upload])
-
- test "returns uploaded image", %{conn: conn, image: image} do
- desc = "Description of the image"
-
- media =
- conn
- |> post("/api/v1/media", %{"file" => image, "description" => desc})
- |> json_response(:ok)
-
- assert media["type"] == "image"
- assert media["description"] == desc
- assert media["id"]
-
- object = Repo.get(Object, media["id"])
- assert object.data["actor"] == User.ap_id(conn.assigns[:user])
- end
- end
-
test "getting a list of mutes", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -550,48 +512,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "PUT /api/v1/media/:id" do
- setup do
- actor = insert(:user)
-
- file = %Plug.Upload{
- content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an_image.jpg"
- }
-
- {:ok, %Object{} = object} =
- ActivityPub.upload(
- file,
- actor: User.ap_id(actor),
- description: "test-m"
- )
-
- [actor: actor, object: object]
- end
-
- test "updates name of media", %{conn: conn, actor: actor, object: object} do
- media =
- conn
- |> assign(:user, actor)
- |> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
- |> json_response(:ok)
-
- assert media["description"] == "test-media"
- assert refresh_record(object).data["name"] == "test-media"
- end
-
- test "returns error wheb request is bad", %{conn: conn, actor: actor, object: object} do
- media =
- conn
- |> assign(:user, actor)
- |> put("/api/v1/media/#{object.id}", %{})
- |> json_response(400)
-
- assert media == %{"error" => "bad_request"}
- end
- end
-
describe "DELETE /auth/sign_out" do
test "redirect to root page", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 39695c4436056db0b25cfa5e361630791923df84 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 1 Oct 2019 14:45:04 +0700
Subject: Extract suggestions actions from `MastodonAPIController` to
`SuggestionController`
---
.../controllers/suggestion_controller_test.exs | 92 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 83 -------------------
2 files changed, 92 insertions(+), 83 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/suggestion_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs
new file mode 100644
index 000000000..78620a873
--- /dev/null
+++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs
@@ -0,0 +1,92 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Config
+
+ import ExUnit.CaptureLog
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ user = insert(:user)
+ other_user = insert(:user)
+ host = Config.get([Pleroma.Web.Endpoint, :url, :host])
+ url500 = "http://test500?#{host}{user.nickname}"
+ url200 = "http://test200?#{host}{user.nickname}"
+
+ mock(fn
+ %{method: :get, url: ^url500} ->
+ %Tesla.Env{status: 500, body: "bad request"}
+
+ %{method: :get, url: ^url200} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ ~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{
+ other_user.ap_id
+ }","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}])
+ }
+ end)
+
+ [user: user, other_user: other_user]
+ end
+
+ clear_config(:suggestions)
+
+ test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
+ Config.put([:suggestions, :enabled], false)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(200)
+
+ assert res == []
+ end
+
+ test "returns error", %{conn: conn, user: user} do
+ Config.put([:suggestions, :enabled], true)
+ Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
+
+ assert capture_log(fn ->
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(500)
+
+ assert res == "Something went wrong"
+ end) =~ "Could not retrieve suggestions"
+ end
+
+ test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do
+ Config.put([:suggestions, :enabled], true)
+ Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(200)
+
+ assert res == [
+ %{
+ "acct" => "yj455",
+ "avatar" => "https://social.heldscal.la/avatar/201.jpeg",
+ "avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
+ "id" => 0
+ },
+ %{
+ "acct" => other_user.ap_id,
+ "avatar" => "https://social.heldscal.la/avatar/202.jpeg",
+ "avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",
+ "id" => other_user.id
+ }
+ ]
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index da5606165..47357863c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Ecto.Changeset
alias Pleroma.Config
alias Pleroma.Notification
- alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
@@ -16,7 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.Push
- import ExUnit.CaptureLog
import Pleroma.Factory
import Swoosh.TestAssertions
import Tesla.Mock
@@ -431,87 +429,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
- describe "GET /api/v1/suggestions" do
- setup do
- user = insert(:user)
- other_user = insert(:user)
- host = Config.get([Pleroma.Web.Endpoint, :url, :host])
- url500 = "http://test500?#{host}{user.nickname}"
- url200 = "http://test200?#{host}{user.nickname}"
-
- mock(fn
- %{method: :get, url: ^url500} ->
- %Tesla.Env{status: 500, body: "bad request"}
-
- %{method: :get, url: ^url200} ->
- %Tesla.Env{
- status: 200,
- body:
- ~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{
- other_user.ap_id
- }","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}])
- }
- end)
-
- [user: user, other_user: other_user]
- end
-
- clear_config(:suggestions)
-
- test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
- Config.put([:suggestions, :enabled], false)
-
- res =
- conn
- |> assign(:user, user)
- |> get("/api/v1/suggestions")
- |> json_response(200)
-
- assert res == []
- end
-
- test "returns error", %{conn: conn, user: user} do
- Config.put([:suggestions, :enabled], true)
- Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
-
- assert capture_log(fn ->
- res =
- conn
- |> assign(:user, user)
- |> get("/api/v1/suggestions")
- |> json_response(500)
-
- assert res == "Something went wrong"
- end) =~ "Could not retrieve suggestions"
- end
-
- test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do
- Config.put([:suggestions, :enabled], true)
- Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
-
- res =
- conn
- |> assign(:user, user)
- |> get("/api/v1/suggestions")
- |> json_response(200)
-
- assert res == [
- %{
- "acct" => "yj455",
- "avatar" => "https://social.heldscal.la/avatar/201.jpeg",
- "avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
- "id" => 0
- },
- %{
- "acct" => other_user.ap_id,
- "avatar" => "https://social.heldscal.la/avatar/202.jpeg",
- "avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",
- "id" => other_user.id
- }
- ]
- end
- end
-
describe "DELETE /auth/sign_out" do
test "redirect to root page", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 2dad6dd0201135f5ab8ff50448b0787f36db0607 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 1 Oct 2019 15:21:46 +0700
Subject: Extract apps actions from `MastodonAPIController` to `AppController`
---
.../controllers/app_controller_test.exs | 60 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 49 ------------------
2 files changed, 60 insertions(+), 49 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/app_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/app_controller_test.exs b/test/web/mastodon_api/controllers/app_controller_test.exs
new file mode 100644
index 000000000..51788155b
--- /dev/null
+++ b/test/web/mastodon_api/controllers/app_controller_test.exs
@@ -0,0 +1,60 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
+ use Pleroma.Web.ConnCase, async: true
+
+ alias Pleroma.Repo
+ alias Pleroma.Web.OAuth.App
+ alias Pleroma.Web.Push
+
+ import Pleroma.Factory
+
+ test "apps/verify_credentials", %{conn: conn} do
+ token = insert(:oauth_token)
+
+ conn =
+ conn
+ |> assign(:user, token.user)
+ |> assign(:token, token)
+ |> get("/api/v1/apps/verify_credentials")
+
+ app = Repo.preload(token, :app).app
+
+ expected = %{
+ "name" => app.client_name,
+ "website" => app.website,
+ "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
+ }
+
+ assert expected == json_response(conn, 200)
+ end
+
+ test "creates an oauth app", %{conn: conn} do
+ user = insert(:user)
+ app_attrs = build(:oauth_app)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/apps", %{
+ client_name: app_attrs.client_name,
+ redirect_uris: app_attrs.redirect_uris
+ })
+
+ [app] = Repo.all(App)
+
+ expected = %{
+ "name" => app.client_name,
+ "website" => app.website,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret,
+ "id" => app.id |> to_string(),
+ "redirect_uri" => app.redirect_uris,
+ "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
+ }
+
+ assert expected == json_response(conn, 200)
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 47357863c..68fe751e7 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -12,8 +12,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.OAuth.App
- alias Pleroma.Web.Push
import Pleroma.Factory
import Swoosh.TestAssertions
@@ -27,53 +25,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
clear_config([:instance, :public])
clear_config([:rich_media, :enabled])
- test "apps/verify_credentials", %{conn: conn} do
- token = insert(:oauth_token)
-
- conn =
- conn
- |> assign(:user, token.user)
- |> assign(:token, token)
- |> get("/api/v1/apps/verify_credentials")
-
- app = Repo.preload(token, :app).app
-
- expected = %{
- "name" => app.client_name,
- "website" => app.website,
- "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
- }
-
- assert expected == json_response(conn, 200)
- end
-
- test "creates an oauth app", %{conn: conn} do
- user = insert(:user)
- app_attrs = build(:oauth_app)
-
- conn =
- conn
- |> assign(:user, user)
- |> post("/api/v1/apps", %{
- client_name: app_attrs.client_name,
- redirect_uris: app_attrs.redirect_uris
- })
-
- [app] = Repo.all(App)
-
- expected = %{
- "name" => app.client_name,
- "website" => app.website,
- "client_id" => app.client_id,
- "client_secret" => app.client_secret,
- "id" => app.id |> to_string(),
- "redirect_uri" => app.redirect_uris,
- "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
- }
-
- assert expected == json_response(conn, 200)
- end
-
test "getting a list of mutes", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From af690d10336124968e2a0fe0e73decb2d48819cb Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 1 Oct 2019 15:54:45 +0700
Subject: Extract auth actions from `MastodonAPIController` to `AuthController`
---
.../controllers/auth_controller_test.exs | 121 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 91 ----------------
2 files changed, 121 insertions(+), 91 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/auth_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/auth_controller_test.exs b/test/web/mastodon_api/controllers/auth_controller_test.exs
new file mode 100644
index 000000000..98b2a82e7
--- /dev/null
+++ b/test/web/mastodon_api/controllers/auth_controller_test.exs
@@ -0,0 +1,121 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Config
+ alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
+
+ import Pleroma.Factory
+ import Swoosh.TestAssertions
+
+ describe "GET /web/login" 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 to the saved path after log in", %{conn: conn, path: path} do
+ app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
+ auth = insert(:oauth_authorization, app: app)
+
+ conn =
+ conn
+ |> put_session(:return_to, path)
+ |> get("/web/login", %{code: auth.token})
+
+ assert conn.status == 302
+ assert redirected_to(conn) == path
+ end
+
+ test "redirects to the getting-started page when referer is not present", %{conn: conn} do
+ app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
+ auth = insert(:oauth_authorization, app: app)
+
+ conn = get(conn, "/web/login", %{code: auth.token})
+
+ assert conn.status == 302
+ assert redirected_to(conn) == "/web/getting-started"
+ end
+ end
+
+ describe "POST /auth/password, with valid parameters" do
+ setup %{conn: conn} do
+ user = insert(:user)
+ conn = post(conn, "/auth/password?email=#{user.email}")
+ %{conn: conn, user: user}
+ end
+
+ test "it returns 204", %{conn: conn} do
+ assert json_response(conn, :no_content)
+ end
+
+ test "it creates a PasswordResetToken record for user", %{user: user} do
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+ assert token_record
+ end
+
+ test "it sends an email to user", %{user: user} do
+ ObanHelpers.perform_all()
+ token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
+
+ email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
+ notify_email = Config.get([:instance, :notify_email])
+ instance_name = Config.get([:instance, :name])
+
+ assert_email_sent(
+ from: {instance_name, notify_email},
+ to: {user.name, user.email},
+ html_body: email.html_body
+ )
+ end
+ end
+
+ describe "POST /auth/password, with invalid parameters" do
+ setup do
+ user = insert(:user)
+ {:ok, user: user}
+ end
+
+ test "it returns 404 when user is not found", %{conn: conn, user: user} do
+ conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
+ assert conn.status == 404
+ assert conn.resp_body == ""
+ end
+
+ test "it returns 400 when user is not local", %{conn: conn, user: user} do
+ {:ok, user} = Repo.update(Ecto.Changeset.change(user, local: false))
+ conn = post(conn, "/auth/password?email=#{user.email}")
+ assert conn.status == 400
+ assert conn.resp_body == ""
+ end
+ end
+
+ describe "DELETE /auth/sign_out" do
+ test "redirect to root page", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/auth/sign_out")
+
+ assert conn.status == 302
+ assert redirected_to(conn) == "/"
+ end
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 68fe751e7..2ec5ad2be 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -9,12 +9,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Repo
- alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
- import Swoosh.TestAssertions
import Tesla.Mock
setup do
@@ -303,95 +301,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert return_to == path
end
-
- test "redirects to the saved path after log in", %{conn: conn, path: path} do
- app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
- auth = insert(:oauth_authorization, app: app)
-
- conn =
- conn
- |> put_session(:return_to, path)
- |> get("/web/login", %{code: auth.token})
-
- assert conn.status == 302
- assert redirected_to(conn) == path
- end
-
- test "redirects to the getting-started page when referer is not present", %{conn: conn} do
- app = insert(:oauth_app, client_name: "Mastodon-Local", redirect_uris: ".")
- auth = insert(:oauth_authorization, app: app)
-
- conn = get(conn, "/web/login", %{code: auth.token})
-
- assert conn.status == 302
- assert redirected_to(conn) == "/web/getting-started"
- end
- end
-
- describe "POST /auth/password, with valid parameters" do
- setup %{conn: conn} do
- user = insert(:user)
- conn = post(conn, "/auth/password?email=#{user.email}")
- %{conn: conn, user: user}
- end
-
- test "it returns 204", %{conn: conn} do
- assert json_response(conn, :no_content)
- end
-
- test "it creates a PasswordResetToken record for user", %{user: user} do
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
- assert token_record
- end
-
- test "it sends an email to user", %{user: user} do
- ObanHelpers.perform_all()
- token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
-
- email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
- notify_email = Config.get([:instance, :notify_email])
- instance_name = Config.get([:instance, :name])
-
- assert_email_sent(
- from: {instance_name, notify_email},
- to: {user.name, user.email},
- html_body: email.html_body
- )
- end
- end
-
- describe "POST /auth/password, with invalid parameters" do
- setup do
- user = insert(:user)
- {:ok, user: user}
- end
-
- test "it returns 404 when user is not found", %{conn: conn, user: user} do
- conn = post(conn, "/auth/password?email=nonexisting_#{user.email}")
- assert conn.status == 404
- assert conn.resp_body == ""
- end
-
- test "it returns 400 when user is not local", %{conn: conn, user: user} do
- {:ok, user} = Repo.update(Changeset.change(user, local: false))
- conn = post(conn, "/auth/password?email=#{user.email}")
- assert conn.status == 400
- assert conn.resp_body == ""
- end
- end
-
- describe "DELETE /auth/sign_out" do
- test "redirect to root page", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> delete("/auth/sign_out")
-
- assert conn.status == 302
- assert redirected_to(conn) == "/"
- end
end
describe "empty_array, stubs for mastodon api" do
--
cgit v1.2.3
From 0f9c2c8b87672517aa040a2cbe1c297b29acc317 Mon Sep 17 00:00:00 2001
From: Maxim Filippov
Date: Tue, 1 Oct 2019 18:10:04 +0300
Subject: Send an identifier alongside with error message in OAuthController
---
test/web/oauth/oauth_controller_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test')
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 0cf755806..4d0741d14 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -852,6 +852,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert resp = json_response(conn, 403)
assert resp["error"] == "Password reset is required"
+ assert resp["identifier"] == "password_reset_required"
refute Map.has_key?(resp, "access_token")
end
--
cgit v1.2.3
From e0b654e202554f001a5de3df4ccb8021fd3a517a Mon Sep 17 00:00:00 2001
From: Thibaut Girka
Date: Tue, 1 Oct 2019 17:51:27 +0200
Subject: Add tests
---
test/web/activity_pub/activity_pub_test.exs | 33 +++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index a203d1d30..f29497847 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -839,6 +839,39 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ describe "announcing a private object" do
+ test "adds an announce activity to the db if the audience is not widened" do
+ user = insert(:user)
+ {:ok, note_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ object = Object.normalize(note_activity)
+
+ {:ok, announce_activity, object} = ActivityPub.announce(user, object, nil, true, false)
+
+ assert announce_activity.data["to"] == [User.ap_followers(user)]
+
+ assert announce_activity.data["object"] == object.data["id"]
+ assert announce_activity.data["actor"] == user.ap_id
+ assert announce_activity.data["context"] == object.data["context"]
+ end
+
+ test "does not add an announce activity to the db if the audience is widened" do
+ user = insert(:user)
+ {:ok, note_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ object = Object.normalize(note_activity)
+
+ assert {:error, _} = ActivityPub.announce(user, object, nil, true, true)
+ end
+
+ test "does not add an announce activity to the db if the announcer is not the author" do
+ user = insert(:user)
+ announcer = insert(:user)
+ {:ok, note_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
+ object = Object.normalize(note_activity)
+
+ assert {:error, _} = ActivityPub.announce(announcer, object, nil, true, false)
+ end
+ end
+
describe "unannouncing an object" do
test "unannouncing a previously announced object" do
note_activity = insert(:note_activity)
--
cgit v1.2.3
From 7d5a9f3f6d393c744364148568cfb9b0249789fc Mon Sep 17 00:00:00 2001
From: Thibaut Girka
Date: Tue, 1 Oct 2019 19:08:25 +0200
Subject: Add tests for privately announcing statuses via API
---
test/web/common_api/common_api_test.exs | 12 ++++++++++++
.../controllers/status_controller_test.exs | 18 ++++++++++++++++++
2 files changed, 30 insertions(+)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 0f4a5eb25..2d3c41e82 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -231,6 +231,18 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
end
+ test "repeating a status privately" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+ {:ok, %Activity{} = announce_activity, _} =
+ CommonAPI.repeat(activity.id, user, %{"visibility" => "private"})
+
+ assert Visibility.is_private?(announce_activity)
+ end
+
test "favoriting a status" do
user = insert(:user)
other_user = insert(:user)
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index b194feae6..727a233e7 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -547,6 +547,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert to_string(activity.id) == id
end
+ test "reblogs privately and returns the reblogged status", %{conn: conn} do
+ activity = insert(:note_activity)
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/reblog", %{"visibility" => "private"})
+
+ assert %{
+ "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 0},
+ "reblogged" => true,
+ "visibility" => "private"
+ } = json_response(conn, 200)
+
+ assert to_string(activity.id) == id
+ end
+
test "reblogged status for another user", %{conn: conn} do
activity = insert(:note_activity)
user1 = insert(:user)
--
cgit v1.2.3
From c541b83befdaaea93304cc3a33782222e6dee1d1 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Tue, 1 Oct 2019 20:00:27 +0000
Subject: Track failed proxy urls and don't request them again
---
test/reverse_proxy_test.exs | 58 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 51 insertions(+), 7 deletions(-)
(limited to 'test')
diff --git a/test/reverse_proxy_test.exs b/test/reverse_proxy_test.exs
index 3a83c4c48..0672f57db 100644
--- a/test/reverse_proxy_test.exs
+++ b/test/reverse_proxy_test.exs
@@ -42,6 +42,18 @@ defmodule Pleroma.ReverseProxyTest do
end)
end
+ describe "reverse proxy" do
+ test "do not track successful request", %{conn: conn} do
+ user_agent_mock("hackney/1.15.1", 2)
+ url = "/success"
+
+ conn = ReverseProxy.call(conn, url)
+
+ assert conn.status == 200
+ assert Cachex.get(:failed_proxy_url_cache, url) == {:ok, nil}
+ end
+ end
+
describe "user-agent" do
test "don't keep", %{conn: conn} do
user_agent_mock("hackney/1.15.1", 2)
@@ -71,9 +83,15 @@ defmodule Pleroma.ReverseProxyTest do
user_agent_mock("hackney/1.15.1", 0)
assert capture_log(fn ->
- ReverseProxy.call(conn, "/user-agent", max_body_length: 4)
+ ReverseProxy.call(conn, "/huge-file", max_body_length: 4)
end) =~
- "[error] Elixir.Pleroma.ReverseProxy: request to \"/user-agent\" failed: :body_too_large"
+ "[error] Elixir.Pleroma.ReverseProxy: request to \"/huge-file\" failed: :body_too_large"
+
+ assert {:ok, true} == Cachex.get(:failed_proxy_url_cache, "/huge-file")
+
+ assert capture_log(fn ->
+ ReverseProxy.call(conn, "/huge-file", max_body_length: 4)
+ end) == ""
end
defp stream_mock(invokes, with_close? \\ false) do
@@ -140,28 +158,54 @@ defmodule Pleroma.ReverseProxyTest do
describe "returns error on" do
test "500", %{conn: conn} do
error_mock(500)
+ url = "/status/500"
- capture_log(fn -> ReverseProxy.call(conn, "/status/500") end) =~
+ capture_log(fn -> ReverseProxy.call(conn, url) end) =~
"[error] Elixir.Pleroma.ReverseProxy: request to /status/500 failed with HTTP status 500"
+
+ assert Cachex.get(:failed_proxy_url_cache, url) == {:ok, true}
+
+ {:ok, ttl} = Cachex.ttl(:failed_proxy_url_cache, url)
+ assert ttl <= 60_000
end
test "400", %{conn: conn} do
error_mock(400)
+ url = "/status/400"
- capture_log(fn -> ReverseProxy.call(conn, "/status/400") end) =~
+ capture_log(fn -> ReverseProxy.call(conn, url) end) =~
"[error] Elixir.Pleroma.ReverseProxy: request to /status/400 failed with HTTP status 400"
+
+ assert Cachex.get(:failed_proxy_url_cache, url) == {:ok, true}
+ assert Cachex.ttl(:failed_proxy_url_cache, url) == {:ok, nil}
+ end
+
+ test "403", %{conn: conn} do
+ error_mock(403)
+ url = "/status/403"
+
+ capture_log(fn ->
+ ReverseProxy.call(conn, url, failed_request_ttl: :timer.seconds(120))
+ end) =~
+ "[error] Elixir.Pleroma.ReverseProxy: request to /status/403 failed with HTTP status 403"
+
+ {:ok, ttl} = Cachex.ttl(:failed_proxy_url_cache, url)
+ assert ttl > 100_000
end
test "204", %{conn: conn} do
- ClientMock
- |> expect(:request, fn :get, "/status/204", _, _, _ -> {:ok, 204, [], %{}} end)
+ url = "/status/204"
+ expect(ClientMock, :request, fn :get, _url, _, _, _ -> {:ok, 204, [], %{}} end)
capture_log(fn ->
- conn = ReverseProxy.call(conn, "/status/204")
+ conn = ReverseProxy.call(conn, url)
assert conn.resp_body == "Request failed: No Content"
assert conn.halted
end) =~
"[error] Elixir.Pleroma.ReverseProxy: request to \"/status/204\" failed with HTTP status 204"
+
+ assert Cachex.get(:failed_proxy_url_cache, url) == {:ok, true}
+ assert Cachex.ttl(:failed_proxy_url_cache, url) == {:ok, nil}
end
end
--
cgit v1.2.3
From 427d0c2a007db6c8424c64a8f3504420e5203bef Mon Sep 17 00:00:00 2001
From: Thibaut Girka
Date: Tue, 1 Oct 2019 21:40:35 +0200
Subject: Store private announcements in object.data["announcements"], filter
them on display
---
.../controllers/status_controller_test.exs | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index 727a233e7..b648ad6ff 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -557,7 +557,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|> post("/api/v1/statuses/#{activity.id}/reblog", %{"visibility" => "private"})
assert %{
- "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 0},
+ "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
"reblogged" => true,
"visibility" => "private"
} = json_response(conn, 200)
@@ -1167,6 +1167,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert Enum.empty?(response)
end
+ test "does not return users who have reblogged the status privately", %{
+ conn: %{assigns: %{user: user}} = conn,
+ activity: activity
+ } do
+ other_user = insert(:user)
+
+ {:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{"visibility" => "private"})
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
other_user = insert(:user)
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
--
cgit v1.2.3
From 1255ec888d5f1a186b499bf9e5c23c8c7332ed4d Mon Sep 17 00:00:00 2001
From: feld
Date: Tue, 1 Oct 2019 22:16:29 +0000
Subject: Revert "Add upload limits to /api/v1/instance"
This reverts commit db27c0dd8b18763ff2abb124ee8d641a4580cdaa.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 68fe751e7..ae67ee89d 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -135,7 +135,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
"thumbnail" => _,
"languages" => _,
"registrations" => _,
- "poll_limits" => _
+ "poll_limits" => _,
+ "upload_limit" => _,
+ "avatar_upload_limit" => _,
+ "background_upload_limit" => _,
+ "banner_upload_limit" => _
} = result
assert email == from_config_email
--
cgit v1.2.3
From c8b01f6667a9b5b158103de449a7769c9274bcc3 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 2 Oct 2019 14:13:52 +0700
Subject: Extract instance actions from `MastodonAPIController` to
`InstanceController`
---
.../controllers/instance_controller_test.exs | 84 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 75 -------------------
2 files changed, 84 insertions(+), 75 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/instance_controller_test.exs
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/instance_controller_test.exs b/test/web/mastodon_api/controllers/instance_controller_test.exs
new file mode 100644
index 000000000..f8049f81f
--- /dev/null
+++ b/test/web/mastodon_api/controllers/instance_controller_test.exs
@@ -0,0 +1,84 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+ import Pleroma.Factory
+
+ test "get instance information", %{conn: conn} do
+ conn = get(conn, "/api/v1/instance")
+ assert result = json_response(conn, 200)
+
+ email = Pleroma.Config.get([:instance, :email])
+ # Note: not checking for "max_toot_chars" since it's optional
+ assert %{
+ "uri" => _,
+ "title" => _,
+ "description" => _,
+ "version" => _,
+ "email" => from_config_email,
+ "urls" => %{
+ "streaming_api" => _
+ },
+ "stats" => _,
+ "thumbnail" => _,
+ "languages" => _,
+ "registrations" => _,
+ "poll_limits" => _,
+ "upload_limit" => _,
+ "avatar_upload_limit" => _,
+ "background_upload_limit" => _,
+ "banner_upload_limit" => _
+ } = result
+
+ assert email == from_config_email
+ end
+
+ test "get instance stats", %{conn: conn} do
+ user = insert(:user, %{local: true})
+
+ user2 = insert(:user, %{local: true})
+ {:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
+
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
+
+ {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
+
+ # Stats should count users with missing or nil `info.deactivated` value
+
+ {:ok, _user} =
+ user.id
+ |> User.get_cached_by_id()
+ |> User.update_info(&Ecto.Changeset.change(&1, %{deactivated: nil}))
+
+ Pleroma.Stats.force_update()
+
+ conn = get(conn, "/api/v1/instance")
+
+ assert result = json_response(conn, 200)
+
+ stats = result["stats"]
+
+ assert stats
+ assert stats["user_count"] == 1
+ assert stats["status_count"] == 1
+ assert stats["domain_count"] == 2
+ end
+
+ test "get peers", %{conn: conn} do
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
+
+ Pleroma.Stats.force_update()
+
+ conn = get(conn, "/api/v1/instance/peers")
+
+ assert result = json_response(conn, 200)
+
+ assert ["peer1.com", "peer2.com"] == Enum.sort(result)
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e642e3c1a..7a58b13dc 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -5,7 +5,6 @@
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
- alias Ecto.Changeset
alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Repo
@@ -114,80 +113,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] = json_response(third_conn, 200)
end
- test "get instance information", %{conn: conn} do
- conn = get(conn, "/api/v1/instance")
- assert result = json_response(conn, 200)
-
- email = Config.get([:instance, :email])
- # Note: not checking for "max_toot_chars" since it's optional
- assert %{
- "uri" => _,
- "title" => _,
- "description" => _,
- "version" => _,
- "email" => from_config_email,
- "urls" => %{
- "streaming_api" => _
- },
- "stats" => _,
- "thumbnail" => _,
- "languages" => _,
- "registrations" => _,
- "poll_limits" => _,
- "upload_limit" => _,
- "avatar_upload_limit" => _,
- "background_upload_limit" => _,
- "banner_upload_limit" => _
- } = result
-
- assert email == from_config_email
- end
-
- test "get instance stats", %{conn: conn} do
- user = insert(:user, %{local: true})
-
- user2 = insert(:user, %{local: true})
- {:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
-
- insert(:user, %{local: false, nickname: "u@peer1.com"})
- insert(:user, %{local: false, nickname: "u@peer2.com"})
-
- {:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
-
- # Stats should count users with missing or nil `info.deactivated` value
-
- {:ok, _user} =
- user.id
- |> User.get_cached_by_id()
- |> User.update_info(&Changeset.change(&1, %{deactivated: nil}))
-
- Pleroma.Stats.force_update()
-
- conn = get(conn, "/api/v1/instance")
-
- assert result = json_response(conn, 200)
-
- stats = result["stats"]
-
- assert stats
- assert stats["user_count"] == 1
- assert stats["status_count"] == 1
- assert stats["domain_count"] == 2
- end
-
- test "get peers", %{conn: conn} do
- insert(:user, %{local: false, nickname: "u@peer1.com"})
- insert(:user, %{local: false, nickname: "u@peer2.com"})
-
- Pleroma.Stats.force_update()
-
- conn = get(conn, "/api/v1/instance/peers")
-
- assert result = json_response(conn, 200)
-
- assert ["peer1.com", "peer2.com"] == Enum.sort(result)
- end
-
test "put settings", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 0fc29deba06b6a897f3534ce68abfdadcab12a6b Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 2 Oct 2019 15:24:21 +0700
Subject: Add tests for Pleroma.JobQueueMonitor
---
test/job_queue_monitor_test.exs | 70 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 test/job_queue_monitor_test.exs
(limited to 'test')
diff --git a/test/job_queue_monitor_test.exs b/test/job_queue_monitor_test.exs
new file mode 100644
index 000000000..17c6f3246
--- /dev/null
+++ b/test/job_queue_monitor_test.exs
@@ -0,0 +1,70 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# 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
--
cgit v1.2.3
From 86880b9821671ee07a65ca7e65b68b900759b483 Mon Sep 17 00:00:00 2001
From: Thibaut Girka
Date: Wed, 2 Oct 2019 12:14:08 +0200
Subject: Inline object when Announcing a self-owned private object
---
test/web/activity_pub/transmogrifier_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6c64be10b..b995f0224 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1076,6 +1076,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
describe "prepare outgoing" do
+ test "it inlines private announced objects" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey", "visibility" => "private"})
+
+ {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
+ object = modified["object"]
+
+ assert modified["object"]["content"] == "hey"
+ assert modified["object"]["actor"] == modified["object"]["attributedTo"]
+ end
+
test "it turns mentions into tags" do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 1c6e1055c876c7ac4a4d42259aebd07c942561e2 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 2 Oct 2019 19:16:34 +0700
Subject: Add CustomEmojiController
---
test/web/activity_pub/transmogrifier_test.exs | 1 -
.../controllers/custom_emoji_controller_test.exs | 22 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 17 -----------------
3 files changed, 22 insertions(+), 18 deletions(-)
create mode 100644 test/web/mastodon_api/controllers/custom_emoji_controller_test.exs
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index b995f0224..6c208bdc0 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1084,7 +1084,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
{:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
- object = modified["object"]
assert modified["object"]["content"] == "hey"
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
diff --git a/test/web/mastodon_api/controllers/custom_emoji_controller_test.exs b/test/web/mastodon_api/controllers/custom_emoji_controller_test.exs
new file mode 100644
index 000000000..2d988b0b8
--- /dev/null
+++ b/test/web/mastodon_api/controllers/custom_emoji_controller_test.exs
@@ -0,0 +1,22 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# 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
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 7a58b13dc..e8fd4827c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -159,23 +159,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 = [
--
cgit v1.2.3
From d3c404af124c7083b1f23466b9e82df5d2a407d0 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 2 Oct 2019 20:05:14 +0700
Subject: Add MastoFEController
---
test/web/masto_fe_controller_test.exs | 83 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 72 -------------------
2 files changed, 83 insertions(+), 72 deletions(-)
create mode 100644 test/web/masto_fe_controller_test.exs
(limited to 'test')
diff --git a/test/web/masto_fe_controller_test.exs b/test/web/masto_fe_controller_test.exs
new file mode 100644
index 000000000..04f144049
--- /dev/null
+++ b/test/web/masto_fe_controller_test.exs
@@ -0,0 +1,83 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.MastoFEController do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.User
+ alias Pleroma.Config
+ 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
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e8fd4827c..c03003dac 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -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,62 +143,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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)
--
cgit v1.2.3
From 9b68aab8b3cf576f91566cd659e4e5719dccb15a Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 2 Oct 2019 21:12:01 +0700
Subject: Fix credo warning
---
test/web/masto_fe_controller_test.exs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/masto_fe_controller_test.exs b/test/web/masto_fe_controller_test.exs
index 04f144049..ab9dab352 100644
--- a/test/web/masto_fe_controller_test.exs
+++ b/test/web/masto_fe_controller_test.exs
@@ -5,8 +5,9 @@
defmodule Pleroma.Web.MastodonAPI.MastoFEController do
use Pleroma.Web.ConnCase
- alias Pleroma.User
alias Pleroma.Config
+ alias Pleroma.User
+
import Pleroma.Factory
clear_config([:instance, :public])
--
cgit v1.2.3
From 7f2bc577250ccea26c133502787d0bbdcbc839ee Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 1 Oct 2019 17:15:58 +0700
Subject: Move `follows`, `mutes` and `blocks` actions to AccountController
---
.../controllers/account_controller_test.exs | 30 ++++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 30 ----------------------
2 files changed, 30 insertions(+), 30 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs
index 8c8017838..6a59c3d94 100644
--- a/test/web/mastodon_api/controllers/account_controller_test.exs
+++ b/test/web/mastodon_api/controllers/account_controller_test.exs
@@ -849,4 +849,34 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
assert [] = json_response(conn, 200)
end
end
+
+ test "getting a list of mutes", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.mute(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/mutes")
+
+ other_user_id = to_string(other_user.id)
+ assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
+ end
+
+ test "getting a list of blocks", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, user} = User.block(user, other_user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/blocks")
+
+ other_user_id = to_string(other_user.id)
+ assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index c03003dac..0e5f78f04 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -20,36 +20,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
clear_config([:rich_media, :enabled])
- test "getting a list of mutes", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, user} = User.mute(user, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/mutes")
-
- other_user_id = to_string(other_user.id)
- assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
- end
-
- test "getting a list of blocks", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, user} = User.block(user, other_user)
-
- conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/blocks")
-
- other_user_id = to_string(other_user.id)
- assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
- end
-
test "unimplemented follow_requests, blocks, domain blocks" do
user = insert(:user)
--
cgit v1.2.3
From e0c68eeb024c7d91b098c4e0eb6ad57551ea9ef1 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 2 Oct 2019 18:27:01 +0700
Subject: Move `:favourites` and `:bookmarks` actions to StatusController
---
.../controllers/status_controller_test.exs | 47 +++++++++++++++++++++
.../mastodon_api/mastodon_api_controller_test.exs | 48 ----------------------
2 files changed, 47 insertions(+), 48 deletions(-)
(limited to 'test')
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index b648ad6ff..a4bbfe055 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -1242,4 +1242,51 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"descendants" => [%{"id" => ^id4}, %{"id" => ^id5}]
} = response
end
+
+ test "returns the favorites of a user", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
+
+ {:ok, _, _} = CommonAPI.favorite(activity.id, user)
+
+ first_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/favourites")
+
+ assert [status] = json_response(first_conn, 200)
+ assert status["id"] == to_string(activity.id)
+
+ assert [{"link", _link_header}] =
+ Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
+
+ # Honours query params
+ {:ok, second_activity} =
+ CommonAPI.post(other_user, %{
+ "status" =>
+ "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
+ })
+
+ {:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
+
+ last_like = status["id"]
+
+ second_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/favourites?since_id=#{last_like}")
+
+ assert [second_status] = json_response(second_conn, 200)
+ assert second_status["id"] == to_string(second_activity.id)
+
+ third_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/favourites?limit=0")
+
+ assert [] = json_response(third_conn, 200)
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 0e5f78f04..42a8779c0 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Notification
alias Pleroma.Repo
- alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -34,53 +33,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end)
end
- test "returns the favorites of a user", %{conn: conn} do
- user = insert(:user)
- other_user = insert(:user)
-
- {:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
-
- {:ok, _, _} = CommonAPI.favorite(activity.id, user)
-
- first_conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/favourites")
-
- assert [status] = json_response(first_conn, 200)
- assert status["id"] == to_string(activity.id)
-
- assert [{"link", _link_header}] =
- Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
-
- # Honours query params
- {:ok, second_activity} =
- CommonAPI.post(other_user, %{
- "status" =>
- "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
- })
-
- {:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
-
- last_like = status["id"]
-
- second_conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/favourites?since_id=#{last_like}")
-
- assert [second_status] = json_response(second_conn, 200)
- assert second_status["id"] == to_string(second_activity.id)
-
- third_conn =
- conn
- |> assign(:user, user)
- |> get("/api/v1/favourites?limit=0")
-
- assert [] = json_response(third_conn, 200)
- end
-
describe "link headers" do
test "preserves parameters in link headers", %{conn: conn} do
user = insert(:user)
--
cgit v1.2.3
From 06d9df79c5c99069dd12e863c99167eb20b6495b Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Wed, 2 Oct 2019 00:37:08 +0300
Subject: Mastodon API: Add `pleroma.unread_conversation_count` to the Account
entity
---
test/conversation/participation_test.exs | 4 +
.../controllers/conversation_controller_test.exs | 101 +++++++++++++++++++--
test/web/mastodon_api/views/account_view_test.exs | 21 +++++
.../controllers/pleroma_api_controller_test.exs | 2 +
4 files changed, 118 insertions(+), 10 deletions(-)
(limited to 'test')
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index a27167d42..f430bdf75 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -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
diff --git a/test/web/mastodon_api/controllers/conversation_controller_test.exs b/test/web/mastodon_api/controllers/conversation_controller_test.exs
index 7117fc76a..a308a7620 100644
--- a/test/web/mastodon_api/controllers/conversation_controller_test.exs
+++ b/test/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -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
- # Apparently undocumented API endpoint
- res_conn =
+ 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)
- |> post("/api/v1/conversations/#{res_id}/read")
+ |> get("/api/v1/conversations")
+ |> json_response(200)
- assert response = json_response(res_conn, 200)
- assert length(response["accounts"]) == 2
- assert response["last_status"]["id"] == direct.id
- assert response["unread"] == false
+ 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"
+ })
- # (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
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 62b2ab7e3..b7a4938a6 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -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
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
index 7eaeda4a0..8a6528cbb 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
alias Pleroma.Conversation.Participation
alias Pleroma.Notification
alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -73,6 +74,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
--
cgit v1.2.3
From 5dc14c89cecc121ffb047c2a7c972af0b0f89ef8 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Fri, 4 Oct 2019 06:47:36 +0200
Subject: =?UTF-8?q?notification=5Fview.ex:=20Make=20sure=20`account`=20isn?=
=?UTF-8?q?=E2=80=99t=20empty?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Related: https://git.pleroma.social/pleroma/pleroma/issues/1203
---
test/web/mastodon_api/views/notification_view_test.exs | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'test')
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 81ab82e2b..c9043a69a 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -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
--
cgit v1.2.3
From 821729208506980bc65e9671c5462b629dffddaa Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 4 Oct 2019 01:05:50 +0300
Subject: Fix get_cached_by_nickname_or_id not allowing to get local users by
nickname
Closes #1293
---
test/user_test.exs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
(limited to 'test')
diff --git a/test/user_test.exs b/test/user_test.exs
index 126bd69e8..1bc853c94 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -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
--
cgit v1.2.3
From 568a995d64c91f339989077da06e381b4b8cb070 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 4 Oct 2019 16:32:42 +0200
Subject: ActivityPub: Change addressing of Undo.
---
test/web/activity_pub/activity_pub_test.exs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f29497847..c9f2a92e7 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -811,10 +811,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
@@ -890,7 +891,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"
--
cgit v1.2.3
From 2a7f44acfe7075947982546f3dfef61a9cbe45e9 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 4 Oct 2019 17:10:49 +0200
Subject: ActivityPub.Utils: Fix undo test.
---
test/web/activity_pub/utils_test.exs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index b1c1d6f71..c57ea7eb9 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -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"
--
cgit v1.2.3
From 8325858ed229304297df9f57d6e4a359cfa2b4a8 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Fri, 4 Oct 2019 15:17:32 +0000
Subject: tests: streamer: add a test for blocked transitive activities
---
test/web/streamer/streamer_test.exs | 74 ++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 18 deletions(-)
(limited to 'test')
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
index b8fcd41fa..d33eb1e42 100644
--- a/test/web/streamer/streamer_test.exs
+++ b/test/web/streamer/streamer_test.exs
@@ -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
--
cgit v1.2.3
From 83631752af053b02a05abe0e9f7d6c7cf9a5154a Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Fri, 4 Oct 2019 22:20:53 +0300
Subject: removed legacy api: "/objects/:uuid/likes"
---
.../activity_pub/activity_pub_controller_test.exs | 63 ----------------------
1 file changed, 63 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 1ffa91b70..6a3e48b5e 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -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)
--
cgit v1.2.3
From e07e9cb75e6605218acea1ef41772ca29124bd0d Mon Sep 17 00:00:00 2001
From: kaniini
Date: Sat, 5 Oct 2019 10:00:05 +0000
Subject: Revert "Merge branch 'user-info-unread-direct-conversation' into
'develop'"
This reverts merge request !1737
---
test/conversation/participation_test.exs | 4 -
.../controllers/conversation_controller_test.exs | 101 ++-------------------
test/web/mastodon_api/views/account_view_test.exs | 21 -----
.../controllers/pleroma_api_controller_test.exs | 2 -
4 files changed, 10 insertions(+), 118 deletions(-)
(limited to 'test')
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index f430bdf75..a27167d42 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -6,7 +6,6 @@ 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
@@ -31,8 +30,6 @@ 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)
@@ -158,7 +155,6 @@ 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
diff --git a/test/web/mastodon_api/controllers/conversation_controller_test.exs b/test/web/mastodon_api/controllers/conversation_controller_test.exs
index a308a7620..7117fc76a 100644
--- a/test/web/mastodon_api/controllers/conversation_controller_test.exs
+++ b/test/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -10,23 +10,19 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
import Pleroma.Factory
- test "returns a list of conversations", %{conn: conn} do
+ test "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}!",
@@ -56,100 +52,23 @@ 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}] =
+ # Apparently undocumented API endpoint
+ res_conn =
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
+ |> post("/api/v1/conversations/#{res_id}/read")
- # 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"
- })
+ 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/#{direct.id}/context")
+ |> get("/api/v1/statuses/#{res_last_status["id"]}/context")
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
end
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index b7a4938a6..62b2ab7e3 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -418,27 +418,6 @@ 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
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
index 8a6528cbb..7eaeda4a0 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
alias Pleroma.Conversation.Participation
alias Pleroma.Notification
alias Pleroma.Repo
- alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -74,7 +73,6 @@ 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
--
cgit v1.2.3
From 977e711e22dd5171cbff241c7e763de8d34eef26 Mon Sep 17 00:00:00 2001
From: Thibaut Girka
Date: Wed, 2 Oct 2019 13:18:51 +0200
Subject: Import object from self-Announce whenever possible
---
test/fixtures/mastodon-announce-private.json | 35 +++++++++++++++++++++++++++
test/support/http_request_mock.ex | 8 ++++++
test/web/activity_pub/transmogrifier_test.exs | 20 ++++++++++++++-
3 files changed, 62 insertions(+), 1 deletion(-)
create mode 100644 test/fixtures/mastodon-announce-private.json
(limited to 'test')
diff --git a/test/fixtures/mastodon-announce-private.json b/test/fixtures/mastodon-announce-private.json
new file mode 100644
index 000000000..9b868b13d
--- /dev/null
+++ b/test/fixtures/mastodon-announce-private.json
@@ -0,0 +1,35 @@
+{
+ "type": "Announce",
+ "to": [
+ "http://mastodon.example.org/users/admin/followers"
+ ],
+ "published": "2018-02-17T19:39:15Z",
+ "object": {
+ "type": "Note",
+ "id": "http://mastodon.example.org/@admin/99541947525187368",
+ "attributedTo": "http://mastodon.example.org/users/admin",
+ "content": "this is a private toot",
+ "to": [
+ "http://mastodon.example.org/users/admin/followers"
+ ]
+ },
+ "id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
+ "atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
+ "actor": "http://mastodon.example.org/users/admin",
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "toot": "http://joinmastodon.org/ns#",
+ "sensitive": "as:sensitive",
+ "ostatus": "http://ostatus.org#",
+ "movedTo": "as:movedTo",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "atomUri": "ostatus:atomUri",
+ "Hashtag": "as:Hashtag",
+ "Emoji": "toot:Emoji"
+ }
+ ]
+}
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 5506c0626..7a87a2b35 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -349,6 +349,14 @@ defmodule HttpRequestMock do
}}
end
+ def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 404,
+ body: ""
+ }}
+ end
+
def get("https://shitposter.club/notice/7369654", _, _, _) do
{:ok,
%Tesla.Env{
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index b995f0224..d25334104 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -442,6 +442,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
end
+ test "it works for incoming announces with an inlined activity" do
+ data =
+ File.read!("test/fixtures/mastodon-announce-private.json")
+ |> Poison.decode!()
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Announce"
+
+ assert data["id"] ==
+ "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
+
+ object = Object.normalize(data["object"])
+
+ assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
+ assert object.data["content"] == "this is a private toot"
+ end
+
test "it does not clobber the addressing on announce activities" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
@@ -1084,7 +1103,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
{:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
- object = modified["object"]
assert modified["object"]["content"] == "hey"
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
--
cgit v1.2.3
From b1ff66dc5f0f3915152314677bcd2379be0dd43b Mon Sep 17 00:00:00 2001
From: Thibaut Girka
Date: Sat, 5 Oct 2019 12:46:06 +0200
Subject: Add test for handling Announces with inlined object from different
origin
---
test/fixtures/bogus-mastodon-announce.json | 43 +++++++++++++++++++++++++++
test/support/http_request_mock.ex | 8 +++++
test/web/activity_pub/transmogrifier_test.exs | 8 +++++
3 files changed, 59 insertions(+)
create mode 100644 test/fixtures/bogus-mastodon-announce.json
(limited to 'test')
diff --git a/test/fixtures/bogus-mastodon-announce.json b/test/fixtures/bogus-mastodon-announce.json
new file mode 100644
index 000000000..0485b80b9
--- /dev/null
+++ b/test/fixtures/bogus-mastodon-announce.json
@@ -0,0 +1,43 @@
+{
+ "type": "Announce",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "published": "2018-02-17T19:39:15Z",
+ "object": {
+ "type": "Note",
+ "id": "https://mastodon.social/users/emelie/statuses/101849165031453404",
+ "attributedTo": "https://mastodon.social/users/emelie",
+ "content": "this is a public toot",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://mastodon.social/users/emelie",
+ "https://mastodon.social/users/emelie/followers"
+ ]
+ },
+ "id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
+ "cc": [
+ "http://mastodon.example.org/users/admin",
+ "http://mastodon.example.org/users/admin/followers"
+ ],
+ "atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
+ "actor": "http://mastodon.example.org/users/admin",
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "toot": "http://joinmastodon.org/ns#",
+ "sensitive": "as:sensitive",
+ "ostatus": "http://ostatus.org#",
+ "movedTo": "as:movedTo",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "atomUri": "ostatus:atomUri",
+ "Hashtag": "as:Hashtag",
+ "Emoji": "toot:Emoji"
+ }
+ ]
+}
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index 7a87a2b35..b825a9307 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -46,6 +46,14 @@ defmodule HttpRequestMock do
}}
end
+ def get("https://mastodon.social/users/emelie/statuses/101849165031453404", _, _, _) do
+ {:ok,
+ %Tesla.Env{
+ status: 404,
+ body: ""
+ }}
+ end
+
def get("https://mastodon.social/users/emelie", _, _, _) do
{:ok,
%Tesla.Env{
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index d25334104..02f606709 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -461,6 +461,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert object.data["content"] == "this is a private toot"
end
+ test "it rejects incoming announces with an inlined activity from another origin" do
+ data =
+ File.read!("test/fixtures/bogus-mastodon-announce.json")
+ |> Poison.decode!()
+
+ assert :error = Transmogrifier.handle_incoming(data)
+ end
+
test "it does not clobber the addressing on announce activities" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
--
cgit v1.2.3
From 4b8524f392e659d568ba6b0648952d7a1e314be0 Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 5 Oct 2019 14:49:45 +0200
Subject: ActivityPub / Transmogrifier: Correctly store incoming Update id.
---
test/web/activity_pub/transmogrifier_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6c208bdc0..475313316 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -546,6 +546,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
+ assert data["id"] == update_data["id"]
+
user = User.get_cached_by_ap_id(data["actor"])
assert user.name == "gargle"
--
cgit v1.2.3
From 276a52016307707fa6a2f91bd9a3038dcfb71ba7 Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 5 Oct 2019 14:53:50 +0200
Subject: CommonAPI: Create profile updates as public.
This saves us lots of sending out because we can use sharedInbox.
---
test/web/common_api/common_api_test.exs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'test')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 2d3c41e82..83df44c36 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -14,6 +14,8 @@ defmodule Pleroma.Web.CommonAPITest do
import Pleroma.Factory
+ require Pleroma.Constants
+
clear_config([:instance, :safe_dm_mentions])
clear_config([:instance, :limit])
clear_config([:instance, :max_pinned_statuses])
@@ -96,11 +98,13 @@ defmodule Pleroma.Web.CommonAPITest do
test "it adds emoji when updating profiles" do
user = insert(:user, %{name: ":firefox:"})
- CommonAPI.update(user)
+ {:ok, activity} = CommonAPI.update(user)
user = User.get_cached_by_ap_id(user.ap_id)
[firefox] = user.info.source_data["tag"]
assert firefox["name"] == ":firefox:"
+
+ assert Pleroma.Constants.as_public() in activity.recipients
end
describe "posting" do
--
cgit v1.2.3
From 8249924485965148f3a690c5d76e5f8b3bd78940 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Wed, 2 Oct 2019 00:37:08 +0300
Subject: Mastodon API: Add `pleroma.unread_conversation_count` to the Account
entity
---
test/conversation/participation_test.exs | 4 +
.../controllers/conversation_controller_test.exs | 101 +++++++++++++++++++--
test/web/mastodon_api/views/account_view_test.exs | 21 +++++
.../controllers/pleroma_api_controller_test.exs | 2 +
4 files changed, 118 insertions(+), 10 deletions(-)
(limited to 'test')
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index a27167d42..f430bdf75 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -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
diff --git a/test/web/mastodon_api/controllers/conversation_controller_test.exs b/test/web/mastodon_api/controllers/conversation_controller_test.exs
index 7117fc76a..a308a7620 100644
--- a/test/web/mastodon_api/controllers/conversation_controller_test.exs
+++ b/test/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -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
- # Apparently undocumented API endpoint
- res_conn =
+ 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)
- |> post("/api/v1/conversations/#{res_id}/read")
+ |> get("/api/v1/conversations")
+ |> json_response(200)
- assert response = json_response(res_conn, 200)
- assert length(response["accounts"]) == 2
- assert response["last_status"]["id"] == direct.id
- assert response["unread"] == false
+ 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"
+ })
- # (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
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 62b2ab7e3..b7a4938a6 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -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
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
index 7eaeda4a0..8a6528cbb 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
alias Pleroma.Conversation.Participation
alias Pleroma.Notification
alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -73,6 +74,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
--
cgit v1.2.3
From fefbd31c6e60e25778ed01c522273375d4f04266 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sun, 6 Oct 2019 16:22:35 +0300
Subject: Move local keys out of `user.info`
---
test/signature_test.exs | 5 ++---
test/user_test.exs | 8 ++++----
2 files changed, 6 insertions(+), 7 deletions(-)
(limited to 'test')
diff --git a/test/signature_test.exs b/test/signature_test.exs
index d5bf63d7d..96c8ba07a 100644
--- a/test/signature_test.exs
+++ b/test/signature_test.exs
@@ -80,7 +80,7 @@ defmodule Pleroma.SignatureTest do
user =
insert(:user, %{
ap_id: "https://mastodon.social/users/lambadalambda",
- info: %{keys: @private_key}
+ keys: @private_key
})
assert Signature.sign(
@@ -94,8 +94,7 @@ defmodule Pleroma.SignatureTest do
end
test "it returns error" do
- user =
- insert(:user, %{ap_id: "https://mastodon.social/users/lambadalambda", info: %{keys: ""}})
+ user = insert(:user, %{ap_id: "https://mastodon.social/users/lambadalambda", keys: ""})
assert Signature.sign(
user,
diff --git a/test/user_test.exs b/test/user_test.exs
index 1bc853c94..ae21286e4 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1457,15 +1457,15 @@ defmodule Pleroma.UserTest do
describe "ensure_keys_present" do
test "it creates keys for a user and stores them in info" do
user = insert(:user)
- refute is_binary(user.info.keys)
+ refute is_binary(user.keys)
{:ok, user} = User.ensure_keys_present(user)
- assert is_binary(user.info.keys)
+ assert is_binary(user.keys)
end
test "it doesn't create keys if there already are some" do
- user = insert(:user, %{info: %{keys: "xxx"}})
+ user = insert(:user, keys: "xxx")
{:ok, user} = User.ensure_keys_present(user)
- assert user.info.keys == "xxx"
+ assert user.keys == "xxx"
end
end
--
cgit v1.2.3
From 1d8e956c32e412283aed0cebf90df11121d897bb Mon Sep 17 00:00:00 2001
From: feld
Date: Sun, 6 Oct 2019 14:13:04 +0000
Subject: Use the user.id instead of nickname in report URLs
Ensures links to profiles of remote users work.
---
test/emails/admin_email_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test')
diff --git a/test/emails/admin_email_test.exs b/test/emails/admin_email_test.exs
index 31eac5f12..02c277a33 100644
--- a/test/emails/admin_email_test.exs
+++ b/test/emails/admin_email_test.exs
@@ -19,8 +19,8 @@ defmodule Pleroma.Emails.AdminEmailTest do
AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
- reporter_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.nickname)
- account_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, account.nickname)
+ reporter_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
+ account_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
assert res.to == [{to_user.name, to_user.email}]
assert res.from == {config[:name], config[:notify_email]}
--
cgit v1.2.3
From 58aeabd020ae7355aea6b63a331b164e8b23a6c0 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Mon, 7 Oct 2019 02:55:09 +0200
Subject: mrf/simple_policy: check actor against accept/reject
---
test/web/activity_pub/mrf/simple_policy_test.exs | 26 +++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
(limited to 'test')
diff --git a/test/web/activity_pub/mrf/simple_policy_test.exs b/test/web/activity_pub/mrf/simple_policy_test.exs
index 7203b27da..df0f223f8 100644
--- a/test/web/activity_pub/mrf/simple_policy_test.exs
+++ b/test/web/activity_pub/mrf/simple_policy_test.exs
@@ -236,7 +236,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(remote_message) == {:ok, remote_message}
end
- test "has a matching host" do
+ test "activity has a matching host" do
Config.put([:mrf_simple, :reject], ["remote.instance"])
remote_message = build_remote_message()
@@ -244,13 +244,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(remote_message) == {:reject, nil}
end
- test "match with wildcard domain" do
+ test "activity matches with wildcard domain" do
Config.put([:mrf_simple, :reject], ["*.remote.instance"])
remote_message = build_remote_message()
assert SimplePolicy.filter(remote_message) == {:reject, nil}
end
+
+ test "actor has a matching host" do
+ Config.put([:mrf_simple, :reject], ["remote.instance"])
+
+ remote_user = build_remote_user()
+
+ assert SimplePolicy.filter(remote_user) == {:reject, nil}
+ end
end
describe "when :accept" do
@@ -264,7 +272,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(remote_message) == {:ok, remote_message}
end
- test "is not empty but it doesn't have a matching host" do
+ test "is not empty but activity doesn't have a matching host" do
Config.put([:mrf_simple, :accept], ["non.matching.remote"])
local_message = build_local_message()
@@ -274,7 +282,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(remote_message) == {:reject, nil}
end
- test "has a matching host" do
+ test "activity has a matching host" do
Config.put([:mrf_simple, :accept], ["remote.instance"])
local_message = build_local_message()
@@ -284,7 +292,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(remote_message) == {:ok, remote_message}
end
- test "match with wildcard domain" do
+ test "activity matches with wildcard domain" do
Config.put([:mrf_simple, :accept], ["*.remote.instance"])
local_message = build_local_message()
@@ -293,6 +301,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
assert SimplePolicy.filter(local_message) == {:ok, local_message}
assert SimplePolicy.filter(remote_message) == {:ok, remote_message}
end
+
+ test "actor has a matching host" do
+ Config.put([:mrf_simple, :accept], ["remote.instance"])
+
+ remote_user = build_remote_user()
+
+ assert SimplePolicy.filter(remote_user) == {:ok, remote_user}
+ end
end
describe "when :avatar_removal" do
--
cgit v1.2.3
From 4b3f77a99ff849f7593f63f7dccd206683b34d97 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Mon, 7 Oct 2019 12:20:41 +0000
Subject: Extract RSS Feed functionality from OStatus
---
test/emails/admin_email_test.exs | 4 +-
test/user_test.exs | 4 +-
test/web/feed/feed_controller_test.exs | 227 +++++++++++++++++++++++++++
test/web/metadata/feed_test.exs | 18 +++
test/web/ostatus/ostatus_controller_test.exs | 201 ------------------------
5 files changed, 249 insertions(+), 205 deletions(-)
create mode 100644 test/web/feed/feed_controller_test.exs
create mode 100644 test/web/metadata/feed_test.exs
(limited to 'test')
diff --git a/test/emails/admin_email_test.exs b/test/emails/admin_email_test.exs
index 02c277a33..ad89f9213 100644
--- a/test/emails/admin_email_test.exs
+++ b/test/emails/admin_email_test.exs
@@ -19,8 +19,8 @@ defmodule Pleroma.Emails.AdminEmailTest do
AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
- reporter_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
- account_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
+ reporter_url = Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id)
+ account_url = Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
assert res.to == [{to_user.name, to_user.email}]
assert res.from == {config[:name], config[:notify_email]}
diff --git a/test/user_test.exs b/test/user_test.exs
index ae21286e4..019e7b400 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -515,7 +515,7 @@ defmodule Pleroma.UserTest do
user = insert(:user)
assert User.ap_id(user) ==
- Pleroma.Web.Router.Helpers.o_status_url(
+ Pleroma.Web.Router.Helpers.feed_url(
Pleroma.Web.Endpoint,
:feed_redirect,
user.nickname
@@ -526,7 +526,7 @@ defmodule Pleroma.UserTest do
user = insert(:user)
assert User.ap_followers(user) ==
- Pleroma.Web.Router.Helpers.o_status_url(
+ Pleroma.Web.Router.Helpers.feed_url(
Pleroma.Web.Endpoint,
:feed_redirect,
user.nickname
diff --git a/test/web/feed/feed_controller_test.exs b/test/web/feed/feed_controller_test.exs
new file mode 100644
index 000000000..1f44eae20
--- /dev/null
+++ b/test/web/feed/feed_controller_test.exs
@@ -0,0 +1,227 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Feed.FeedControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+
+ alias Pleroma.Object
+ alias Pleroma.User
+
+ test "gets a feed", %{conn: conn} do
+ activity = insert(:note_activity)
+
+ note =
+ insert(:note,
+ data: %{
+ "attachment" => [
+ %{
+ "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}]
+ }
+ ],
+ "inReplyTo" => activity.data["id"]
+ }
+ )
+
+ note_activity = insert(:note_activity, note: note)
+ object = Object.normalize(note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> get("/users/#{user.nickname}/feed.atom")
+
+ assert response(conn, 200) =~ object.data["content"]
+ end
+
+ test "returns 404 for a missing feed", %{conn: conn} do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> get("/users/nonexisting/feed.atom")
+
+ assert response(conn, 404)
+ end
+
+ describe "feed_redirect" do
+ test "undefined format. it redirects to feed", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/users/#{user.nickname}")
+ |> response(302)
+
+ assert response ==
+ "You are being redirected."
+ end
+
+ test "undefined format. it returns error when user not found", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/users/jimm")
+ |> response(404)
+
+ assert response == ~S({"error":"Not found"})
+ end
+
+ test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}")
+ |> json_response(200)
+
+ assert response["endpoints"] == %{
+ "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
+ "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
+ "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
+ "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
+ "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
+ }
+
+ assert response["@context"] == [
+ "https://www.w3.org/ns/activitystreams",
+ "http://localhost:4001/schemas/litepub-0.1.jsonld",
+ %{"@language" => "und"}
+ ]
+
+ assert Map.take(response, [
+ "followers",
+ "following",
+ "id",
+ "inbox",
+ "manuallyApprovesFollowers",
+ "name",
+ "outbox",
+ "preferredUsername",
+ "summary",
+ "tag",
+ "type",
+ "url"
+ ]) == %{
+ "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
+ "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
+ "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
+ "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
+ "manuallyApprovesFollowers" => false,
+ "name" => user.name,
+ "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
+ "preferredUsername" => user.nickname,
+ "summary" => user.bio,
+ "tag" => [],
+ "type" => "Person",
+ "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
+ }
+ end
+
+ test "activity+json format. it returns error whe use not found", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/jimm")
+ |> json_response(404)
+
+ assert response == "Not found"
+ end
+
+ test "json format. it redirects on actual feed of user", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/users/#{user.nickname}")
+ |> json_response(200)
+
+ assert response["endpoints"] == %{
+ "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
+ "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
+ "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
+ "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
+ "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
+ }
+
+ assert response["@context"] == [
+ "https://www.w3.org/ns/activitystreams",
+ "http://localhost:4001/schemas/litepub-0.1.jsonld",
+ %{"@language" => "und"}
+ ]
+
+ assert Map.take(response, [
+ "followers",
+ "following",
+ "id",
+ "inbox",
+ "manuallyApprovesFollowers",
+ "name",
+ "outbox",
+ "preferredUsername",
+ "summary",
+ "tag",
+ "type",
+ "url"
+ ]) == %{
+ "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
+ "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
+ "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
+ "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
+ "manuallyApprovesFollowers" => false,
+ "name" => user.name,
+ "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
+ "preferredUsername" => user.nickname,
+ "summary" => user.bio,
+ "tag" => [],
+ "type" => "Person",
+ "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
+ }
+ end
+
+ test "json format. it returns error whe use not found", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/users/jimm")
+ |> json_response(404)
+
+ assert response == "Not found"
+ end
+
+ test "html format. it redirects on actual feed of user", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> get("/users/#{user.nickname}")
+ |> response(200)
+
+ assert response ==
+ Fallback.RedirectController.redirector_with_meta(
+ conn,
+ %{user: user}
+ ).resp_body
+ end
+
+ test "html format. it returns error when user not found", %{conn: conn} do
+ response =
+ conn
+ |> get("/users/jimm")
+ |> json_response(404)
+
+ assert response == %{"error" => "Not found"}
+ end
+ end
+end
diff --git a/test/web/metadata/feed_test.exs b/test/web/metadata/feed_test.exs
new file mode 100644
index 000000000..50e9ce52e
--- /dev/null
+++ b/test/web/metadata/feed_test.exs
@@ -0,0 +1,18 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Metadata.Providers.FeedTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.Web.Metadata.Providers.Feed
+
+ test "it renders a link to user's atom feed" do
+ user = insert(:user, nickname: "lain")
+
+ assert Feed.build_tags(%{user: user}) == [
+ {:link,
+ [rel: "alternate", type: "application/atom+xml", href: "/users/lain/feed.atom"], []}
+ ]
+ end
+end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index f06023dff..b1af918d8 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -72,28 +72,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
end
end
- test "gets a feed", %{conn: conn} do
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- conn =
- conn
- |> put_req_header("content-type", "application/atom+xml")
- |> get("/users/#{user.nickname}/feed.atom")
-
- assert response(conn, 200) =~ object.data["content"]
- end
-
- test "returns 404 for a missing feed", %{conn: conn} do
- conn =
- conn
- |> put_req_header("content-type", "application/atom+xml")
- |> get("/users/nonexisting/feed.atom")
-
- assert response(conn, 404)
- end
-
describe "GET object/2" do
test "gets an object", %{conn: conn} do
note_activity = insert(:note_activity)
@@ -355,185 +333,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
end
end
- describe "feed_redirect" do
- test "undefined format. it redirects to feed", %{conn: conn} do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- response =
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/users/#{user.nickname}")
- |> response(302)
-
- assert response ==
- "You are being redirected."
- end
-
- test "undefined format. it returns error when user not found", %{conn: conn} do
- response =
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/users/jimm")
- |> response(404)
-
- assert response == ~S({"error":"Not found"})
- end
-
- test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- response =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/users/#{user.nickname}")
- |> json_response(200)
-
- assert response["endpoints"] == %{
- "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
- "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
- "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
- "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
- "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
- }
-
- assert response["@context"] == [
- "https://www.w3.org/ns/activitystreams",
- "http://localhost:4001/schemas/litepub-0.1.jsonld",
- %{"@language" => "und"}
- ]
-
- assert Map.take(response, [
- "followers",
- "following",
- "id",
- "inbox",
- "manuallyApprovesFollowers",
- "name",
- "outbox",
- "preferredUsername",
- "summary",
- "tag",
- "type",
- "url"
- ]) == %{
- "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
- "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
- "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
- "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
- "manuallyApprovesFollowers" => false,
- "name" => user.name,
- "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
- "preferredUsername" => user.nickname,
- "summary" => user.bio,
- "tag" => [],
- "type" => "Person",
- "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
- }
- end
-
- test "activity+json format. it returns error whe use not found", %{conn: conn} do
- response =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/users/jimm")
- |> json_response(404)
-
- assert response == "Not found"
- end
-
- test "json format. it redirects on actual feed of user", %{conn: conn} do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- response =
- conn
- |> put_req_header("accept", "application/json")
- |> get("/users/#{user.nickname}")
- |> json_response(200)
-
- assert response["endpoints"] == %{
- "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
- "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
- "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
- "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
- "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
- }
-
- assert response["@context"] == [
- "https://www.w3.org/ns/activitystreams",
- "http://localhost:4001/schemas/litepub-0.1.jsonld",
- %{"@language" => "und"}
- ]
-
- assert Map.take(response, [
- "followers",
- "following",
- "id",
- "inbox",
- "manuallyApprovesFollowers",
- "name",
- "outbox",
- "preferredUsername",
- "summary",
- "tag",
- "type",
- "url"
- ]) == %{
- "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
- "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
- "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
- "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
- "manuallyApprovesFollowers" => false,
- "name" => user.name,
- "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
- "preferredUsername" => user.nickname,
- "summary" => user.bio,
- "tag" => [],
- "type" => "Person",
- "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
- }
- end
-
- test "json format. it returns error whe use not found", %{conn: conn} do
- response =
- conn
- |> put_req_header("accept", "application/json")
- |> get("/users/jimm")
- |> json_response(404)
-
- assert response == "Not found"
- end
-
- test "html format. it redirects on actual feed of user", %{conn: conn} do
- note_activity = insert(:note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
-
- response =
- conn
- |> get("/users/#{user.nickname}")
- |> response(200)
-
- assert response ==
- Fallback.RedirectController.redirector_with_meta(
- conn,
- %{user: user}
- ).resp_body
- end
-
- test "html format. it returns error when user not found", %{conn: conn} do
- response =
- conn
- |> get("/users/jimm")
- |> json_response(404)
-
- assert response == %{"error" => "Not found"}
- end
- end
-
describe "GET /notice/:id/embed_player" do
test "render embed player", %{conn: conn} do
note_activity = insert(:note_activity)
--
cgit v1.2.3