Refactor all tests that acessed the embeded object

This commit is contained in:
rinpatch 2019-04-17 15:46:59 +03:00
parent c3a2052806
commit ff8d76c670
7 changed files with 14 additions and 21 deletions

View File

@ -14,6 +14,6 @@ defmodule Pleroma.ScheduledActivityWorkerTest do
refute Repo.get(ScheduledActivity, scheduled_activity.id) refute Repo.get(ScheduledActivity, scheduled_activity.id)
activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id)) activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))
assert activity.data["object"]["content"] == "hi" assert Pleroma.Object.normalize(activity).data["content"] == "hi"
end end
end end

View File

@ -4,6 +4,7 @@
defmodule Pleroma.UserTest do defmodule Pleroma.UserTest do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Builders.UserBuilder alias Pleroma.Builders.UserBuilder
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
@ -256,7 +257,7 @@ defmodule Pleroma.UserTest do
activity = Repo.one(Pleroma.Activity) activity = Repo.one(Pleroma.Activity)
assert registered_user.ap_id in activity.recipients assert registered_user.ap_id in activity.recipients
assert activity.data["object"]["content"] =~ "cool site" assert Object.normalize(activity).data["content"] =~ "cool site"
assert activity.actor == welcome_user.ap_id assert activity.actor == welcome_user.ap_id
Pleroma.Config.put([:instance, :welcome_user_nickname], nil) Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
@ -1132,14 +1133,14 @@ defmodule Pleroma.UserTest do
"status" => "heweoo!" "status" => "heweoo!"
}) })
id1 = activity1.data["object"]["id"] id1 = Object.normalize(activity1).data["id"]
{:ok, activity2} = {:ok, activity2} =
CommonAPI.post(user, %{ CommonAPI.post(user, %{
"status" => "heweoo!" "status" => "heweoo!"
}) })
id2 = activity2.data["object"]["id"] id2 = Object.normalize(activity2).data["id"]
assert {:ok, user_state1} = User.bookmark(user, id1) assert {:ok, user_state1} = User.bookmark(user, id1)
assert user_state1.bookmarks == [id1] assert user_state1.bookmarks == [id1]

View File

@ -250,25 +250,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
# public # public
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "public")) {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "public"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 1
assert object.data["repliesCount"] == 1 assert object.data["repliesCount"] == 1
# unlisted # unlisted
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "unlisted")) {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "unlisted"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2 assert object.data["repliesCount"] == 2
# private # private
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "private")) {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "private"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2 assert object.data["repliesCount"] == 2
# direct # direct
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "direct")) {:ok, _} = CommonAPI.post(user2, Map.put(reply_data, "visibility", "direct"))
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2 assert object.data["repliesCount"] == 2
end end
end end
@ -820,22 +816,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
_ = CommonAPI.delete(direct_reply.id, user2) _ = CommonAPI.delete(direct_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2 assert object.data["repliesCount"] == 2
_ = CommonAPI.delete(private_reply.id, user2) _ = CommonAPI.delete(private_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 2
assert object.data["repliesCount"] == 2 assert object.data["repliesCount"] == 2
_ = CommonAPI.delete(public_reply.id, user2) _ = CommonAPI.delete(public_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 1
assert object.data["repliesCount"] == 1 assert object.data["repliesCount"] == 1
_ = CommonAPI.delete(unlisted_reply.id, user2) _ = CommonAPI.delete(unlisted_reply.id, user2)
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id) assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
assert data["object"]["repliesCount"] == 0
assert object.data["repliesCount"] == 0 assert object.data["repliesCount"] == 0
end end
end end

View File

@ -187,15 +187,15 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = Map.put(data, "object", object) data = Map.put(data, "object", object)
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
assert data["to"] == [] assert data["to"] == []
assert data["cc"] == to assert data["cc"] == to
object = data["object"] object_data = Object.normalize(activity).data
assert object["to"] == [] assert object_data["to"] == []
assert object["cc"] == to assert object_data["cc"] == to
end end
test "it works for incoming follow requests" do test "it works for incoming follow requests" do
@ -331,7 +331,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = data =
File.read!("test/fixtures/mastodon-announce.json") File.read!("test/fixtures/mastodon-announce.json")
|> Poison.decode!() |> Poison.decode!()
|> Map.put("object", activity.data["object"]["id"]) |> Map.put("object", Object.normalize(activity).data["id"])
|> Map.put("to", ["http://mastodon.example.org/users/admin/followers"]) |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"])
|> Map.put("cc", []) |> Map.put("cc", [])

View File

@ -42,7 +42,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user) user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"}) {:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"})
assert activity.data["object"]["emoji"]["moominmamma"] assert Object.normalize(activity).data["emoji"]["moominmamma"]
end end
test "it adds emoji when updating profiles" do test "it adds emoji when updating profiles" do

View File

@ -2791,9 +2791,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"content" => "xD", "id" => id} = json_response(conn1, 200) assert %{"content" => "xD", "id" => id} = json_response(conn1, 200)
activity = Activity.get_by_id(id) activity = Activity.get_by_id_with_object(id)
assert activity.data["object"]["inReplyTo"] == replied_to.data["object"]["id"] assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"]
assert Activity.get_in_reply_to_activity(activity).id == replied_to.id assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
# Reblog from the third user # Reblog from the third user

View File

@ -61,7 +61,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|> Map.put("content", nil) |> Map.put("content", nil)
Object.change(note_object, %{data: data}) Object.change(note_object, %{data: data})
|> Repo.update() |> Object.update_and_set_cache()
User.get_cached_by_ap_id(note.data["actor"]) User.get_cached_by_ap_id(note.data["actor"])