summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2018-03-30 15:01:53 +0200
committerlain <lain@soykaf.club>2018-03-30 15:01:53 +0200
commit4afbef39f49948ddd3b1cd1bbda58ff7e3ac2785 (patch)
tree6959e12d9058c981f3b69c77b8b0290049651cd6 /test
parent480932c8e524e1a80c9c8ef1a1aa23379f633afe (diff)
downloadpleroma-4afbef39f49948ddd3b1cd1bbda58ff7e3ac2785.tar.gz
pleroma-4afbef39f49948ddd3b1cd1bbda58ff7e3ac2785.zip
Format the code.
Diffstat (limited to 'test')
-rw-r--r--test/activity_test.exs4
-rw-r--r--test/formatter_test.exs51
-rw-r--r--test/notification_test.exs34
-rw-r--r--test/plugs/authentication_plug_test.exs44
-rw-r--r--test/support/builders/activity_builder.ex8
-rw-r--r--test/support/builders/user_builder.ex1
-rw-r--r--test/support/channel_case.ex4
-rw-r--r--test/support/conn_case.ex4
-rw-r--r--test/support/factory.ex28
-rw-r--r--test/support/httpoison_mock.ex1057
-rw-r--r--test/support/ostatus_mock.ex1
-rw-r--r--test/test_helper.exs1
-rw-r--r--test/upload_test.exs25
-rw-r--r--test/user_test.exs52
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs27
-rw-r--r--test/web/activity_pub/activity_pub_test.exs52
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs192
-rw-r--r--test/web/common_api/common_api_utils_test.exs6
-rw-r--r--test/web/mastodon_api/account_view_test.exs7
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs410
-rw-r--r--test/web/mastodon_api/status_view_test.exs9
-rw-r--r--test/web/oauth/authorization_test.exs22
-rw-r--r--test/web/oauth/token_test.exs10
-rw-r--r--test/web/ostatus/activity_representer_test.exs80
-rw-r--r--test/web/ostatus/feed_representer_test.exs17
-rw-r--r--test/web/ostatus/incoming_documents/delete_handling_test.exs9
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs66
-rw-r--r--test/web/ostatus/ostatus_test.exs126
-rw-r--r--test/web/salmon/salmon_test.exs13
-rw-r--r--test/web/twitter_api/representers/activity_representer_test.exs42
-rw-r--r--test/web/twitter_api/representers/object_representer_test.exs9
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs350
-rw-r--r--test/web/twitter_api/twitter_api_test.exs110
-rw-r--r--test/web/twitter_api/views/user_view_test.exs10
-rw-r--r--test/web/views/error_view_test.exs7
-rw-r--r--test/web/web_finger/web_finger_test.exs14
-rw-r--r--test/web/websub/websub_controller_test.exs30
-rw-r--r--test/web/websub/websub_test.exs85
-rw-r--r--test/xml_builder_test.exs14
39 files changed, 1984 insertions, 1047 deletions
diff --git a/test/activity_test.exs b/test/activity_test.exs
index 366a2f957..55849c522 100644
--- a/test/activity_test.exs
+++ b/test/activity_test.exs
@@ -18,7 +18,9 @@ defmodule Pleroma.ActivityTest do
test "returns the activity that created an object" do
activity = insert(:note_activity)
- found_activity = Pleroma.Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
+
+ found_activity =
+ Pleroma.Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])
assert activity == found_activity
end
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 9ec2cc9f2..b7246252f 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -7,44 +7,56 @@ defmodule Pleroma.FormatterTest do
describe ".add_hashtag_links" do
test "turns hashtags into links" do
text = "I love #cofe and #2hu"
- expected_text = "I love <a href='http://localhost:4001/tag/cofe' rel='tag'>#cofe</a> and <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a>"
+
+ expected_text =
+ "I love <a href='http://localhost:4001/tag/cofe' rel='tag'>#cofe</a> and <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a>"
tags = Formatter.parse_tags(text)
- assert expected_text == Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize
+
+ assert expected_text ==
+ Formatter.add_hashtag_links({[], text}, tags) |> Formatter.finalize()
end
end
describe ".add_links" do
test "turning urls into links" do
text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla."
- expected = "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>."
- assert Formatter.add_links({[], text}) |> Formatter.finalize == expected
+ expected =
+ "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>."
+
+ assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
text = "https://mastodon.social/@lambadalambda"
- expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
- assert Formatter.add_links({[], text}) |> Formatter.finalize == expected
+ expected =
+ "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
+
+ assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
text = "@lambadalambda"
expected = "@lambadalambda"
- assert Formatter.add_links({[], text}) |> Formatter.finalize == expected
+ assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
text = "http://www.cs.vu.nl/~ast/intel/"
expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>"
- assert Formatter.add_links({[], text}) |> Formatter.finalize == expected
+ assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
- expected = "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
- assert Formatter.add_links({[], text}) |> Formatter.finalize == expected
+ expected =
+ "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
+
+ assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
- expected = "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
- assert Formatter.add_links({[], text}) |> Formatter.finalize == expected
+ expected =
+ "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
+
+ assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected
end
end
@@ -60,9 +72,14 @@ defmodule Pleroma.FormatterTest do
{subs, text} = Formatter.add_user_links({[], text}, mentions)
assert length(subs) == 3
- Enum.each(subs, fn({uuid, _}) -> assert String.contains?(text, uuid) end)
+ Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
- expected_text = "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{archaeme.ap_id}'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{archaeme_remote.ap_id}'>@<span>archaeme</span></a></span>"
+ expected_text =
+ "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{
+ archaeme.ap_id
+ }'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{
+ archaeme_remote.ap_id
+ }'>@<span>archaeme</span></a></span>"
assert expected_text == Formatter.finalize({subs, text})
end
@@ -71,6 +88,7 @@ defmodule Pleroma.FormatterTest do
describe ".parse_tags" do
test "parses tags in the text" do
text = "Here's a #Test. Maybe these are #working or not. What about #漢字? And #は。"
+
expected = [
{"#Test", "test"},
{"#working", "working"},
@@ -92,7 +110,7 @@ defmodule Pleroma.FormatterTest do
expected_result = [
{"@gsimg", gsimg},
{"@archaeme", archaeme},
- {"@archaeme@archae.me", archaeme_remote},
+ {"@archaeme@archae.me", archaeme_remote}
]
assert Formatter.parse_mentions(text) == expected_result
@@ -101,7 +119,8 @@ defmodule Pleroma.FormatterTest do
test "it adds cool emoji" do
text = "I love :moominmamma:"
- expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
+ expected_result =
+ "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
assert Formatter.emojify(text) == expected_result
end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 1504004c8..568ad642c 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -10,7 +10,10 @@ defmodule Pleroma.NotificationTest do
other_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{
+ "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
+ })
{:ok, [notification, other_notification]} = Notification.create_notifications(activity)
@@ -37,7 +40,9 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, notification} = Notification.get(other_user, notification.id)
@@ -48,7 +53,9 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+
{:ok, [notification]} = Notification.create_notifications(activity)
{:error, _notification} = Notification.get(user, notification.id)
end
@@ -59,7 +66,9 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+
{:ok, [notification]} = Notification.create_notifications(activity)
{:ok, notification} = Notification.dismiss(other_user, notification.id)
@@ -70,7 +79,9 @@ defmodule Pleroma.NotificationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
+
{:ok, [notification]} = Notification.create_notifications(activity)
{:error, _notification} = Notification.dismiss(user, notification.id)
end
@@ -82,9 +93,18 @@ defmodule Pleroma.NotificationTest do
other_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"})
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{
+ "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
+ })
+
{:ok, _notifs} = Notification.create_notifications(activity)
- {:ok, activity} = TwitterAPI.create_status(user, %{"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"})
+
+ {:ok, activity} =
+ TwitterAPI.create_status(user, %{
+ "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
+ })
+
{:ok, _notifs} = Notification.create_notifications(activity)
Notification.clear(other_user)
diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs
index 5480dab43..729ac8ae5 100644
--- a/test/plugs/authentication_plug_test.exs
+++ b/test/plugs/authentication_plug_test.exs
@@ -37,22 +37,24 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
describe "without an authorization header" do
test "it halts the application" do
- conn = build_conn()
- |> Plug.Session.call(Plug.Session.init(@session_opts))
- |> fetch_session
- |> AuthenticationPlug.call(%{})
+ conn =
+ build_conn()
+ |> Plug.Session.call(Plug.Session.init(@session_opts))
+ |> fetch_session
+ |> AuthenticationPlug.call(%{})
assert conn.status == 403
assert conn.halted == true
end
test "it assigns a nil user if the 'optional' option is used" do
- conn = build_conn()
- |> Plug.Session.call(Plug.Session.init(@session_opts))
- |> fetch_session
- |> AuthenticationPlug.call(%{optional: true})
+ conn =
+ build_conn()
+ |> Plug.Session.call(Plug.Session.init(@session_opts))
+ |> fetch_session
+ |> AuthenticationPlug.call(%{optional: true})
- assert %{ user: nil } == conn.assigns
+ assert %{user: nil} == conn.assigns
end
end
@@ -73,9 +75,9 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
build_conn()
|> Plug.Session.call(Plug.Session.init(@session_opts))
|> fetch_session
- |> AuthenticationPlug.call(%{optional: true, fetcher: &fetch_nil/1 })
+ |> AuthenticationPlug.call(%{optional: true, fetcher: &fetch_nil/1})
- assert %{ user: nil } == conn.assigns
+ assert %{user: nil} == conn.assigns
end
end
@@ -113,7 +115,7 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
|> put_req_header("authorization", header)
|> AuthenticationPlug.call(opts)
- assert %{ user: nil } == conn.assigns
+ assert %{user: nil} == conn.assigns
end
end
@@ -126,13 +128,14 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
header = basic_auth_enc("dude", "guy")
- conn = conn
+ conn =
+ conn
|> Plug.Session.call(Plug.Session.init(@session_opts))
|> fetch_session
|> put_req_header("authorization", header)
|> AuthenticationPlug.call(opts)
- assert %{ user: @user } == conn.assigns
+ assert %{user: @user} == conn.assigns
assert get_session(conn, :user_id) == @user.id
assert conn.halted == false
end
@@ -147,7 +150,8 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
header = basic_auth_enc("dude", "guy")
- conn = conn
+ conn =
+ conn
|> Plug.Session.call(Plug.Session.init(@session_opts))
|> fetch_session
|> put_req_header("authorization", header)
@@ -167,14 +171,15 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
header = basic_auth_enc("dude", "THIS IS WRONG")
- conn = conn
+ conn =
+ conn
|> Plug.Session.call(Plug.Session.init(@session_opts))
|> fetch_session
|> put_session(:user_id, @user.id)
|> put_req_header("authorization", header)
|> AuthenticationPlug.call(opts)
- assert %{ user: @user } == conn.assigns
+ assert %{user: @user} == conn.assigns
assert get_session(conn, :user_id) == @user.id
assert conn.halted == false
end
@@ -182,8 +187,9 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
describe "with an assigned user" do
test "it does nothing, returning the incoming conn", %{conn: conn} do
- conn = conn
- |> assign(:user, @user)
+ conn =
+ conn
+ |> assign(:user, @user)
conn_result = AuthenticationPlug.call(conn, %{})
diff --git a/test/support/builders/activity_builder.ex b/test/support/builders/activity_builder.ex
index 0ebf633b3..d9c188955 100644
--- a/test/support/builders/activity_builder.ex
+++ b/test/support/builders/activity_builder.ex
@@ -4,17 +4,19 @@ defmodule Pleroma.Builders.ActivityBuilder do
def build(data \\ %{}, opts \\ %{}) do
user = opts[:user] || Pleroma.Factory.insert(:user)
+
activity = %{
- "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id,
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
"actor" => user.ap_id,
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"type" => "Create",
"object" => %{
"type" => "Note",
"content" => "test",
- "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
}
+
Map.merge(activity, data)
end
@@ -24,7 +26,7 @@ defmodule Pleroma.Builders.ActivityBuilder do
end
def insert_list(times, data \\ %{}, opts \\ %{}) do
- Enum.map(1..times, fn (n) ->
+ Enum.map(1..times, fn n ->
{:ok, activity} = insert(data, opts)
activity
end)
diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex
index 1e1e80ac9..7a1ca79b5 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -10,6 +10,7 @@ defmodule Pleroma.Builders.UserBuilder do
bio: "A tester.",
ap_id: "some id"
}
+
Map.merge(user, data)
end
diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex
index aec3061b3..68995a01d 100644
--- a/test/support/channel_case.ex
+++ b/test/support/channel_case.ex
@@ -25,13 +25,13 @@ defmodule Pleroma.Web.ChannelCase do
end
end
-
setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
+
unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
+
:ok
end
-
end
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index a83ef3b3a..2e6707087 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -26,14 +26,14 @@ defmodule Pleroma.Web.ConnCase do
end
end
-
setup tags do
Cachex.clear(:user_cache)
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo)
+
unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()})
end
+
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
-
end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 1445fe828..8e21e2562 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -9,20 +9,27 @@ defmodule Pleroma.Factory do
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: sequence(:bio, &"Tester Number #{&1}")
}
- %{ user | ap_id: Pleroma.User.ap_id(user), follower_address: Pleroma.User.ap_followers(user), following: [Pleroma.User.ap_id(user)] }
+
+ %{
+ user
+ | ap_id: Pleroma.User.ap_id(user),
+ follower_address: Pleroma.User.ap_followers(user),
+ following: [Pleroma.User.ap_id(user)]
+ }
end
def note_factory do
text = sequence(:text, &"This is :moominmamma: note #{&1}")
user = insert(:user)
+
data = %{
"type" => "Note",
"content" => text,
- "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id,
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
"actor" => user.ap_id,
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
- "published" => DateTime.utc_now() |> DateTime.to_iso8601,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
"likes" => [],
"like_count" => 0,
"context" => "2hu",
@@ -40,13 +47,14 @@ defmodule Pleroma.Factory do
def note_activity_factory do
note = insert(:note)
+
data = %{
- "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
"type" => "Create",
"actor" => note.data["actor"],
"to" => note.data["to"],
"object" => note.data,
- "published" => DateTime.utc_now() |> DateTime.to_iso8601,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
"context" => note.data["context"]
}
@@ -62,11 +70,11 @@ defmodule Pleroma.Factory do
user = insert(:user)
data = %{
- "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
"actor" => user.ap_id,
"type" => "Like",
"object" => note_activity.data["object"]["id"],
- "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
+ "published_at" => DateTime.utc_now() |> DateTime.to_iso8601()
}
%Pleroma.Activity{
@@ -79,11 +87,11 @@ defmodule Pleroma.Factory do
followed = insert(:user)
data = %{
- "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
"actor" => follower.ap_id,
"type" => "Follow",
"object" => followed.ap_id,
- "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
+ "published_at" => DateTime.utc_now() |> DateTime.to_iso8601()
}
%Pleroma.Activity{
@@ -96,7 +104,7 @@ defmodule Pleroma.Factory do
topic: "http://example.org",
callback: "http://example/org/callback",
secret: "here's a secret",
- valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, 100),
+ valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 100),
state: "requested"
}
end
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
index c70598691..ba35c4460 100644
--- a/test/support/httpoison_mock.ex
+++ b/test/support/httpoison_mock.ex
@@ -3,461 +3,712 @@ defmodule HTTPoisonMock do
def get(url, body \\ [], headers \\ [])
- def get("http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
- }}
- end
- def get("http://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "nonexistant@social.heldscal.la"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 500,
- body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "shp@social.heldscal.la"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://social.heldscal.la/user/23211"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://social.heldscal.la/user/29191"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
- }}
- end
-
- def get("https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
- }}
- end
-
- def get("https://mastodon.social/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://mastodon.social/users/lambadalambda"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
- }}
- end
-
- def get("https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
- }}
- end
-
- def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://shitposter.club/user/1"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
- }}
- end
-
- def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
- }}
- end
-
- def get("https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
- }}
- end
-
- def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
- }}
- end
-
- def get("http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
- }}
- end
-
- def get("https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=https://social.stopwatchingus-heidelberg.de/user/18330", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
- }}
- end
-
- def get("https://pleroma.soykaf.com/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://pleroma.soykaf.com/users/lain"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
- }}
- end
-
- def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
- }}
+ def get(
+ "http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/framasoft@framatube.org.json")
+ }}
+ end
+
+ def get(
+ "http://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/winterdienst_webfinger.json")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "nonexistant@social.heldscal.la"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 500,
+ body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=shp@social.heldscal.la",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "shp@social.heldscal.la"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://social.heldscal.la/user/23211"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/23211",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://social.heldscal.la/user/29191"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
+ }}
+ end
+
+ def get(
+ "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
+ }}
+ end
+
+ def get(
+ "https://mastodon.social/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://mastodon.social/users/lambadalambda"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
+ )
+ }}
+ end
+
+ def get(
+ "https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/lambadalambda",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml"
+ )
+ }}
+ end
+
+ def get(
+ "https://shitposter.club/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://shitposter.club/user/1"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
+ }}
+ end
+
+ def get(
+ "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/1",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
+ }}
+ end
+
+ def get(
+ "https://shitposter.club/.well-known/webfinger?resource=https://shitposter.club/user/5381",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/spc_5381_xrd.xml")
+ }}
+ end
+
+ def get(
+ "http://gs.example.org/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "http://gs.example.org:4040/index.php/user/1"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
+ )
+ }}
+ end
+
+ def get(
+ "http://gs.example.org/.well-known/webfinger?resource=http://gs.example.org:4040/index.php/user/1",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml"
+ )
+ }}
+ end
+
+ def get(
+ "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=https://social.stopwatchingus-heidelberg.de/user/18330",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
+ }}
+ end
+
+ def get(
+ "https://pleroma.soykaf.com/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://pleroma.soykaf.com/users/lain"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
+ }}
+ end
+
+ def get(
+ "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/lain",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
+ }}
end
def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml"
+ )
+ }}
end
def get("https://shitposter.club/api/statuses/user_timeline/5381.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/spc_5381.atom")
+ }}
end
def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml"
+ )
+ }}
end
def get("https://mastodon.social/users/lambadalambda.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom")
- }}
- end
-
- def get("https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom"
+ )
+ }}
+ end
+
+ def get(
+ "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
+ _body,
+ _headers
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
+ }}
end
def get("https://pleroma.soykaf.com/users/lain/feed.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml"
+ )
+ }}
end
def get("https://social.sakamoto.gq/users/eal/feed.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/sakamoto_eal_feed.atom")
+ }}
end
def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml"
+ )
+ }}
end
def get("https://shitposter.club/notice/2827873", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
+ }}
end
def get("https://shitposter.club/api/statuses/show/2827873.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml"
+ )
+ }}
end
def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml")
- }}
- end
-
- def post("https://social.heldscal.la/main/push/hub", {:form, data}, ["Content-type": "application/x-www-form-urlencoded"]) do
- {:ok, %Response{
- status_code: 202
- }}
- end
-
- def get("https://pawoo.net/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://pawoo.net/users/pekorino"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
- }}
- end
-
- def get("https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!(
+ "test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml"
+ )
+ }}
+ end
+
+ def post(
+ "https://social.heldscal.la/main/push/hub",
+ {:form, data},
+ "Content-type": "application/x-www-form-urlencoded"
+ ) do
+ {:ok,
+ %Response{
+ status_code: 202
+ }}
+ end
+
+ def get(
+ "https://pawoo.net/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://pawoo.net/users/pekorino"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
+ }}
+ end
+
+ def get(
+ "https://pawoo.net/.well-known/webfinger?resource=https://pawoo.net/users/pekorino",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
+ }}
end
def get("https://pawoo.net/users/pekorino.atom", _, _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
- }}
- end
-
- def get("https://mamot.fr/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://mamot.fr/users/Skruyb"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
- }}
- end
-
- def get("https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
- }}
- end
-
- def get("https://social.sakamoto.gq/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], [params: [resource: "https://social.sakamoto.gq/users/eal"], follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
- }}
- end
-
- def get("https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
- }}
- end
-
- def get("https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/shp", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner")
- }}
- end
-
- def get("https://squeet.me/xrd/?uri=lain@squeet.me", [Accept: "application/xrd+xml,application/jrd+json"], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
+ }}
+ end
+
+ def get(
+ "https://mamot.fr/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://mamot.fr/users/Skruyb"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+ }}
+ end
+
+ def get(
+ "https://mamot.fr/.well-known/webfinger?resource=https://mamot.fr/users/Skruyb",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+ }}
+ end
+
+ def get(
+ "https://social.sakamoto.gq/.well-known/webfinger",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ params: [resource: "https://social.sakamoto.gq/users/eal"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
+ }}
+ end
+
+ def get(
+ "https://social.sakamoto.gq/.well-known/webfinger?resource=https://social.sakamoto.gq/users/eal",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/eal_sakamoto.xml")
+ }}
+ end
+
+ def get(
+ "https://pleroma.soykaf.com/.well-known/webfinger?resource=https://pleroma.soykaf.com/users/shp",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.webfigner")
+ }}
+ end
+
+ def get(
+ "https://squeet.me/xrd/?uri=lain@squeet.me",
+ [Accept: "application/xrd+xml,application/jrd+json"],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
+ }}
end
def get("https://mamot.fr/users/Skruyb.atom", _, _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
+ }}
end
- def get("https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056", [Accept: "application/atom+xml"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")
- }}
+ def get(
+ "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056",
+ [Accept: "application/atom+xml"],
+ _
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/sakamoto.atom")
+ }}
end
def get("https://pleroma.soykaf.com/users/shp/feed.atom", _, _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed")
- }}
- end
-
- def get("http://social.heldscal.la/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
- }}
- end
-
- def get("http://macgirvin.com/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
- }}
- end
-
- def get("http://mastodon.social/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
- }}
- end
-
- def get("http://shitposter.club/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
- }}
- end
-
- def get("http://pleroma.soykaf.com/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta")
- }}
- end
-
- def get("http://social.sakamoto.gq/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
- }}
- end
-
- def get("http://gs.example.org/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
- }}
- end
-
- def get("http://pawoo.net/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/pawoo.net_host_meta")
- }}
- end
-
- def get("http://mamot.fr/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mamot.fr_host_meta")
- }}
- end
-
- def get("http://mastodon.xyz/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mastodon.xyz_host_meta")
- }}
- end
-
- def get("http://social.wxcafe.net/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.wxcafe.net_host_meta")
- }}
- end
-
- def get("http://squeet.me/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")
- }}
- end
-
- def get("http://social.stopwatchingus-heidelberg.de/.well-known/host-meta", [], [follow_redirect: true]) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta")
- }}
- end
-
- def get("http://mastodon.example.org/users/admin", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
- }}
- end
-
- def get("https://masto.quad.moe/users/_HellPie", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/hellpie.json")
- }}
- end
-
- def get("https://niu.moe/users/rye", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/rye.json")
- }}
- end
-
- def get("https://mst3k.interlinked.me/users/luciferMysticus", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
- }}
- end
-
- def get("https://mstdn.io/users/mayuutann", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
- }}
- end
-
- def get("http://mastodon.example.org/@admin/99541947525187367", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/mastodon-note-object.json")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shp@pleroma.soykaf.com.feed")
+ }}
end
- def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", ["Accept": "application/activity+json"], _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
- }}
+ def get("http://social.heldscal.la/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/social.heldscal.la_host_meta")
+ }}
+ end
+
+ def get("http://macgirvin.com/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/macgirvin.com_host_meta")
+ }}
+ end
+
+ def get("http://mastodon.social/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mastodon.social_host_meta")
+ }}
+ end
+
+ def get("http://shitposter.club/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/shitposter.club_host_meta")
+ }}
+ end
+
+ def get("http://pleroma.soykaf.com/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/pleroma.soykaf.com_host_meta")
+ }}
+ end
+
+ def get("http://social.sakamoto.gq/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/social.sakamoto.gq_host_meta")
+ }}
+ end
+
+ def get("http://gs.example.org/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/gs.example.org_host_meta")
+ }}
+ end
+
+ def get("http://pawoo.net/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/pawoo.net_host_meta")
+ }}
+ end
+
+ def get("http://mamot.fr/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mamot.fr_host_meta")
+ }}
+ end
+
+ def get("http://mastodon.xyz/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mastodon.xyz_host_meta")
+ }}
+ end
+
+ def get("http://social.wxcafe.net/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/social.wxcafe.net_host_meta")
+ }}
+ end
+
+ def get("http://squeet.me/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/squeet.me_host_meta")
+ }}
+ end
+
+ def get(
+ "http://social.stopwatchingus-heidelberg.de/.well-known/host-meta",
+ [],
+ follow_redirect: true
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body:
+ File.read!("test/fixtures/httpoison_mock/social.stopwatchingus-heidelberg.de_host_meta")
+ }}
+ end
+
+ def get("http://mastodon.example.org/users/admin", [Accept: "application/activity+json"], _) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
+ }}
+ end
+
+ def get("https://masto.quad.moe/users/_HellPie", [Accept: "application/activity+json"], _) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/hellpie.json")
+ }}
+ end
+
+ def get("https://niu.moe/users/rye", [Accept: "application/activity+json"], _) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/rye.json")
+ }}
+ end
+
+ def get(
+ "https://mst3k.interlinked.me/users/luciferMysticus",
+ [Accept: "application/activity+json"],
+ _
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
+ }}
+ end
+
+ def get("https://mstdn.io/users/mayuutann", [Accept: "application/activity+json"], _) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mayumayu.json")
+ }}
+ end
+
+ def get(
+ "http://mastodon.example.org/@admin/99541947525187367",
+ [Accept: "application/activity+json"],
+ _
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/mastodon-note-object.json")
+ }}
+ end
+
+ def get(
+ "https://mstdn.io/users/mayuutann/statuses/99568293732299394",
+ [Accept: "application/activity+json"],
+ _
+ ) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/mayumayupost.json")
+ }}
end
def get("https://shitposter.club/notice/7369654", _, _) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.html")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/7369654.html")
+ }}
end
def get("https://shitposter.club/api/statuses/show/7369654.atom", _body, _headers) do
- {:ok, %Response{
- status_code: 200,
- body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
- }}
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/7369654.atom")
+ }}
end
def get(url, body, headers) do
- {:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
+ {:error,
+ "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{
+ inspect(headers)
+ }"}
end
def post(url, body, headers) do
diff --git a/test/support/ostatus_mock.ex b/test/support/ostatus_mock.ex
index c26e91990..36865ae02 100644
--- a/test/support/ostatus_mock.ex
+++ b/test/support/ostatus_mock.ex
@@ -1,5 +1,6 @@
defmodule Pleroma.Web.OStatusMock do
import Pleroma.Factory
+
def handle_incoming(_doc) do
insert(:note_activity)
end
diff --git a/test/test_helper.exs b/test/test_helper.exs
index a2a9c7fd9..94ba68ff8 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -2,4 +2,3 @@ ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
{:ok, _} = Application.ensure_all_started(:ex_machina)
-
diff --git a/test/upload_test.exs b/test/upload_test.exs
index f90c4d713..d68b3e7ba 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -4,20 +4,37 @@ defmodule Pleroma.UploadTest do
describe "Storing a file" do
test "copies the file to the configured folder" do
- 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"
+ }
+
data = Upload.store(file)
assert data["name"] == "an [image.jpg"
- assert List.first(data["url"])["href"] == "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg"
+
+ assert List.first(data["url"])["href"] ==
+ "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg"
end
test "fixes an incorrect content type" do
- file = %Plug.Upload{content_type: "application/octet-stream", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"}
+ file = %Plug.Upload{
+ content_type: "application/octet-stream",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an [image.jpg"
+ }
+
data = Upload.store(file)
assert hd(data["url"])["mediaType"] == "image/jpeg"
end
test "does not modify a valid content type" do
- file = %Plug.Upload{content_type: "image/png", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"}
+ file = %Plug.Upload{
+ content_type: "image/png",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an [image.jpg"
+ }
+
data = Upload.store(file)
assert hd(data["url"])["mediaType"] == "image/png"
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 35de0a7ce..6e9025f2a 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -10,15 +10,15 @@ defmodule Pleroma.UserTest do
import Ecto.Query
test "ap_id returns the activity pub id for the user" do
- user = UserBuilder.build
+ user = UserBuilder.build()
- expected_ap_id = "#{Pleroma.Web.base_url}/users/#{user.nickname}"
+ expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
assert expected_ap_id == User.ap_id(user)
end
test "ap_followers returns the followers collection for the user" do
- user = UserBuilder.build
+ user = UserBuilder.build()
expected_followers_collection = "#{User.ap_id(user)}/followers"
@@ -67,7 +67,7 @@ defmodule Pleroma.UserTest do
followed = insert(:user)
user = insert(:user, %{following: [User.ap_followers(followed)]})
- {:ok, user, _activity } = User.unfollow(user, followed)
+ {:ok, user, _activity} = User.unfollow(user, followed)
user = Repo.get(User, user.id)
@@ -83,7 +83,6 @@ defmodule Pleroma.UserTest do
assert user.following == [user.ap_id]
end
-
test "test if a user is following another user" do
followed = insert(:user)
user = insert(:user, %{following: [User.ap_followers(followed)]})
@@ -104,12 +103,12 @@ defmodule Pleroma.UserTest do
test "it requires an email, name, nickname and password, bio is optional" do
@full_user_data
- |> Map.keys
- |> Enum.each(fn (key) ->
+ |> Map.keys()
+ |> Enum.each(fn key ->
params = Map.delete(@full_user_data, key)
changeset = User.register_changeset(%User{}, params)
- assert (if key == :bio, do: changeset.valid?, else: not changeset.valid?)
+ assert if key == :bio, do: changeset.valid?, else: not changeset.valid?
end)
end
@@ -120,7 +119,11 @@ defmodule Pleroma.UserTest do
assert is_binary(changeset.changes[:password_hash])
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
- assert changeset.changes[:following] == [User.ap_followers(%User{nickname: @full_user_data.nickname})]
+
+ assert changeset.changes[:following] == [
+ User.ap_followers(%User{nickname: @full_user_data.nickname})
+ ]
+
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
end
end
@@ -158,12 +161,24 @@ defmodule Pleroma.UserTest do
test "returns an ap_id for a user" do
user = insert(:user)
- assert User.ap_id(user) == Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, user.nickname)
+
+ assert User.ap_id(user) ==
+ Pleroma.Web.Router.Helpers.o_status_url(
+ Pleroma.Web.Endpoint,
+ :feed_redirect,
+ user.nickname
+ )
end
test "returns an ap_followers link for a user" do
user = insert(:user)
- assert User.ap_followers(user) == Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, user.nickname) <> "/followers"
+
+ assert User.ap_followers(user) ==
+ Pleroma.Web.Router.Helpers.o_status_url(
+ Pleroma.Web.Endpoint,
+ :feed_redirect,
+ user.nickname
+ ) <> "/followers"
end
describe "remote user creation changeset" do
@@ -184,7 +199,8 @@ defmodule Pleroma.UserTest do
test "it sets the follower_adress" do
cs = User.remote_user_creation(@valid_remote)
# remote users get a fake local follower address
- assert cs.changes.follower_address == User.ap_followers(%User{ nickname: @valid_remote[:nickname] })
+ assert cs.changes.follower_address ==
+ User.ap_followers(%User{nickname: @valid_remote[:nickname]})
end
test "it enforces the fqn format for nicknames" do
@@ -196,7 +212,7 @@ defmodule Pleroma.UserTest do
test "it has required fields" do
[:name, :nickname, :ap_id]
- |> Enum.each(fn (field) ->
+ |> Enum.each(fn field ->
cs = User.remote_user_creation(Map.delete(@valid_remote, field))
refute cs.valid?
end)
@@ -204,7 +220,7 @@ defmodule Pleroma.UserTest do
test "it restricts some sizes" do
[bio: 5000, name: 100]
- |> Enum.each(fn ({field, size}) ->
+ |> Enum.each(fn {field, size} ->
string = String.pad_leading(".", size)
cs = User.remote_user_creation(Map.put(@valid_remote, field, string))
assert cs.valid?
@@ -323,7 +339,11 @@ defmodule Pleroma.UserTest do
user_two = insert(:user, local: false)
addressed = insert(:user, local: true)
addressed_remote = insert(:user, local: false)
- {:ok, activity} = CommonAPI.post(actor, %{"status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"})
+
+ {:ok, activity} =
+ CommonAPI.post(actor, %{
+ "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
+ })
assert [addressed] == User.get_recipients_from_activity(activity)
@@ -379,7 +399,7 @@ defmodule Pleroma.UserTest do
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 }
+ data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
assert {:ok, %User{}} = User.insert_or_update_user(data)
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index c8082cd03..28d765d83 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -9,9 +9,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns a json representation of the user", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/users/#{user.nickname}")
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}")
user = Repo.get(User, user.id)
@@ -22,11 +23,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
describe "/object/:uuid" do
test "it returns a json representation of the object", %{conn: conn} do
note = insert(:note)
- uuid = String.split(note.data["id"], "/") |> List.last
+ uuid = String.split(note.data["id"], "/") |> List.last()
- conn = conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/objects/#{uuid}")
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
end
@@ -34,12 +36,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
describe "/users/:nickname/inbox" do
test "it inserts an incoming activity into the database", %{conn: conn} do
- data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
- conn = conn
- |> assign(:valid_signature, true)
- |> put_req_header("content-type", "application/activity+json")
- |> post("/inbox", data)
+ conn =
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
assert "ok" == json_response(conn, 200)
:timer.sleep(500)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 96792bca5..cf25abfc1 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "insertion" do
test "returns the activity if one with the same id is already in" do
activity = insert(:note_activity)
- {:ok, new_activity}= ActivityPub.insert(activity.data)
+ {:ok, new_activity} = ActivityPub.insert(activity.data)
assert activity == new_activity
end
@@ -37,6 +37,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert is_binary(activity.data["id"])
given_id = "bla"
+
data = %{
"ok" => true,
"id" => given_id
@@ -63,7 +64,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "create activities" do
test "removes doubled 'to' recipients" do
- {:ok, activity} = ActivityPub.create(%{to: ["user1", "user1", "user2"], actor: %User{ap_id: "1"}, context: "", object: %{}})
+ {:ok, activity} =
+ ActivityPub.create(%{
+ to: ["user1", "user1", "user2"],
+ actor: %User{ap_id: "1"},
+ context: "",
+ object: %{}
+ })
+
assert activity.data["to"] == ["user1", "user2"]
assert activity.actor == "1"
assert activity.recipients == ["user1", "user2"]
@@ -124,11 +132,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "public fetch activities" do
test "retrieves public activities" do
- _activities = ActivityPub.fetch_public_activities
+ _activities = ActivityPub.fetch_public_activities()
- %{public: public} = ActivityBuilder.public_and_non_public
+ %{public: public} = ActivityBuilder.public_and_non_public()
- activities = ActivityPub.fetch_public_activities
+ activities = ActivityPub.fetch_public_activities()
assert length(activities) == 1
assert Enum.at(activities, 0) == public
end
@@ -137,7 +145,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
activities = ActivityBuilder.insert_list(30)
last_expected = List.last(activities)
- activities = ActivityPub.fetch_public_activities
+ activities = ActivityPub.fetch_public_activities()
last = List.last(activities)
assert length(activities) == 20
@@ -232,7 +240,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
assert object.data["announcement_count"] == 1
assert object.data["announcements"] == [user.ap_id]
- assert announce_activity.data["to"] == [User.ap_followers(user), note_activity.data["actor"]]
+
+ assert announce_activity.data["to"] == [
+ User.ap_followers(user),
+ note_activity.data["actor"]
+ ]
+
assert announce_activity.data["object"] == object.data["id"]
assert announce_activity.data["actor"] == user.ap_id
assert announce_activity.data["context"] == object.data["context"]
@@ -241,7 +254,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "uploading files" do
test "copies the file to the configured folder" do
- 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"
+ }
{:ok, %Object{} = object} = ActivityPub.upload(file)
assert object.data["name"] == "an_image.jpg"
@@ -268,11 +285,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "fetching an object" do
test "it fetches an object" do
- {:ok, object} = ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
assert activity.data["id"]
- {:ok, object_again} = ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+ {:ok, object_again} =
+ ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
assert [attachment] = object.data["attachment"]
assert is_list(attachment["url"])
@@ -285,7 +305,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
assert activity.data["id"]
- {:ok, object_again} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
+ {:ok, object_again} =
+ ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
assert object == object_again
end
@@ -344,7 +365,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = insert(:user)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
user_data = Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})
- {:ok, update} = ActivityPub.update(%{actor: user_data["id"], to: [user.follower_address], cc: [], object: user_data})
+
+ {:ok, update} =
+ ActivityPub.update(%{
+ actor: user_data["id"],
+ to: [user.follower_address],
+ cc: [],
+ object: user_data
+ })
assert update.data["actor"] == user.ap_id
assert update.data["to"] == [user.follower_address]
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 375e74ad9..060ebe9f1 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -16,9 +16,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it ignores an incoming notice if we already have it" do
activity = insert(:note_activity)
- data = File.read!("test/fixtures/mastodon-post-activity.json")
- |> Poison.decode!
- |> Map.put("object", activity.data["object"])
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", activity.data["object"])
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
@@ -26,51 +27,72 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
test "it fetches replied-to activities if we don't have them" do
- data = File.read!("test/fixtures/mastodon-post-activity.json")
- |> Poison.decode!
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
- object = data["object"]
- |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
+ object =
+ data["object"]
+ |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
- data = data
- |> Map.put("object", object)
+ data =
+ data
+ |> Map.put("object", object)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
- assert activity = Activity.get_create_activity_by_object_ap_id("tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment")
- assert returned_activity.data["object"]["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
+ assert activity =
+ Activity.get_create_activity_by_object_ap_id(
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+ )
+
+ assert returned_activity.data["object"]["inReplyToAtomUri"] ==
+ "https://shitposter.club/notice/2827873"
+
assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
end
test "it works for incoming notices" do
- data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
- assert data["context"] == "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
+
+ assert data["id"] ==
+ "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
+
+ assert data["context"] ==
+ "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
+
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+
assert data["cc"] == [
- "http://mastodon.example.org/users/admin/followers",
- "http://localtesting.pleroma.lol/users/lain"
- ]
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ]
+
assert data["actor"] == "http://mastodon.example.org/users/admin"
object = data["object"]
assert object["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822"
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+
assert object["cc"] == [
- "http://mastodon.example.org/users/admin/followers",
- "http://localtesting.pleroma.lol/users/lain"
- ]
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ]
+
assert object["actor"] == "http://mastodon.example.org/users/admin"
assert object["attributedTo"] == "http://mastodon.example.org/users/admin"
- assert object["context"] == "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
+
+ assert object["context"] ==
+ "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
+
assert object["sensitive"] == true
end
test "it works for incoming notices with hashtags" do
- data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!
+ data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
assert Enum.at(data["object"]["tag"], 2) == "moo"
@@ -78,8 +100,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it works for incoming follow requests" do
user = insert(:user)
- data = File.read!("test/fixtures/mastodon-follow-activity.json") |> Poison.decode!
- |> Map.put("object", user.ap_id)
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json") |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -93,8 +117,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
- data = File.read!("test/fixtures/mastodon-like.json") |> Poison.decode!
- |> Map.put("object", activity.data["object"]["id"])
+ data =
+ File.read!("test/fixtures/mastodon-like.json") |> Poison.decode!()
+ |> Map.put("object", activity.data["object"]["id"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -105,14 +130,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
test "it works for incoming announces" do
- data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!
+ data = File.read!("test/fixtures/mastodon-announce.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"
- assert data["object"] == "http://mastodon.example.org/users/admin/statuses/99541947525187367"
+
+ assert data["id"] ==
+ "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
+
+ assert data["object"] ==
+ "http://mastodon.example.org/users/admin/statuses/99541947525187367"
assert Activity.get_create_activity_by_object_ap_id(data["object"])
end
@@ -121,53 +150,77 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
- data = File.read!("test/fixtures/mastodon-announce.json")
- |> Poison.decode!
- |> Map.put("object", activity.data["object"]["id"])
+ data =
+ File.read!("test/fixtures/mastodon-announce.json")
+ |> Poison.decode!()
+ |> Map.put("object", activity.data["object"]["id"])
{: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"
+
+ assert data["id"] ==
+ "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
+
assert data["object"] == activity.data["object"]["id"]
assert Activity.get_create_activity_by_object_ap_id(data["object"]).id == activity.id
end
test "it works for incoming update activities" do
- data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!
- object = update_data["object"]
- |> Map.put("actor", data["actor"])
- |> Map.put("id", data["actor"])
+ update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
+
+ object =
+ update_data["object"]
+ |> Map.put("actor", data["actor"])
+ |> Map.put("id", data["actor"])
- update_data = update_data
- |> Map.put("actor", data["actor"])
- |> Map.put("object", object)
+ update_data =
+ update_data
+ |> Map.put("actor", data["actor"])
+ |> Map.put("object", object)
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
user = User.get_cached_by_ap_id(data["actor"])
assert user.name == "gargle"
- assert user.avatar["url"] == [%{"href" => "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"}]
- assert user.info["banner"]["url"] == [%{"href" => "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}]
+
+ assert user.avatar["url"] == [
+ %{
+ "href" =>
+ "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
+ }
+ ]
+
+ assert user.info["banner"]["url"] == [
+ %{
+ "href" =>
+ "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
+ }
+ ]
+
assert user.bio == "<p>Some bio</p>"
end
test "it works for incoming deletes" do
activity = insert(:note_activity)
- data = File.read!("test/fixtures/mastodon-delete.json")
- |> Poison.decode!
- object = data["object"]
- |> Map.put("id", activity.data["object"]["id"])
+ data =
+ File.read!("test/fixtures/mastodon-delete.json")
+ |> Poison.decode!()
+
+ object =
+ data["object"]
+ |> Map.put("id", activity.data["object"]["id"])
- data = data
- |> Map.put("object", object)
- |> Map.put("actor", activity.data["actor"])
+ data =
+ data
+ |> Map.put("object", object)
+ |> Map.put("actor", activity.data["actor"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -180,7 +233,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
object = modified["object"]
@@ -192,7 +246,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
}
expected_tag = %{
- "href" => Pleroma.Web.Endpoint.url <> "/tags/2hu",
+ "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
"type" => "Hashtag",
"name" => "#2hu"
}
@@ -247,7 +301,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
+
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
@@ -256,7 +312,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
describe "user upgrade" do
test "it upgrades a user to activitypub" do
- user = insert(:user, %{nickname: "rye@niu.moe", local: false, ap_id: "https://niu.moe/users/rye", follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})})
+ user =
+ insert(:user, %{
+ nickname: "rye@niu.moe",
+ local: false,
+ ap_id: "https://niu.moe/users/rye",
+ follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
+ })
+
user_two = insert(:user, %{following: [user.follower_address]})
{:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
@@ -279,8 +342,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
activity = Repo.get(Activity, activity.id)
assert user.follower_address in activity.recipients
- assert %{"url" => [%{"href" => "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"}]} = user.avatar
- assert %{"url" => [%{"href" => "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}]} = user.info["banner"]
+
+ assert %{
+ "url" => [
+ %{
+ "href" =>
+ "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
+ }
+ ]
+ } = user.avatar
+
+ assert %{
+ "url" => [
+ %{
+ "href" =>
+ "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
+ }
+ ]
+ } = user.info["banner"]
+
refute "..." in activity.recipients
unrelated_activity = Repo.get(Activity, unrelated_activity.id)
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index f6a7da9ed..689bdd61e 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -3,7 +3,8 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
use Pleroma.DataCase
test "it adds attachment links to a given text and attachment set" do
- name = "Sakura%20Mana%20%E2%80%93%20Turned%20on%20by%20a%20Senior%20OL%20with%20a%20Temptating%20Tight%20Skirt-s%20Full%20Hipline%20and%20Panty%20Shot-%20Beautiful%20Thick%20Thighs-%20and%20Erotic%20Ass-%20-2015-%20--%20Oppaitime%208-28-2017%206-50-33%20PM.png"
+ name =
+ "Sakura%20Mana%20%E2%80%93%20Turned%20on%20by%20a%20Senior%20OL%20with%20a%20Temptating%20Tight%20Skirt-s%20Full%20Hipline%20and%20Panty%20Shot-%20Beautiful%20Thick%20Thighs-%20and%20Erotic%20Ass-%20-2015-%20--%20Oppaitime%208-28-2017%206-50-33%20PM.png"
attachment = %{
"url" => [%{"href" => name}]
@@ -11,6 +12,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
res = Utils.add_attachments("", [attachment])
- assert res == "<br><a href=\"#{name}\" class='attachment'>Sakura Mana – Turned on by a Se…</a>"
+ assert res ==
+ "<br><a href=\"#{name}\" class='attachment'>Sakura Mana – Turned on by a Se…</a>"
end
end
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index 5eefa61e1..597690bf7 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -5,7 +5,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
alias Pleroma.User
test "Represent a user account" do
- user = insert(:user, %{info: %{"note_count" => 5, "follower_count" => 3}, nickname: "shp@shitposter.club", inserted_at: ~N[2017-08-15 15:47:06.597036]})
+ user =
+ insert(:user, %{
+ info: %{"note_count" => 5, "follower_count" => 3},
+ nickname: "shp@shitposter.club",
+ inserted_at: ~N[2017-08-15 15:47:06.597036]
+ })
expected = %{
id: to_string(user.id),
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index a655fa74b..2c9cdd194 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -14,17 +14,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/timelines/home")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/timelines/home")
assert length(json_response(conn, 200)) == 0
{:ok, user} = User.follow(user, following)
- conn = build_conn()
- |> assign(:user, user)
- |> get("/api/v1/timelines/home")
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/timelines/home")
assert [%{"content" => "test"}] = json_response(conn, 200)
end
@@ -32,44 +34,57 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "the public timeline", %{conn: conn} do
following = insert(:user)
- capture_log fn ->
+ capture_log(fn ->
{:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
- {:ok, [_activity]} = OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
- conn = conn
- |> get("/api/v1/timelines/public", %{"local" => "False"})
+ {: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"})
+ 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"})
+ conn =
+ build_conn()
+ |> get("/api/v1/timelines/public", %{"local" => "1"})
assert [%{"content" => "test"}] = json_response(conn, 200)
- end
+ end)
end
test "posting a status", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "cofe", "spoiler_text" => "2hu", "sensitive" => "false"})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "cofe",
+ "spoiler_text" => "2hu",
+ "sensitive" => "false"
+ })
+
+ assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
+ json_response(conn, 200)
- assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = json_response(conn, 200)
assert Repo.get(Activity, id)
end
test "posting a sensitive status", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
assert %{"content" => "cofe", "id" => id, "sensitive" => true} = json_response(conn, 200)
assert Repo.get(Activity, id)
@@ -80,9 +95,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, replied_to} = TwitterAPI.create_status(user, %{"status" => "cofe"})
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
@@ -95,9 +111,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "verify_credentials", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/verify_credentials")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/verify_credentials")
assert %{"id" => id} = json_response(conn, 200)
assert id == to_string(user.id)
@@ -106,8 +123,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "get a status", %{conn: conn} do
activity = insert(:note_activity)
- conn = conn
- |> get("/api/v1/statuses/#{activity.id}")
+ conn =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}")
assert %{"id" => id} = json_response(conn, 200)
assert id == to_string(activity.id)
@@ -118,9 +136,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
activity = insert(:note_activity)
author = User.get_by_ap_id(activity.data["actor"])
- conn = conn
- |> assign(:user, author)
- |> delete("/api/v1/statuses/#{activity.id}")
+ conn =
+ conn
+ |> assign(:user, author)
+ |> delete("/api/v1/statuses/#{activity.id}")
assert %{} = json_response(conn, 200)
@@ -131,9 +150,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
activity = insert(:note_activity)
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> delete("/api/v1/statuses/#{activity.id}")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> delete("/api/v1/statuses/#{activity.id}")
assert %{"error" => _} = json_response(conn, 403)
@@ -146,14 +166,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+
{:ok, [_notification]} = Notification.create_notifications(activity)
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/notifications")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications")
+
+ expected_response =
+ "hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
- expected_response = "hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
assert response == expected_response
end
@@ -162,14 +187,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+
{:ok, [notification]} = Notification.create_notifications(activity)
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/notifications/#{notification.id}")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications/#{notification.id}")
+
+ expected_response =
+ "hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
- expected_response = "hi <span><a href=\"#{user.ap_id}\">@<span>#{user.nickname}</span></a></span>"
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
assert response == expected_response
end
@@ -178,12 +208,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(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})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
assert %{} = json_response(conn, 200)
end
@@ -192,18 +225,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+ {:ok, activity} =
+ TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
+
{:ok, [_notification]} = Notification.create_notifications(activity)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/notifications/clear")
+ 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")
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/notifications")
assert all = json_response(conn, 200)
assert all == []
@@ -215,11 +252,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
activity = insert(:note_activity)
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/reblog")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/#{activity.id}/reblog")
+
+ assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
+ json_response(conn, 200)
- assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} = json_response(conn, 200)
assert to_string(activity.id) == id
end
end
@@ -229,11 +269,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
activity = insert(:note_activity)
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/favourite")
+ 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 %{"id" => id, "favourites_count" => 1, "favourited" => true} = json_response(conn, 200)
assert to_string(activity.id) == id
end
end
@@ -245,11 +288,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/statuses/#{activity.id}/unfavourite")
+ 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 %{"id" => id, "favourites_count" => 0, "favourited" => false} = json_response(conn, 200)
assert to_string(activity.id) == id
end
end
@@ -261,8 +307,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = User.get_by_ap_id(note_two.data["actor"])
- conn = conn
- |> get("/api/v1/accounts/#{user.id}/statuses")
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/statuses")
assert [%{"id" => id}] = json_response(conn, 200)
@@ -273,20 +320,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
note = insert(:note_activity)
user = User.get_by_ap_id(note.data["actor"])
- file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
- media = TwitterAPI.upload(file, "json")
- |> Poison.decode!
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
- {:ok, image_post} = TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
+ media =
+ TwitterAPI.upload(file, "json")
+ |> Poison.decode!()
- conn = conn
- |> get("/api/v1/accounts/#{user.id}/statuses", %{"only_media" => "true"})
+ {:ok, image_post} =
+ TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["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"})
+ 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)
@@ -299,9 +355,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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]})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/relationships", %{"id" => [other_user.id]})
assert [relationship] = json_response(conn, 200)
@@ -312,26 +369,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "account fetching", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> get("/api/v1/accounts/#{user.id}")
+ conn =
+ 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")
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/-1")
assert %{"error" => "Can't find user"} = json_response(conn, 404)
end
test "media upload", %{conn: conn} do
- 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"
+ }
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/media", %{"file" => file})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/media", %{"file" => file})
assert media = json_response(conn, 200)
@@ -341,16 +405,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "hashtag timeline", %{conn: conn} do
following = insert(:user)
- capture_log fn ->
+ capture_log(fn ->
{:ok, activity} = TwitterAPI.create_status(following, %{"status" => "test #2hu"})
- {:ok, [_activity]} = OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
- conn = conn
- |> get("/api/v1/timelines/tag/2hu")
+
+ {:ok, [_activity]} =
+ OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
+
+ conn =
+ conn
+ |> get("/api/v1/timelines/tag/2hu")
assert [%{"id" => id}] = json_response(conn, 200)
assert id == to_string(activity.id)
- end
+ end)
end
test "getting followers", %{conn: conn} do
@@ -358,8 +426,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
- conn = conn
- |> get("/api/v1/accounts/#{other_user.id}/followers")
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{other_user.id}/followers")
assert [%{"id" => id}] = json_response(conn, 200)
assert id == to_string(user.id)
@@ -370,8 +439,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = insert(:user)
{:ok, user} = User.follow(user, other_user)
- conn = conn
- |> get("/api/v1/accounts/#{user.id}/following")
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following")
assert [%{"id" => id}] = json_response(conn, 200)
assert id == to_string(other_user.id)
@@ -381,23 +451,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/follow")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/follow")
assert %{"id" => _id, "following" => true} = json_response(conn, 200)
user = Repo.get(User, user.id)
- conn = build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unfollow")
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unfollow")
assert %{"id" => _id, "following" => false} = json_response(conn, 200)
user = Repo.get(User, user.id)
- conn = build_conn()
- |> assign(:user, user)
- |> post("/api/v1/follows", %{"uri" => other_user.nickname})
+
+ 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)
@@ -407,16 +482,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
other_user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/block")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/block")
assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
user = Repo.get(User, user.id)
- conn = build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/unblock")
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/unblock")
assert %{"id" => _id, "blocking" => false} = json_response(conn, 200)
end
@@ -427,9 +505,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, user} = User.block(user, other_user)
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/blocks")
+ 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)
@@ -440,10 +519,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = insert(:user)
["mute", "unmute"]
- |> Enum.each(fn(endpoint) ->
- conn = build_conn()
- |> assign(:user, user)
- |> post("/api/v1/accounts/#{other_user.id}/#{endpoint}")
+ |> Enum.each(fn endpoint ->
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/accounts/#{other_user.id}/#{endpoint}")
assert %{"id" => id} = json_response(conn, 200)
assert id == to_string(other_user.id)
@@ -454,10 +534,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user = insert(:user)
["blocks", "domain_blocks", "mutes", "follow_requests"]
- |> Enum.each(fn(endpoint) ->
- conn = build_conn()
- |> assign(:user, user)
- |> get("/api/v1/#{endpoint}")
+ |> Enum.each(fn endpoint ->
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/#{endpoint}")
assert [] = json_response(conn, 200)
end)
@@ -468,9 +549,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
_user_two = insert(:user, %{nickname: "shp@shitposter.club"})
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/accounts/search", %{"q" => "2hu"})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/search", %{"q" => "2hu"})
assert [account] = json_response(conn, 200)
assert account["id"] == to_string(user_three.id)
@@ -484,8 +566,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
- conn = conn
- |> get("/api/v1/search", %{"q" => "2hu"})
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "2hu"})
assert results = json_response(conn, 200)
@@ -499,19 +582,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "search fetches remote statuses", %{conn: conn} do
- capture_log fn ->
- conn = conn
- |> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
+ capture_log(fn ->
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
+
assert results = json_response(conn, 200)
[status] = results["statuses"]
assert status["uri"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
- end
+ end)
end
test "search fetches remote accounts", %{conn: conn} do
- conn = conn
- |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"})
+ conn =
+ conn
+ |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"})
assert results = json_response(conn, 200)
[account] = results["accounts"]
@@ -527,9 +613,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
- conn = conn
- |> assign(:user, user)
- |> get("/api/v1/favourites")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/favourites")
assert [status] = json_response(conn, 200)
assert status["id"] == to_string(activity.id)
@@ -539,9 +626,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "updates the user's bio", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"note" => "I drink #cofe"})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"note" => "I drink #cofe"})
assert user = json_response(conn, 200)
assert user["note"] == "I drink #cofe"
@@ -550,9 +638,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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"})
+ 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"
@@ -561,11 +650,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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"}
+ 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})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
assert user = json_response(conn, 200)
assert user["avatar"] != "https://placehold.it/48x48"
@@ -574,11 +668,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
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"}
+ 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})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
assert user = json_response(conn, 200)
assert user["header"] != "https://placehold.it/700x335"
@@ -594,8 +693,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
Pleroma.Stats.update_stats()
- conn = conn
- |> get("/api/v1/instance")
+ conn =
+ conn
+ |> get("/api/v1/instance")
assert result = json_response(conn, 200)
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 74f5b7133..d9a0a8a95 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -13,8 +13,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: note})
- created_at = (note.data["object"]["published"] || "")
- |> String.replace(~r/\.\d+Z/, ".000Z")
+ created_at =
+ (note.data["object"]["published"] || "")
+ |> String.replace(~r/\.\d+Z/, ".000Z")
expected = %{
id: to_string(note.id),
@@ -57,7 +58,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a reply" do
note = insert(:note_activity)
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
status = StatusView.render("status.json", %{activity: activity})
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 52441fa7d..4a9e2a3ac 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -4,7 +4,15 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
import Pleroma.Factory
test "create an authorization token for a valid app" do
- {:ok, app} = Repo.insert(App.register_changeset(%App{}, %{client_name: "client", scopes: "scope", redirect_uris: "url"}))
+ {:ok, app} =
+ Repo.insert(
+ App.register_changeset(%App{}, %{
+ client_name: "client",
+ scopes: "scope",
+ redirect_uris: "url"
+ })
+ )
+
user = insert(:user)
{:ok, auth} = Authorization.create_authorization(app, user)
@@ -16,7 +24,15 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
end
test "use up a token" do
- {:ok, app} = Repo.insert(App.register_changeset(%App{}, %{client_name: "client", scopes: "scope", redirect_uris: "url"}))
+ {:ok, app} =
+ Repo.insert(
+ App.register_changeset(%App{}, %{
+ client_name: "client",
+ scopes: "scope",
+ redirect_uris: "url"
+ })
+ )
+
user = insert(:user)
{:ok, auth} = Authorization.create_authorization(app, user)
@@ -30,7 +46,7 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do
expired_auth = %Authorization{
user_id: user.id,
app_id: app.id,
- valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, -10),
+ valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), -10),
token: "mytoken",
used: false
}
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index 3bd763989..58448949c 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -6,7 +6,15 @@ defmodule Pleroma.Web.OAuth.TokenTest do
import Pleroma.Factory
test "exchanges a auth token for an access token" do
- {:ok, app} = Repo.insert(App.register_changeset(%App{}, %{client_name: "client", scopes: "scope", redirect_uris: "url"}))
+ {:ok, app} =
+ Repo.insert(
+ App.register_changeset(%App{}, %{
+ client_name: "client",
+ scopes: "scope",
+ redirect_uris: "url"
+ })
+ )
+
user = insert(:user)
{:ok, auth} = Authorization.create_authorization(app, user)
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index 3ee9034a7..8bf3bc775 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -16,9 +16,12 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
tuple = ActivityRepresenter.to_simple_form(activity, user)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
- assert String.contains?(res, ~s{<link type="text/html" href="https://mastodon.social/users/lambadalambda/updates/2314748" rel="alternate"/>})
+ assert String.contains?(
+ res,
+ ~s{<link type="text/html" href="https://mastodon.social/users/lambadalambda/updates/2314748" rel="alternate"/>}
+ )
end
test "a note activity" do
@@ -46,7 +49,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
tuple = ActivityRepresenter.to_simple_form(note_activity, user)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
assert clean(res) == clean(expected)
end
@@ -61,7 +64,10 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
answer = %{answer | data: data}
note_object = Object.get_by_ap_id(note.data["object"]["id"])
- Repo.update!(Object.change(note_object, %{ data: Map.put(note_object.data, "external_url", "someurl") }))
+
+ Repo.update!(
+ Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
+ )
user = User.get_cached_by_ap_id(answer.data["actor"])
@@ -86,7 +92,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
tuple = ActivityRepresenter.to_simple_form(answer, user)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
assert clean(res) == clean(expected)
end
@@ -102,9 +108,11 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
note_user = User.get_cached_by_ap_id(note.data["actor"])
note = Repo.get(Activity, note.id)
- note_xml = ActivityRepresenter.to_simple_form(note, note_user, true)
- |> :xmerl.export_simple_content(:xmerl_xml)
- |> to_string
+
+ note_xml =
+ ActivityRepresenter.to_simple_form(note, note_user, true)
+ |> :xmerl.export_simple_content(:xmerl_xml)
+ |> to_string
expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
@@ -120,13 +128,16 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
<activity:object>
#{note_xml}
</activity:object>
- <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{note.data["actor"]}"/>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
+ note.data["actor"]
+ }"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
"""
- announce_xml = ActivityRepresenter.to_simple_form(announce, user)
- |> :xmerl.export_simple_content(:xmerl_xml)
- |> to_string
+ announce_xml =
+ ActivityRepresenter.to_simple_form(announce, user)
+ |> :xmerl.export_simple_content(:xmerl_xml)
+ |> to_string
assert clean(expected) == clean(announce_xml)
end
@@ -139,7 +150,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
tuple = ActivityRepresenter.to_simple_form(like, user)
refute is_nil(tuple)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
expected = """
<activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb>
@@ -156,7 +167,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
<link ref="#{like.data["context"]}" rel="ostatus:conversation" />
<link rel="self" type="application/atom+xml" href="#{like.data["id"]}"/>
<thr:in-reply-to ref="#{note.data["id"]}" />
- <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{note.data["actor"]}"/>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
+ note.data["actor"]
+ }"/>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
"""
@@ -166,18 +179,20 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
test "a follow activity" do
follower = insert(:user)
followed = insert(:user)
- {:ok, activity} = ActivityPub.insert(%{
- "type" => "Follow",
- "actor" => follower.ap_id,
- "object" => followed.ap_id,
- "to" => [followed.ap_id]
- })
+
+ {:ok, activity} =
+ ActivityPub.insert(%{
+ "type" => "Follow",
+ "actor" => follower.ap_id,
+ "object" => followed.ap_id,
+ "to" => [followed.ap_id]
+ })
tuple = ActivityRepresenter.to_simple_form(activity, follower)
refute is_nil(tuple)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
@@ -193,7 +208,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
<uri>#{activity.data["object"]}</uri>
</activity:object>
<link rel="self" type="application/atom+xml" href="#{activity.data["id"]}"/>
- <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{activity.data["object"]}"/>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
+ activity.data["object"]
+ }"/>
"""
assert clean(res) == clean(expected)
@@ -209,7 +226,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
refute is_nil(tuple)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
@@ -225,7 +242,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
<uri>#{followed.ap_id}</uri>
</activity:object>
<link rel="self" type="application/atom+xml" href="#{activity.data["id"]}"/>
- <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{followed.ap_id}"/>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
+ followed.ap_id
+ }"/>
"""
assert clean(res) == clean(expected)
@@ -233,13 +252,22 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
test "a delete" do
user = insert(:user)
- activity = %Activity{data: %{ "id" => "ap_id", "type" => "Delete", "actor" => user.ap_id, "object" => "some_id", "published" => "2017-06-18T12:00:18+00:00" }}
+
+ activity = %Activity{
+ data: %{
+ "id" => "ap_id",
+ "type" => "Delete",
+ "actor" => user.ap_id,
+ "object" => "some_id",
+ "published" => "2017-06-18T12:00:18+00:00"
+ }
+ }
tuple = ActivityRepresenter.to_simple_form(activity, nil)
refute is_nil(tuple)
- res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
expected = """
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index 5b8eabcb9..bf3feb14e 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -11,15 +11,19 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
- most_recent_update = note_activity.updated_at
- |> NaiveDateTime.to_iso8601
+ most_recent_update =
+ note_activity.updated_at
+ |> NaiveDateTime.to_iso8601()
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
- user_xml = UserRepresenter.to_simple_form(user)
- |> :xmerl.export_simple_content(:xmerl_xml)
- entry_xml = ActivityRepresenter.to_simple_form(note_activity, user)
- |> :xmerl.export_simple_content(:xmerl_xml)
+ user_xml =
+ UserRepresenter.to_simple_form(user)
+ |> :xmerl.export_simple_content(:xmerl_xml)
+
+ entry_xml =
+ ActivityRepresenter.to_simple_form(note_activity, user)
+ |> :xmerl.export_simple_content(:xmerl_xml)
expected = """
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
@@ -39,6 +43,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
</entry>
</feed>
"""
+
assert clean(res) == clean(expected)
end
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index 43d04dea2..1e041e5b0 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -14,8 +14,13 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
{:ok, like, _object} = Pleroma.Web.ActivityPub.ActivityPub.like(user, object)
- incoming = File.read!("test/fixtures/delete.xml")
- |> String.replace("tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status", note.data["object"]["id"])
+ incoming =
+ File.read!("test/fixtures/delete.xml")
+ |> String.replace(
+ "tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status",
+ note.data["object"]["id"]
+ )
+
{:ok, [delete]} = OStatus.handle_incoming(incoming)
refute Repo.get(Activity, note.id)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 5b8eb8156..ba8855093 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -7,9 +7,11 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "decodes a salmon", %{conn: conn} do
user = insert(:user)
salmon = File.read!("test/fixtures/salmon.xml")
- conn = conn
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/users/#{user.nickname}/salmon", salmon)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/users/#{user.nickname}/salmon", salmon)
assert response(conn, 200)
end
@@ -17,21 +19,30 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "decodes a salmon with a changed magic key", %{conn: conn} do
user = insert(:user)
salmon = File.read!("test/fixtures/salmon.xml")
- conn = conn
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/users/#{user.nickname}/salmon", salmon)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/users/#{user.nickname}/salmon", salmon)
assert response(conn, 200)
# Set a wrong magic-key for a user so it has to refetch
salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
- info = salmon_user.info
- |> Map.put("magic_key", "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB") # Wrong key
+ # Wrong key
+ info =
+ salmon_user.info
+ |> Map.put(
+ "magic_key",
+ "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
+ )
+
Repo.update(User.info_changeset(salmon_user, %{info: info}))
- conn = build_conn()
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/users/#{user.nickname}/salmon", salmon)
+ conn =
+ build_conn()
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/users/#{user.nickname}/salmon", salmon)
assert response(conn, 200)
end
@@ -40,8 +51,9 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
- conn = conn
- |> get("/users/#{user.nickname}/feed.atom")
+ conn =
+ conn
+ |> get("/users/#{user.nickname}/feed.atom")
assert response(conn, 200) =~ note_activity.data["object"]["content"]
end
@@ -49,27 +61,30 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "gets an object", %{conn: conn} do
note_activity = insert(:note_activity)
user = User.get_by_ap_id(note_activity.data["actor"])
- [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"])
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
url = "/objects/#{uuid}"
- conn = conn
- |> get(url)
+ conn =
+ conn
+ |> get(url)
- expected = ActivityRepresenter.to_simple_form(note_activity, user, true)
- |> ActivityRepresenter.wrap_with_entry
- |> :xmerl.export_simple(:xmerl_xml)
- |> to_string
+ expected =
+ ActivityRepresenter.to_simple_form(note_activity, user, true)
+ |> ActivityRepresenter.wrap_with_entry()
+ |> :xmerl.export_simple(:xmerl_xml)
+ |> to_string
assert response(conn, 200) == expected
end
test "gets an activity", %{conn: conn} do
note_activity = insert(:note_activity)
- [_, uuid] = hd Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
url = "/activities/#{uuid}"
- conn = conn
- |> get(url)
+ conn =
+ conn
+ |> get(url)
assert response(conn, 200)
end
@@ -78,8 +93,9 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
note_activity = insert(:note_activity)
url = "/notice/#{note_activity.id}"
- conn = conn
- |> get(url)
+ conn =
+ conn
+ |> get(url)
assert response(conn, 200)
end
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 7f67b9ec0..3e7cf0155 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -20,12 +20,18 @@ defmodule Pleroma.Web.OStatusTest do
assert user.info["note_count"] == 1
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
+
+ assert activity.data["object"]["id"] ==
+ "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
+
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
assert activity.data["object"]["published"] == "2017-04-23T14:51:03+00:00"
- assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
+
+ assert activity.data["context"] ==
+ "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
+
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
- assert activity.data["object"]["emoji"] == %{ "marko" => "marko.png", "reimu" => "reimu.png" }
+ assert activity.data["object"]["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
assert activity.local == false
end
@@ -65,10 +71,12 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming notes - Mastodon, salmon, reply" do
# It uses the context of the replied to object
Repo.insert!(%Object{
- data: %{
- "id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
- "context" => "2hu"
- }})
+ data: %{
+ "id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
+ "context" => "2hu"
+ }
+ })
+
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
@@ -113,8 +121,13 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"]["content"] == "@<a href=\"https://gs.archae.me/user/4687\" class=\"h-card u-url p-nickname mention\" title=\"shpbot\">shpbot</a> why not indeed."
- assert activity.data["object"]["inReplyTo"] == "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
+
+ assert activity.data["object"]["content"] ==
+ "@<a href=\"https://gs.archae.me/user/4687\" class=\"h-card u-url p-nickname mention\" title=\"shpbot\">shpbot</a> why not indeed."
+
+ assert activity.data["object"]["inReplyTo"] ==
+ "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
+
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
@@ -141,9 +154,11 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/share-gs-local.xml")
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
- incoming = incoming
- |> String.replace("LOCAL_ID", note_activity.data["object"]["id"])
- |> String.replace("LOCAL_USER", user.ap_id)
+
+ incoming =
+ incoming
+ |> String.replace("LOCAL_ID", note_activity.data["object"]["id"])
+ |> String.replace("LOCAL_USER", user.ap_id)
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
@@ -168,7 +183,9 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
- assert activity.data["id"] == "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
+
+ assert activity.data["id"] ==
+ "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
refute activity.local
assert retweeted_activity.data["type"] == "Create"
@@ -178,35 +195,42 @@ defmodule Pleroma.Web.OStatusTest do
end
test "handle incoming favorites - GS, websub" do
- capture_log fn ->
+ capture_log(fn ->
incoming = File.read!("test/fixtures/favorite.xml")
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Like"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
assert activity.data["object"] == favorited_activity.data["object"]["id"]
- assert activity.data["id"] == "tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
+
+ assert activity.data["id"] ==
+ "tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
refute activity.local
assert favorited_activity.data["type"] == "Create"
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
- assert favorited_activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+
+ assert favorited_activity.data["object"]["id"] ==
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+
refute favorited_activity.local
- end
+ end)
end
test "handle conversation references" do
incoming = File.read!("test/fixtures/mastodon_conversation.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- assert activity.data["context"] == "tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
+ assert activity.data["context"] ==
+ "tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
end
test "handle incoming favorites with locally available object - GS, websub" do
note_activity = insert(:note_activity)
- incoming = File.read!("test/fixtures/favorite_with_local_note.xml")
- |> String.replace("localid", note_activity.data["object"]["id"])
+ incoming =
+ File.read!("test/fixtures/favorite_with_local_note.xml")
+ |> String.replace("localid", note_activity.data["object"]["id"])
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
@@ -224,9 +248,15 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
+
+ assert activity.data["object"]["inReplyTo"] ==
+ "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
+
assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
- assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
+
+ assert activity.data["object"]["id"] ==
+ "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
+
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
@@ -234,7 +264,10 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/follow.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Follow"
- assert activity.data["id"] == "tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
+
+ assert activity.data["id"] ==
+ "tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
+
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
@@ -304,7 +337,8 @@ defmodule Pleroma.Web.OStatusTest do
expected = %{
"hub" => "https://social.heldscal.la/main/push/hub",
- "magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
+ "magic_key" =>
+ "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
"name" => "shp",
"nickname" => "shp",
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
@@ -314,10 +348,20 @@ defmodule Pleroma.Web.OStatusTest do
"host" => "social.heldscal.la",
"fqn" => user,
"bio" => "cofe",
- "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]},
+ "avatar" => %{
+ "type" => "Image",
+ "url" => [
+ %{
+ "href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
+ "mediaType" => "image/jpeg",
+ "type" => "Link"
+ }
+ ]
+ },
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
"ap_id" => nil
}
+
assert data == expected
end
@@ -329,7 +373,8 @@ defmodule Pleroma.Web.OStatusTest do
expected = %{
"hub" => "https://social.heldscal.la/main/push/hub",
- "magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
+ "magic_key" =>
+ "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
"name" => "shp",
"nickname" => "shp",
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
@@ -339,28 +384,40 @@ defmodule Pleroma.Web.OStatusTest do
"host" => "social.heldscal.la",
"fqn" => user,
"bio" => "cofe",
- "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]},
+ "avatar" => %{
+ "type" => "Image",
+ "url" => [
+ %{
+ "href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
+ "mediaType" => "image/jpeg",
+ "type" => "Link"
+ }
+ ]
+ },
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
"ap_id" => nil
}
+
assert data == expected
end
end
describe "fetching a status by it's HTML url" do
test "it builds a missing status from an html url" do
- capture_log fn ->
+ capture_log(fn ->
url = "https://shitposter.club/notice/2827873"
- {:ok, [activity] } = OStatus.fetch_activity_from_url(url)
+ {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
assert activity.data["actor"] == "https://shitposter.club/user/1"
- assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
- end
+
+ assert activity.data["object"]["id"] ==
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+ end)
end
test "it works for atom notes, too" do
url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
- {:ok, [activity] } = OStatus.fetch_activity_from_url(url)
+ {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
assert activity.data["object"]["id"] == url
end
@@ -370,6 +427,9 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/nil_mention_entry.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
- assert activity.data["to"] == ["http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers", "https://www.w3.org/ns/activitystreams#Public"]
+ assert activity.data["to"] == [
+ "http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers",
+ "https://www.w3.org/ns/activitystreams#Public"
+ ]
end
end
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index cf70c908f..1b39b4b2d 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -22,7 +22,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
end
test "generates an RSA private key pem" do
- {:ok, key} = Salmon.generate_rsa_pem
+ {:ok, key} = Salmon.generate_rsa_pem()
assert is_binary(key)
assert Regex.match?(~r/RSA/, key)
end
@@ -62,7 +62,8 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
salmon = File.read!("test/fixtures/salmon2.xml")
{:ok, key} = Salmon.fetch_magic_key(salmon)
- assert key == "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB"
+ assert key ==
+ "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB"
end
test "it pushes an activity to remote accounts it's addressed to" do
@@ -75,13 +76,14 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
mentioned_user = insert(:user, user_data)
note = insert(:note)
+
activity_data = %{
- "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
"type" => "Create",
"actor" => note.data["actor"],
"to" => note.data["to"] ++ [mentioned_user.ap_id],
"object" => note.data,
- "published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
+ "published_at" => DateTime.utc_now() |> DateTime.to_iso8601(),
"context" => note.data["context"]
}
@@ -89,9 +91,10 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
user = Repo.get_by(User, ap_id: activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
- poster = fn (url, _data, _headers, _options) ->
+ poster = fn url, _data, _headers, _options ->
assert url == "http://example.org/salmon"
end
+
Salmon.publish(user, activity, poster)
end
end
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 98a1705b0..bb47d4409 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -16,12 +16,19 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
{:ok, announce_activity, _object} = ActivityPub.announce(user, object)
note_activity = Activity.get_by_ap_id(note_activity.data["id"])
- status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user})
+ status =
+ ActivityRepresenter.to_map(announce_activity, %{
+ users: [user, activity_actor],
+ announced_activity: note_activity,
+ for: user
+ })
assert status["id"] == announce_activity.id
assert status["user"] == UserView.render("show.json", %{user: user, for: user})
- retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
+ retweeted_status =
+ ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
+
assert retweeted_status["repeated"] == true
assert retweeted_status["id"] == note_activity.id
assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
@@ -36,7 +43,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
{:ok, like_activity, _object} = ActivityPub.like(user, object)
- status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
+
+ status =
+ ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
assert status["id"] == like_activity.id
assert status["in_reply_to_status_id"] == note_activity.id
@@ -49,7 +58,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
end
test "an activity" do
- {:ok, user} = UserBuilder.insert
+ {:ok, user} = UserBuilder.insert()
# {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
mentioned_user = insert(:user, %{nickname: "shp"})
@@ -70,16 +79,20 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}
}
- content_html = "<script>alert('YAY')</script>Some :2hu: content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
+ content_html =
+ "<script>alert('YAY')</script>Some :2hu: content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
+
content = HtmlSanitizeEx.strip_tags(content_html)
- date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
+ date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601()
+
+ {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert()
- {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
to = [
User.ap_followers(user),
"https://www.w3.org/ns/activitystreams#Public",
mentioned_user.ap_id
]
+
activity = %Activity{
id: 1,
data: %{
@@ -92,7 +105,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"type" => "Note",
"content" => content_html,
"summary" => "2hu",
- "inReplyToStatusId" => 213123,
+ "inReplyToStatusId" => 213_123,
"attachment" => [
object
],
@@ -112,7 +125,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
recipients: to
}
- expected_html = "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{mentioned_user.ap_id}\">@shp</a>"
+ expected_html =
+ "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
+ mentioned_user.ap_id
+ }\">@shp</a>"
expected_status = %{
"id" => activity.id,
@@ -122,7 +138,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"text" => "2hu" <> content,
"is_post_verb" => true,
"created_at" => "Tue May 24 13:26:08 +0000 2016",
- "in_reply_to_status_id" => 213123,
+ "in_reply_to_status_id" => 213_123,
"statusnet_conversation_id" => convo_object.id,
"attachments" => [
ObjectRepresenter.to_map(object)
@@ -141,7 +157,11 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"uri" => activity.data["object"]["id"]
}
- assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
+ assert ActivityRepresenter.to_map(activity, %{
+ user: user,
+ for: follower,
+ mentioned: [mentioned_user]
+ }) == expected_status
end
test "an undo for a follow" do
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
index ac8184407..ebac051dc 100644
--- a/test/web/twitter_api/representers/object_representer_test.exs
+++ b/test/web/twitter_api/representers/object_representer_test.exs
@@ -34,13 +34,16 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
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"
+ "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",
+ url:
+ "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
mimetype: "image/png",
oembed: false,
id: nil
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index eef639112..5abdc2e0e 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -12,13 +12,15 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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"
+ 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
- conn = conn
+ conn =
+ conn
|> with_credentials(user.nickname, "test")
|> post("/api/account/verify_credentials.json")
@@ -29,13 +31,15 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/account/most_recent_notification" do
setup [:valid_user]
+
test "without valid credentials", %{conn: conn} do
- conn = post conn, "/api/account/most_recent_notification.json"
+ conn = post(conn, "/api/account/most_recent_notification.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
test "with credentials", %{conn: conn, user: user} do
- conn = conn
+ conn =
+ conn
|> with_credentials(user.nickname, "test")
|> post("/api/account/most_recent_notification.json", %{id: "200"})
@@ -47,8 +51,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /statuses/update.json" do
setup [:valid_user]
+
test "without valid credentials", %{conn: conn} do
- conn = post conn, "/api/statuses/update.json"
+ conn = post(conn, "/api/statuses/update.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
@@ -56,30 +61,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest 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."}
+ 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: "" })
+ conn = conn_with_creds |> post(request_path, %{status: ""})
assert json_response(conn, 400) == error_response
- conn = conn_with_creds |> post(request_path, %{ status: " " })
+ conn = conn_with_creds |> post(request_path, %{status: " "})
assert json_response(conn, 400) == error_response
- conn = conn_with_creds |> post(request_path, %{ status: "Nice meme." })
- assert json_response(conn, 200) == ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
+ conn = conn_with_creds |> post(request_path, %{status: "Nice meme."})
+
+ assert json_response(conn, 200) ==
+ ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
end
end
describe "GET /statuses/public_timeline.json" do
test "returns statuses", %{conn: conn} do
- {:ok, user} = UserBuilder.insert
+ {:ok, user} = UserBuilder.insert()
activities = ActivityBuilder.insert_list(30, %{}, %{user: user})
ActivityBuilder.insert_list(10, %{}, %{user: user})
since_id = List.last(activities).id
- conn = conn
+ conn =
+ conn
|> get("/api/statuses/public_timeline.json", %{since_id: since_id})
response = json_response(conn, 200)
@@ -94,8 +105,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
actor = Repo.get_by!(User, ap_id: activity.data["actor"])
- conn = conn
- |> get("/api/statuses/show/#{activity.id}.json")
+ conn =
+ conn
+ |> get("/api/statuses/show/#{activity.id}.json")
response = json_response(conn, 200)
@@ -107,8 +119,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "gets user with screen_name", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> get("/api/users/show.json", %{"screen_name" => user.nickname})
+ conn =
+ conn
+ |> get("/api/users/show.json", %{"screen_name" => user.nickname})
response = json_response(conn, 200)
@@ -118,8 +131,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "gets user with user_id", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> get("/api/users/show.json", %{"user_id" => user.id})
+ conn =
+ conn
+ |> get("/api/users/show.json", %{"user_id" => user.id})
response = json_response(conn, 200)
@@ -132,9 +146,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{: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})
+ conn =
+ conn
+ |> with_credentials(logged_in.nickname, "test")
+ |> get("/api/users/show.json", %{"user_id" => user.id})
response = json_response(conn, 200)
@@ -144,14 +159,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /statusnet/conversation/:id.json" do
test "returns the statuses in the conversation", %{conn: conn} do
- {:ok, _user} = UserBuilder.insert
+ {: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"})
- {:ok, object} = Object.context_mapping("2hu") |> Repo.insert
- conn = conn
- |> get("/api/statusnet/conversation/#{object.id}.json")
+ {:ok, object} = Object.context_mapping("2hu") |> Repo.insert()
+
+ conn =
+ conn
+ |> get("/api/statusnet/conversation/#{object.id}.json")
response = json_response(conn, 200)
@@ -161,58 +178,87 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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"
+ 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})
+
+ 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 = Ecto.Changeset.change(current_user, following: [User.ap_followers(user)]) |> Repo.update!
+ current_user =
+ Ecto.Changeset.change(current_user, following: [User.ap_followers(user)])
+ |> Repo.update!()
- conn = conn
+ 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) -> ActivityRepresenter.to_map(activity, %{user: User.get_cached_by_ap_id(activity.data["actor"]), for: current_user}) end)
+
+ assert response ==
+ Enum.map(returned_activities, fn activity ->
+ ActivityRepresenter.to_map(activity, %{
+ user: User.get_cached_by_ap_id(activity.data["actor"]),
+ for: current_user
+ })
+ end)
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"
+ 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} = ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
+ {:ok, activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
- conn = conn
+ 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) == ActivityRepresenter.to_map(activity, %{user: current_user, mentioned: [current_user]})
+
+ assert Enum.at(response, 0) ==
+ ActivityRepresenter.to_map(activity, %{
+ user: current_user,
+ mentioned: [current_user]
+ })
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"}
+
+ 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
@@ -237,9 +283,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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")
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/statuses/user_timeline.json")
response = json_response(conn, 200)
@@ -250,9 +298,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/statuses/user_timeline.json", %{"user_id" => user.id})
response = json_response(conn, 200)
@@ -263,9 +313,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
response = json_response(conn, 200)
@@ -276,28 +328,33 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /friendships/create.json" do
setup [:valid_user]
+
test "without valid credentials", %{conn: conn} do
- conn = post conn, "/api/friendships/create.json"
+ 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})
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/friendships/create.json", %{user_id: followed.id})
current_user = Repo.get(User, 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})
+
+ 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"
+ conn = post(conn, "/api/friendships/destroy.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
@@ -308,40 +365,48 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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})
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/friendships/destroy.json", %{user_id: followed.id})
current_user = Repo.get(User, 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})
+
+ 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"
+ 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})
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/blocks/create.json", %{user_id: blocked.id})
current_user = Repo.get(User, current_user.id)
assert User.blocks?(current_user, blocked)
- assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user})
+
+ 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"
+ conn = post(conn, "/api/blocks/destroy.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
@@ -351,56 +416,66 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, current_user} = User.block(current_user, blocked)
assert User.blocks?(current_user, blocked)
- conn = conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/blocks/destroy.json", %{user_id: blocked.id})
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/blocks/destroy.json", %{user_id: blocked.id})
current_user = Repo.get(User, current_user.id)
assert current_user.info["blocks"] == []
- assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user})
+
+ 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"
+ 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"
+ 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})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
current_user = Repo.get(User, current_user.id)
assert is_map(current_user.avatar)
- assert json_response(conn, 200) == UserView.render("show.json", %{user: current_user, for: current_user})
+
+ assert json_response(conn, 200) ==
+ UserView.render("show.json", %{user: current_user, for: current_user})
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"
+ 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")
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/favorites/create/#{note_activity.id}.json")
assert json_response(conn, 200)
end
@@ -408,9 +483,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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"
+ conn = post(conn, "/api/favorites/destroy/#{note_activity.id}.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
@@ -419,9 +495,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
ActivityPub.like(current_user, object)
- conn = conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/favorites/destroy/#{note_activity.id}.json")
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/favorites/destroy/#{note_activity.id}.json")
assert json_response(conn, 200)
end
@@ -429,9 +506,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
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"
+ conn = post(conn, "/api/statuses/retweet/#{note_activity.id}.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
@@ -440,12 +518,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
request_path = "/api/statuses/retweet/#{note_activity.id}.json"
- response = conn
- |> with_credentials(current_user.nickname, "test")
- |> post(request_path)
+ response =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post(request_path)
+
activity = Repo.get(Activity, note_activity.id)
activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
- assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
+
+ assert json_response(response, 200) ==
+ ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
end
end
@@ -460,8 +542,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
"confirm" => "bear"
}
- conn = conn
- |> post("/api/account/register", data)
+ conn =
+ conn
+ |> post("/api/account/register", data)
user = json_response(conn, 200)
@@ -478,8 +561,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
"confirm" => "bear"
}
- conn = conn
- |> post("/api/account/register", data)
+ conn =
+ conn
+ |> post("/api/account/register", data)
errors = json_response(conn, 400)
@@ -492,9 +576,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = insert(:user)
other_user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
+ 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
@@ -510,11 +595,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{: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")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/followers")
- assert json_response(conn, 200) == UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
+ assert json_response(conn, 200) ==
+ UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
end
end
@@ -528,11 +615,17 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
- conn = conn
- |> assign(:user, user)
- |> get("/api/statuses/friends")
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends")
- assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
+ 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 a given user's friends with user_id", %{conn: conn} do
@@ -544,10 +637,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
- conn = conn
- |> get("/api/statuses/friends", %{"user_id" => user.id})
+ conn =
+ conn
+ |> 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})))
+ 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 a given user's friends with screen_name", %{conn: conn} do
@@ -559,10 +658,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
- conn = conn
- |> get("/api/statuses/friends", %{"screen_name" => user.nickname})
+ conn =
+ conn
+ |> 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})))
+ assert MapSet.equal?(
+ MapSet.new(json_response(conn, 200)),
+ MapSet.new(
+ UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
+ )
+ )
end
end
@@ -576,12 +681,17 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
- conn = conn
- |> assign(:user, user)
- |> get("/api/friends/ids")
+ 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))
+
+ assert MapSet.equal?(
+ MapSet.new(Poison.decode!(json_response(conn, 200))),
+ MapSet.new(expected)
+ )
end
end
@@ -589,9 +699,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "it updates a user's profile", %{conn: conn} do
user = insert(:user)
- conn = conn
- |> assign(:user, user)
- |> post("/api/account/update_profile.json", %{"name" => "new name", "description" => "new description"})
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "name" => "new name",
+ "description" => "new description"
+ })
user = Repo.get!(User, user.id)
assert user.name == "new name"
@@ -619,8 +733,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{: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"})
+ conn =
+ conn
+ |> get("/api/search.json", %{"q" => "2hu", "page" => "1", "rpp" => "1"})
assert [status] = json_response(conn, 200)
assert status["id"] == activity.id
@@ -635,8 +750,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{: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")
+ conn =
+ conn
+ |> get("/api/statusnet/tags/timeline/2hu.json")
assert [status] = json_response(conn, 200)
assert status["id"] == activity.id
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 715a746ef..d4341a867 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -28,23 +28,32 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
object = Repo.insert!(%Object{data: object_data})
input = %{
- "status" => "Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
+ "status" =>
+ "Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
"media_ids" => [object.id]
}
- { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
+ {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+
+ expected_text =
+ "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
- expected_text = "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
assert get_in(activity.data, ["object", "content"]) == expected_text
assert get_in(activity.data, ["object", "type"]) == "Note"
assert get_in(activity.data, ["object", "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"]),
+ "https://www.w3.org/ns/activitystreams#Public"
+ )
+
assert Enum.member?(get_in(activity.data, ["cc"]), "shp")
assert activity.local == true
- assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = activity.data["object"]["emoji"]
+ assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
+ activity.data["object"]["emoji"]
# hashtags
assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
@@ -64,27 +73,31 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "create a status that is a reply" do
user = insert(:user)
+
input = %{
"status" => "Hello again."
}
- { :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
+ {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
input = %{
"status" => "Here's your (you).",
"in_reply_to_status_id" => activity.id
}
- { :ok, reply = %Activity{} } = TwitterAPI.create_status(user, input)
+ {:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
- assert get_in(reply.data, ["object", "context"]) == get_in(activity.data, ["object", "context"])
+
+ assert get_in(reply.data, ["object", "context"]) ==
+ get_in(activity.data, ["object", "context"])
+
assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
end
test "fetch public statuses, excluding remote ones." do
- %{ public: activity, user: user } = ActivityBuilder.public_and_non_public
+ %{public: activity, user: user} = ActivityBuilder.public_and_non_public()
insert(:note_activity, %{local: false})
follower = insert(:user, following: [User.ap_followers(user)])
@@ -92,11 +105,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
statuses = TwitterAPI.fetch_public_statuses(follower)
assert length(statuses) == 1
- assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
+
+ assert Enum.at(statuses, 0) ==
+ ActivityRepresenter.to_map(activity, %{user: user, for: follower})
end
test "fetch whole known network statuses" do
- %{ public: activity, user: user } = ActivityBuilder.public_and_non_public
+ %{public: activity, user: user} = ActivityBuilder.public_and_non_public()
insert(:note_activity, %{local: false})
follower = insert(:user, following: [user.follower_address])
@@ -104,7 +119,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
statuses = TwitterAPI.fetch_public_and_external_statuses(follower)
assert length(statuses) == 2
- assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
+
+ assert Enum.at(statuses, 0) ==
+ ActivityRepresenter.to_map(activity, %{user: user, for: follower})
end
test "fetch friends' statuses" do
@@ -119,7 +136,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert length(statuses) == 2
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user})
- assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]})
+
+ assert Enum.at(statuses, 1) ==
+ ActivityRepresenter.to_map(direct_activity, %{
+ user: direct_activity_user,
+ mentioned: [user]
+ })
end
test "fetch user's mentions" do
@@ -130,12 +152,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
statuses = TwitterAPI.fetch_mentions(user)
assert length(statuses) == 1
- assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user, mentioned: [user]})
+
+ assert Enum.at(statuses, 0) ==
+ ActivityRepresenter.to_map(activity, %{user: activity_user, mentioned: [user]})
end
test "get a user by params" do
user1_result = {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
- {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
+
+ {:ok, user2} =
+ UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
assert {:error, "You need to specify screen_name or user_id"} == TwitterAPI.get_user(nil, nil)
assert user1_result == TwitterAPI.get_user(nil, %{"user_id" => user1.id})
@@ -144,13 +170,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert user1_result == TwitterAPI.get_user(user1, nil)
assert user1_result == TwitterAPI.get_user(user2, %{"user_id" => user1.id})
assert user1_result == TwitterAPI.get_user(user2, %{"screen_name" => user1.nickname})
- assert {:error, "No user with such screen_name"} == TwitterAPI.get_user(nil, %{"screen_name" => "Satan"})
+
+ assert {:error, "No user with such screen_name"} ==
+ TwitterAPI.get_user(nil, %{"screen_name" => "Satan"})
+
assert {:error, "No user with such user_id"} == TwitterAPI.get_user(nil, %{"user_id" => 666})
end
test "fetch user's statuses" do
{:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
- {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
+
+ {:ok, user2} =
+ UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
{:ok, status1} = ActivityBuilder.insert(%{"id" => 1}, %{user: user1})
{:ok, status2} = ActivityBuilder.insert(%{"id" => 2}, %{user: user2})
@@ -180,10 +211,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
user = insert(:user)
followed = insert(:user)
- {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
+ {:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
assert User.ap_followers(followed) in user.following
- { :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
+ {:error, msg} = TwitterAPI.follow(user, %{"user_id" => followed.id})
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
end
@@ -191,13 +222,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
user = insert(:user)
followed = insert(:user)
- {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+ {:ok, user, followed, _activity} =
+ TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+
assert User.ap_followers(followed) in user.following
followed = User.get_by_ap_id(followed.ap_id)
assert followed.info["follower_count"] == 1
- { :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+ {:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
end
@@ -206,10 +239,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
ActivityPub.follow(user, unfollowed)
- {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
+ {:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
assert user.following == []
- { :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
+ {:error, msg} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
assert msg == "Not subscribed!"
end
@@ -219,10 +252,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
ActivityPub.follow(user, unfollowed)
- {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
+ {:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
assert user.following == []
- { :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
+ {:error, msg} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
assert msg == "Not subscribed!"
end
@@ -266,7 +299,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
{:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
- {:ok, object} = Object.context_mapping("2hu") |> Repo.insert
+ {:ok, object} = Object.context_mapping("2hu") |> Repo.insert()
statuses = TwitterAPI.fetch_conversation(user, object.id)
@@ -276,7 +309,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "upload a file" do
- 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"
+ }
response = TwitterAPI.upload(file)
@@ -291,7 +328,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, status} = TwitterAPI.fav(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
- assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
+ assert status ==
+ ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
end
test "it unfavorites a status, returns the updated status" do
@@ -300,9 +338,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
- {:ok, _like_activity, _object } = ActivityPub.like(user, object)
+ {:ok, _like_activity, _object} = ActivityPub.like(user, object)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
- assert ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})["fave_num"] == 1
+
+ assert ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})[
+ "fave_num"
+ ] == 1
{:ok, status} = TwitterAPI.unfav(user, note_activity.id)
@@ -317,7 +358,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, status} = TwitterAPI.repeat(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
- assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
+ assert status ==
+ ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
end
test "it registers a new user and returns the user." do
@@ -333,7 +375,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
fetched_user = Repo.get_by(User, nickname: "lain")
- assert UserView.render("show.json", %{user: user}) == UserView.render("show.json", %{user: fetched_user})
+
+ assert UserView.render("show.json", %{user: user}) ==
+ UserView.render("show.json", %{user: fetched_user})
end
test "it returns the error on registration problems" do
@@ -374,7 +418,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "returns an existing mapping for an existing object" do
- {:ok, object} = Object.context_mapping("random context") |> Repo.insert
+ {:ok, object} = Object.context_mapping("random context") |> Repo.insert()
conversation_id = TwitterAPI.context_to_conversation_id("random context")
assert conversation_id == object.id
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 9e0a8a532..dd55c0b7e 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
test "A user with an avatar object", %{user: user} do
image = "image"
- user = %{ user | avatar: %{ "url" => [%{"href" => image}] }}
+ user = %{user | avatar: %{"url" => [%{"href" => image}]}}
represented = UserView.render("show.json", %{user: user})
assert represented["profile_image_url"] == image
end
@@ -41,7 +41,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"name" => user.name,
"screen_name" => user.nickname,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
- "created_at" => user.inserted_at |> Utils.format_naive_asctime,
+ "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 1,
"friends_count" => 1,
@@ -76,7 +76,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"name" => user.name,
"screen_name" => user.nickname,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
- "created_at" => user.inserted_at |> Utils.format_naive_asctime,
+ "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 0,
"friends_count" => 0,
@@ -112,7 +112,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"name" => follower.name,
"screen_name" => follower.nickname,
"description" => HtmlSanitizeEx.strip_tags(follower.bio),
- "created_at" => follower.inserted_at |> Utils.format_naive_asctime,
+ "created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 0,
"friends_count" => 1,
@@ -155,7 +155,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"name" => user.name,
"screen_name" => user.nickname,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
- "created_at" => user.inserted_at |> Utils.format_naive_asctime,
+ "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 0,
"friends_count" => 0,
diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs
index 48cdc5159..1d443b187 100644
--- a/test/web/views/error_view_test.exs
+++ b/test/web/views/error_view_test.exs
@@ -5,17 +5,16 @@ defmodule Pleroma.Web.ErrorViewTest do
import Phoenix.View
test "renders 404.json" do
- assert render(Pleroma.Web.ErrorView, "404.json", []) ==
- %{errors: %{detail: "Page not found"}}
+ assert render(Pleroma.Web.ErrorView, "404.json", []) == %{errors: %{detail: "Page not found"}}
end
test "render 500.json" do
assert render(Pleroma.Web.ErrorView, "500.json", []) ==
- %{errors: %{detail: "Internal server error"}}
+ %{errors: %{detail: "Internal server error"}}
end
test "render any other" do
assert render(Pleroma.Web.ErrorView, "505.json", []) ==
- %{errors: %{detail: "Internal server error"}}
+ %{errors: %{detail: "Internal server error"}}
end
end
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index c7ad206eb..69216f393 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "returns a link to the xml lrdd" do
host_info = WebFinger.host_meta()
- assert String.contains?(host_info, Pleroma.Web.base_url)
+ assert String.contains?(host_info, Pleroma.Web.base_url())
end
end
@@ -15,7 +15,9 @@ defmodule Pleroma.Web.WebFingerTest do
test "works for fqns" do
user = insert(:user)
- {:ok, result} = WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host}", "XML")
+ {:ok, result} =
+ WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "XML")
+
assert is_binary(result)
end
@@ -33,7 +35,9 @@ defmodule Pleroma.Web.WebFingerTest do
{:ok, data} = WebFinger.finger(user)
- assert data["magic_key"] == "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
+ assert data["magic_key"] ==
+ "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
+
assert data["topic"] == "https://social.heldscal.la/api/statuses/user_timeline/29191.atom"
assert data["subject"] == "acct:shp@social.heldscal.la"
assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
@@ -50,7 +54,9 @@ defmodule Pleroma.Web.WebFingerTest do
{:ok, data} = WebFinger.finger(user)
- assert data["magic_key"] == "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
+ assert data["magic_key"] ==
+ "RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
+
assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom"
assert data["subject"] == "acct:winterdienst@gnusocial.de"
assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296"
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index f6b86eca0..d861c241f 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -18,8 +18,9 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
"hub.lease_seconds": "100"
}
- conn = conn
- |> post(path, data)
+ conn =
+ conn
+ |> post(path, data)
assert response(conn, 202) == "Accepted"
end
@@ -34,14 +35,15 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
"hub.lease_seconds" => "100"
}
- conn = conn
- |> get("/push/subscriptions/#{websub.id}", params)
+ conn =
+ conn
+ |> get("/push/subscriptions/#{websub.id}", params)
websub = Repo.get(WebsubClientSubscription, websub.id)
assert response(conn, 200) == "some challenge"
assert websub.state == "accepted"
- assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now), 100, 5
+ assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now()), 100, 5
end
test "handles incoming feed updates", %{conn: conn} do
@@ -49,10 +51,11 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
doc = "some stuff"
signature = Websub.sign(websub.secret, doc)
- conn = conn
- |> put_req_header("x-hub-signature", "sha1=" <> signature)
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/push/subscriptions/#{websub.id}", doc)
+ conn =
+ conn
+ |> put_req_header("x-hub-signature", "sha1=" <> signature)
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/push/subscriptions/#{websub.id}", doc)
assert response(conn, 200) == "OK"
@@ -64,10 +67,11 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
doc = "some stuff"
signature = Websub.sign("wrong secret", doc)
- conn = conn
- |> put_req_header("x-hub-signature", "sha1=" <> signature)
- |> put_req_header("content-type", "application/atom+xml")
- |> post("/push/subscriptions/#{websub.id}", doc)
+ conn =
+ conn
+ |> put_req_header("x-hub-signature", "sha1=" <> signature)
+ |> put_req_header("content-type", "application/atom+xml")
+ |> post("/push/subscriptions/#{websub.id}", doc)
assert response(conn, 500) == "Error"
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 566ce7fa5..5914a37fc 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.WebsubTest do
sub = insert(:websub_subscription)
topic = sub.topic
- getter = fn (_path, _headers, options) ->
+ getter = fn _path, _headers, options ->
%{
"hub.challenge": challenge,
"hub.lease_seconds": seconds,
@@ -25,10 +25,11 @@ defmodule Pleroma.Web.WebsubTest do
assert String.to_integer(seconds) > 0
- {:ok, %HTTPoison.Response{
- status_code: 200,
- body: challenge
- }}
+ {:ok,
+ %HTTPoison.Response{
+ status_code: 200,
+ body: challenge
+ }}
end
{:ok, sub} = Websub.verify(sub, getter)
@@ -38,11 +39,12 @@ defmodule Pleroma.Web.WebsubTest do
test "a verification of a request that doesn't return 200" do
sub = insert(:websub_subscription)
- getter = fn (_path, _headers, _options) ->
- {:ok, %HTTPoison.Response{
- status_code: 500,
- body: ""
- }}
+ getter = fn _path, _headers, _options ->
+ {:ok,
+ %HTTPoison.Response{
+ status_code: 500,
+ body: ""
+ }}
end
{:error, sub} = Websub.verify(sub, getter)
@@ -61,7 +63,7 @@ defmodule Pleroma.Web.WebsubTest do
"hub.lease_seconds" => "100"
}
- {:ok, subscription } = Websub.incoming_subscription_request(user, data)
+ {:ok, subscription} = Websub.incoming_subscription_request(user, data)
assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
assert subscription.state == "requested"
assert subscription.secret == "a random secret"
@@ -70,7 +72,9 @@ defmodule Pleroma.Web.WebsubTest do
test "an incoming subscription request for an existing subscription" do
user = insert(:user)
- sub = insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
+
+ sub =
+ insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
data = %{
"hub.callback" => sub.callback,
@@ -80,7 +84,7 @@ defmodule Pleroma.Web.WebsubTest do
"hub.lease_seconds" => "100"
}
- {:ok, subscription } = Websub.incoming_subscription_request(user, data)
+ {:ok, subscription} = Websub.incoming_subscription_request(user, data)
assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
assert subscription.state == sub.state
assert subscription.secret == "a random secret"
@@ -90,12 +94,12 @@ defmodule Pleroma.Web.WebsubTest do
end
def accepting_verifier(subscription) do
- {:ok, %{ subscription | state: "accepted" }}
+ {:ok, %{subscription | state: "accepted"}}
end
test "initiate a subscription for a given user and topic" do
subscriber = insert(:user)
- user = insert(:user, %{info: %{ "topic" => "some_topic", "hub" => "some_hub"}})
+ user = insert(:user, %{info: %{"topic" => "some_topic", "hub" => "some_hub"}})
{:ok, websub} = Websub.subscribe(subscriber, user, &accepting_verifier/1)
assert websub.subscribers == [subscriber.ap_id]
@@ -109,12 +113,13 @@ defmodule Pleroma.Web.WebsubTest do
test "discovers the hub and canonical url" do
topic = "https://mastodon.social/users/lambadalambda.atom"
- getter = fn(^topic) ->
+ getter = fn ^topic ->
doc = File.read!("test/fixtures/lambadalambda.atom")
{:ok, %{status_code: 200, body: doc}}
end
{:ok, discovered} = Websub.gather_feed_data(topic, getter)
+
expected = %{
"hub" => "https://mastodon.social/api/push",
"uri" => "https://mastodon.social/users/lambadalambda",
@@ -122,7 +127,17 @@ defmodule Pleroma.Web.WebsubTest do
"name" => "Critical Value",
"host" => "mastodon.social",
"bio" => "a cool dude.",
- "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif?1492379244", "mediaType" => "image/gif", "type" => "Link"}]}
+ "avatar" => %{
+ "type" => "Image",
+ "url" => [
+ %{
+ "href" =>
+ "https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif?1492379244",
+ "mediaType" => "image/gif",
+ "type" => "Link"
+ }
+ ]
+ }
}
assert expected == discovered
@@ -133,9 +148,16 @@ defmodule Pleroma.Web.WebsubTest do
topic = "https://social.heldscal.la/api/statuses/user_timeline/23211.atom"
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
- poster = fn (^hub, {:form, data}, _headers) ->
+ poster = fn ^hub, {:form, data}, _headers ->
assert Keyword.get(data, :"hub.mode") == "subscribe"
- assert Keyword.get(data, :"hub.callback") == Helpers.websub_url(Pleroma.Web.Endpoint, :websub_subscription_confirmation, websub.id)
+
+ assert Keyword.get(data, :"hub.callback") ==
+ Helpers.websub_url(
+ Pleroma.Web.Endpoint,
+ :websub_subscription_confirmation,
+ websub.id
+ )
+
{:ok, %{status_code: 202}}
end
@@ -154,7 +176,7 @@ defmodule Pleroma.Web.WebsubTest do
topic = "https://social.heldscal.la/api/statuses/user_timeline/23211.atom"
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
- poster = fn (^hub, {:form, _data}, _headers) ->
+ poster = fn ^hub, {:form, _data}, _headers ->
{:ok, %{status_code: 202}}
end
@@ -162,7 +184,8 @@ defmodule Pleroma.Web.WebsubTest do
assert websub.state == "rejected"
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
- poster = fn (^hub, {:form, _data}, _headers) ->
+
+ poster = fn ^hub, {:form, _data}, _headers ->
{:ok, %{status_code: 400}}
end
@@ -172,7 +195,7 @@ defmodule Pleroma.Web.WebsubTest do
test "sign a text" do
signed = Websub.sign("secret", "text")
- assert signed == "B8392C23690CCF871F37EC270BE1582DEC57A503" |> String.downcase
+ assert signed == "B8392C23690CCF871F37EC270BE1582DEC57A503" |> String.downcase()
_signed = Websub.sign("secret", [["て"], ['す']])
end
@@ -180,9 +203,21 @@ defmodule Pleroma.Web.WebsubTest do
describe "renewing subscriptions" do
test "it renews subscriptions that have less than a day of time left" do
day = 60 * 60 * 24
- now = NaiveDateTime.utc_now
- still_good = insert(:websub_client_subscription, %{valid_until: NaiveDateTime.add(now, 2 * day), topic: "http://example.org/still_good", state: "accepted"})
- needs_refresh = insert(:websub_client_subscription, %{valid_until: NaiveDateTime.add(now, day - 100), topic: "http://example.org/needs_refresh", state: "accepted"})
+ now = NaiveDateTime.utc_now()
+
+ still_good =
+ insert(:websub_client_subscription, %{
+ valid_until: NaiveDateTime.add(now, 2 * day),
+ topic: "http://example.org/still_good",
+ state: "accepted"
+ })
+
+ needs_refresh =
+ insert(:websub_client_subscription, %{
+ valid_until: NaiveDateTime.add(now, day - 100),
+ topic: "http://example.org/needs_refresh",
+ state: "accepted"
+ })
_refresh = Websub.refresh_subscriptions()
diff --git a/test/xml_builder_test.exs b/test/xml_builder_test.exs
index f502a0f0e..4be7bbd01 100644
--- a/test/xml_builder_test.exs
+++ b/test/xml_builder_test.exs
@@ -3,7 +3,7 @@ defmodule Pleroma.XmlBuilderTest do
alias Pleroma.XmlBuilder
test "Build a basic xml string from a tuple" do
- data = { :feed, %{ xmlns: "http://www.w3.org/2005/Atom"}, "Some content" }
+ data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
expected_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
@@ -11,9 +11,10 @@ defmodule Pleroma.XmlBuilderTest do
end
test "returns a complete document" do
- data = { :feed, %{ xmlns: "http://www.w3.org/2005/Atom"}, "Some content" }
+ data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
- expected_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
+ expected_xml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
assert XmlBuilder.to_doc(data) == expected_xml
end
@@ -34,11 +35,12 @@ defmodule Pleroma.XmlBuilderTest do
:feed,
[
{:guy, "brush"},
- {:lament, %{ configuration: "puzzle" }, "pinhead" }
+ {:lament, %{configuration: "puzzle"}, "pinhead"}
]
}
- expected_xml = ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
+ expected_xml =
+ ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
assert XmlBuilder.to_xml(data) == expected_xml
end
@@ -50,7 +52,7 @@ defmodule Pleroma.XmlBuilderTest do
test "Uses self-closing tags when no content is giving" do
data = {
:link,
- %{ rel: "self" }
+ %{rel: "self"}
}
expected_xml = ~s[<link rel="self" />]