X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_controller_test.exs;h=f8afbaee52b3d4a6995c8aeebb06bb0c6c6e76e9;hb=b403ea4d2b69cef4434ad68babdfb402d8227847;hp=0761d05669b15a50c38b6f21b812b271a8ac7efc;hpb=a9b3f99d48a430b4810662113e2118a68c49af4d;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 0761d0566..f8afbaee5 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -31,10 +31,21 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end test "with credentials", %{conn: conn, user: user} do - conn = conn - |> with_credentials(user.nickname, "test") - |> post("/api/statuses/update.json", %{ status: "Nice meme." }) + 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."} + conn = conn_with_creds |> post(request_path) + assert json_response(conn, 400) == error_response + conn = conn_with_creds |> post(request_path, %{ status: "" }) + assert json_response(conn, 400) == error_response + + 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}) end end @@ -73,12 +84,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(%{"statusnetConversationId" => 1, "context" => "2hu"}) - {:ok, _activity_two} = ActivityBuilder.insert(%{"statusnetConversationId" => 1,"context" => "2hu"}) + {:ok, _activity} = ActivityBuilder.insert(%{"context" => "2hu"}) + {:ok, _activity_two} = ActivityBuilder.insert(%{"context" => "2hu"}) {:ok, _activity_three} = ActivityBuilder.insert(%{"context" => "3hu"}) + {:ok, object} = Object.context_mapping("2hu") |> Repo.insert conn = conn - |> get("/api/statusnet/conversation/1.json") + |> get("/api/statusnet/conversation/#{object.id}.json") response = json_response(conn, 200) @@ -139,7 +151,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest 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"} + 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 @@ -233,6 +245,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do {:ok, current_user} = User.follow(current_user, followed) assert current_user.following == [User.ap_followers(followed)] + ActivityPub.follow(current_user, followed) conn = conn |> with_credentials(current_user.nickname, "test") @@ -320,11 +333,21 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do test "with credentials", %{conn: conn, user: current_user} do note_activity = insert(:note_activity) - conn = conn - |> with_credentials(current_user.nickname, "test") - |> post("/api/statuses/retweet/#{note_activity.id}.json") + request_path = "/api/statuses/retweet/#{note_activity.id}.json" - assert json_response(conn, 200) + user = Repo.get_by(User, ap_id: note_activity.data["actor"]) + response = conn + |> with_credentials(user.nickname, "test") + |> post(request_path) + assert json_response(response, 400) == %{"error" => "You cannot repeat your own notice.", + "request" => 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}) end end @@ -375,10 +398,4 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do header_content = "Basic " <> Base.encode64("#{username}:#{password}") put_req_header(conn, "authorization", header_content) end - - setup do - Supervisor.terminate_child(Pleroma.Supervisor, ConCache) - Supervisor.restart_child(Pleroma.Supervisor, ConCache) - :ok - end end