X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_test.exs;h=bbb261eff3c143459a90b9058b3ba4827fadd3cc;hb=d1c10ad2fb7641c88eec04e9474af143170c507a;hp=da880e67c5652e6b8d5dc6a94b69b20d6f6f73d7;hpb=1af9c777365f3b54edcb572cea4e2e6f185b3099;p=akkoma
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index da880e67c..bbb261eff 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -1,16 +1,15 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
alias Pleroma.Builders.{UserBuilder, ActivityBuilder}
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.TwitterAPI.Utils
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI,UserView,Utils}
alias Pleroma.{Activity, User, Object, Repo}
- alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, UserRepresenter}
+ alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.ActivityPub.ActivityPub
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 = %{
@@ -34,7 +33,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{ :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"
+ assert get_in(activity.data, ["object", "content"]) == "Hello again, @shp.
\nThis is on another line. #2hu #epic #phantasmagoric
\nimage.jpg"
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
@@ -53,10 +52,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."
}
@@ -74,7 +77,7 @@ 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")
+ assert Enum.member?(get_in(reply.data, ["to"]), user.ap_id)
end
test "fetch public statuses, excluding remote ones." do
@@ -188,6 +191,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
assert user.following == [User.ap_followers(followed)]
+ 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."
end
@@ -219,17 +225,17 @@ 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(%{"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
statuses = TwitterAPI.fetch_conversation(user, object.id)
assert length(statuses) == 2
- assert Enum.at(statuses, 0)["id"] == activity.id
- assert Enum.at(statuses, 1)["id"] == activity_two.id
+ assert Enum.at(statuses, 1)["id"] == activity.id
+ assert Enum.at(statuses, 0)["id"] == activity_two.id
end
test "upload a file" do
@@ -303,7 +309,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
fetched_user = Repo.get_by(User, nickname: "lain")
- assert user == UserRepresenter.to_map(fetched_user)
+ assert UserView.render("show.json", %{user: user}) == UserView.render("show.json", %{user: fetched_user})
end
test "it returns the error on registration problems" do
@@ -353,10 +359,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
describe "fetching a user by uri" do
test "fetches a user by uri" do
+ id = "https://mastodon.social/users/lambadalambda"
user = insert(:user)
+ {: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})
- {:ok, represented} = TwitterAPI.get_external_profile(user, user.ap_id)
- assert represented = UserRepresenter.to_map(user, %{for: user})
+ # Also fetches the feed.
+ assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
end
end
end