diff options
Diffstat (limited to 'test/web/twitter_api')
| -rw-r--r-- | test/web/twitter_api/twitter_api_controller_test.exs | 79 | ||||
| -rw-r--r-- | test/web/twitter_api/twitter_api_test.exs | 4 | ||||
| -rw-r--r-- | test/web/twitter_api/views/notification_view_test.exs | 2 | ||||
| -rw-r--r-- | test/web/twitter_api/views/user_view_test.exs | 2 | 
4 files changed, 82 insertions, 5 deletions
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 02aba0bc8..c2ea41aa3 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do    alias Pleroma.Web.TwitterAPI.NotificationView    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.TwitterAPI.TwitterAPI +  alias Comeonin.Pbkdf2    import Pleroma.Factory @@ -443,7 +444,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do      test "with credentials", %{conn: conn, user: current_user} do        blocked = insert(:user) -      {:ok, current_user} = User.block(current_user, blocked) +      {:ok, current_user, blocked} = TwitterAPI.block(current_user, %{"user_id" => blocked.id})        assert User.blocks?(current_user, blocked)        conn = @@ -801,6 +802,82 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do      assert user.bio == "Hello,<br>World! I<br> am a test."    end +  describe "POST /api/pleroma/change_password" do +    setup [:valid_user] + +    test "without credentials", %{conn: conn} do +      conn = post(conn, "/api/pleroma/change_password") +      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/change_password", %{ +          "password" => "hi", +          "new_password" => "newpass", +          "new_password_confirmation" => "newpass" +        }) + +      assert json_response(conn, 200) == %{"error" => "Invalid password."} +    end + +    test "with credentials, valid password and new password and confirmation not matching", %{ +      conn: conn, +      user: current_user +    } do +      conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> post("/api/pleroma/change_password", %{ +          "password" => "test", +          "new_password" => "newpass", +          "new_password_confirmation" => "notnewpass" +        }) + +      assert json_response(conn, 200) == %{ +               "error" => "New password does not match confirmation." +             } +    end + +    test "with credentials, valid password and invalid new password", %{ +      conn: conn, +      user: current_user +    } do +      conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> post("/api/pleroma/change_password", %{ +          "password" => "test", +          "new_password" => "", +          "new_password_confirmation" => "" +        }) + +      assert json_response(conn, 200) == %{ +               "error" => "New password can't be blank." +             } +    end + +    test "with credentials, valid password and matching new password and confirmation", %{ +      conn: conn, +      user: current_user +    } do +      conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> post("/api/pleroma/change_password", %{ +          "password" => "test", +          "new_password" => "newpass", +          "new_password_confirmation" => "newpass" +        }) + +      assert json_response(conn, 200) == %{"status" => "success"} +      fetched_user = Repo.get(User, current_user.id) +      assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true +    end +  end +    describe "POST /api/pleroma/delete_account" do      setup [:valid_user] diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index af565c0e5..4716abb84 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -166,7 +166,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    test "Unblock another user using user_id" do      unblocked = insert(:user)      user = insert(:user) -    User.block(user, unblocked) +    {:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})      {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})      assert user.info["blocks"] == [] @@ -175,7 +175,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    test "Unblock another user using screen_name" do      unblocked = insert(:user)      user = insert(:user) -    User.block(user, unblocked) +    {:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})      {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})      assert user.info["blocks"] == [] diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index e3b140657..79eafda7d 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -24,7 +24,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do      {:ok, follower} = User.follow(follower, user)      {:ok, activity} = ActivityPub.follow(follower, user) -    Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) +    Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))      [follow_notif] = Notification.for_user(user)      represented = %{ diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index dd55c0b7e..9f8bf4cdc 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -31,7 +31,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do      User.follow(second_follower, user)      User.follow(user, follower)      {:ok, user} = User.update_follower_count(user) -    Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) +    Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))      image = "http://localhost:4001/images/avi.png"      banner = "http://localhost:4001/images/banner.png"  | 
