Merge branch 'develop' into dtluna/pleroma-feature/unfollow-activity
This commit is contained in:
commit
b403ea4d2b
91 changed files with 7808 additions and 328 deletions
|
|
@ -22,6 +22,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
|
||||
retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
|
||||
assert retweeted_status["repeated"] == true
|
||||
assert retweeted_status["id"] == note_activity.id
|
||||
assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
|
||||
|
||||
assert status["retweeted_status"] == retweeted_status
|
||||
end
|
||||
|
|
@ -69,6 +71,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
content = HtmlSanitizeEx.strip_tags(content_html)
|
||||
date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
|
||||
|
||||
{:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
|
||||
|
||||
activity = %Activity{
|
||||
id: 1,
|
||||
data: %{
|
||||
|
|
@ -84,14 +88,15 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"type" => "Note",
|
||||
"content" => content_html,
|
||||
"inReplyToStatusId" => 213123,
|
||||
"statusnetConversationId" => 4711,
|
||||
"attachment" => [
|
||||
object
|
||||
],
|
||||
"like_count" => 5,
|
||||
"announcement_count" => 3
|
||||
"announcement_count" => 3,
|
||||
"context" => "2hu"
|
||||
},
|
||||
"published" => date
|
||||
"published" => date,
|
||||
"context" => "2hu"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +111,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"is_post_verb" => true,
|
||||
"created_at" => "Tue May 24 13:26:08 +0000 2016",
|
||||
"in_reply_to_status_id" => 213123,
|
||||
"statusnet_conversation_id" => 4711,
|
||||
"statusnet_conversation_id" => convo_object.id,
|
||||
"attachments" => [
|
||||
ObjectRepresenter.to_map(object)
|
||||
],
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
|
|||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"rights" => %{}
|
||||
"rights" => %{},
|
||||
"statusnet_profile_url" => user.ap_id
|
||||
}
|
||||
|
||||
assert represented == UserRepresenter.to_map(user)
|
||||
|
|
@ -72,7 +73,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
|
|||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => true,
|
||||
"rights" => %{}
|
||||
"rights" => %{},
|
||||
"statusnet_profile_url" => user.ap_id
|
||||
}
|
||||
|
||||
assert represented == UserRepresenter.to_map(user, %{for: follower})
|
||||
|
|
|
|||
|
|
@ -84,12 +84,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
describe "GET /statusnet/conversation/:id.json" do
|
||||
test "returns the statuses in the conversation", %{conn: conn} do
|
||||
{:ok, _user} = UserBuilder.insert
|
||||
{:ok, _activity} = ActivityBuilder.insert(%{"statusnetConversationId" => 1, "context" => "2hu"})
|
||||
{:ok, _activity_two} = ActivityBuilder.insert(%{"statusnetConversationId" => 1,"context" => "2hu"})
|
||||
{:ok, _activity} = ActivityBuilder.insert(%{"context" => "2hu"})
|
||||
{:ok, _activity_two} = ActivityBuilder.insert(%{"context" => "2hu"})
|
||||
{:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"})
|
||||
|
||||
{:ok, object} = Object.context_mapping("2hu") |> Repo.insert
|
||||
conn = conn
|
||||
|> get("/api/statusnet/conversation/1.json")
|
||||
|> get("/api/statusnet/conversation/#{object.id}.json")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -244,6 +245,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
{:ok, current_user} = User.follow(current_user, followed)
|
||||
assert current_user.following == [User.ap_followers(followed)]
|
||||
ActivityPub.follow(current_user, followed)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|
|
@ -396,10 +398,4 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
header_content = "Basic " <> Base.encode64("#{username}:#{password}")
|
||||
put_req_header(conn, "authorization", header_content)
|
||||
end
|
||||
|
||||
setup do
|
||||
Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
|
||||
Supervisor.restart_child(Pleroma.Supervisor, ConCache)
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,19 +33,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<br>This is on another line."
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>.<br>This is on another line.<br><a href='http://example.org/image.jpg'>http://example.org/image.jpg</a>"
|
||||
assert get_in(activity.data, ["object", "type"]) == "Note"
|
||||
assert get_in(activity.data, ["object", "actor"]) == user.ap_id
|
||||
assert get_in(activity.data, ["actor"]) == user.ap_id
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), User.ap_followers(user))
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), "https://www.w3.org/ns/activitystreams#Public")
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
|
||||
assert activity.local == true
|
||||
|
||||
# Add a context + 'statusnet_conversation_id'
|
||||
# Add a context
|
||||
assert is_binary(get_in(activity.data, ["context"]))
|
||||
assert is_binary(get_in(activity.data, ["object", "context"]))
|
||||
assert get_in(activity.data, ["object", "statusnetConversationId"]) == activity.id
|
||||
assert get_in(activity.data, ["statusnetConversationId"]) == activity.id
|
||||
|
||||
assert is_list(activity.data["object"]["attachment"])
|
||||
|
||||
|
|
@ -69,15 +68,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
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.data, ["statusnetConversationId"]) == get_in(activity.data, ["statusnetConversationId"])
|
||||
assert get_in(reply.data, ["object", "statusnetConversationId"]) == get_in(activity.data, ["object", "statusnetConversationId"])
|
||||
assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
|
||||
assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
|
||||
assert Enum.member?(get_in(reply.data, ["to"]), "some_cool_id")
|
||||
end
|
||||
|
||||
test "fetch public statuses" do
|
||||
test "fetch public statuses, excluding remote ones." do
|
||||
%{ public: activity, user: user } = ActivityBuilder.public_and_non_public
|
||||
insert(:note_activity, %{local: false})
|
||||
|
||||
follower = insert(:user, following: [User.ap_followers(user)])
|
||||
|
||||
|
|
@ -87,6 +85,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
|
||||
end
|
||||
|
||||
test "fetch whole known network statuses" do
|
||||
%{ public: activity, user: user } = ActivityBuilder.public_and_non_public
|
||||
insert(:note_activity, %{local: false})
|
||||
|
||||
follower = insert(:user, following: [User.ap_followers(user)])
|
||||
|
||||
statuses = TwitterAPI.fetch_public_and_external_statuses(follower)
|
||||
|
||||
assert length(statuses) == 2
|
||||
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
|
||||
end
|
||||
|
||||
test "fetch friends' statuses" do
|
||||
user = insert(:user, %{following: ["someguy/followers"]})
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"to" => ["someguy/followers"]})
|
||||
|
|
@ -180,6 +190,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
test "Unfollow another user using user_id" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
ActivityPub.follow(user, unfollowed)
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert user.following == []
|
||||
|
|
@ -192,6 +203,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
|
||||
ActivityPub.follow(user, unfollowed)
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert user.following == []
|
||||
|
||||
|
|
@ -201,11 +214,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "fetch statuses in a context using the conversation id" do
|
||||
{:ok, user} = UserBuilder.insert()
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"statusnetConversationId" => 1, "context" => "2hu"})
|
||||
{:ok, activity_two} = ActivityBuilder.insert(%{"statusnetConversationId" => 1,"context" => "2hu"})
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"context" => "2hu"})
|
||||
{:ok, activity_two} = ActivityBuilder.insert(%{"context" => "2hu"})
|
||||
{:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"})
|
||||
|
||||
statuses = TwitterAPI.fetch_conversation(user, 1)
|
||||
{:ok, object} = Object.context_mapping("2hu") |> Repo.insert
|
||||
|
||||
statuses = TwitterAPI.fetch_conversation(user, object.id)
|
||||
|
||||
assert length(statuses) == 2
|
||||
assert Enum.at(statuses, 0)["id"] == activity.id
|
||||
|
|
@ -314,9 +329,33 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
refute Repo.get_by(User, nickname: "lain")
|
||||
end
|
||||
|
||||
test "it assigns an integer conversation_id" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
status = ActivityRepresenter.to_map(note_activity, %{user: user})
|
||||
|
||||
assert is_number(status["statusnet_conversation_id"])
|
||||
end
|
||||
|
||||
setup do
|
||||
Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
|
||||
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "context_to_conversation_id" do
|
||||
test "creates a mapping object" do
|
||||
conversation_id = TwitterAPI.context_to_conversation_id("random context")
|
||||
object = Object.get_by_ap_id("random context")
|
||||
|
||||
assert conversation_id == object.id
|
||||
end
|
||||
|
||||
test "returns an existing mapping for an existing object" do
|
||||
{:ok, object} = Object.context_mapping("random context") |> Repo.insert
|
||||
conversation_id = TwitterAPI.context_to_conversation_id("random context")
|
||||
|
||||
assert conversation_id == object.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue