config :pleroma, :websub, Pleroma.Web.WebsubMock
config :pleroma, :ostatus, Pleroma.Web.OStatusMock
-config :pleroma, :httpoison, HTTPoisonMock
config :tesla, adapter: Tesla.Mock
try do
defmodule Pleroma.HTTP.Connection do
@hackney_options [pool: :default]
+ @adapter Application.get_env(:tesla, :adapter)
@doc """
Configure a client connection
"""
@spec new(Keyword.t()) :: Tesla.Env.client()
def new(opts \\ []) do
- Tesla.client([], {Tesla.Adapter.Hackney, hackney_options(opts)})
+ Tesla.client([], {@adapter, hackney_options(opts)})
end
# fetch Hackney options
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
import Pleroma.Factory
alias Pleroma.Web.Router.Helpers
+ import Tesla.Mock
+
+ setup do
+ mock fn
+ %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}
+ %{method: :post, url: "http://example.org/needs_refresh"} ->
+ %Tesla.Env{status: 200, body: ""}
+ end
+
+ :ok
+ end
test "a verification of a request that is accepted" do
sub = insert(:websub_subscription)
assert String.to_integer(seconds) > 0
{:ok,
- %HTTPoison.Response{
- status_code: 200,
+ %Tesla.Env{
+ status: 200,
body: challenge
}}
end
getter = fn _path, _headers, _options ->
{:ok,
- %HTTPoison.Response{
- status_code: 500,
+ %Tesla.Env{
+ status: 500,
body: ""
}}
end
test "discovers the hub and canonical url" do
topic = "https://mastodon.social/users/lambadalambda.atom"
- getter = fn ^topic ->
- doc = File.read!("test/fixtures/lambadalambda.atom")
- {:ok, %{status_code: 200, body: doc}}
- end
-
- {:ok, discovered} = Websub.gather_feed_data(topic, getter)
+ {:ok, discovered} = Websub.gather_feed_data(topic)
expected = %{
"hub" => "https://mastodon.social/api/push",
websub.id
)
- {:ok, %{status_code: 202}}
+ {:ok, %{status: 202}}
end
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, 2 * day),
topic: "http://example.org/still_good",
+ hub: "http://example.org/still_good",
state: "accepted"
})
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, day - 100),
topic: "http://example.org/needs_refresh",
+ hub: "http://example.org/needs_refresh",
state: "accepted"
})