2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-03-20 14:30:44 -06:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
2017-06-19 15:12:37 -06:00
|
|
|
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
|
2017-03-21 14:09:20 -06:00
|
|
|
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
|
2018-04-19 12:46:59 -06:00
|
|
|
alias Pleroma.{Repo, Activity, User, Object, Notification}
|
2017-04-14 10:27:17 -06:00
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
2017-06-19 15:12:37 -06:00
|
|
|
alias Pleroma.Web.TwitterAPI.UserView
|
2018-04-19 12:46:59 -06:00
|
|
|
alias Pleroma.Web.TwitterAPI.NotificationView
|
2017-09-16 06:33:47 -06:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2017-11-14 08:34:48 -07:00
|
|
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
2018-05-21 15:17:34 -06:00
|
|
|
alias Comeonin.Pbkdf2
|
2018-12-12 06:28:00 -07:00
|
|
|
alias Ecto.Changeset
|
2017-03-20 14:30:44 -06:00
|
|
|
|
2017-04-13 09:22:44 -06:00
|
|
|
import Pleroma.Factory
|
2017-03-20 14:30:44 -06:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
@banner "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
|
|
|
|
2018-12-01 04:00:53 -07:00
|
|
|
describe "POST /api/account/update_profile_banner" do
|
|
|
|
test "it updates the banner", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => @banner})
|
|
|
|
|> json_response(200)
|
2018-12-02 03:20:38 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
user = refresh_record(user)
|
2018-12-02 03:20:38 -07:00
|
|
|
assert user.info.banner["type"] == "Image"
|
2018-12-01 04:00:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /api/qvitter/update_background_image" do
|
|
|
|
test "it updates the background", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => @banner})
|
|
|
|
|> json_response(200)
|
2018-12-02 03:20:38 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
user = refresh_record(user)
|
2018-12-02 03:20:38 -07:00
|
|
|
assert user.info.background["type"] == "Image"
|
2018-12-01 04:00:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-20 14:30:44 -06:00
|
|
|
describe "POST /api/account/verify_credentials" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-03-20 14:30:44 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/account/verify_credentials.json")
|
2017-03-20 14:30:44 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: user} do
|
2018-12-11 05:31:52 -07:00
|
|
|
response =
|
2018-03-30 07:01:53 -06:00
|
|
|
conn
|
2017-03-20 14:30:44 -06:00
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> post("/api/account/verify_credentials.json")
|
2018-12-11 05:31:52 -07:00
|
|
|
|> json_response(200)
|
2017-03-20 14:30:44 -06:00
|
|
|
|
2017-12-05 04:18:04 -07:00
|
|
|
assert response == UserView.render("show.json", %{user: user, token: response["token"]})
|
2017-03-20 14:30:44 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-21 11:17:35 -06:00
|
|
|
describe "POST /statuses/update.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-03-21 11:17:35 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/statuses/update.json")
|
2017-03-21 11:17:35 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: user} do
|
2017-04-23 10:08:25 -06:00
|
|
|
conn_with_creds = conn |> with_credentials(user.nickname, "test")
|
|
|
|
request_path = "/api/statuses/update.json"
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
error_response = %{
|
|
|
|
"request" => request_path,
|
|
|
|
"error" => "Client must provide a 'status' parameter with a value."
|
|
|
|
}
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
conn =
|
|
|
|
conn_with_creds
|
|
|
|
|> post(request_path)
|
|
|
|
|
2017-04-23 10:08:25 -06:00
|
|
|
assert json_response(conn, 400) == error_response
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
conn =
|
|
|
|
conn_with_creds
|
|
|
|
|> post(request_path, %{status: ""})
|
|
|
|
|
2017-04-23 10:08:25 -06:00
|
|
|
assert json_response(conn, 400) == error_response
|
2017-03-21 11:17:35 -06:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
conn =
|
|
|
|
conn_with_creds
|
|
|
|
|> post(request_path, %{status: " "})
|
|
|
|
|
2017-04-24 03:09:11 -06:00
|
|
|
assert json_response(conn, 400) == error_response
|
|
|
|
|
2018-08-06 05:10:49 -06:00
|
|
|
# we post with visibility private in order to avoid triggering relay
|
2018-12-11 05:31:52 -07:00
|
|
|
conn =
|
|
|
|
conn_with_creds
|
|
|
|
|> post(request_path, %{status: "Nice meme.", visibility: "private"})
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
|
2017-03-21 11:17:35 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-21 14:09:20 -06:00
|
|
|
describe "GET /statuses/public_timeline.json" do
|
2018-12-27 23:43:40 -07:00
|
|
|
setup [:valid_user]
|
|
|
|
|
2017-03-21 14:09:20 -06:00
|
|
|
test "returns statuses", %{conn: conn} do
|
2018-11-30 09:07:37 -07:00
|
|
|
user = insert(:user)
|
2017-03-21 14:09:20 -06:00
|
|
|
activities = ActivityBuilder.insert_list(30, %{}, %{user: user})
|
|
|
|
ActivityBuilder.insert_list(10, %{}, %{user: user})
|
|
|
|
since_id = List.last(activities).id
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
2017-03-21 14:09:20 -06:00
|
|
|
|> get("/api/statuses/public_timeline.json", %{since_id: since_id})
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 10
|
|
|
|
end
|
2018-11-06 06:44:00 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
2018-11-06 06:44:00 -07:00
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, false)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> get("/api/statuses/public_timeline.json")
|
|
|
|
|> json_response(403)
|
|
|
|
|
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, true)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
end
|
|
|
|
|
2018-12-27 23:43:40 -07:00
|
|
|
test "returns 200 to authenticated request when the instance is not public",
|
|
|
|
%{conn: conn, user: user} do
|
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, false)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> get("/api/statuses/public_timeline.json")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, true)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
end
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
2018-11-06 06:44:00 -07:00
|
|
|
conn
|
|
|
|
|> get("/api/statuses/public_timeline.json")
|
|
|
|
|> json_response(200)
|
|
|
|
end
|
2018-12-27 23:43:40 -07:00
|
|
|
|
|
|
|
test "returns 200 to authenticated request when the instance is public",
|
|
|
|
%{conn: conn, user: user} do
|
|
|
|
conn
|
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> get("/api/statuses/public_timeline.json")
|
|
|
|
|> json_response(200)
|
|
|
|
end
|
2018-11-06 06:44:00 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /statuses/public_and_external_timeline.json" do
|
2018-12-27 23:43:40 -07:00
|
|
|
setup [:valid_user]
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
|
2018-11-06 06:44:00 -07:00
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, false)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> get("/api/statuses/public_and_external_timeline.json")
|
|
|
|
|> json_response(403)
|
|
|
|
|
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, true)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
end
|
|
|
|
|
2018-12-27 23:43:40 -07:00
|
|
|
test "returns 200 to authenticated request when the instance is not public",
|
|
|
|
%{conn: conn, user: user} do
|
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, false)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> get("/api/statuses/public_and_external_timeline.json")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
instance =
|
|
|
|
Application.get_env(:pleroma, :instance)
|
|
|
|
|> Keyword.put(:public, true)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, :instance, instance)
|
|
|
|
end
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
|
2018-11-06 06:44:00 -07:00
|
|
|
conn
|
|
|
|
|> get("/api/statuses/public_and_external_timeline.json")
|
|
|
|
|> json_response(200)
|
|
|
|
end
|
2018-12-27 23:43:40 -07:00
|
|
|
|
|
|
|
test "returns 200 to authenticated request when the instance is public",
|
|
|
|
%{conn: conn, user: user} do
|
|
|
|
conn
|
|
|
|
|> with_credentials(user.nickname, "test")
|
|
|
|
|> get("/api/statuses/public_and_external_timeline.json")
|
|
|
|
|> json_response(200)
|
|
|
|
end
|
2017-03-21 14:09:20 -06:00
|
|
|
end
|
|
|
|
|
2017-03-23 18:16:28 -06:00
|
|
|
describe "GET /statuses/show/:id.json" do
|
|
|
|
test "returns one status", %{conn: conn} do
|
2018-03-27 14:24:19 -06:00
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
|
2017-03-23 18:16:28 -06:00
|
|
|
actor = Repo.get_by!(User, ap_id: activity.data["actor"])
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> get("/api/statuses/show/#{activity.id}.json")
|
2017-03-23 18:16:28 -06:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
2017-03-28 06:04:13 -06:00
|
|
|
assert response == ActivityRepresenter.to_map(activity, %{user: actor})
|
2017-03-23 18:16:28 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-14 08:34:48 -07:00
|
|
|
describe "GET /users/show.json" do
|
|
|
|
test "gets user with screen_name", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> get("/api/users/show.json", %{"screen_name" => user.nickname})
|
2017-11-14 08:34:48 -07:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert response["id"] == user.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "gets user with user_id", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> get("/api/users/show.json", %{"user_id" => user.id})
|
2017-11-14 08:34:48 -07:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert response["id"] == user.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "gets a user for a logged in user", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
logged_in = insert(:user)
|
|
|
|
|
|
|
|
{:ok, logged_in, user, _activity} = TwitterAPI.follow(logged_in, %{"user_id" => user.id})
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(logged_in.nickname, "test")
|
|
|
|
|> get("/api/users/show.json", %{"user_id" => user.id})
|
2017-11-14 08:34:48 -07:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert response["following"] == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-28 09:22:44 -06:00
|
|
|
describe "GET /statusnet/conversation/:id.json" do
|
|
|
|
test "returns the statuses in the conversation", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
{:ok, _user} = UserBuilder.insert()
|
2018-04-02 07:28:35 -06:00
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
|
2017-06-30 08:41:09 -06:00
|
|
|
{:ok, _activity_two} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
|
|
|
|
{:ok, _activity_three} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
|
2017-03-28 09:22:44 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
2018-04-02 07:28:35 -06:00
|
|
|
|> get("/api/statusnet/conversation/#{activity.data["context_id"]}.json")
|
2017-03-28 09:22:44 -06:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-22 10:25:59 -06:00
|
|
|
describe "GET /statuses/friends_timeline.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-03-22 10:25:59 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = get(conn, "/api/statuses/friends_timeline.json")
|
2017-03-22 10:25:59 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
2017-04-16 07:28:28 -06:00
|
|
|
user = insert(:user)
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
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})
|
|
|
|
|
2017-04-16 07:28:28 -06:00
|
|
|
other_user = insert(:user)
|
2017-03-22 10:25:59 -06:00
|
|
|
ActivityBuilder.insert_list(10, %{}, %{user: other_user})
|
|
|
|
since_id = List.last(activities).id
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
current_user =
|
2018-12-12 06:28:00 -07:00
|
|
|
Changeset.change(current_user, following: [User.ap_followers(user)])
|
2018-03-30 07:01:53 -06:00
|
|
|
|> Repo.update!()
|
2017-03-22 10:25:59 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
2017-03-22 10:25:59 -06:00
|
|
|
|> 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
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
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)
|
2017-03-22 10:25:59 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-13 12:08:50 -07:00
|
|
|
describe "GET /statuses/dm_timeline.json" do
|
|
|
|
test "it show direct messages", %{conn: conn} do
|
|
|
|
user_one = insert(:user)
|
|
|
|
user_two = insert(:user)
|
|
|
|
|
|
|
|
{:ok, user_two} = User.follow(user_two, user_one)
|
|
|
|
|
|
|
|
{:ok, direct} =
|
|
|
|
CommonAPI.post(user_one, %{
|
|
|
|
"status" => "Hi @#{user_two.nickname}!",
|
|
|
|
"visibility" => "direct"
|
|
|
|
})
|
|
|
|
|
2018-11-16 11:47:36 -07:00
|
|
|
{:ok, direct_two} =
|
|
|
|
CommonAPI.post(user_two, %{
|
|
|
|
"status" => "Hi @#{user_one.nickname}!",
|
|
|
|
"visibility" => "direct"
|
|
|
|
})
|
|
|
|
|
2018-11-13 12:08:50 -07:00
|
|
|
{:ok, _follower_only} =
|
|
|
|
CommonAPI.post(user_one, %{
|
|
|
|
"status" => "Hi @#{user_two.nickname}!",
|
|
|
|
"visibility" => "private"
|
|
|
|
})
|
|
|
|
|
|
|
|
# Only direct should be visible here
|
|
|
|
res_conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user_two)
|
|
|
|
|> get("/api/statuses/dm_timeline.json")
|
|
|
|
|
2018-11-16 11:47:36 -07:00
|
|
|
[status, status_two] = json_response(res_conn, 200)
|
|
|
|
assert status["id"] == direct_two.id
|
|
|
|
assert status_two["id"] == direct.id
|
2018-11-13 12:08:50 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-20 04:53:53 -06:00
|
|
|
describe "GET /statuses/mentions.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-20 04:53:53 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = get(conn, "/api/statuses/mentions.json")
|
2017-04-20 04:53:53 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
2018-03-30 07:01:53 -06:00
|
|
|
{:ok, activity} =
|
|
|
|
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user})
|
2017-04-20 04:53:53 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
2017-04-20 04:53:53 -06:00
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/statuses/mentions.json")
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert Enum.at(response, 0) ==
|
|
|
|
ActivityRepresenter.to_map(activity, %{
|
|
|
|
user: current_user,
|
|
|
|
mentioned: [current_user]
|
|
|
|
})
|
2017-04-20 04:53:53 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-19 12:46:59 -06:00
|
|
|
describe "GET /api/qvitter/statuses/notifications.json" do
|
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
conn = get(conn, "/api/qvitter/statuses/notifications.json")
|
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
2018-05-07 12:51:14 -06:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
2018-06-03 11:11:22 -06:00
|
|
|
{:ok, _activity} =
|
2018-05-07 12:51:14 -06:00
|
|
|
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
|
2018-04-19 12:46:59 -06:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/qvitter/statuses/notifications.json")
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
|
|
|
|
assert response ==
|
2018-04-20 05:10:57 -06:00
|
|
|
NotificationView.render("notification.json", %{
|
|
|
|
notifications: Notification.for_user(current_user),
|
|
|
|
for: current_user
|
|
|
|
})
|
2018-04-19 12:46:59 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-06 16:25:16 -07:00
|
|
|
describe "POST /api/qvitter/statuses/notifications/read" do
|
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
|
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials, without any params", %{conn: conn, user: current_user} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/qvitter/statuses/notifications/read")
|
|
|
|
|
|
|
|
assert json_response(conn, 400) == %{
|
|
|
|
"error" => "You need to specify latest_id",
|
|
|
|
"request" => "/api/qvitter/statuses/notifications/read"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials, with params", %{conn: conn, user: current_user} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} =
|
|
|
|
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
|
|
|
|
|
|
|
|
response_conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/qvitter/statuses/notifications.json")
|
|
|
|
|
|
|
|
[notification] = response = json_response(response_conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
|
|
|
|
assert notification["is_seen"] == 0
|
|
|
|
|
|
|
|
response_conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
|
|
|
|
|
|
|
|
[notification] = response = json_response(response_conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
|
|
|
|
assert notification["is_seen"] == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-17 07:31:19 -06:00
|
|
|
describe "GET /statuses/user_timeline.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-17 07:31:19 -06:00
|
|
|
test "without any params", %{conn: conn} do
|
|
|
|
conn = get(conn, "/api/statuses/user_timeline.json")
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 400) == %{
|
|
|
|
"error" => "You need to specify screen_name or user_id",
|
|
|
|
"request" => "/api/statuses/user_timeline.json"
|
|
|
|
}
|
2017-04-17 07:31:19 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "with user_id", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
|
|
|
|
|
|
|
|
conn = get(conn, "/api/statuses/user_timeline.json", %{"user_id" => user.id})
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with screen_name", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
|
|
|
|
|
|
|
|
conn = get(conn, "/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: current_user})
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/statuses/user_timeline.json")
|
2017-04-17 07:31:19 -06:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: current_user})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials with user_id", %{conn: conn, user: current_user} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/statuses/user_timeline.json", %{"user_id" => user.id})
|
2017-04-17 07:31:19 -06:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials screen_name", %{conn: conn, user: current_user} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1}, %{user: user})
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/statuses/user_timeline.json", %{"screen_name" => user.nickname})
|
2017-04-17 07:31:19 -06:00
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
2018-12-26 22:30:01 -07:00
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials with user_id, excluding RTs", %{conn: conn, user: current_user} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = ActivityBuilder.insert(%{"id" => 1, "type" => "Create"}, %{user: user})
|
|
|
|
{:ok, _} = ActivityBuilder.insert(%{"id" => 2, "type" => "Announce"}, %{user: user})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/statuses/user_timeline.json", %{
|
|
|
|
"user_id" => user.id,
|
|
|
|
"include_rts" => "false"
|
|
|
|
})
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> get("/api/statuses/user_timeline.json", %{"user_id" => user.id, "include_rts" => "0"})
|
|
|
|
|
|
|
|
response = json_response(conn, 200)
|
|
|
|
|
2017-04-17 07:31:19 -06:00
|
|
|
assert length(response) == 1
|
|
|
|
assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-22 11:36:08 -06:00
|
|
|
describe "POST /friendships/create.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-03-22 11:36:08 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/friendships/create.json")
|
2017-03-22 11:36:08 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
2017-04-16 07:28:28 -06:00
|
|
|
followed = insert(:user)
|
2017-03-22 11:36:08 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/friendships/create.json", %{user_id: followed.id})
|
2017-03-22 11:36:08 -06:00
|
|
|
|
|
|
|
current_user = Repo.get(User, current_user.id)
|
2017-11-19 22:52:02 -07:00
|
|
|
assert User.ap_followers(followed) in current_user.following
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
UserView.render("show.json", %{user: followed, for: current_user})
|
2017-03-22 11:36:08 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-23 06:13:09 -06:00
|
|
|
describe "POST /friendships/destroy.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-03-23 06:13:09 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/friendships/destroy.json")
|
2017-03-23 06:13:09 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
2017-04-16 07:28:28 -06:00
|
|
|
followed = insert(:user)
|
2017-03-23 06:13:09 -06:00
|
|
|
|
|
|
|
{:ok, current_user} = User.follow(current_user, followed)
|
2017-11-19 22:52:02 -07:00
|
|
|
assert User.ap_followers(followed) in current_user.following
|
2017-05-07 11:28:23 -06:00
|
|
|
ActivityPub.follow(current_user, followed)
|
2017-03-23 06:13:09 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
|
2017-03-23 06:13:09 -06:00
|
|
|
|
|
|
|
current_user = Repo.get(User, current_user.id)
|
2017-11-19 22:52:02 -07:00
|
|
|
assert current_user.following == [current_user.ap_id]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
UserView.render("show.json", %{user: followed, for: current_user})
|
2017-03-23 06:13:09 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-07 15:04:53 -07:00
|
|
|
describe "POST /blocks/create.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-11-07 15:04:53 -07:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/blocks/create.json")
|
2017-11-07 15:04:53 -07:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
|
|
|
blocked = insert(:user)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/blocks/create.json", %{user_id: blocked.id})
|
2017-11-07 15:04:53 -07:00
|
|
|
|
|
|
|
current_user = Repo.get(User, current_user.id)
|
|
|
|
assert User.blocks?(current_user, blocked)
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
UserView.render("show.json", %{user: blocked, for: current_user})
|
2017-11-07 15:04:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /blocks/destroy.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-11-07 15:04:53 -07:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/blocks/destroy.json")
|
2017-11-07 15:04:53 -07:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
|
|
|
blocked = insert(:user)
|
|
|
|
|
2018-05-22 03:41:17 -06:00
|
|
|
{:ok, current_user, blocked} = TwitterAPI.block(current_user, %{"user_id" => blocked.id})
|
2017-11-07 15:04:53 -07:00
|
|
|
assert User.blocks?(current_user, blocked)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
|
2017-11-07 15:04:53 -07:00
|
|
|
|
|
|
|
current_user = Repo.get(User, current_user.id)
|
2018-11-30 09:07:37 -07:00
|
|
|
assert current_user.info.blocks == []
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
UserView.render("show.json", %{user: blocked, for: current_user})
|
2017-11-07 15:04:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-10 07:00:57 -06:00
|
|
|
describe "GET /help/test.json" do
|
|
|
|
test "returns \"ok\"", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = get(conn, "/api/help/test.json")
|
2017-04-10 07:00:57 -06:00
|
|
|
assert json_response(conn, 200) == "ok"
|
2017-04-17 03:43:44 -06:00
|
|
|
end
|
2017-04-16 04:25:38 -06:00
|
|
|
end
|
|
|
|
|
2017-04-16 08:06:19 -06:00
|
|
|
describe "POST /api/qvitter/update_avatar.json" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-16 08:06:19 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/qvitter/update_avatar.json")
|
2017-04-16 08:06:19 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
2018-02-25 09:48:31 -07:00
|
|
|
avatar_image = File.read!("test/fixtures/avatar_data_uri")
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
|
2017-04-16 08:06:19 -06:00
|
|
|
|
|
|
|
current_user = Repo.get(User, current_user.id)
|
|
|
|
assert is_map(current_user.avatar)
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
UserView.render("show.json", %{user: current_user, for: current_user})
|
2017-04-16 08:06:19 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-24 00:05:54 -06:00
|
|
|
describe "GET /api/qvitter/mutes.json" do
|
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "unimplemented mutes without valid credentials", %{conn: conn} do
|
|
|
|
conn = get(conn, "/api/qvitter/mutes.json")
|
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
|
2018-12-11 05:31:52 -07:00
|
|
|
response =
|
2018-06-24 00:05:54 -06:00
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> get("/api/qvitter/mutes.json")
|
2018-12-11 05:31:52 -07:00
|
|
|
|> json_response(200)
|
2018-06-24 16:24:41 -06:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
assert [] = response
|
2018-06-24 00:05:54 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-13 09:22:44 -06:00
|
|
|
describe "POST /api/favorites/create/:id" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-13 09:22:44 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
note_activity = insert(:note_activity)
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/favorites/create/#{note_activity.id}.json")
|
2017-04-13 09:22:44 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
|
|
|
note_activity = insert(:note_activity)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/favorites/create/#{note_activity.id}.json")
|
2017-04-13 09:22:44 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
2018-06-03 11:11:22 -06:00
|
|
|
|
|
|
|
test "with credentials, invalid param", %{conn: conn, user: current_user} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/favorites/create/wrong.json")
|
|
|
|
|
|
|
|
assert json_response(conn, 400)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials, invalid activity", %{conn: conn, user: current_user} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/favorites/create/1.json")
|
|
|
|
|
|
|
|
assert json_response(conn, 500)
|
|
|
|
end
|
2017-04-13 09:22:44 -06:00
|
|
|
end
|
|
|
|
|
2017-04-14 10:27:17 -06:00
|
|
|
describe "POST /api/favorites/destroy/:id" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-14 10:27:17 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
note_activity = insert(:note_activity)
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/favorites/destroy/#{note_activity.id}.json")
|
2017-04-14 10:27:17 -06:00
|
|
|
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)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/favorites/destroy/#{note_activity.id}.json")
|
2017-04-14 10:27:17 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-15 06:09:54 -06:00
|
|
|
describe "POST /api/statuses/retweet/:id" do
|
|
|
|
setup [:valid_user]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-15 06:09:54 -06:00
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
note_activity = insert(:note_activity)
|
2018-03-30 07:01:53 -06:00
|
|
|
conn = post(conn, "/api/statuses/retweet/#{note_activity.id}.json")
|
2017-04-15 06:09:54 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
|
|
|
note_activity = insert(:note_activity)
|
|
|
|
|
2017-04-23 16:11:38 -06:00
|
|
|
request_path = "/api/statuses/retweet/#{note_activity.id}.json"
|
2017-04-15 06:09:54 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post(request_path)
|
|
|
|
|
2017-04-23 16:11:38 -06:00
|
|
|
activity = Repo.get(Activity, note_activity.id)
|
2017-04-26 00:55:00 -06:00
|
|
|
activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert json_response(response, 200) ==
|
|
|
|
ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
|
2017-04-15 06:09:54 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-13 19:29:55 -06:00
|
|
|
describe "POST /api/statuses/unretweet/:id" do
|
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "without valid credentials", %{conn: conn} do
|
|
|
|
note_activity = insert(:note_activity)
|
2018-06-13 19:45:27 -06:00
|
|
|
conn = post(conn, "/api/statuses/unretweet/#{note_activity.id}.json")
|
2018-06-13 19:29:55 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials", %{conn: conn, user: current_user} do
|
|
|
|
note_activity = insert(:note_activity)
|
|
|
|
|
|
|
|
request_path = "/api/statuses/retweet/#{note_activity.id}.json"
|
|
|
|
|
|
|
|
_response =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post(request_path)
|
|
|
|
|
|
|
|
request_path = String.replace(request_path, "retweet", "unretweet")
|
|
|
|
|
|
|
|
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})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-16 03:01:24 -06:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> post("/api/account/register", data)
|
2017-04-16 03:01:24 -06:00
|
|
|
|
|
|
|
user = json_response(conn, 200)
|
|
|
|
|
|
|
|
fetched_user = Repo.get_by(User, nickname: "lain")
|
2017-06-19 15:12:37 -06:00
|
|
|
assert user == UserView.render("show.json", %{user: fetched_user})
|
2017-04-16 03:01:24 -06:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> post("/api/account/register", data)
|
2017-04-16 03:01:24 -06:00
|
|
|
|
|
|
|
errors = json_response(conn, 400)
|
|
|
|
|
|
|
|
assert is_binary(errors["error"])
|
2017-04-10 07:00:57 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-12 06:28:00 -07:00
|
|
|
describe "POST /api/account/password_reset, with valid parameters" do
|
|
|
|
setup %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
conn = post(conn, "/api/account/password_reset?email=#{user.email}")
|
|
|
|
%{conn: conn, user: user}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns 204", %{conn: conn} do
|
|
|
|
assert json_response(conn, :no_content)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it creates a PasswordResetToken record for user", %{user: user} do
|
|
|
|
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
|
|
|
assert token_record
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends an email to user", %{user: user} do
|
|
|
|
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
|
|
|
|
|
|
|
Swoosh.TestAssertions.assert_email_sent(
|
|
|
|
Pleroma.UserEmail.password_reset_email(user, token_record.token)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /api/account/password_reset, with invalid parameters" do
|
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "it returns 500 when user is not found", %{conn: conn, user: user} do
|
|
|
|
conn = post(conn, "/api/account/password_reset?email=nonexisting_#{user.email}")
|
|
|
|
assert json_response(conn, :internal_server_error)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns 500 when user is not local", %{conn: conn, user: user} do
|
|
|
|
{:ok, user} = Repo.update(Changeset.change(user, local: false))
|
|
|
|
conn = post(conn, "/api/account/password_reset?email=#{user.email}")
|
|
|
|
assert json_response(conn, :internal_server_error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-20 03:41:30 -07:00
|
|
|
describe "GET /api/account/confirm_email/:id/:token" do
|
2018-12-18 07:13:52 -07:00
|
|
|
setup do
|
|
|
|
user = insert(:user)
|
2018-12-19 06:27:16 -07:00
|
|
|
info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)
|
2018-12-18 07:13:52 -07:00
|
|
|
|
|
|
|
{:ok, user} =
|
|
|
|
user
|
|
|
|
|> Changeset.change()
|
|
|
|
|> Changeset.put_embed(:info, info_change)
|
|
|
|
|> Repo.update()
|
|
|
|
|
|
|
|
assert user.info.confirmation_pending
|
|
|
|
|
|
|
|
[user: user]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it redirects to root url", %{conn: conn, user: user} do
|
2018-12-20 03:41:30 -07:00
|
|
|
conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
|
2018-12-18 07:13:52 -07:00
|
|
|
|
|
|
|
assert 302 == conn.status
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it confirms the user account", %{conn: conn, user: user} do
|
2018-12-20 03:41:30 -07:00
|
|
|
get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
|
2018-12-18 07:13:52 -07:00
|
|
|
|
|
|
|
user = Repo.get(User, user.id)
|
|
|
|
|
|
|
|
refute user.info.confirmation_pending
|
|
|
|
refute user.info.confirmation_token
|
|
|
|
end
|
2018-12-20 03:41:30 -07:00
|
|
|
|
|
|
|
test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
|
|
|
|
conn = get(conn, "/api/account/confirm_email/0/#{user.info.confirmation_token}")
|
|
|
|
|
|
|
|
assert 500 == conn.status
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns 500 if token is invalid", %{conn: conn, user: user} do
|
|
|
|
conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
|
|
|
|
|
|
|
|
assert 500 == conn.status
|
|
|
|
end
|
2018-12-18 07:13:52 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /api/account/resend_confirmation_email" do
|
|
|
|
setup do
|
2018-12-20 04:48:48 -07:00
|
|
|
setting = Pleroma.Config.get([:instance, :account_activation_required])
|
|
|
|
|
|
|
|
unless setting do
|
|
|
|
Pleroma.Config.put([:instance, :account_activation_required], true)
|
|
|
|
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
|
|
|
|
end
|
|
|
|
|
2018-12-18 07:13:52 -07:00
|
|
|
user = insert(:user)
|
2018-12-19 06:27:16 -07:00
|
|
|
info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)
|
2018-12-18 07:13:52 -07:00
|
|
|
|
|
|
|
{:ok, user} =
|
|
|
|
user
|
|
|
|
|> Changeset.change()
|
|
|
|
|> Changeset.put_embed(:info, info_change)
|
|
|
|
|> Repo.update()
|
|
|
|
|
|
|
|
assert user.info.confirmation_pending
|
|
|
|
|
|
|
|
[user: user]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns 204 No Content", %{conn: conn, user: user} do
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/resend_confirmation_email?email=#{user.email}")
|
|
|
|
|> json_response(:no_content)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends confirmation email", %{conn: conn, user: user} do
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/resend_confirmation_email?email=#{user.email}")
|
|
|
|
|
|
|
|
Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-10 10:44:57 -06:00
|
|
|
describe "GET /api/externalprofile/show" do
|
|
|
|
test "it returns the user", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
2017-11-06 15:33:44 -07:00
|
|
|
other_user = insert(:user)
|
2017-05-10 10:44:57 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
|
2017-05-10 10:44:57 -06:00
|
|
|
|
2017-11-06 15:33:44 -07:00
|
|
|
assert json_response(conn, 200) == UserView.render("show.json", %{user: other_user})
|
2017-05-10 10:44:57 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-20 12:29:15 -06:00
|
|
|
describe "GET /api/statuses/followers" do
|
|
|
|
test "it returns a user's followers", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
follower_one = insert(:user)
|
|
|
|
follower_two = insert(:user)
|
2018-02-12 02:13:54 -07:00
|
|
|
_not_follower = insert(:user)
|
2017-07-20 12:29:15 -06:00
|
|
|
|
|
|
|
{:ok, follower_one} = User.follow(follower_one, user)
|
|
|
|
{:ok, follower_two} = User.follow(follower_two, user)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/statuses/followers")
|
2017-07-20 12:29:15 -06:00
|
|
|
|
2018-04-02 05:13:04 -06:00
|
|
|
expected = UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
|
|
|
|
result = json_response(conn, 200)
|
|
|
|
assert Enum.sort(expected) == Enum.sort(result)
|
2017-07-20 12:29:15 -06:00
|
|
|
end
|
2018-12-02 10:14:13 -07:00
|
|
|
|
|
|
|
test "it returns a given user's followers with user_id", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
follower_one = insert(:user)
|
|
|
|
follower_two = insert(:user)
|
|
|
|
not_follower = insert(:user)
|
|
|
|
|
|
|
|
{:ok, follower_one} = User.follow(follower_one, user)
|
|
|
|
{:ok, follower_two} = User.follow(follower_two, user)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, not_follower)
|
|
|
|
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
|
|
|
|
|
|
|
assert MapSet.equal?(
|
|
|
|
MapSet.new(json_response(conn, 200)),
|
|
|
|
MapSet.new(
|
|
|
|
UserView.render("index.json", %{
|
|
|
|
users: [follower_one, follower_two],
|
|
|
|
for: not_follower
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns empty for a hidden network", %{conn: conn} do
|
|
|
|
user = insert(:user, %{info: %{hide_network: true}})
|
|
|
|
follower_one = insert(:user)
|
|
|
|
follower_two = insert(:user)
|
|
|
|
not_follower = insert(:user)
|
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
{:ok, _follower_one} = User.follow(follower_one, user)
|
|
|
|
{:ok, _follower_two} = User.follow(follower_two, user)
|
2018-12-02 10:14:13 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
response =
|
2018-12-02 10:14:13 -07:00
|
|
|
conn
|
|
|
|
|> assign(:user, not_follower)
|
|
|
|
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
2018-12-11 05:31:52 -07:00
|
|
|
|> json_response(200)
|
2018-12-02 10:14:13 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
assert [] == response
|
2018-12-02 10:14:13 -07:00
|
|
|
end
|
2018-12-05 13:14:06 -07:00
|
|
|
|
|
|
|
test "it returns the followers for a hidden network if requested by the user themselves", %{
|
|
|
|
conn: conn
|
|
|
|
} do
|
|
|
|
user = insert(:user, %{info: %{hide_network: true}})
|
|
|
|
follower_one = insert(:user)
|
|
|
|
follower_two = insert(:user)
|
2018-12-11 05:31:52 -07:00
|
|
|
_not_follower = insert(:user)
|
2018-12-05 13:14:06 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
{:ok, _follower_one} = User.follow(follower_one, user)
|
|
|
|
{:ok, _follower_two} = User.follow(follower_two, user)
|
2018-12-05 13:14:06 -07:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/statuses/followers", %{"user_id" => user.id})
|
|
|
|
|
|
|
|
refute [] == json_response(conn, 200)
|
|
|
|
end
|
2017-07-20 12:29:15 -06:00
|
|
|
end
|
|
|
|
|
2018-12-28 11:08:07 -07:00
|
|
|
describe "GET /api/statuses/blocks" do
|
|
|
|
test "it returns the list of users blocked by requester", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, user} = User.block(user, other_user)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/statuses/blocks")
|
|
|
|
|
|
|
|
expected = UserView.render("index.json", %{users: [other_user], for: user})
|
|
|
|
result = json_response(conn, 200)
|
|
|
|
assert Enum.sort(expected) == Enum.sort(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-20 12:35:30 -06:00
|
|
|
describe "GET /api/statuses/friends" do
|
2017-12-18 07:23:04 -07:00
|
|
|
test "it returns the logged in user's friends", %{conn: conn} do
|
2017-07-20 12:35:30 -06:00
|
|
|
user = insert(:user)
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
2018-02-12 02:13:54 -07:00
|
|
|
_not_followed = insert(:user)
|
2017-07-20 12:35:30 -06:00
|
|
|
|
|
|
|
{:ok, user} = User.follow(user, followed_one)
|
|
|
|
{:ok, user} = User.follow(user, followed_two)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/statuses/friends")
|
2017-07-20 12:35:30 -06:00
|
|
|
|
2018-04-02 05:13:04 -06:00
|
|
|
expected = UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
|
|
|
result = json_response(conn, 200)
|
|
|
|
assert Enum.sort(expected) == Enum.sort(result)
|
2017-07-20 12:35:30 -06:00
|
|
|
end
|
2017-12-18 07:23:04 -07:00
|
|
|
|
|
|
|
test "it returns a given user's friends with user_id", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
2018-02-12 02:13:54 -07:00
|
|
|
_not_followed = insert(:user)
|
2017-12-18 07:23:04 -07:00
|
|
|
|
|
|
|
{:ok, user} = User.follow(user, followed_one)
|
|
|
|
{:ok, user} = User.follow(user, followed_two)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
2018-05-31 06:27:42 -06:00
|
|
|
|> assign(:user, user)
|
2018-03-30 07:01:53 -06:00
|
|
|
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
2017-12-18 07:23:04 -07:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
assert MapSet.equal?(
|
|
|
|
MapSet.new(json_response(conn, 200)),
|
|
|
|
MapSet.new(
|
|
|
|
UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
|
|
|
)
|
|
|
|
)
|
2017-12-18 07:23:04 -07:00
|
|
|
end
|
|
|
|
|
2018-12-02 10:14:13 -07:00
|
|
|
test "it returns empty for a hidden network", %{conn: conn} do
|
|
|
|
user = insert(:user, %{info: %{hide_network: true}})
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
|
|
|
not_followed = insert(:user)
|
|
|
|
|
|
|
|
{:ok, user} = User.follow(user, followed_one)
|
|
|
|
{:ok, user} = User.follow(user, followed_two)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, not_followed)
|
|
|
|
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
|
|
|
|
|
|
|
assert [] == json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
2018-12-05 13:14:06 -07:00
|
|
|
test "it returns friends for a hidden network if the user themselves request it", %{
|
|
|
|
conn: conn
|
|
|
|
} do
|
|
|
|
user = insert(:user, %{info: %{hide_network: true}})
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
2018-12-11 05:31:52 -07:00
|
|
|
_not_followed = insert(:user)
|
2018-12-05 13:14:06 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
{:ok, _user} = User.follow(user, followed_one)
|
|
|
|
{:ok, _user} = User.follow(user, followed_two)
|
2018-12-05 13:14:06 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
response =
|
2018-12-05 13:14:06 -07:00
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/statuses/friends", %{"user_id" => user.id})
|
2018-12-11 05:31:52 -07:00
|
|
|
|> json_response(200)
|
2018-12-05 13:14:06 -07:00
|
|
|
|
2018-12-11 05:31:52 -07:00
|
|
|
refute [] == response
|
2018-12-05 13:14:06 -07:00
|
|
|
end
|
|
|
|
|
2017-12-18 07:23:04 -07:00
|
|
|
test "it returns a given user's friends with screen_name", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
2018-02-12 02:13:54 -07:00
|
|
|
_not_followed = insert(:user)
|
2017-12-18 07:23:04 -07:00
|
|
|
|
|
|
|
{:ok, user} = User.follow(user, followed_one)
|
|
|
|
{:ok, user} = User.follow(user, followed_two)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
2018-05-31 06:27:42 -06:00
|
|
|
|> assign(:user, user)
|
2018-03-30 07:01:53 -06:00
|
|
|
|> get("/api/statuses/friends", %{"screen_name" => user.nickname})
|
2017-12-18 07:23:04 -07:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
assert MapSet.equal?(
|
|
|
|
MapSet.new(json_response(conn, 200)),
|
|
|
|
MapSet.new(
|
|
|
|
UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
|
|
|
|
)
|
|
|
|
)
|
2017-12-18 07:23:04 -07:00
|
|
|
end
|
2017-07-20 12:35:30 -06:00
|
|
|
end
|
|
|
|
|
2017-11-14 07:04:58 -07:00
|
|
|
describe "GET /friends/ids" do
|
|
|
|
test "it returns a user's friends", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
2018-02-12 02:13:54 -07:00
|
|
|
_not_followed = insert(:user)
|
2017-11-14 07:04:58 -07:00
|
|
|
|
|
|
|
{:ok, user} = User.follow(user, followed_one)
|
|
|
|
{:ok, user} = User.follow(user, followed_two)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/friends/ids")
|
2017-11-14 07:04:58 -07:00
|
|
|
|
2017-11-20 10:16:43 -07:00
|
|
|
expected = [followed_one.id, followed_two.id]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert MapSet.equal?(
|
|
|
|
MapSet.new(Poison.decode!(json_response(conn, 200))),
|
|
|
|
MapSet.new(expected)
|
|
|
|
)
|
2017-11-14 07:04:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-29 07:14:00 -06:00
|
|
|
describe "POST /api/account/update_profile.json" do
|
2018-02-12 01:33:01 -07:00
|
|
|
test "it updates a user's profile", %{conn: conn} do
|
2017-08-29 07:14:00 -06:00
|
|
|
user = insert(:user)
|
2018-12-02 12:03:53 -07:00
|
|
|
user2 = insert(:user)
|
2017-08-29 07:14:00 -06:00
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/update_profile.json", %{
|
|
|
|
"name" => "new name",
|
2018-12-02 12:03:53 -07:00
|
|
|
"description" => "hi @#{user2.nickname}"
|
2018-03-30 07:01:53 -06:00
|
|
|
})
|
2017-08-29 07:14:00 -06:00
|
|
|
|
|
|
|
user = Repo.get!(User, user.id)
|
|
|
|
assert user.name == "new name"
|
2018-12-02 12:08:53 -07:00
|
|
|
|
|
|
|
assert user.bio ==
|
2018-12-05 13:16:53 -07:00
|
|
|
"hi <span><a data-user='#{user2.id}' class='mention' href='#{user2.ap_id}'>@<span>#{
|
|
|
|
user2.nickname
|
|
|
|
}</span></a></span>"
|
2017-08-29 07:14:00 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
|
|
|
end
|
2018-05-28 12:19:20 -06:00
|
|
|
|
2018-12-05 11:22:40 -07:00
|
|
|
test "it sets and un-sets hide_network", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/update_profile.json", %{
|
|
|
|
"hide_network" => "true"
|
|
|
|
})
|
|
|
|
|
|
|
|
user = Repo.get!(User, user.id)
|
|
|
|
assert user.info.hide_network == true
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/update_profile.json", %{
|
|
|
|
"hide_network" => "false"
|
|
|
|
})
|
|
|
|
|
|
|
|
user = Repo.get!(User, user.id)
|
|
|
|
assert user.info.hide_network == false
|
|
|
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
|
|
|
end
|
|
|
|
|
2018-05-28 12:19:20 -06:00
|
|
|
test "it locks an account", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/update_profile.json", %{
|
|
|
|
"locked" => "true"
|
|
|
|
})
|
|
|
|
|
|
|
|
user = Repo.get!(User, user.id)
|
2018-11-30 09:07:37 -07:00
|
|
|
assert user.info.locked == true
|
2018-05-28 12:19:20 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it unlocks an account", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/update_profile.json", %{
|
|
|
|
"locked" => "false"
|
|
|
|
})
|
|
|
|
|
|
|
|
user = Repo.get!(User, user.id)
|
2018-11-30 09:07:37 -07:00
|
|
|
assert user.info.locked == false
|
2018-05-28 12:19:20 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
|
|
|
|
end
|
2017-08-29 07:14:00 -06:00
|
|
|
end
|
|
|
|
|
2017-03-20 14:30:44 -06:00
|
|
|
defp valid_user(_context) do
|
2017-04-20 16:51:09 -06:00
|
|
|
user = insert(:user)
|
2017-03-20 14:30:44 -06:00
|
|
|
[user: user]
|
|
|
|
end
|
|
|
|
|
|
|
|
defp with_credentials(conn, username, password) do
|
|
|
|
header_content = "Basic " <> Base.encode64("#{username}:#{password}")
|
|
|
|
put_req_header(conn, "authorization", header_content)
|
|
|
|
end
|
2017-09-16 06:33:47 -06:00
|
|
|
|
|
|
|
describe "GET /api/search.json" do
|
|
|
|
test "it returns search results", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
|
|
|
|
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> get("/api/search.json", %{"q" => "2hu", "page" => "1", "rpp" => "1"})
|
2017-09-16 06:33:47 -06:00
|
|
|
|
|
|
|
assert [status] = json_response(conn, 200)
|
|
|
|
assert status["id"] == activity.id
|
|
|
|
end
|
|
|
|
end
|
2017-09-17 03:45:16 -06:00
|
|
|
|
|
|
|
describe "GET /api/statusnet/tags/timeline/:tag.json" do
|
2018-02-12 01:33:01 -07:00
|
|
|
test "it returns the tags timeline", %{conn: conn} do
|
2017-09-17 03:45:16 -06:00
|
|
|
user = insert(:user)
|
|
|
|
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about #2hu"})
|
|
|
|
{:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> get("/api/statusnet/tags/timeline/2hu.json")
|
2017-09-17 03:45:16 -06:00
|
|
|
|
|
|
|
assert [status] = json_response(conn, 200)
|
|
|
|
assert status["id"] == activity.id
|
|
|
|
end
|
|
|
|
end
|
2018-04-28 05:01:43 -06:00
|
|
|
|
|
|
|
test "Convert newlines to <br> in bio", %{conn: conn} do
|
2018-04-29 03:28:26 -06:00
|
|
|
user = insert(:user)
|
2018-04-28 05:01:43 -06:00
|
|
|
|
2018-06-03 11:11:22 -06:00
|
|
|
_conn =
|
2018-04-29 03:28:26 -06:00
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/account/update_profile.json", %{
|
|
|
|
"description" => "Hello,\r\nWorld! I\n am a test."
|
|
|
|
})
|
2018-04-28 05:01:43 -06:00
|
|
|
|
2018-04-29 03:28:26 -06:00
|
|
|
user = Repo.get!(User, user.id)
|
|
|
|
assert user.bio == "Hello,<br>World! I<br> am a test."
|
2018-04-28 05:01:43 -06:00
|
|
|
end
|
2018-05-11 05:32:59 -06:00
|
|
|
|
2018-05-21 15:17:34 -06:00
|
|
|
describe "POST /api/pleroma/change_password" do
|
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "without credentials", %{conn: conn} do
|
|
|
|
conn = post(conn, "/api/pleroma/change_password")
|
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/pleroma/change_password", %{
|
|
|
|
"password" => "hi",
|
|
|
|
"new_password" => "newpass",
|
|
|
|
"new_password_confirmation" => "newpass"
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials, valid password and new password and confirmation not matching", %{
|
|
|
|
conn: conn,
|
|
|
|
user: current_user
|
|
|
|
} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/pleroma/change_password", %{
|
|
|
|
"password" => "test",
|
|
|
|
"new_password" => "newpass",
|
|
|
|
"new_password_confirmation" => "notnewpass"
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"error" => "New password does not match confirmation."
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials, valid password and invalid new password", %{
|
|
|
|
conn: conn,
|
|
|
|
user: current_user
|
|
|
|
} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/pleroma/change_password", %{
|
|
|
|
"password" => "test",
|
|
|
|
"new_password" => "",
|
|
|
|
"new_password_confirmation" => ""
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{
|
|
|
|
"error" => "New password can't be blank."
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials, valid password and matching new password and confirmation", %{
|
|
|
|
conn: conn,
|
|
|
|
user: current_user
|
|
|
|
} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
|
|
|
|> post("/api/pleroma/change_password", %{
|
|
|
|
"password" => "test",
|
|
|
|
"new_password" => "newpass",
|
|
|
|
"new_password_confirmation" => "newpass"
|
|
|
|
})
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{"status" => "success"}
|
|
|
|
fetched_user = Repo.get(User, current_user.id)
|
|
|
|
assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-13 07:24:15 -06:00
|
|
|
describe "POST /api/pleroma/delete_account" do
|
2018-05-11 05:32:59 -06:00
|
|
|
setup [:valid_user]
|
|
|
|
|
|
|
|
test "without credentials", %{conn: conn} do
|
2018-05-13 07:24:15 -06:00
|
|
|
conn = post(conn, "/api/pleroma/delete_account")
|
2018-05-11 05:32:59 -06:00
|
|
|
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
2018-05-13 07:24:15 -06:00
|
|
|
|> post("/api/pleroma/delete_account", %{"password" => "hi"})
|
2018-05-11 05:32:59 -06:00
|
|
|
|
2018-05-13 07:24:15 -06:00
|
|
|
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
2018-05-11 05:32:59 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "with credentials and valid password", %{conn: conn, user: current_user} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> with_credentials(current_user.nickname, "test")
|
2018-05-13 07:24:15 -06:00
|
|
|
|> post("/api/pleroma/delete_account", %{"password" => "test"})
|
2018-05-11 05:32:59 -06:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == %{"status" => "success"}
|
2018-06-03 11:11:22 -06:00
|
|
|
# Wait a second for the started task to end
|
|
|
|
:timer.sleep(1000)
|
2018-05-11 05:32:59 -06:00
|
|
|
end
|
|
|
|
end
|
2018-06-06 17:46:55 -06:00
|
|
|
|
|
|
|
describe "GET /api/pleroma/friend_requests" do
|
|
|
|
test "it lists friend requests" do
|
2018-12-01 04:46:08 -07:00
|
|
|
user = insert(:user)
|
2018-06-06 17:46:55 -06:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
2018-11-30 09:07:37 -07:00
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2018-06-06 17:46:55 -06:00
|
|
|
|
|
|
|
user = Repo.get(User, user.id)
|
|
|
|
other_user = Repo.get(User, other_user.id)
|
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/pleroma/friend_requests")
|
|
|
|
|
|
|
|
assert [relationship] = json_response(conn, 200)
|
|
|
|
assert other_user.id == relationship["id"]
|
|
|
|
end
|
|
|
|
end
|
2018-06-06 18:04:03 -06:00
|
|
|
|
|
|
|
describe "POST /api/pleroma/friendships/approve" do
|
|
|
|
test "it approves a friend request" do
|
2018-12-01 04:46:08 -07:00
|
|
|
user = insert(:user)
|
2018-06-06 18:04:03 -06:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
2018-11-30 09:07:37 -07:00
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2018-06-06 18:04:03 -06:00
|
|
|
|
|
|
|
user = Repo.get(User, user.id)
|
|
|
|
other_user = Repo.get(User, other_user.id)
|
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/pleroma/friendships/approve", %{"user_id" => to_string(other_user.id)})
|
|
|
|
|
|
|
|
assert relationship = json_response(conn, 200)
|
|
|
|
assert other_user.id == relationship["id"]
|
|
|
|
assert relationship["follows_you"] == true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /api/pleroma/friendships/deny" do
|
|
|
|
test "it denies a friend request" do
|
2018-12-01 04:46:08 -07:00
|
|
|
user = insert(:user)
|
2018-06-06 18:04:03 -06:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
2018-11-30 09:07:37 -07:00
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2018-06-06 18:04:03 -06:00
|
|
|
|
|
|
|
user = Repo.get(User, user.id)
|
|
|
|
other_user = Repo.get(User, other_user.id)
|
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
|
|
|
|
conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> post("/api/pleroma/friendships/deny", %{"user_id" => to_string(other_user.id)})
|
|
|
|
|
|
|
|
assert relationship = json_response(conn, 200)
|
|
|
|
assert other_user.id == relationship["id"]
|
|
|
|
assert relationship["follows_you"] == false
|
|
|
|
end
|
|
|
|
end
|
2018-11-14 12:33:23 -07:00
|
|
|
|
|
|
|
describe "GET /api/pleroma/search_user" do
|
|
|
|
test "it returns users, ordered by similarity", %{conn: conn} do
|
|
|
|
user = insert(:user, %{name: "eal"})
|
|
|
|
user_two = insert(:user, %{name: "ean"})
|
|
|
|
user_three = insert(:user, %{name: "ebn"})
|
|
|
|
|
2018-11-14 12:41:12 -07:00
|
|
|
resp =
|
|
|
|
conn
|
|
|
|
|> get(twitter_api_search__path(conn, :search_user), query: "eal")
|
|
|
|
|> json_response(200)
|
2018-11-14 12:33:23 -07:00
|
|
|
|
|
|
|
assert length(resp) == 3
|
2018-11-14 12:41:12 -07:00
|
|
|
assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end)
|
2018-11-14 12:33:23 -07:00
|
|
|
end
|
|
|
|
end
|
2018-12-04 08:35:57 -07:00
|
|
|
|
2018-12-05 03:37:06 -07:00
|
|
|
describe "POST /api/media/upload" do
|
|
|
|
setup context do
|
|
|
|
Pleroma.DataCase.ensure_local_uploader(context)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it performs the upload and sets `data[actor]` with AP id of uploader user", %{
|
|
|
|
conn: conn
|
|
|
|
} do
|
2018-12-04 08:35:57 -07:00
|
|
|
user = insert(:user)
|
2018-12-05 03:37:06 -07:00
|
|
|
|
|
|
|
upload_filename = "test/fixtures/image_tmp.jpg"
|
|
|
|
File.cp!("test/fixtures/image.jpg", upload_filename)
|
|
|
|
|
|
|
|
file = %Plug.Upload{
|
|
|
|
content_type: "image/jpg",
|
|
|
|
path: Path.absname(upload_filename),
|
|
|
|
filename: "image.jpg"
|
|
|
|
}
|
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> put_req_header("content-type", "application/octet-stream")
|
|
|
|
|> post("/api/media/upload", %{
|
|
|
|
"media" => file
|
|
|
|
})
|
|
|
|
|> json_response(:ok)
|
|
|
|
|
|
|
|
assert response["media_id"]
|
|
|
|
object = Repo.get(Object, response["media_id"])
|
|
|
|
assert object
|
|
|
|
assert object.data["actor"] == User.ap_id(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /api/media/metadata/create" do
|
|
|
|
setup do
|
2018-12-04 08:35:57 -07:00
|
|
|
object = insert(:note)
|
2018-12-05 03:37:06 -07:00
|
|
|
user = User.get_by_ap_id(object.data["actor"])
|
|
|
|
%{object: object, user: user}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns :forbidden status on attempt to modify someone else's upload", %{
|
|
|
|
conn: conn,
|
|
|
|
object: object
|
|
|
|
} do
|
|
|
|
initial_description = object.data["name"]
|
|
|
|
another_user = insert(:user)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> assign(:user, another_user)
|
|
|
|
|> post("/api/media/metadata/create", %{"media_id" => object.id})
|
|
|
|
|> json_response(:forbidden)
|
|
|
|
|
|
|
|
object = Repo.get(Object, object.id)
|
|
|
|
assert object.data["name"] == initial_description
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it updates `data[name]` of referenced Object with provided value", %{
|
|
|
|
conn: conn,
|
|
|
|
object: object,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
description = "Informative description of the image. Initial value: #{object.data["name"]}}"
|
2018-12-04 08:35:57 -07:00
|
|
|
|
2018-12-04 09:45:09 -07:00
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
2018-12-05 03:37:06 -07:00
|
|
|
|> post("/api/media/metadata/create", %{
|
2018-12-04 09:45:09 -07:00
|
|
|
"media_id" => object.id,
|
|
|
|
"alt_text" => %{"text" => description}
|
|
|
|
})
|
|
|
|
|> json_response(:no_content)
|
2018-12-04 08:35:57 -07:00
|
|
|
|
2018-12-05 01:56:31 -07:00
|
|
|
object = Repo.get(Object, object.id)
|
2018-12-04 08:35:57 -07:00
|
|
|
assert object.data["name"] == description
|
|
|
|
end
|
|
|
|
end
|
2017-03-20 14:30:44 -06:00
|
|
|
end
|