+
+ test "account lookup", %{conn: conn} do
+ %{nickname: acct} = insert(:user, %{nickname: "nickname"})
+ %{nickname: acct_two} = insert(:user, %{nickname: "nickname@notlocaldoma.in"})
+
+ result =
+ conn
+ |> get("/api/v1/accounts/lookup?acct=#{acct}")
+ |> json_response_and_validate_schema(200)
+
+ assert %{"acct" => ^acct} = result
+
+ result =
+ conn
+ |> get("/api/v1/accounts/lookup?acct=#{acct_two}")
+ |> json_response_and_validate_schema(200)
+
+ assert %{"acct" => ^acct_two} = result
+
+ _result =
+ conn
+ |> get("/api/v1/accounts/lookup?acct=unexisting_nickname")
+ |> json_response_and_validate_schema(404)
+ end
+
+ test "account lookup with restrict unauthenticated profiles for local" do
+ clear_config([:restrict_unauthenticated, :profiles, :local], true)
+
+ user = insert(:user, local: true)
+ reading_user = insert(:user)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/lookup?acct=#{user.nickname}")
+
+ assert json_response_and_validate_schema(conn, 401)
+
+ conn =
+ build_conn()
+ |> assign(:user, reading_user)
+ |> assign(:token, insert(:oauth_token, user: reading_user, scopes: ["read:accounts"]))
+ |> get("/api/v1/accounts/lookup?acct=#{user.nickname}")
+
+ assert %{"id" => id} = json_response_and_validate_schema(conn, 200)
+ assert id == user.id
+ end
+
+ test "account lookup with restrict unauthenticated profiles for remote" do
+ clear_config([:restrict_unauthenticated, :profiles, :remote], true)
+
+ user = insert(:user, nickname: "user@example.com", local: false)
+ reading_user = insert(:user)
+
+ conn =
+ build_conn()
+ |> get("/api/v1/accounts/lookup?acct=#{user.nickname}")
+
+ assert json_response_and_validate_schema(conn, 401)
+
+ conn =
+ build_conn()
+ |> assign(:user, reading_user)
+ |> assign(:token, insert(:oauth_token, user: reading_user, scopes: ["read:accounts"]))
+ |> get("/api/v1/accounts/lookup?acct=#{user.nickname}")
+
+ assert %{"id" => id} = json_response_and_validate_schema(conn, 200)
+ assert id == user.id
+ end
+
+ test "create a note on a user" do
+ %{conn: conn} = oauth_access(["write:accounts", "read:follows"])
+ other_user = insert(:user)
+
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/v1/accounts/#{other_user.id}/note", %{
+ "comment" => "Example note"
+ })
+
+ assert [%{"note" => "Example note"}] =
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> get("/api/v1/accounts/relationships?id=#{other_user.id}")
+ |> json_response_and_validate_schema(200)
+ end
+
+ describe "remove from followers" do
+ setup do: oauth_access(["follow"])
+
+ test "removing user from followers", %{conn: conn, user: user} do
+ %{id: other_user_id} = other_user = insert(:user)
+
+ CommonAPI.follow(other_user, user)
+
+ assert %{"id" => ^other_user_id, "followed_by" => false} =
+ conn
+ |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers")
+ |> json_response_and_validate_schema(200)
+
+ refute User.following?(other_user, user)
+ end
+
+ test "removing remote user from followers", %{conn: conn, user: user} do
+ %{id: other_user_id} = other_user = insert(:user, local: false)
+
+ CommonAPI.follow(other_user, user)
+
+ assert User.following?(other_user, user)
+
+ assert %{"id" => ^other_user_id, "followed_by" => false} =
+ conn
+ |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers")
+ |> json_response_and_validate_schema(200)
+
+ refute User.following?(other_user, user)
+ end
+
+ test "removing user from followers errors", %{user: user, conn: conn} do
+ # self remove
+ conn_res = post(conn, "/api/v1/accounts/#{user.id}/remove_from_followers")
+
+ assert %{"error" => "Can not unfollow yourself"} =
+ json_response_and_validate_schema(conn_res, 400)
+
+ # remove non existing user
+ conn_res = post(conn, "/api/v1/accounts/doesntexist/remove_from_followers")
+ assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn_res, 404)
+ end
+ end