tests: fix a lot of the remaining test failures
authorWilliam Pitcock <nenolod@dereferenced.org>
Sun, 25 Nov 2018 22:49:39 +0000 (22:49 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 4 Dec 2018 04:52:09 +0000 (04:52 +0000)
test/web/common_api/common_api_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/ostatus/ostatus_test.exs
test/web/twitter_api/twitter_api_test.exs
test/web/twitter_api/views/activity_view_test.exs

index 3f81d952ccafe28547d6808577b7244ee12d99f1..3dc5f6f8441b1407a18b17decc850ed82ac9589d 100644 (file)
@@ -36,8 +36,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
           "content_type" => "text/html"
         })
 
-      object =
-        Object.normalize(activity.data["object"])
+      object = Object.normalize(activity.data["object"])
 
       assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
     end
@@ -53,8 +52,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
           "content_type" => "text/markdown"
         })
 
-      object =
-        Object.normalize(activity.data["object"])
+      object = Object.normalize(activity.data["object"])
 
       assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
     end
index 098acb59ffa9a65dd3e8a0636929671cffe9ad65..c30f253d9624d982c7e43065b63294a45d642169 100644 (file)
@@ -2,7 +2,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
   use Pleroma.Web.ConnCase
 
   alias Pleroma.Web.TwitterAPI.TwitterAPI
-  alias Pleroma.{Repo, User, Activity, Notification}
+  alias Pleroma.{Repo, User, Activity, Notification, Object}
   alias Pleroma.Web.{OStatus, CommonAPI}
   alias Pleroma.Web.ActivityPub.ActivityPub
 
@@ -219,9 +219,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
 
     activity = Repo.get(Activity, id)
+    object = Object.normalize(activity.data["object"])
 
     assert activity.data["context"] == replied_to.data["context"]
-    assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
+    assert object.data["inReplyToStatusId"] == replied_to.id
   end
 
   test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
index 73e2b5482a571ec11e3c8d37fbdb63588a94b88f..b5805c66843ee73fdab7821faccfb0738d778c40 100644 (file)
@@ -22,8 +22,7 @@ defmodule Pleroma.Web.OStatusTest do
     assert activity.data["type"] == "Create"
     assert object.data["type"] == "Note"
 
-    assert object.data["id"] ==
-             "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
+    assert object.data["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 object.data["published"] == "2017-04-23T14:51:03+00:00"
@@ -268,8 +267,7 @@ defmodule Pleroma.Web.OStatusTest do
 
     assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
 
-    assert object.data["id"] ==
-             "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
+    assert object.data["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
index 28230699f3e29f33d3939436e4d187f71430011c..bc53fe68a1d4b53f3350e0626b078e8bef1e35fc 100644 (file)
@@ -33,13 +33,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     }
 
     {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+    object = Object.normalize(activity.data["object"])
 
     expected_text =
       "Hello again, <span><a class='mention' 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(object.data, ["content"]) == expected_text
+    assert get_in(object.data, ["type"]) == "Note"
+    assert get_in(object.data, ["actor"]) == user.ap_id
     assert get_in(activity.data, ["actor"]) == user.ap_id
     assert Enum.member?(get_in(activity.data, ["cc"]), User.ap_followers(user))
 
@@ -52,18 +53,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     assert activity.local == true
 
     assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
-             activity.data["object"]["emoji"]
+             object.data["emoji"]
 
     # hashtags
-    assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
+    assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
 
     # Add a context
     assert is_binary(get_in(activity.data, ["context"]))
-    assert is_binary(get_in(activity.data, ["object", "context"]))
+    assert is_binary(get_in(object.data, ["context"]))
 
-    assert is_list(activity.data["object"]["attachment"])
+    assert is_list(object.data["attachment"])
 
-    assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data
+    assert activity.data["object"] == object.data["id"]
 
     user = User.get_by_ap_id(user.ap_id)
 
@@ -78,6 +79,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     }
 
     {:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+    object = Object.normalize(activity.data["object"])
 
     input = %{
       "status" => "Here's your (you).",
@@ -85,14 +87,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     }
 
     {:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
+    reply_object = Object.normalize(reply.data["object"])
 
     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_object.data, ["context"]) == get_in(object.data, ["context"])
 
-    assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
-    assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
+    assert get_in(reply_object.data, ["inReplyTo"]) == get_in(activity.data, ["object"])
+    assert get_in(reply_object.data, ["inReplyToStatusId"]) == activity.id
   end
 
   test "Follow another user using user_id" do
index 5cef06f882e7017c3c473685a978d92fa96bcacd..f4741cf243e00508db1ca1b7dced704a17ba6731 100644 (file)
@@ -7,7 +7,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
   alias Pleroma.Web.TwitterAPI.UserView
   alias Pleroma.Web.TwitterAPI.TwitterAPI
   alias Pleroma.Repo
-  alias Pleroma.Activity
+  alias Pleroma.{Activity, Object}
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
 
@@ -19,10 +19,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
     other_user = insert(:user, %{nickname: "shp"})
 
     {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+    object = Object.normalize(activity.data["object"])
 
     result = ActivityView.render("activity.json", activity: activity)
 
-    convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
+    convo_id = TwitterAPI.context_to_conversation_id(object.data["context"])
 
     expected = %{
       "activity_type" => "post",
@@ -30,8 +31,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
       "attentions" => [
         UserView.render("show.json", %{user: other_user})
       ],
-      "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
-      "external_url" => activity.data["object"]["id"],
+      "created_at" => object.data["published"] |> Utils.date_to_asctime(),
+      "external_url" => object.data["id"],
       "fave_num" => 0,
       "favorited" => false,
       "id" => activity.id,
@@ -50,7 +51,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
         "Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
       "tags" => [],
       "text" => "Hey @shp!",
-      "uri" => activity.data["object"]["id"],
+      "uri" => object.data["id"],
       "user" => UserView.render("show.json", %{user: user}),
       "visibility" => "direct",
       "summary" => nil
@@ -63,8 +64,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
     {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+    object = Object.normalize(activity.data["object"])
 
-    convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
+    convo_id = TwitterAPI.context_to_conversation_id(object.data["context"])
 
     mocks = [
       {
@@ -162,9 +164,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
     other_user = insert(:user, %{nickname: "shp"})
 
     {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
-    {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
+    {:ok, announce, object} = CommonAPI.repeat(activity.id, other_user)
 
-    convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
+    convo_id = TwitterAPI.context_to_conversation_id(object.data["context"])
 
     activity = Repo.get(Activity, activity.id)