diff options
| author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-09-11 17:19:58 +0300 | 
|---|---|---|
| committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-09-11 17:19:58 +0300 | 
| commit | 0bda85857e8f320ee7b91d8203fd621e1e2d5180 (patch) | |
| tree | c77346be760cff6c3f50eceee778ef43a4bd252a /test/web/mastodon_api | |
| parent | 4d18a50f3c4b6654339a6a8df71160e23b45cac0 (diff) | |
| parent | 9fb88c814ddadd9138ef29550a856938491a1ca4 (diff) | |
| download | pleroma-0bda85857e8f320ee7b91d8203fd621e1e2d5180.tar.gz pleroma-0bda85857e8f320ee7b91d8203fd621e1e2d5180.zip  | |
Merge remote-tracking branch 'remotes/origin/develop' into media-preview-proxy
# Conflicts:
#	lib/pleroma/instances/instance.ex
Diffstat (limited to 'test/web/mastodon_api')
| -rw-r--r-- | test/web/mastodon_api/controllers/search_controller_test.exs | 12 | ||||
| -rw-r--r-- | test/web/mastodon_api/controllers/status_controller_test.exs | 101 | 
2 files changed, 76 insertions, 37 deletions
diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 24d1959f8..04dc6f445 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -282,18 +282,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        capture_log(fn ->          {:ok, %{id: activity_id}} =            CommonAPI.post(insert(:user), %{ -            status: "check out https://shitposter.club/notice/2827873" +            status: "check out http://mastodon.example.org/@admin/99541947525187367"            })          results =            conn -          |> get("/api/v1/search?q=https://shitposter.club/notice/2827873") +          |> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")            |> json_response_and_validate_schema(200) -        [status, %{"id" => ^activity_id}] = results["statuses"] - -        assert status["uri"] == -                 "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" +        assert [ +                 %{"url" => "http://mastodon.example.org/@admin/99541947525187367"}, +                 %{"id" => ^activity_id} +               ] = results["statuses"]        end)      end diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index f221884e7..633a25e50 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -4,9 +4,9 @@  defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    use Pleroma.Web.ConnCase +  use Oban.Testing, repo: Pleroma.Repo    alias Pleroma.Activity -  alias Pleroma.ActivityExpiration    alias Pleroma.Config    alias Pleroma.Conversation.Participation    alias Pleroma.Object @@ -29,8 +29,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      setup do: oauth_access(["write:statuses"])      test "posting a status does not increment reblog_count when relaying", %{conn: conn} do -      Pleroma.Config.put([:instance, :federating], true) -      Pleroma.Config.get([:instance, :allow_relay], true) +      Config.put([:instance, :federating], true) +      Config.get([:instance, :allow_relay], true)        response =          conn @@ -103,7 +103,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do        # An activity that will expire:        # 2 hours -      expires_in = 120 * 60 +      expires_in = 2 * 60 * 60 + +      expires_at = DateTime.add(DateTime.utc_now(), expires_in)        conn_four =          conn @@ -113,29 +115,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do            "expires_in" => expires_in          }) -      assert fourth_response = -               %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200) - -      assert activity = Activity.get_by_id(fourth_id) -      assert expiration = ActivityExpiration.get_by_activity_id(fourth_id) - -      estimated_expires_at = -        NaiveDateTime.utc_now() -        |> NaiveDateTime.add(expires_in) -        |> NaiveDateTime.truncate(:second) +      assert %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200) -      # This assert will fail if the test takes longer than a minute. I sure hope it never does: -      assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60 +      assert Activity.get_by_id(fourth_id) -      assert fourth_response["pleroma"]["expires_at"] == -               NaiveDateTime.to_iso8601(expiration.scheduled_at) +      assert_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: fourth_id}, +        scheduled_at: expires_at +      )      end      test "it fails to create a status if `expires_in` is less or equal than an hour", %{        conn: conn      } do -      # 1 hour -      expires_in = 60 * 60 +      # 1 minute +      expires_in = 1 * 60        assert %{"error" => "Expiry date is too soon"} =                 conn @@ -146,8 +141,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 })                 |> json_response_and_validate_schema(422) -      # 30 minutes -      expires_in = 30 * 60 +      # 5 minutes +      expires_in = 5 * 60        assert %{"error" => "Expiry date is too soon"} =                 conn @@ -160,8 +155,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      end      test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do -      Pleroma.Config.put([:mrf_keyword, :reject], ["GNO"]) -      Pleroma.Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy]) +      Config.put([:mrf_keyword, :reject], ["GNO"]) +      Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])        assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =                 conn @@ -1146,6 +1141,52 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 |> post("/api/v1/statuses/#{activity_two.id}/pin")                 |> json_response_and_validate_schema(400)      end + +    test "on pin removes deletion job, on unpin reschedule deletion" do +      %{conn: conn} = oauth_access(["write:accounts", "write:statuses"]) +      expires_in = 2 * 60 * 60 + +      expires_at = DateTime.add(DateTime.utc_now(), expires_in) + +      assert %{"id" => id} = +               conn +               |> put_req_header("content-type", "application/json") +               |> post("api/v1/statuses", %{ +                 "status" => "oolong", +                 "expires_in" => expires_in +               }) +               |> json_response_and_validate_schema(200) + +      assert_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: id}, +        scheduled_at: expires_at +      ) + +      assert %{"id" => ^id, "pinned" => true} = +               conn +               |> put_req_header("content-type", "application/json") +               |> post("/api/v1/statuses/#{id}/pin") +               |> json_response_and_validate_schema(200) + +      refute_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: id}, +        scheduled_at: expires_at +      ) + +      assert %{"id" => ^id, "pinned" => false} = +               conn +               |> put_req_header("content-type", "application/json") +               |> post("/api/v1/statuses/#{id}/unpin") +               |> json_response_and_validate_schema(200) + +      assert_enqueued( +        worker: Pleroma.Workers.PurgeExpiredActivity, +        args: %{activity_id: id}, +        scheduled_at: expires_at +      ) +    end    end    describe "cards" do @@ -1681,19 +1722,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    test "expires_at is nil for another user" do      %{conn: conn, user: user} = oauth_access(["read:statuses"]) +    expires_at = DateTime.add(DateTime.utc_now(), 1_000_000)      {:ok, activity} = CommonAPI.post(user, %{status: "foobar", expires_in: 1_000_000}) -    expires_at = -      activity.id -      |> ActivityExpiration.get_by_activity_id() -      |> Map.get(:scheduled_at) -      |> NaiveDateTime.to_iso8601() - -    assert %{"pleroma" => %{"expires_at" => ^expires_at}} = +    assert %{"pleroma" => %{"expires_at" => a_expires_at}} =               conn               |> get("/api/v1/statuses/#{activity.id}")               |> json_response_and_validate_schema(:ok) +    {:ok, a_expires_at, 0} = DateTime.from_iso8601(a_expires_at) +    assert DateTime.diff(expires_at, a_expires_at) == 0 +      %{conn: conn} = oauth_access(["read:statuses"])      assert %{"pleroma" => %{"expires_at" => nil}} =  | 
