Format the code.
This commit is contained in:
parent
480932c8e5
commit
4afbef39f4
111 changed files with 4912 additions and 2769 deletions
|
|
@ -16,12 +16,19 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
{: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})
|
||||
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"] == UserView.render("show.json", %{user: user, for: user})
|
||||
|
||||
retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
|
||||
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"]
|
||||
|
|
@ -36,7 +43,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
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})
|
||||
|
||||
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
|
||||
|
|
@ -49,7 +58,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
end
|
||||
|
||||
test "an activity" do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
{:ok, user} = UserBuilder.insert()
|
||||
# {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
|
||||
mentioned_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
|
|
@ -70,16 +79,20 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
}
|
||||
}
|
||||
|
||||
content_html = "<script>alert('YAY')</script>Some :2hu: 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
|
||||
content_html =
|
||||
"<script>alert('YAY')</script>Some :2hu: 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()
|
||||
|
||||
{:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert()
|
||||
|
||||
{:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
|
||||
to = [
|
||||
User.ap_followers(user),
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
mentioned_user.ap_id
|
||||
]
|
||||
|
||||
activity = %Activity{
|
||||
id: 1,
|
||||
data: %{
|
||||
|
|
@ -92,7 +105,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"type" => "Note",
|
||||
"content" => content_html,
|
||||
"summary" => "2hu",
|
||||
"inReplyToStatusId" => 213123,
|
||||
"inReplyToStatusId" => 213_123,
|
||||
"attachment" => [
|
||||
object
|
||||
],
|
||||
|
|
@ -112,7 +125,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
recipients: to
|
||||
}
|
||||
|
||||
expected_html = "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{mentioned_user.ap_id}\">@shp</a>"
|
||||
expected_html =
|
||||
"<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
|
||||
mentioned_user.ap_id
|
||||
}\">@shp</a>"
|
||||
|
||||
expected_status = %{
|
||||
"id" => activity.id,
|
||||
|
|
@ -122,7 +138,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"text" => "2hu" <> content,
|
||||
"is_post_verb" => true,
|
||||
"created_at" => "Tue May 24 13:26:08 +0000 2016",
|
||||
"in_reply_to_status_id" => 213123,
|
||||
"in_reply_to_status_id" => 213_123,
|
||||
"statusnet_conversation_id" => convo_object.id,
|
||||
"attachments" => [
|
||||
ObjectRepresenter.to_map(object)
|
||||
|
|
@ -141,7 +157,11 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
|
|||
"uri" => activity.data["object"]["id"]
|
||||
}
|
||||
|
||||
assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
|
||||
assert ActivityRepresenter.to_map(activity, %{
|
||||
user: user,
|
||||
for: follower,
|
||||
mentioned: [mentioned_user]
|
||||
}) == expected_status
|
||||
end
|
||||
|
||||
test "an undo for a follow" do
|
||||
|
|
|
|||
|
|
@ -34,13 +34,16 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
|
|||
id: nil,
|
||||
data: %{
|
||||
"mediaType" => "image/png",
|
||||
"name" => "blabla", "type" => "Document",
|
||||
"url" => "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
|
||||
"name" => "blabla",
|
||||
"type" => "Document",
|
||||
"url" =>
|
||||
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
|
||||
}
|
||||
}
|
||||
|
||||
expected_object = %{
|
||||
url: "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
|
||||
url:
|
||||
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
|
||||
mimetype: "image/png",
|
||||
oembed: false,
|
||||
id: nil
|
||||
|
|
|
|||
|
|
@ -12,13 +12,15 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "POST /api/account/verify_credentials" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/account/verify_credentials.json"
|
||||
conn = post(conn, "/api/account/verify_credentials.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: user} do
|
||||
conn = conn
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(user.nickname, "test")
|
||||
|> post("/api/account/verify_credentials.json")
|
||||
|
||||
|
|
@ -29,13 +31,15 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "POST /api/account/most_recent_notification" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/account/most_recent_notification.json"
|
||||
conn = post(conn, "/api/account/most_recent_notification.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: user} do
|
||||
conn = conn
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(user.nickname, "test")
|
||||
|> post("/api/account/most_recent_notification.json", %{id: "200"})
|
||||
|
||||
|
|
@ -47,8 +51,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "POST /statuses/update.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/statuses/update.json"
|
||||
conn = post(conn, "/api/statuses/update.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
|
|
@ -56,30 +61,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
conn_with_creds = conn |> with_credentials(user.nickname, "test")
|
||||
request_path = "/api/statuses/update.json"
|
||||
|
||||
error_response = %{"request" => request_path,
|
||||
"error" => "Client must provide a 'status' parameter with a value."}
|
||||
error_response = %{
|
||||
"request" => request_path,
|
||||
"error" => "Client must provide a 'status' parameter with a value."
|
||||
}
|
||||
|
||||
conn = conn_with_creds |> post(request_path)
|
||||
assert json_response(conn, 400) == error_response
|
||||
|
||||
conn = conn_with_creds |> post(request_path, %{ status: "" })
|
||||
conn = conn_with_creds |> post(request_path, %{status: ""})
|
||||
assert json_response(conn, 400) == error_response
|
||||
|
||||
conn = conn_with_creds |> post(request_path, %{ status: " " })
|
||||
conn = conn_with_creds |> post(request_path, %{status: " "})
|
||||
assert json_response(conn, 400) == error_response
|
||||
|
||||
conn = conn_with_creds |> post(request_path, %{ status: "Nice meme." })
|
||||
assert json_response(conn, 200) == ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
||||
conn = conn_with_creds |> post(request_path, %{status: "Nice meme."})
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /statuses/public_timeline.json" do
|
||||
test "returns statuses", %{conn: conn} do
|
||||
{:ok, user} = UserBuilder.insert
|
||||
{:ok, user} = UserBuilder.insert()
|
||||
activities = ActivityBuilder.insert_list(30, %{}, %{user: user})
|
||||
ActivityBuilder.insert_list(10, %{}, %{user: user})
|
||||
since_id = List.last(activities).id
|
||||
|
||||
conn = conn
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/statuses/public_timeline.json", %{since_id: since_id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
|
@ -94,8 +105,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
|
||||
actor = Repo.get_by!(User, ap_id: activity.data["actor"])
|
||||
|
||||
conn = conn
|
||||
|> get("/api/statuses/show/#{activity.id}.json")
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/statuses/show/#{activity.id}.json")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -107,8 +119,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "gets user with screen_name", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/users/show.json", %{"screen_name" => user.nickname})
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/users/show.json", %{"screen_name" => user.nickname})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -118,8 +131,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "gets user with user_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -132,9 +146,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
{:ok, logged_in, user, _activity} = TwitterAPI.follow(logged_in, %{"user_id" => user.id})
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(logged_in.nickname, "test")
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(logged_in.nickname, "test")
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -144,14 +159,16 @@ 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, _user} = UserBuilder.insert()
|
||||
{: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
|
||||
conn = conn
|
||||
|> get("/api/statusnet/conversation/#{object.id}.json")
|
||||
{:ok, object} = Object.context_mapping("2hu") |> Repo.insert()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/statusnet/conversation/#{object.id}.json")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -161,58 +178,87 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "GET /statuses/friends_timeline.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = get conn, "/api/statuses/friends_timeline.json"
|
||||
conn = get(conn, "/api/statuses/friends_timeline.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
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})
|
||||
|
||||
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})
|
||||
|
||||
other_user = insert(:user)
|
||||
ActivityBuilder.insert_list(10, %{}, %{user: other_user})
|
||||
since_id = List.last(activities).id
|
||||
|
||||
current_user = Ecto.Changeset.change(current_user, following: [User.ap_followers(user)]) |> Repo.update!
|
||||
current_user =
|
||||
Ecto.Changeset.change(current_user, following: [User.ap_followers(user)])
|
||||
|> Repo.update!()
|
||||
|
||||
conn = conn
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/friends_timeline.json", %{since_id: since_id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert length(response) == 10
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
describe "GET /statuses/mentions.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = get conn, "/api/statuses/mentions.json"
|
||||
conn = get(conn, "/api/statuses/mentions.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
|
||||
{:ok, activity} =
|
||||
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
|
||||
|
||||
conn = conn
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/mentions.json")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert length(response) == 1
|
||||
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: current_user, mentioned: [current_user]})
|
||||
|
||||
assert Enum.at(response, 0) ==
|
||||
ActivityRepresenter.to_map(activity, %{
|
||||
user: current_user,
|
||||
mentioned: [current_user]
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /statuses/user_timeline.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without any params", %{conn: conn} do
|
||||
conn = get(conn, "/api/statuses/user_timeline.json")
|
||||
assert json_response(conn, 400) == %{"error" => "You need to specify screen_name or user_id", "request" => "/api/statuses/user_timeline.json"}
|
||||
|
||||
assert json_response(conn, 400) == %{
|
||||
"error" => "You need to specify screen_name or user_id",
|
||||
"request" => "/api/statuses/user_timeline.json"
|
||||
}
|
||||
end
|
||||
|
||||
test "with user_id", %{conn: conn} do
|
||||
|
|
@ -237,9 +283,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: current_user})
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/user_timeline.json")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/user_timeline.json")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -250,9 +298,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "with credentials with user_id", %{conn: conn, user: current_user} do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/user_timeline.json", %{"user_id" => user.id})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/user_timeline.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -263,9 +313,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "with credentials screen_name", %{conn: conn, user: current_user} do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> get("/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
|
|
@ -276,28 +328,33 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
describe "POST /friendships/create.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/friendships/create.json"
|
||||
conn = post(conn, "/api/friendships/create.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
followed = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/friendships/create.json", %{user_id: followed.id})
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/friendships/create.json", %{user_id: followed.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert User.ap_followers(followed) in current_user.following
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: followed, for: current_user})
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: followed, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /friendships/destroy.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/friendships/destroy.json"
|
||||
conn = post(conn, "/api/friendships/destroy.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
|
|
@ -308,40 +365,48 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
assert User.ap_followers(followed) in current_user.following
|
||||
ActivityPub.follow(current_user, followed)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.following == [current_user.ap_id]
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: followed, for: current_user})
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: followed, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /blocks/create.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/blocks/create.json"
|
||||
conn = post(conn, "/api/blocks/create.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials", %{conn: conn, user: current_user} do
|
||||
blocked = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/blocks/create.json", %{user_id: blocked.id})
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/blocks/create.json", %{user_id: blocked.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert User.blocks?(current_user, blocked)
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user})
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: blocked, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /blocks/destroy.json" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without valid credentials", %{conn: conn} do
|
||||
conn = post conn, "/api/blocks/destroy.json"
|
||||
conn = post(conn, "/api/blocks/destroy.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
|
|
@ -351,56 +416,66 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, current_user} = User.block(current_user, blocked)
|
||||
assert User.blocks?(current_user, blocked)
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert current_user.info["blocks"] == []
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: blocked, for: current_user})
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: blocked, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /help/test.json" do
|
||||
test "returns \"ok\"", %{conn: conn} do
|
||||
conn = get conn, "/api/help/test.json"
|
||||
conn = get(conn, "/api/help/test.json")
|
||||
assert json_response(conn, 200) == "ok"
|
||||
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"
|
||||
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
|
||||
avatar_image = File.read!("test/fixtures/avatar_data_uri")
|
||||
conn = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
|
||||
|
||||
current_user = Repo.get(User, current_user.id)
|
||||
assert is_map(current_user.avatar)
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: current_user, for: current_user})
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("show.json", %{user: 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"
|
||||
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")
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/favorites/create/#{note_activity.id}.json")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
|
|
@ -408,9 +483,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
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"
|
||||
conn = post(conn, "/api/favorites/destroy/#{note_activity.id}.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
|
|
@ -419,9 +495,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
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")
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/favorites/destroy/#{note_activity.id}.json")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
|
|
@ -429,9 +506,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
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"
|
||||
conn = post(conn, "/api/statuses/retweet/#{note_activity.id}.json")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
|
|
@ -440,12 +518,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
|
||||
request_path = "/api/statuses/retweet/#{note_activity.id}.json"
|
||||
|
||||
response = conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post(request_path)
|
||||
response =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post(request_path)
|
||||
|
||||
activity = Repo.get(Activity, note_activity.id)
|
||||
activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||
assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
|
||||
|
||||
assert json_response(response, 200) ==
|
||||
ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -460,8 +542,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
"confirm" => "bear"
|
||||
}
|
||||
|
||||
conn = conn
|
||||
|> post("/api/account/register", data)
|
||||
conn =
|
||||
conn
|
||||
|> post("/api/account/register", data)
|
||||
|
||||
user = json_response(conn, 200)
|
||||
|
||||
|
|
@ -478,8 +561,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
"confirm" => "bear"
|
||||
}
|
||||
|
||||
conn = conn
|
||||
|> post("/api/account/register", data)
|
||||
conn =
|
||||
conn
|
||||
|> post("/api/account/register", data)
|
||||
|
||||
errors = json_response(conn, 400)
|
||||
|
||||
|
|
@ -492,9 +576,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
|
||||
|
||||
assert json_response(conn, 200) == UserView.render("show.json", %{user: other_user})
|
||||
end
|
||||
|
|
@ -510,11 +595,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, follower_one} = User.follow(follower_one, user)
|
||||
{:ok, follower_two} = User.follow(follower_two, user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/statuses/followers")
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/statuses/followers")
|
||||
|
||||
assert json_response(conn, 200) == UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
|
||||
assert json_response(conn, 200) ==
|
||||
UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -528,11 +615,17 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/statuses/friends")
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/statuses/friends")
|
||||
|
||||
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
|
||||
assert MapSet.equal?(
|
||||
MapSet.new(json_response(conn, 200)),
|
||||
MapSet.new(
|
||||
UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
test "it returns a given user's friends with user_id", %{conn: conn} do
|
||||
|
|
@ -544,10 +637,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
||||
|
||||
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
|
||||
assert MapSet.equal?(
|
||||
MapSet.new(json_response(conn, 200)),
|
||||
MapSet.new(
|
||||
UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
||||
|
|
@ -559,10 +658,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/statuses/friends", %{"screen_name" => user.nickname})
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/statuses/friends", %{"screen_name" => user.nickname})
|
||||
|
||||
assert MapSet.equal?(MapSet.new(json_response(conn, 200)), MapSet.new(UserView.render("index.json", %{users: [followed_one, followed_two], for: user})))
|
||||
assert MapSet.equal?(
|
||||
MapSet.new(json_response(conn, 200)),
|
||||
MapSet.new(
|
||||
UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -576,12 +681,17 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/friends/ids")
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/friends/ids")
|
||||
|
||||
expected = [followed_one.id, followed_two.id]
|
||||
assert MapSet.equal?(MapSet.new(Poison.decode!(json_response(conn, 200))), MapSet.new(expected))
|
||||
|
||||
assert MapSet.equal?(
|
||||
MapSet.new(Poison.decode!(json_response(conn, 200))),
|
||||
MapSet.new(expected)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -589,9 +699,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
test "it updates a user's profile", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/account/update_profile.json", %{"name" => "new name", "description" => "new description"})
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/account/update_profile.json", %{
|
||||
"name" => "new name",
|
||||
"description" => "new description"
|
||||
})
|
||||
|
||||
user = Repo.get!(User, user.id)
|
||||
assert user.name == "new name"
|
||||
|
|
@ -619,8 +733,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
|
||||
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
|
||||
|
||||
conn = conn
|
||||
|> get("/api/search.json", %{"q" => "2hu", "page" => "1", "rpp" => "1"})
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/search.json", %{"q" => "2hu", "page" => "1", "rpp" => "1"})
|
||||
|
||||
assert [status] = json_response(conn, 200)
|
||||
assert status["id"] == activity.id
|
||||
|
|
@ -635,8 +750,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about #2hu"})
|
||||
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
|
||||
|
||||
conn = conn
|
||||
|> get("/api/statusnet/tags/timeline/2hu.json")
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/statusnet/tags/timeline/2hu.json")
|
||||
|
||||
assert [status] = json_response(conn, 200)
|
||||
assert status["id"] == activity.id
|
||||
|
|
|
|||
|
|
@ -28,23 +28,32 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
object = Repo.insert!(%Object{data: object_data})
|
||||
|
||||
input = %{
|
||||
"status" => "Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
|
||||
"status" =>
|
||||
"Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
|
||||
"media_ids" => [object.id]
|
||||
}
|
||||
|
||||
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
|
||||
|
||||
expected_text =
|
||||
"Hello again, <span><a href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
|
||||
expected_text = "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
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, ["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"]),
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
)
|
||||
|
||||
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"]
|
||||
assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
|
||||
activity.data["object"]["emoji"]
|
||||
|
||||
# hashtags
|
||||
assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
|
||||
|
|
@ -64,27 +73,31 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "create a status that is a reply" do
|
||||
user = insert(:user)
|
||||
|
||||
input = %{
|
||||
"status" => "Hello again."
|
||||
}
|
||||
|
||||
{ :ok, activity = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
|
||||
|
||||
input = %{
|
||||
"status" => "Here's your (you).",
|
||||
"in_reply_to_status_id" => activity.id
|
||||
}
|
||||
|
||||
{ :ok, reply = %Activity{} } = TwitterAPI.create_status(user, input)
|
||||
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
|
||||
|
||||
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, ["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
|
||||
end
|
||||
|
||||
test "fetch public statuses, excluding remote ones." do
|
||||
%{ public: activity, user: user } = ActivityBuilder.public_and_non_public
|
||||
%{public: activity, user: user} = ActivityBuilder.public_and_non_public()
|
||||
insert(:note_activity, %{local: false})
|
||||
|
||||
follower = insert(:user, following: [User.ap_followers(user)])
|
||||
|
|
@ -92,11 +105,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
statuses = TwitterAPI.fetch_public_statuses(follower)
|
||||
|
||||
assert length(statuses) == 1
|
||||
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: user, for: follower})
|
||||
|
||||
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
|
||||
%{public: activity, user: user} = ActivityBuilder.public_and_non_public()
|
||||
insert(:note_activity, %{local: false})
|
||||
|
||||
follower = insert(:user, following: [user.follower_address])
|
||||
|
|
@ -104,7 +119,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
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})
|
||||
|
||||
assert Enum.at(statuses, 0) ==
|
||||
ActivityRepresenter.to_map(activity, %{user: user, for: follower})
|
||||
end
|
||||
|
||||
test "fetch friends' statuses" do
|
||||
|
|
@ -119,7 +136,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
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: direct_activity_user, mentioned: [user]})
|
||||
|
||||
assert Enum.at(statuses, 1) ==
|
||||
ActivityRepresenter.to_map(direct_activity, %{
|
||||
user: direct_activity_user,
|
||||
mentioned: [user]
|
||||
})
|
||||
end
|
||||
|
||||
test "fetch user's mentions" do
|
||||
|
|
@ -130,12 +152,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
statuses = TwitterAPI.fetch_mentions(user)
|
||||
|
||||
assert length(statuses) == 1
|
||||
assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user, mentioned: [user]})
|
||||
|
||||
assert Enum.at(statuses, 0) ==
|
||||
ActivityRepresenter.to_map(activity, %{user: activity_user, mentioned: [user]})
|
||||
end
|
||||
|
||||
test "get a user by params" do
|
||||
user1_result = {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
|
||||
{:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
|
||||
|
||||
{:ok, user2} =
|
||||
UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
|
||||
|
||||
assert {:error, "You need to specify screen_name or user_id"} == TwitterAPI.get_user(nil, nil)
|
||||
assert user1_result == TwitterAPI.get_user(nil, %{"user_id" => user1.id})
|
||||
|
|
@ -144,13 +170,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert user1_result == TwitterAPI.get_user(user1, nil)
|
||||
assert user1_result == TwitterAPI.get_user(user2, %{"user_id" => user1.id})
|
||||
assert user1_result == TwitterAPI.get_user(user2, %{"screen_name" => user1.nickname})
|
||||
assert {:error, "No user with such screen_name"} == TwitterAPI.get_user(nil, %{"screen_name" => "Satan"})
|
||||
|
||||
assert {:error, "No user with such screen_name"} ==
|
||||
TwitterAPI.get_user(nil, %{"screen_name" => "Satan"})
|
||||
|
||||
assert {:error, "No user with such user_id"} == TwitterAPI.get_user(nil, %{"user_id" => 666})
|
||||
end
|
||||
|
||||
test "fetch user's statuses" do
|
||||
{:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
|
||||
{:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
|
||||
|
||||
{:ok, user2} =
|
||||
UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
|
||||
|
||||
{:ok, status1} = ActivityBuilder.insert(%{"id" => 1}, %{user: user1})
|
||||
{:ok, status2} = ActivityBuilder.insert(%{"id" => 2}, %{user: user2})
|
||||
|
|
@ -180,10 +211,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
{:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert User.ap_followers(followed) in user.following
|
||||
|
||||
{ :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
{:error, msg} = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||
end
|
||||
|
||||
|
|
@ -191,13 +222,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
{:ok, user, followed, _activity} =
|
||||
TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
|
||||
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})
|
||||
{:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
assert msg == "Could not follow user: #{followed.nickname} is already on your list."
|
||||
end
|
||||
|
||||
|
|
@ -206,10 +239,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
ActivityPub.follow(user, unfollowed)
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
{:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert user.following == []
|
||||
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
{:error, msg} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
|
|
@ -219,10 +252,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
ActivityPub.follow(user, unfollowed)
|
||||
|
||||
{:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
{:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert user.following == []
|
||||
|
||||
{ :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
{:error, msg} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
|
|
@ -266,7 +299,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{: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
|
||||
{:ok, object} = Object.context_mapping("2hu") |> Repo.insert()
|
||||
|
||||
statuses = TwitterAPI.fetch_conversation(user, object.id)
|
||||
|
||||
|
|
@ -276,7 +309,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "upload a file" do
|
||||
file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
response = TwitterAPI.upload(file)
|
||||
|
||||
|
|
@ -291,7 +328,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{: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})
|
||||
assert status ==
|
||||
ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
|
||||
end
|
||||
|
||||
test "it unfavorites a status, returns the updated status" do
|
||||
|
|
@ -300,9 +338,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
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)
|
||||
{: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
|
||||
|
||||
assert ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})[
|
||||
"fave_num"
|
||||
] == 1
|
||||
|
||||
{:ok, status} = TwitterAPI.unfav(user, note_activity.id)
|
||||
|
||||
|
|
@ -317,7 +358,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{: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})
|
||||
assert status ==
|
||||
ActivityRepresenter.to_map(updated_activity, %{user: activity_user, for: user})
|
||||
end
|
||||
|
||||
test "it registers a new user and returns the user." do
|
||||
|
|
@ -333,7 +375,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
||||
fetched_user = Repo.get_by(User, nickname: "lain")
|
||||
assert UserView.render("show.json", %{user: user}) == UserView.render("show.json", %{user: 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
|
||||
|
|
@ -374,7 +418,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
test "returns an existing mapping for an existing object" do
|
||||
{:ok, object} = Object.context_mapping("random context") |> Repo.insert
|
||||
{:ok, object} = Object.context_mapping("random context") |> Repo.insert()
|
||||
conversation_id = TwitterAPI.context_to_conversation_id("random context")
|
||||
|
||||
assert conversation_id == object.id
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
|
||||
test "A user with an avatar object", %{user: user} do
|
||||
image = "image"
|
||||
user = %{ user | avatar: %{ "url" => [%{"href" => image}] }}
|
||||
user = %{user | avatar: %{"url" => [%{"href" => image}]}}
|
||||
represented = UserView.render("show.json", %{user: user})
|
||||
assert represented["profile_image_url"] == image
|
||||
end
|
||||
|
|
@ -41,7 +41,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 1,
|
||||
"friends_count" => 1,
|
||||
|
|
@ -76,7 +76,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 0,
|
||||
|
|
@ -112,7 +112,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"name" => follower.name,
|
||||
"screen_name" => follower.nickname,
|
||||
"description" => HtmlSanitizeEx.strip_tags(follower.bio),
|
||||
"created_at" => follower.inserted_at |> Utils.format_naive_asctime,
|
||||
"created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 1,
|
||||
|
|
@ -155,7 +155,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
|||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime,
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue