tests: fix a lot of the remaining test failures

This commit is contained in:
William Pitcock 2018-11-25 22:49:39 +00:00
parent 4ca4c83871
commit f7e15d3257
5 changed files with 31 additions and 30 deletions

View 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

View 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

View 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

View 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

View 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)