X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_controller_test.exs;h=6866a362f3bd0f4e85fad1c5499cdd4e5683b4b1;hb=1555c66650967c5023b2a4f7a44a683d803091c6;hp=c2ea41aa3bb7f3ff905e891031a3b4897410bae1;hpb=c2dcd767cf4abaa88da946e12ca643840b65e184;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 c2ea41aa3..6866a362f 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -260,7 +260,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do test "with credentials", %{conn: conn, user: current_user} do other_user = insert(:user) - {:ok, activity} = + {:ok, _activity} = ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) conn = @@ -510,6 +510,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert json_response(conn, 200) end + + 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 end describe "POST /api/favorites/destroy/:id" do @@ -562,6 +580,40 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/statuses/unretweet/:id" do + setup [:valid_user] + + test "without valid credentials", %{conn: conn} do + note_activity = insert(:note_activity) + conn = post(conn, "/api/statuses/retweet/#{note_activity.id}.json") + 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 + describe "POST /api/account/register" do test "it creates a new user", %{conn: conn} do data = %{ @@ -668,6 +720,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do conn = conn + |> assign(:user, user) |> get("/api/statuses/friends", %{"user_id" => user.id}) assert MapSet.equal?( @@ -689,6 +742,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do conn = conn + |> assign(:user, user) |> get("/api/statuses/friends", %{"screen_name" => user.nickname}) assert MapSet.equal?( @@ -791,7 +845,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do test "Convert newlines to
in bio", %{conn: conn} do user = insert(:user) - conn = + _conn = conn |> assign(:user, user) |> post("/api/account/update_profile.json", %{ @@ -902,6 +956,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> post("/api/pleroma/delete_account", %{"password" => "test"}) assert json_response(conn, 200) == %{"status" => "success"} + # Wait a second for the started task to end + :timer.sleep(1000) end end end