X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_controller_test.exs;h=02aba0bc8859ba105ce73d919275667f6b69955a;hb=06c97f211fc4a8c9c9c7e77143c3398ade817ab4;hp=2cbcfd08611017281bfcd1f0e5e8bed0c7819a4d;hpb=1b57522bba4bbe2843b7c68d37e0530387e5b8f3;p=akkoma
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 2cbcfd086..02aba0bc8 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -2,9 +2,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
- alias Pleroma.{Repo, Activity, User, Object}
+ alias Pleroma.{Repo, Activity, User, Object, Notification}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.TwitterAPI.TwitterAPI
@@ -160,15 +161,13 @@ 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, _activity} = ActivityBuilder.insert(%{"type" => "Create", "context" => "2hu"})
+ {: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")
+ |> get("/api/statusnet/conversation/#{activity.data["context_id"]}.json")
response = json_response(conn, 200)
@@ -249,6 +248,37 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ 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
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+
+ 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 ==
+ NotificationView.render("notification.json", %{
+ notifications: Notification.for_user(current_user),
+ for: current_user
+ })
+ end
+ end
+
describe "GET /statuses/user_timeline.json" do
setup [:valid_user]
@@ -756,4 +786,45 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert status["id"] == activity.id
end
end
+
+ test "Convert newlines to
in bio", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "description" => "Hello,\r\nWorld! I\n am a test."
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.bio == "Hello,
World! I
am a test."
+ end
+
+ describe "POST /api/pleroma/delete_account" do
+ setup [:valid_user]
+
+ test "without credentials", %{conn: conn} do
+ conn = post(conn, "/api/pleroma/delete_account")
+ 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/delete_account", %{"password" => "hi"})
+
+ assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ end
+
+ test "with credentials and valid password", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/delete_account", %{"password" => "test"})
+
+ assert json_response(conn, 200) == %{"status" => "success"}
+ end
+ end
end