diff options
| author | Maxim Filippov <colixer@gmail.com> | 2019-10-27 16:05:32 +0300 | 
|---|---|---|
| committer | Maxim Filippov <colixer@gmail.com> | 2019-10-27 16:05:32 +0300 | 
| commit | 8eff05d4c62c4d3300fee173cad84f75a0aafb4d (patch) | |
| tree | e16009fe073edd6315d94afe539b55cfd75dcf71 /test | |
| parent | b08b1d5d91968fbe94e20897ee3529216dd50a0a (diff) | |
| download | pleroma-8eff05d4c62c4d3300fee173cad84f75a0aafb4d.tar.gz pleroma-8eff05d4c62c4d3300fee173cad84f75a0aafb4d.zip | |
Strip status data from Flag (when federating or closing/resolving report)
Diffstat (limited to 'test')
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 132 | ||||
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 5 | 
2 files changed, 98 insertions, 39 deletions
| diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index cbd81b698..ddc6493c0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -1255,45 +1255,99 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      assert 3 = length(activities)    end -  test "it can create a Flag activity" do -    reporter = insert(:user) -    target_account = insert(:user) -    {:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"}) -    context = Utils.generate_context_id() -    content = "foobar" - -    reporter_ap_id = reporter.ap_id -    target_ap_id = target_account.ap_id -    activity_ap_id = activity.data["id"] - -    activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id) - -    assert {:ok, activity} = -             ActivityPub.flag(%{ -               actor: reporter, -               context: context, -               account: target_account, -               statuses: [activity], -               content: content -             }) - -    note_obj = %{ -      "type" => "Note", -      "id" => activity_ap_id, -      "content" => content, -      "published" => activity_with_object.object.data["published"], -      "actor" => AccountView.render("show.json", %{user: target_account}) -    } - -    assert %Activity{ -             actor: ^reporter_ap_id, -             data: %{ -               "type" => "Flag", -               "content" => ^content, -               "context" => ^context, -               "object" => [^target_ap_id, ^note_obj] -             } -           } = activity +  describe "flag/1" do +    setup do +      reporter = insert(:user) +      target_account = insert(:user) +      content = "foobar" +      {:ok, activity} = CommonAPI.post(target_account, %{"status" => content}) +      context = Utils.generate_context_id() + +      reporter_ap_id = reporter.ap_id +      target_ap_id = target_account.ap_id +      activity_ap_id = activity.data["id"] + +      activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id) + +      {:ok, +       %{ +         reporter: reporter, +         context: context, +         target_account: target_account, +         reported_activity: activity, +         content: content, +         activity_ap_id: activity_ap_id, +         activity_with_object: activity_with_object, +         reporter_ap_id: reporter_ap_id, +         target_ap_id: target_ap_id +       }} +    end + +    test "it can create a Flag activity", +         %{ +           reporter: reporter, +           context: context, +           target_account: target_account, +           reported_activity: reported_activity, +           content: content, +           activity_ap_id: activity_ap_id, +           activity_with_object: activity_with_object, +           reporter_ap_id: reporter_ap_id, +           target_ap_id: target_ap_id +         } do +      assert {:ok, activity} = +               ActivityPub.flag(%{ +                 actor: reporter, +                 context: context, +                 account: target_account, +                 statuses: [reported_activity], +                 content: content +               }) + +      note_obj = %{ +        "type" => "Note", +        "id" => activity_ap_id, +        "content" => content, +        "published" => activity_with_object.object.data["published"], +        "actor" => AccountView.render("show.json", %{user: target_account}) +      } + +      assert %Activity{ +               actor: ^reporter_ap_id, +               data: %{ +                 "type" => "Flag", +                 "content" => ^content, +                 "context" => ^context, +                 "object" => [^target_ap_id, ^note_obj] +               } +             } = activity +    end + +    test_with_mock "strips status data from Flag, before federating it", +                   %{ +                     reporter: reporter, +                     context: context, +                     target_account: target_account, +                     reported_activity: reported_activity, +                     content: content +                   }, +                   Utils, +                   [:passthrough], +                   [] do +      {:ok, activity} = +        ActivityPub.flag(%{ +          actor: reporter, +          context: context, +          account: target_account, +          statuses: [reported_activity], +          content: content +        }) + +      new_data = +        put_in(activity.data, ["object"], [target_account.ap_id, reported_activity.data["id"]]) + +      assert_called(Utils.maybe_federate(%{activity | data: new_data})) +    end    end    test "fetch_activities/2 returns activities addressed to a list " do diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 709aa4dbe..d69ed38a7 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -421,6 +421,11 @@ defmodule Pleroma.Web.CommonAPITest do        {:ok, report} = CommonAPI.update_report_state(report_id, "resolved")        assert report.data["state"] == "resolved" + +      [reported_user, activity_id] = report.data["object"] + +      assert reported_user == target_user.ap_id +      assert activity_id == activity.data["id"]      end      test "does not update report state when state is unsupported" do | 
