diff options
Diffstat (limited to 'test/web')
5 files changed, 72 insertions, 26 deletions
| diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 38c98f658..b988e4437 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -184,36 +184,43 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert User.invisible?(user)      end -    test "it fetches the appropriate tag-restricted posts" do -      user = insert(:user) +    test "it returns a user that accepts chat messages" do +      user_id = "http://mastodon.example.org/users/admin" +      {:ok, user} = ActivityPub.make_user_from_ap_id(user_id) -      {:ok, status_one} = CommonAPI.post(user, %{status: ". #test"}) -      {:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"}) -      {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"}) +      assert user.accepts_chat_messages +    end +  end -      fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"}) +  test "it fetches the appropriate tag-restricted posts" do +    user = insert(:user) -      fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]}) +    {:ok, status_one} = CommonAPI.post(user, %{status: ". #test"}) +    {:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"}) +    {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"}) -      fetch_three = -        ActivityPub.fetch_activities([], %{ -          type: "Create", -          tag: ["test", "essais"], -          tag_reject: ["reject"] -        }) +    fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"}) -      fetch_four = -        ActivityPub.fetch_activities([], %{ -          type: "Create", -          tag: ["test"], -          tag_all: ["test", "reject"] -        }) +    fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]}) -      assert fetch_one == [status_one, status_three] -      assert fetch_two == [status_one, status_two, status_three] -      assert fetch_three == [status_one, status_two] -      assert fetch_four == [status_three] -    end +    fetch_three = +      ActivityPub.fetch_activities([], %{ +        type: "Create", +        tag: ["test", "essais"], +        tag_reject: ["reject"] +      }) + +    fetch_four = +      ActivityPub.fetch_activities([], %{ +        type: "Create", +        tag: ["test"], +        tag_all: ["test", "reject"] +      }) + +    assert fetch_one == [status_one, status_three] +    assert fetch_two == [status_one, status_two, status_three] +    assert fetch_three == [status_one, status_two] +    assert fetch_four == [status_three]    end    describe "insertion" do diff --git a/test/web/activity_pub/object_validators/chat_validation_test.exs b/test/web/activity_pub/object_validators/chat_validation_test.exs index ec1e497fa..50bf03515 100644 --- a/test/web/activity_pub/object_validators/chat_validation_test.exs +++ b/test/web/activity_pub/object_validators/chat_validation_test.exs @@ -161,6 +161,17 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do        refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, []))      end +    test "does not validate if the recipient is not accepting chat messages", %{ +      valid_chat_message: valid_chat_message, +      recipient: recipient +    } do +      recipient +      |> Ecto.Changeset.change(%{accepts_chat_messages: false}) +      |> Pleroma.Repo.update!() + +      refute match?({:ok, _object, _meta}, ObjectValidator.validate(valid_chat_message, [])) +    end +      test "does not validate if the actor or the recipient is not in our system", %{        valid_chat_message: valid_chat_message      } do diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index bec15a996..98c7c9d09 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -158,4 +158,23 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do        assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})      end    end + +  describe "acceptsChatMessages" do +    test "it returns this value if it is set" do +      true_user = insert(:user, accepts_chat_messages: true) +      false_user = insert(:user, accepts_chat_messages: false) +      nil_user = insert(:user, accepts_chat_messages: nil) + +      assert %{"capabilities" => %{"acceptsChatMessages" => true}} = +               UserView.render("user.json", user: true_user) + +      assert %{"capabilities" => %{"acceptsChatMessages" => false}} = +               UserView.render("user.json", user: false_user) + +      refute Map.has_key?( +               UserView.render("user.json", user: nil_user)["capabilities"], +               "acceptsChatMessages" +             ) +    end +  end  end diff --git a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs index b55bb76a7..638626b45 100644 --- a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs +++ b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs @@ -108,6 +108,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do        assert user_data["locked"] == true      end +    test "updates the user's chat acceptance status", %{conn: conn} do +      conn = patch(conn, "/api/v1/accounts/update_credentials", %{accepts_chat_messages: "false"}) + +      assert user_data = json_response_and_validate_schema(conn, 200) +      assert user_data["pleroma"]["accepts_chat_messages"] == false +    end +      test "updates the user's allow_following_move", %{user: user, conn: conn} do        assert user.allow_following_move == true diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index f5bfc9c67..17f035add 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -90,7 +90,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_followers_count: false,          hide_follows_count: false,          relationship: %{}, -        skip_thread_containment: false +        skip_thread_containment: false, +        accepts_chat_messages: nil        }      } @@ -186,7 +187,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_followers_count: false,          hide_follows_count: false,          relationship: %{}, -        skip_thread_containment: false +        skip_thread_containment: false, +        accepts_chat_messages: nil        }      } | 
