X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fostatus%2Factivity_representer_test.exs;h=5cb135b4c065f35390e02f55e2f09e8c678f9f4d;hb=1b3d92192194baf6b431cd9f0ce58062d1b703d5;hp=3ee9034a7763c92b09454fd0b2c4983bf7c2ffe4;hpb=611ca385dea3d611a97579000311cc42684305e6;p=akkoma
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index 3ee9034a7..5cb135b4c 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -1,12 +1,24 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase
- alias Pleroma.Web.OStatus.ActivityRepresenter
- alias Pleroma.{User, Activity, Object}
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
+ alias Pleroma.Web.OStatus.ActivityRepresenter
import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "an external note activity" do
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
@@ -16,9 +28,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{})
+ assert String.contains?(
+ res,
+ ~s{}
+ )
end
test "a note activity" do
@@ -46,7 +61,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 +76,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 +104,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 +120,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 = """
http://activitystrea.ms/schema/1.0/activity
@@ -120,13 +140,16 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
#{note_xml}
-
+
"""
- 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 +162,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 = """
http://activitystrea.ms/schema/1.0/favorite
@@ -156,7 +179,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
-
+
"""
@@ -166,18 +191,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 = """
http://activitystrea.ms/schema/1.0/activity
@@ -193,7 +220,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
#{activity.data["object"]}
-
+
"""
assert clean(res) == clean(expected)
@@ -209,7 +238,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 = """
http://activitystrea.ms/schema/1.0/activity
@@ -225,7 +254,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
#{followed.ap_id}
-
+
"""
assert clean(res) == clean(expected)
@@ -233,13 +264,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 = """
http://activitystrea.ms/schema/1.0/activity