diff options
Diffstat (limited to 'test/web/websub/websub_test.exs')
-rw-r--r-- | test/web/websub/websub_test.exs | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 36ea82299..5fe91d0f8 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -1,6 +1,12 @@ +defmodule Pleroma.Web.WebsubMock do + def verify(sub) do + {:ok, sub} + end +end defmodule Pleroma.Web.WebsubTest do use Pleroma.DataCase alias Pleroma.Web.Websub + alias Pleroma.Web.Websub.WebsubServerSubscription import Pleroma.Factory test "a verification of a request that is accepted" do @@ -29,7 +35,6 @@ defmodule Pleroma.Web.WebsubTest do test "a verification of a request that doesn't return 200" do sub = insert(:websub_subscription) - topic = sub.topic getter = fn (_path, _headers, _options) -> {:ok, %HTTPoison.Response{ @@ -41,4 +46,45 @@ defmodule Pleroma.Web.WebsubTest do {:error, sub} = Websub.verify(sub, getter) assert sub.state == "rejected" end + + test "an incoming subscription request" do + user = insert(:user) + + data = %{ + "hub.callback" => "http://example.org/sub", + "hub.mode" => "subscription", + "hub.topic" => Pleroma.Web.OStatus.feed_path(user), + "hub.secret" => "a random secret", + "hub.lease_seconds" => "100" + } + + + {:ok, subscription } = Websub.incoming_subscription_request(user, data) + assert subscription.topic == Pleroma.Web.OStatus.feed_path(user) + assert subscription.state == "requested" + assert subscription.secret == "a random secret" + assert subscription.callback == "http://example.org/sub" + end + + test "an incoming subscription request for an existing subscription" do + user = insert(:user) + sub = insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user)) + + data = %{ + "hub.callback" => sub.callback, + "hub.mode" => "subscription", + "hub.topic" => Pleroma.Web.OStatus.feed_path(user), + "hub.secret" => "a random secret", + "hub.lease_seconds" => "100" + } + + + {:ok, subscription } = Websub.incoming_subscription_request(user, data) + assert subscription.topic == Pleroma.Web.OStatus.feed_path(user) + assert subscription.state == sub.state + assert subscription.secret == "a random secret" + assert subscription.callback == sub.callback + assert length(Repo.all(WebsubServerSubscription)) == 1 + assert subscription.id == sub.id + end end |