Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into bugfix/repeated-follow-unfollow
This commit is contained in:
commit
ef5033d7a7
47 changed files with 1721 additions and 92 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
|
||||
|
|
@ -3,7 +3,7 @@ defmodule Pleroma.Builders.ActivityBuilder do
|
|||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
||||
def build(data \\ %{}, opts \\ %{}) do
|
||||
user = opts[:user] || UserBuilder.build
|
||||
user = opts[:user] || Pleroma.Factory.insert(:user)
|
||||
activity = %{
|
||||
"id" => 1,
|
||||
"actor" => user.ap_id,
|
||||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Builders.ActivityBuilder do
|
|||
end
|
||||
|
||||
def public_and_non_public do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
user = Pleroma.Factory.insert(:user)
|
||||
|
||||
public = build(%{"id" => 1}, %{user: user})
|
||||
non_public = build(%{"id" => 2, "to" => []}, %{user: user})
|
||||
|
|
|
|||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ defmodule Pleroma.UserTest do
|
|||
alias Pleroma.User
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "ap_id returns the activity pub id for the user" do
|
||||
host =
|
||||
Application.get_env(:pleroma, Pleroma.Web.Endpoint)
|
||||
|
|
@ -25,21 +27,21 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
|
||||
test "follow takes a user and another user" do
|
||||
{ :ok, user } = UserBuilder.insert
|
||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user } = User.follow(user, following)
|
||||
{:ok, user } = User.follow(user, followed)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
|
||||
assert user.following == [User.ap_followers(following)]
|
||||
assert user.following == [User.ap_followers(followed)]
|
||||
end
|
||||
|
||||
test "unfollow takes a user and another user" do
|
||||
{ :ok, following } = UserBuilder.insert(%{nickname: "guy"})
|
||||
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(following)]})
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
||||
{:ok, user } = User.unfollow(user, following)
|
||||
{:ok, user } = User.unfollow(user, followed)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
|
||||
|
|
@ -47,10 +49,41 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
|
||||
test "test if a user is following another user" do
|
||||
{ :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
|
||||
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(followed)]})
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
||||
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
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -2,12 +2,54 @@ 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
|
||||
{:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
||||
# {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
mentioned_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
# {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
||||
follower = insert(:user, %{following: [User.ap_followers(user)]})
|
||||
|
||||
object = %Object{
|
||||
data: %{
|
||||
|
|
@ -23,7 +65,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
}
|
||||
}
|
||||
|
||||
content_html = "Some content mentioning <a href='shp'>@shp</shp>"
|
||||
content_html = "Some content mentioning <a href='#{mentioned_user.ap_id}'>@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
|
||||
|
||||
|
|
@ -45,7 +87,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"statusnetConversationId" => 4711,
|
||||
"attachment" => [
|
||||
object
|
||||
]
|
||||
],
|
||||
"like_count" => 5,
|
||||
"announcement_count" => 3
|
||||
},
|
||||
"published" => date
|
||||
}
|
||||
|
|
@ -68,7 +112,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
|
||||
|
|
|
|||
|
|
@ -5,13 +5,23 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
|
|||
alias Pleroma.Web.TwitterAPI.Representers.UserRepresenter
|
||||
alias Pleroma.Builders.UserBuilder
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
user = insert(:user)
|
||||
[user: user]
|
||||
end
|
||||
|
||||
test "A user with an avatar object", %{user: user} do
|
||||
image = "image"
|
||||
user = %{ user | avatar: %{ "url" => [%{"href" => image}] }}
|
||||
represented = UserRepresenter.to_map(user)
|
||||
assert represented["profile_image_url"] == image
|
||||
end
|
||||
|
||||
test "A user", %{user: user} do
|
||||
image = "https://placehold.it/48x48"
|
||||
|
||||
represented = %{
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
@ -91,10 +94,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
user = insert(:user)
|
||||
activities = ActivityBuilder.insert_list(30, %{"to" => [User.ap_followers(user)]}, %{user: user})
|
||||
returned_activities = ActivityBuilder.insert_list(10, %{"to" => [User.ap_followers(user)]}, %{user: user})
|
||||
{:ok, other_user} = UserBuilder.insert(%{ap_id: "glimmung", nickname: "nockame"})
|
||||
other_user = insert(:user)
|
||||
ActivityBuilder.insert_list(10, %{}, %{user: other_user})
|
||||
since_id = List.last(activities).id
|
||||
|
||||
|
|
@ -107,7 +110,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
response = json_response(conn, 200)
|
||||
|
||||
assert length(response) == 10
|
||||
assert response == Enum.map(returned_activities, fn (activity) -> ActivityRepresenter.to_map(activity, %{user: user, for: current_user}) end)
|
||||
assert response == Enum.map(returned_activities, fn (activity) -> ActivityRepresenter.to_map(activity, %{user: User.get_cached_by_ap_id(activity.data["actor"]), for: current_user}) end)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -119,7 +122,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, followed } = UserBuilder.insert(%{name: "some guy"})
|
||||
followed = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|
|
@ -139,7 +142,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, followed } = UserBuilder.insert(%{name: "some guy"})
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, current_user} = User.follow(current_user, followed)
|
||||
assert current_user.following == [User.ap_followers(followed)]
|
||||
|
|
@ -154,6 +157,121 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /api/qvitter/update_avatar.json" do
|
||||
setup [:valid_user]
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/qvitter/update_avatar.json"
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/qvitter/update_avatar.json", %{img: Pleroma.Web.ActivityPub.ActivityPubTest.data_uri})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert is_map(current_user.avatar)
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(current_user, %{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
|
||||
|
||||
defp valid_user(_context) do
|
||||
{ :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"})
|
||||
[user: user]
|
||||
|
|
@ -163,4 +281,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
|
||||
|
|
@ -72,7 +78,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "fetch public statuses" do
|
||||
%{ public: activity, user: user } = ActivityBuilder.public_and_non_public
|
||||
{:ok, follower } = UserBuilder.insert(%{name: "dude", ap_id: "idididid", following: [User.ap_followers(user)]})
|
||||
|
||||
follower = insert(:user, following: [User.ap_followers(user)])
|
||||
|
||||
statuses = TwitterAPI.fetch_public_statuses(follower)
|
||||
|
||||
|
|
@ -81,19 +88,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "fetch friends' statuses" do
|
||||
ActivityBuilder.public_and_non_public
|
||||
|
||||
user = insert(:user, %{following: ["someguy/followers"]})
|
||||
{: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"]})
|
||||
{:ok, direct_activity} = ActivityBuilder.insert(%{"to" => [user.ap_id]})
|
||||
|
||||
statuses = TwitterAPI.fetch_friend_statuses(user)
|
||||
|
||||
activity_user = Repo.get_by(User, ap_id: activity.data["actor"])
|
||||
direct_activity_user = Repo.get_by(User, ap_id: direct_activity.data["actor"])
|
||||
|
||||
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]})
|
||||
assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]})
|
||||
end
|
||||
|
||||
test "fetch a single status" do
|
||||
|
|
@ -107,8 +113,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "Follow another user" do
|
||||
{ :ok, user } = UserBuilder.insert
|
||||
{ :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{ :ok, user, followed, activity } = TwitterAPI.follow(user, followed.id)
|
||||
|
||||
|
|
@ -123,8 +129,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "Unfollow another user" do
|
||||
{ :ok, followed } = UserBuilder.insert(%{nickname: "guy"})
|
||||
{ :ok, user } = UserBuilder.insert(%{following: [User.ap_followers(followed)]})
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
|
||||
{ :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
|
||||
|
||||
|
|
@ -159,8 +165,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
test "it can parse mentions and return the relevant users" do
|
||||
text = "@gsimg According to @archaeme , that is @daggsy."
|
||||
|
||||
{:ok, gsimg} = UserBuilder.insert(%{nickname: "gsimg"})
|
||||
{:ok, archaeme} = UserBuilder.insert(%{nickname: "archaeme"})
|
||||
gsimg = insert(:user, %{nickname: "gsimg"})
|
||||
archaeme = insert(:user, %{nickname: "archaeme"})
|
||||
|
||||
expected_result = [
|
||||
{"@gsimg", gsimg},
|
||||
|
|
@ -173,12 +179,86 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
test "it adds user links to an existing text" do
|
||||
text = "@gsimg According to @archaeme , that is @daggsy."
|
||||
|
||||
{:ok, _gsimg} = UserBuilder.insert(%{nickname: "gsimg", ap_id: "first_link" })
|
||||
{:ok, _archaeme} = UserBuilder.insert(%{nickname: "archaeme", ap_id: "second_link"})
|
||||
gsimg = insert(:user, %{nickname: "gsimg"})
|
||||
archaeme = insert(:user, %{nickname: "archaeme"})
|
||||
|
||||
mentions = TwitterAPI.parse_mentions(text)
|
||||
expected_text = "<a href='first_link'>@gsimg</a> According to <a href='second_link'>@archaeme</a> , that is @daggsy."
|
||||
expected_text = "<a href='#{gsimg.ap_id}'>@gsimg</a> According to <a href='#{archaeme.ap_id}'>@archaeme</a> , that is @daggsy."
|
||||
|
||||
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