Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow-by-screen-name
This commit is contained in:
commit
9a8c348aed
42 changed files with 1665 additions and 69 deletions
18
test/activity_test.exs
Normal file
18
test/activity_test.exs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
defmodule Pleroma.ActivityTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "returns an activity by it's AP id" do
|
||||
activity = insert(:note_activity)
|
||||
found_activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
|
||||
|
||||
assert activity == found_activity
|
||||
end
|
||||
|
||||
test "returns activities by it's objects AP ids" do
|
||||
activity = insert(:note_activity)
|
||||
[found_activity] = Pleroma.Activity.all_by_object_ap_id(activity.data["object"]["id"])
|
||||
|
||||
assert activity == found_activity
|
||||
end
|
||||
end
|
||||
11
test/object_test.exs
Normal file
11
test/object_test.exs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
defmodule Pleroma.ObjectTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "returns an object by it's AP id" do
|
||||
object = insert(:note)
|
||||
found_object = Pleroma.Object.get_by_ap_id(object.data["id"])
|
||||
|
||||
assert object == found_object
|
||||
end
|
||||
end
|
||||
67
test/support/factory.ex
Normal file
67
test/support/factory.ex
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
defmodule Pleroma.Factory do
|
||||
use ExMachina.Ecto, repo: Pleroma.Repo
|
||||
|
||||
def user_factory do
|
||||
user = %Pleroma.User{
|
||||
name: sequence(:name, &"Test User #{&1}"),
|
||||
email: sequence(:email, &"user#{&1}@example.com"),
|
||||
nickname: sequence(:nickname, &"nick#{&1}"),
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
|
||||
bio: sequence(:bio, &"Tester Number #{&1}"),
|
||||
}
|
||||
%{ user | ap_id: Pleroma.User.ap_id(user) }
|
||||
end
|
||||
|
||||
def note_factory do
|
||||
text = sequence(:text, &"This is note #{&1}")
|
||||
|
||||
user = insert(:user)
|
||||
data = %{
|
||||
"type" => "Note",
|
||||
"content" => text,
|
||||
"id" => Pleroma.Web.ActivityPub.ActivityPub.generate_object_id,
|
||||
"actor" => user.ap_id,
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
|
||||
"likes" => [],
|
||||
"like_count" => 0
|
||||
}
|
||||
|
||||
%Pleroma.Object{
|
||||
data: data
|
||||
}
|
||||
end
|
||||
|
||||
def note_activity_factory do
|
||||
note = insert(:note)
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.ActivityPub.generate_activity_id,
|
||||
"type" => "Create",
|
||||
"actor" => note.data["actor"],
|
||||
"to" => note.data["to"],
|
||||
"object" => note.data,
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data
|
||||
}
|
||||
end
|
||||
|
||||
def like_activity_factory do
|
||||
note_activity = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.ActivityPub.generate_activity_id,
|
||||
"actor" => user.ap_id,
|
||||
"type" => "Like",
|
||||
"object" => note_activity.data["object"]["id"],
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
ExUnit.start()
|
||||
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
|
||||
{:ok, _} = Application.ensure_all_started(:ex_machina)
|
||||
|
||||
|
|
|
|||
|
|
@ -53,4 +53,35 @@ defmodule Pleroma.UserTest do
|
|||
assert User.following?(user, followed)
|
||||
refute User.following?(followed, user)
|
||||
end
|
||||
|
||||
describe "user registration" do
|
||||
@full_user_data %{
|
||||
bio: "A guy",
|
||||
name: "my name",
|
||||
nickname: "nick",
|
||||
password: "test",
|
||||
password_confirmation: "test",
|
||||
email: "email@example.com"
|
||||
}
|
||||
|
||||
test "it requires a bio, email, name, nickname and password" do
|
||||
@full_user_data
|
||||
|> Map.keys
|
||||
|> Enum.each(fn (key) ->
|
||||
params = Map.delete(@full_user_data, key)
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
assert changeset.valid? == false
|
||||
end)
|
||||
end
|
||||
|
||||
test "it sets the password_hash, ap_id and following fields" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
assert changeset.valid?
|
||||
|
||||
assert is_binary(changeset.changes[:password_hash])
|
||||
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
|
||||
assert changeset.changes[:following] == [User.ap_followers(%User{nickname: @full_user_data.nickname})]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.{Activity, Object}
|
||||
alias Pleroma.{Activity, Object, User}
|
||||
alias Pleroma.Builders.ActivityBuilder
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "insertion" do
|
||||
test "inserts a given map into the activity database, giving it an id if it has none." do
|
||||
data = %{
|
||||
|
|
@ -94,6 +96,85 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert length(activities) == 10
|
||||
assert last == last_expected
|
||||
end
|
||||
|
||||
test "retrieves ids up to max_id" do
|
||||
_first_activities = ActivityBuilder.insert_list(10)
|
||||
activities = ActivityBuilder.insert_list(20)
|
||||
later_activities = ActivityBuilder.insert_list(10)
|
||||
max_id = List.first(later_activities).id
|
||||
last_expected = List.last(activities)
|
||||
|
||||
activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id})
|
||||
last = List.last(activities)
|
||||
|
||||
assert length(activities) == 20
|
||||
assert last == last_expected
|
||||
end
|
||||
end
|
||||
|
||||
describe "like an object" do
|
||||
test "adds a like activity to the db" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||
|
||||
assert like_activity.data["actor"] == user.ap_id
|
||||
assert like_activity.data["type"] == "Like"
|
||||
assert like_activity.data["object"] == object.data["id"]
|
||||
assert like_activity.data["to"] == [User.ap_followers(user), note_activity.data["actor"]]
|
||||
assert object.data["like_count"] == 1
|
||||
assert object.data["likes"] == [user.ap_id]
|
||||
|
||||
# Just return the original activity if the user already liked it.
|
||||
{:ok, same_like_activity, object} = ActivityPub.like(user, object)
|
||||
|
||||
assert like_activity == same_like_activity
|
||||
assert object.data["likes"] == [user.ap_id]
|
||||
|
||||
[note_activity] = Activity.all_by_object_ap_id(object.data["id"])
|
||||
assert note_activity.data["object"]["like_count"] == 1
|
||||
|
||||
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
|
||||
assert object.data["like_count"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "unliking" do
|
||||
test "unliking a previously liked object" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
user = insert(:user)
|
||||
|
||||
# Unliking something that hasn't been liked does nothing
|
||||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
assert Repo.get(Activity, like_activity.id) == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "announcing an object" do
|
||||
test "adds an announce activity to the db" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
|
||||
assert object.data["announcement_count"] == 1
|
||||
assert object.data["announcements"] == [user.ap_id]
|
||||
assert announce_activity.data["to"] == [User.ap_followers(user), note_activity.data["actor"]]
|
||||
assert announce_activity.data["object"] == object.data["id"]
|
||||
assert announce_activity.data["actor"] == user.ap_id
|
||||
end
|
||||
end
|
||||
|
||||
describe "uploading files" do
|
||||
|
|
|
|||
|
|
@ -2,7 +2,46 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
use Pleroma.DataCase
|
||||
alias Pleroma.{User, Activity, Object}
|
||||
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Builders.UserBuilder
|
||||
import Pleroma.Factory
|
||||
|
||||
test "an announce activity" do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity)
|
||||
activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
|
||||
{:ok, announce_activity, _object} = ActivityPub.announce(user, object)
|
||||
note_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
||||
|
||||
status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user})
|
||||
|
||||
assert status["id"] == announce_activity.id
|
||||
assert status["user"] == UserRepresenter.to_map(user, %{for: user})
|
||||
|
||||
retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
|
||||
assert retweeted_status["repeated"] == true
|
||||
|
||||
assert status["retweeted_status"] == retweeted_status
|
||||
end
|
||||
|
||||
test "a like activity" do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object)
|
||||
status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
|
||||
|
||||
assert status["id"] == like_activity.id
|
||||
assert status["in_reply_to_status_id"] == note_activity.id
|
||||
|
||||
note_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
||||
activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||
liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
|
||||
assert liked_status["favorited"] == true
|
||||
end
|
||||
|
||||
test "an activity" do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
|
|
@ -23,8 +62,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
}
|
||||
}
|
||||
|
||||
content = "Some content mentioning @shp"
|
||||
date = DateTime.utc_now() |> DateTime.to_iso8601
|
||||
content_html = "Some content mentioning <a href='shp'>@shp</shp>"
|
||||
content = HtmlSanitizeEx.strip_tags(content_html)
|
||||
date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
|
||||
|
||||
activity = %Activity{
|
||||
id: 1,
|
||||
|
|
@ -39,12 +79,14 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"object" => %{
|
||||
"published" => date,
|
||||
"type" => "Note",
|
||||
"content" => content,
|
||||
"content" => content_html,
|
||||
"inReplyToStatusId" => 213123,
|
||||
"statusnetConversationId" => 4711,
|
||||
"attachment" => [
|
||||
object
|
||||
]
|
||||
],
|
||||
"like_count" => 5,
|
||||
"announcement_count" => 3
|
||||
},
|
||||
"published" => date
|
||||
}
|
||||
|
|
@ -56,10 +98,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"user" => UserRepresenter.to_map(user, %{for: follower}),
|
||||
"is_local" => true,
|
||||
"attentions" => [],
|
||||
"statusnet_html" => content,
|
||||
"statusnet_html" => content_html,
|
||||
"text" => content,
|
||||
"is_post_verb" => true,
|
||||
"created_at" => date,
|
||||
"created_at" => "Tue May 24 13:26:08 +0000 2016",
|
||||
"in_reply_to_status_id" => 213123,
|
||||
"statusnet_conversation_id" => 4711,
|
||||
"attachments" => [
|
||||
|
|
@ -67,7 +109,11 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
],
|
||||
"attentions" => [
|
||||
UserRepresenter.to_map(mentioned_user, %{for: follower})
|
||||
]
|
||||
],
|
||||
"fave_num" => 5,
|
||||
"repeat_num" => 3,
|
||||
"favorited" => false,
|
||||
"repeated" => false
|
||||
}
|
||||
|
||||
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter}
|
||||
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
|
||||
alias Pleroma.{Repo, Activity, User}
|
||||
alias Pleroma.{Repo, Activity, User, Object}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "POST /api/account/verify_credentials" do
|
||||
setup [:valid_user]
|
||||
|
|
@ -127,7 +130,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.following == [User.ap_followers(followed)]
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(followed)
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(followed, %{for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -150,7 +153,104 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.following == []
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(followed)
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(followed, %{for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/favorites/create/:id" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
conn = post conn, "/api/favorites/create/#{note_activity.id}.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/favorites/create/#{note_activity.id}.json")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/favorites/destroy/:id" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
conn = post conn, "/api/favorites/destroy/#{note_activity.id}.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
ActivityPub.like(current_user, object)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/favorites/destroy/#{note_activity.id}.json")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/statuses/retweet/:id" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
conn = post conn, "/api/statuses/retweet/#{note_activity.id}.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/statuses/retweet/#{note_activity.id}.json")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/account/register" do
|
||||
test "it creates a new user", %{conn: conn} do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "close the world.",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
}
|
||||
|
||||
conn = conn
|
||||
|> post("/api/account/register", data)
|
||||
|
||||
user = json_response(conn, 200)
|
||||
|
||||
fetched_user = Repo.get_by(User, nickname: "lain")
|
||||
assert user == UserRepresenter.to_map(fetched_user)
|
||||
end
|
||||
|
||||
test "it returns errors on a problem", %{conn: conn} do
|
||||
data = %{
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "close the world.",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
}
|
||||
|
||||
conn = conn
|
||||
|> post("/api/account/register", data)
|
||||
|
||||
errors = json_response(conn, 400)
|
||||
|
||||
assert is_binary(errors["error"])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -163,4 +263,10 @@ 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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
alias Pleroma.Builders.{UserBuilder, ActivityBuilder}
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.{Activity, User, Object, Repo}
|
||||
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
||||
alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, UserRepresenter}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "create a status" do
|
||||
user = UserBuilder.build(%{ap_id: "142344"})
|
||||
|
|
@ -24,14 +27,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
object = Repo.insert!(%Object{data: object_data})
|
||||
|
||||
input = %{
|
||||
"status" => "Hello again, @shp.<script></script>",
|
||||
"status" => "Hello again, @shp.<script></script>\nThis is on another line.",
|
||||
"media_ids" => [object.id]
|
||||
}
|
||||
|
||||
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
|
||||
assert get_in(activity.data, ["object", "content"]) == "Hello again, <a href='shp'>@shp</a>."
|
||||
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", "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")
|
||||
|
|
@ -44,6 +48,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert get_in(activity.data, ["statusnetConversationId"]) == activity.id
|
||||
|
||||
assert is_list(activity.data["object"]["attachment"])
|
||||
|
||||
assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data
|
||||
end
|
||||
|
||||
test "create a status that is a reply" do
|
||||
|
|
@ -82,15 +88,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "fetch friends' statuses" do
|
||||
ActivityBuilder.public_and_non_public
|
||||
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"to" => ["someguy/followers"]})
|
||||
{:ok, direct_activity} = ActivityBuilder.insert(%{"to" => ["some other id"]})
|
||||
{:ok, user} = UserBuilder.insert(%{ap_id: "some other id", following: ["someguy/followers"]})
|
||||
|
||||
statuses = TwitterAPI.fetch_friend_statuses(user)
|
||||
|
||||
activity_user = Repo.get_by(User, ap_id: activity.data["actor"])
|
||||
|
||||
assert length(statuses) == 1
|
||||
assert length(statuses) == 2
|
||||
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user})
|
||||
assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: activity_user, mentioned: [user]})
|
||||
end
|
||||
|
||||
test "fetch a single status" do
|
||||
|
|
@ -184,4 +193,78 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
assert TwitterAPI.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)
|
||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
||||
|
||||
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
|
||||
end
|
||||
|
||||
test "it unfavorites 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"])
|
||||
object = Object.get_by_ap_id(note_activity.data["object"]["id"])
|
||||
|
||||
{:ok, _like_activity, _object } = ActivityPub.like(user, object)
|
||||
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)
|
||||
|
||||
assert status["fave_num"] == 0
|
||||
end
|
||||
|
||||
test "it retweets a status and returns the retweet" do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity)
|
||||
activity_user = Repo.get_by!(User, ap_id: note_activity.data["actor"])
|
||||
|
||||
{:ok, status} = TwitterAPI.retweet(user, note_activity)
|
||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
||||
|
||||
assert status == ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
|
||||
end
|
||||
|
||||
test "it registers a new user and returns the user." do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "close the world.",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
||||
fetched_user = Repo.get_by(User, nickname: "lain")
|
||||
assert user == UserRepresenter.to_map(fetched_user)
|
||||
end
|
||||
|
||||
test "it returns the error on registration problems" do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "close the world.",
|
||||
"password" => "bear"
|
||||
}
|
||||
|
||||
{:error, error_object} = TwitterAPI.register_user(data)
|
||||
|
||||
assert is_binary(error_object[:error])
|
||||
refute Repo.get_by(User, nickname: "lain")
|
||||
end
|
||||
|
||||
setup do
|
||||
Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
|
||||
Supervisor.restart_child(Pleroma.Supervisor, ConCache)
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue