import Pleroma.Factory
- describe "POST /api/account/verify_credentials" do
- setup [:valid_user]
+ describe "POST /api/account/update_profile_banner" do
+ test "it updates the banner", %{conn: conn} do
+ user = insert(:user)
- test "without valid credentials", %{conn: conn} do
- conn = post(conn, "/api/account/verify_credentials.json")
- assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
- end
+ new_banner =
+ "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
- test "with credentials", %{conn: conn, user: user} do
- conn =
+ response =
conn
- |> with_credentials(user.nickname, "test")
- |> post("/api/account/verify_credentials.json")
+ |> assign(:user, user)
+ |> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => new_banner})
+ |> json_response(200)
+ end
+ end
- assert response = json_response(conn, 200)
- assert response == UserView.render("show.json", %{user: user, token: response["token"]})
+ describe "POST /api/qvitter/update_background_image" do
+ test "it updates the background", %{conn: conn} do
+ user = insert(:user)
+
+ new_bg =
+ "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => new_bg})
+ |> json_response(200)
end
end
- describe "POST /api/account/most_recent_notification" do
+ describe "POST /api/account/verify_credentials" 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/verify_credentials.json")
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
end
conn =
conn
|> with_credentials(user.nickname, "test")
- |> post("/api/account/most_recent_notification.json", %{id: "200"})
+ |> post("/api/account/verify_credentials.json")
- assert json_response(conn, 200)
- user = User.get_by_nickname(user.nickname)
- assert user.info["most_recent_notification"] == 200
+ assert response = json_response(conn, 200)
+ assert response == UserView.render("show.json", %{user: user, token: response["token"]})
end
end
describe "GET /statuses/public_timeline.json" do
test "returns statuses", %{conn: conn} do
- {:ok, user} = UserBuilder.insert()
+ user = insert(:user)
activities = ActivityBuilder.insert_list(30, %{}, %{user: user})
ActivityBuilder.insert_list(10, %{}, %{user: user})
since_id = List.last(activities).id
end
end
+ 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"
+ })
+
+ {:ok, direct_two} =
+ CommonAPI.post(user_two, %{
+ "status" => "Hi @#{user_one.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {: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")
+
+ [status, status_two] = json_response(res_conn, 200)
+ assert status["id"] == direct_two.id
+ assert status_two["id"] == direct.id
+ end
+ end
+
describe "GET /statuses/mentions.json" do
setup [:valid_user]
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
current_user = Repo.get(User, current_user.id)
- assert current_user.info["blocks"] == []
+ assert current_user.info.blocks == []
assert json_response(conn, 200) ==
UserView.render("show.json", %{user: blocked, for: current_user})
result = json_response(conn, 200)
assert Enum.sort(expected) == Enum.sort(result)
end
+
+ 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)
+
+ {: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 [] == json_response(conn, 200)
+ end
+
+ 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)
+ not_follower = insert(:user)
+
+ {: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", %{"user_id" => user.id})
+
+ refute [] == json_response(conn, 200)
+ end
end
describe "GET /api/statuses/friends" do
)
end
+ 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
+
+ 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)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_one)
+ {:ok, user} = User.follow(user, followed_two)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends", %{"user_id" => user.id})
+
+ refute [] == json_response(conn, 200)
+ end
+
test "it returns a given user's friends with screen_name", %{conn: conn} do
user = insert(:user)
followed_one = insert(:user)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
+ 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
+
test "it locks an account", %{conn: conn} do
user = insert(:user)
})
user = Repo.get!(User, user.id)
- assert user.info["locked"] == true
+ assert user.info.locked == true
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
})
user = Repo.get!(User, user.id)
- assert user.info["locked"] == false
+ assert user.info.locked == false
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
describe "GET /api/pleroma/friend_requests" do
test "it lists friend requests" do
- user = insert(:user, %{info: %{"locked" => true}})
+ user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = ActivityPub.follow(other_user, user)
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
other_user = Repo.get(User, other_user.id)
describe "POST /api/pleroma/friendships/approve" do
test "it approves a friend request" do
- user = insert(:user, %{info: %{"locked" => true}})
+ user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = ActivityPub.follow(other_user, user)
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
other_user = Repo.get(User, other_user.id)
describe "POST /api/pleroma/friendships/deny" do
test "it denies a friend request" do
- user = insert(:user, %{info: %{"locked" => true}})
+ user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = ActivityPub.follow(other_user, user)
+ {:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
other_user = Repo.get(User, other_user.id)
assert relationship["follows_you"] == false
end
end
+
+ 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"})
+
+ resp =
+ conn
+ |> get(twitter_api_search__path(conn, :search_user), query: "eal")
+ |> json_response(200)
+
+ assert length(resp) == 3
+ assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end)
+ end
+ end
end