fixes for tests

This commit is contained in:
Alex S 2019-04-22 16:16:19 +07:00
parent 229ce6abbc
commit 85953c0836
3 changed files with 11 additions and 4 deletions

View file

@ -280,7 +280,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> ActivityPub.contain_timeline(user)
|> Enum.reverse()
user = Repo.preload(user, :bookmarks)
user = Repo.preload(user, bookmarks: :activity)
conn
|> add_link_headers(:home_timeline, activities)

View file

@ -85,7 +85,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
activity_object = Object.normalize(activity)
favorited = opts[:for] && opts[:for].ap_id in (activity_object.data["likes"] || [])
bookmarked = opts[:for] && activity_object.data["id"] in opts[:for].bookmarks
bookmarked =
opts[:for] && Ecto.assoc_loaded?(opts[:for].bookmarks) &&
Enum.any?(opts[:for].bookmarks, fn b ->
b.activity_id == activity.id or b.activity.data["object"]["id"] == object
end)
mentions =
activity.recipients
@ -150,7 +155,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
bookmarked =
opts[:for] && Ecto.assoc_loaded?(opts[:for].bookmarks) &&
Enum.any?(opts[:for].bookmarks, fn b -> b.activity_id == activity.id end)
Enum.any?(opts[:for].bookmarks, fn b ->
b.activity_id == activity.id
end)
attachment_data = object.data["attachment"] || []
attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)

View file

@ -1022,7 +1022,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user2 = insert(:user)
user3 = insert(:user)
CommonAPI.favorite(activity.id, user2)
{:ok, user2} = User.bookmark(user2, activity.data["object"]["id"])
{:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)