diff options
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/factory.ex | 21 | ||||
| -rw-r--r-- | test/support/http_request_mock.ex | 34 | 
2 files changed, 48 insertions, 7 deletions
| diff --git a/test/support/factory.ex b/test/support/factory.ex index 1787c1088..62d1de717 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -1,5 +1,5 @@  # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.Factory do @@ -143,6 +143,25 @@ defmodule Pleroma.Factory do      |> Map.merge(attrs)    end +  defp expiration_offset_by_minutes(attrs, minutes) do +    scheduled_at = +      NaiveDateTime.utc_now() +      |> NaiveDateTime.add(:timer.minutes(minutes), :millisecond) +      |> NaiveDateTime.truncate(:second) + +    %Pleroma.ActivityExpiration{} +    |> Map.merge(attrs) +    |> Map.put(:scheduled_at, scheduled_at) +  end + +  def expiration_in_the_past_factory(attrs \\ %{}) do +    expiration_offset_by_minutes(attrs, -60) +  end + +  def expiration_in_the_future_factory(attrs \\ %{}) do +    expiration_offset_by_minutes(attrs, 61) +  end +    def article_activity_factory do      article = insert(:article) diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 3adb5ba3b..55b141dd8 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -17,9 +17,12 @@ defmodule HttpRequestMock do      with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do        res      else -      {_, _r} = error -> -        # Logger.warn(r) -        error +      error -> +        with {:error, message} <- error do +          Logger.warn(message) +        end + +        {_, _r} = error      end    end @@ -968,9 +971,25 @@ defmodule HttpRequestMock do       }}    end +  def get("http://example.com/rel_me/anchor", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}} +  end + +  def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}} +  end + +  def get("http://example.com/rel_me/link", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}} +  end + +  def get("http://example.com/rel_me/null", _, _, _) do +    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}} +  end +    def get(url, query, body, headers) do      {:error, -     "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{ +     "Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{         inspect(headers)       }"}    end @@ -1032,7 +1051,10 @@ defmodule HttpRequestMock do       }}    end -  def post(url, _query, _body, _headers) do -    {:error, "Not implemented the mock response for post #{inspect(url)}"} +  def post(url, query, body, headers) do +    {:error, +     "Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{ +       inspect(headers) +     }"}    end  end | 
