X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_test.exs;h=715a746ef7805bc26a82f62653670bfb8d639cbb;hb=c1d529ee9491fc0040cd4327c783aabf76cb66a8;hp=f591bef4a02ad6f1cbb772d25095208e2047e4ff;hpb=d4de38e8fff3154259e08292de60900488c210d6;p=akkoma
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index f591bef4a..715a746ef 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -1,7 +1,8 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
alias Pleroma.Builders.{UserBuilder, ActivityBuilder}
- alias Pleroma.Web.TwitterAPI.{TwitterAPI,UserView,Utils}
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
+ alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.{Activity, User, Object, Repo}
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -9,7 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
import Pleroma.Factory
test "create a status" do
- user = UserBuilder.build(%{ap_id: "142344"})
+ user = insert(:user)
_mentioned_user = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
object_data = %{
@@ -27,21 +28,24 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
object = Repo.insert!(%Object{data: object_data})
input = %{
- "status" => "Hello again, @shp.\nThis is on another line. #2hu #epic #phantasmagoric",
+ "status" => "Hello again, @shp.\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
"media_ids" => [object.id]
}
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
- assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.
\nThis is on another line. #2hu #epic #phantasmagoric
\nimage.jpg"
+ expected_text = "Hello again, @shp.<script></script>
This is on another :moominmamma: line. #2hu #epic #phantasmagoric
image.jpg"
+ 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(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, ["cc"]), 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 Enum.member?(get_in(activity.data, ["cc"]), "shp")
assert activity.local == true
+ assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = activity.data["object"]["emoji"]
+
# hashtags
assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
@@ -52,10 +56,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert is_list(activity.data["object"]["attachment"])
assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data
+
+ user = User.get_by_ap_id(user.ap_id)
+
+ assert user.info["note_count"] == 1
end
test "create a status that is a reply" do
- user = UserBuilder.build(%{ap_id: "some_cool_id"})
+ user = insert(:user)
input = %{
"status" => "Hello again."
}
@@ -73,7 +81,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert get_in(reply.data, ["object", "context"]) == get_in(activity.data, ["object", "context"])
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, excluding remote ones." do
@@ -92,7 +99,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
%{ public: activity, user: user } = ActivityBuilder.public_and_non_public
insert(:note_activity, %{local: false})
- follower = insert(:user, following: [User.ap_followers(user)])
+ follower = insert(:user, following: [user.follower_address])
statuses = TwitterAPI.fetch_public_and_external_statuses(follower)
@@ -174,7 +181,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
followed = insert(:user)
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
- assert user.following == [User.ap_followers(followed)]
+ assert User.ap_followers(followed) in user.following
{ :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
@@ -185,7 +192,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
followed = insert(:user)
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
- assert user.following == [User.ap_followers(followed)]
+ assert User.ap_followers(followed) in user.following
+
+ followed = User.get_by_ap_id(followed.ap_id)
+ assert followed.info["follower_count"] == 1
{ :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
@@ -216,11 +226,45 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert msg == "Not subscribed!"
end
+ test "Block another user using user_id" do
+ user = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, user, blocked} = TwitterAPI.block(user, %{"user_id" => blocked.id})
+ assert User.blocks?(user, blocked)
+ end
+
+ test "Block another user using screen_name" do
+ user = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, user, blocked} = TwitterAPI.block(user, %{"screen_name" => blocked.nickname})
+ assert User.blocks?(user, blocked)
+ end
+
+ test "Unblock another user using user_id" do
+ unblocked = insert(:user)
+ user = insert(:user)
+ User.block(user, unblocked)
+
+ {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
+ assert user.info["blocks"] == []
+ end
+
+ test "Unblock another user using screen_name" do
+ unblocked = insert(:user)
+ user = insert(:user)
+ User.block(user, unblocked)
+
+ {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
+ assert user.info["blocks"] == []
+ end
+
test "fetch statuses in a context using the conversation id" do
{:ok, user} = UserBuilder.insert()
- {:ok, activity} = ActivityBuilder.insert(%{"context" => "2hu"})
- {:ok, activity_two} = ActivityBuilder.insert(%{"context" => "2hu"})
- {:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"})
+ {:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
+ {:ok, activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
+ {:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
{:ok, object} = Object.context_mapping("2hu") |> Repo.insert
@@ -239,25 +283,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert is_binary(response)
end
- test "it adds user links to an existing text" do
- text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
-
- gsimg = insert(:user, %{nickname: "gsimg"})
- archaeme = insert(:user, %{nickname: "archaeme"})
- archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
-
- mentions = Pleroma.Formatter.parse_mentions(text)
- expected_text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme"
-
- assert Utils.add_user_links(text, mentions) == expected_text
- end
-
test "it favorites a status, returns the updated status" do
user = insert(:user)
note_activity = insert(:note_activity)
activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
- {:ok, status} = TwitterAPI.favorite(user, note_activity)
+ {:ok, status} = TwitterAPI.fav(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
@@ -273,7 +304,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
assert ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})["fave_num"] == 1
- {:ok, status} = TwitterAPI.unfavorite(user, note_activity)
+ {:ok, status} = TwitterAPI.unfav(user, note_activity.id)
assert status["fave_num"] == 0
end
@@ -283,7 +314,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
note_activity = insert(:note_activity)
activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
- {:ok, status} = TwitterAPI.retweet(user, note_activity)
+ {:ok, status} = TwitterAPI.repeat(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
@@ -357,10 +388,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
remote = User.get_by_ap_id(id)
- assert represented == UserView.render("show.json", %{user: remote, for: user})
+ assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
# Also fetches the feed.
- assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
+ # assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
end
end
end