diff options
| author | lain <lain@soykaf.club> | 2020-05-06 11:44:30 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-05-06 11:44:30 +0200 | 
| commit | 205313e54146c00374e3edfa951132a7229fa16d (patch) | |
| tree | db392c5ef71a2a40fb8a041635d2536b34dc454d /test/web/activity_pub | |
| parent | 9637cded21cef1e6c531dd46d5f5245c4c3ed03c (diff) | |
| parent | 07e7c80bc9e919cd92ca9dda1e21384142e5bd77 (diff) | |
| download | pleroma-205313e54146c00374e3edfa951132a7229fa16d.tar.gz pleroma-205313e54146c00374e3edfa951132a7229fa16d.zip  | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 22 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 50 | 
2 files changed, 64 insertions, 8 deletions
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index a8f1f0e26..5c8d20ac4 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -820,21 +820,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        activity: activity      } do        user = insert(:user) +      conn = assign(conn, :user, user)        object = Map.put(activity["object"], "sensitive", true)        activity = Map.put(activity, "object", object) -      result = +      response =          conn -        |> assign(:user, user)          |> put_req_header("content-type", "application/activity+json")          |> post("/users/#{user.nickname}/outbox", activity)          |> json_response(201) -      assert Activity.get_by_ap_id(result["id"]) -      assert result["object"] -      assert %Object{data: object} = Object.normalize(result["object"]) -      assert object["sensitive"] == activity["object"]["sensitive"] -      assert object["content"] == activity["object"]["content"] +      assert Activity.get_by_ap_id(response["id"]) +      assert response["object"] +      assert %Object{data: response_object} = Object.normalize(response["object"]) +      assert response_object["sensitive"] == true +      assert response_object["content"] == activity["object"]["content"] + +      representation = +        conn +        |> put_req_header("accept", "application/activity+json") +        |> get(response["id"]) +        |> json_response(200) + +      assert representation["object"]["sensitive"] == true      end      test "it rejects an incoming activity with bogus type", %{conn: conn, activity: activity} do diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index edd7dfb22..84ead93bb 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -18,9 +18,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.Federator +  import ExUnit.CaptureLog +  import Mock    import Pleroma.Factory    import Tesla.Mock -  import Mock    setup do      mock(fn env -> apply(HttpRequestMock, :request, [env]) end) @@ -2403,4 +2404,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do       u3: %{r1: r3_1.id, r2: r3_2.id},       u4: %{r1: r4_1.id}}    end + +  describe "maybe_update_follow_information/1" do +    setup do +      clear_config([:instance, :external_user_synchronization], true) + +      user = %{ +        local: false, +        ap_id: "https://gensokyo.2hu/users/raymoo", +        following_address: "https://gensokyo.2hu/users/following", +        follower_address: "https://gensokyo.2hu/users/followers", +        type: "Person" +      } + +      %{user: user} +    end + +    test "logs an error when it can't fetch the info", %{user: user} do +      assert capture_log(fn -> +               ActivityPub.maybe_update_follow_information(user) +             end) =~ "Follower/Following counter update for #{user.ap_id} failed" +    end + +    test "just returns the input if the user type is Application", %{ +      user: user +    } do +      user = +        user +        |> Map.put(:type, "Application") + +      refute capture_log(fn -> +               assert ^user = ActivityPub.maybe_update_follow_information(user) +             end) =~ "Follower/Following counter update for #{user.ap_id} failed" +    end + +    test "it just returns the input if the user has no following/follower addresses", %{ +      user: user +    } do +      user = +        user +        |> Map.put(:following_address, nil) +        |> Map.put(:follower_address, nil) + +      refute capture_log(fn -> +               assert ^user = ActivityPub.maybe_update_follow_information(user) +             end) =~ "Follower/Following counter update for #{user.ap_id} failed" +    end +  end  end  | 
